]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
Addat inital upload
authorJiri Kubias <jiri.kubias@gmail.com>
Wed, 16 Sep 2009 12:14:00 +0000 (14:14 +0200)
committerJiri Kubias <jiri.kubias@gmail.com>
Wed, 16 Sep 2009 12:14:00 +0000 (14:14 +0200)
19 files changed:
board/lpc2364_addat/Makefile [new file with mode: 0644]
board/lpc2364_addat/Makefile.omk [new file with mode: 0644]
board/lpc2364_addat/config.addat [new file with mode: 0644]
board/lpc2364_addat/config.addat~ [new file with mode: 0644]
board/lpc2364_addat/defines/Makefile [new file with mode: 0644]
board/lpc2364_addat/defines/Makefile.omk [new file with mode: 0644]
board/lpc2364_addat/defines/system_def.h [new file with mode: 0644]
board/lpc2364_addat/libs/Makefile [new file with mode: 0644]
board/lpc2364_addat/libs/Makefile.omk [new file with mode: 0644]
board/lpc2364_addat/libs/deb_led_board.h [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/Makefile [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/Makefile.omk [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/board.ld [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/error.c [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/error.h [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/hwinit.c [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/startcfg.c [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/startcfg.h [new file with mode: 0644]
board/lpc2364_addat/libs/hwinit/test.c [new file with mode: 0644]

diff --git a/board/lpc2364_addat/Makefile b/board/lpc2364_addat/Makefile
new file mode 100644 (file)
index 0000000..76b56fd
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/board/lpc2364_addat/Makefile.omk b/board/lpc2364_addat/Makefile.omk
new file mode 100644 (file)
index 0000000..e97bb68
--- /dev/null
@@ -0,0 +1,3 @@
+# -*- makefile -*-
+
+SUBDIRS = defines 
diff --git a/board/lpc2364_addat/config.addat b/board/lpc2364_addat/config.addat
new file mode 100644 (file)
index 0000000..5842bd7
--- /dev/null
@@ -0,0 +1,56 @@
+# -*- makefile -*-
+
+ARCH=arm
+MACH=lpc23xx
+BOARD=lpc2364_addat
+
+CROSS_COMPILE = arm-elf-
+TARGET_ARCH = -mcpu=arm7tdmi 
+
+
+CFLAGS += -DARCH_$(shell echo $(ARCH) | tr a-z A-Z)
+CFLAGS += -DMACH_$(shell echo $(MACH) | tr a-z A-Z)
+
+
+
+ifndef GCC_VERSION
+  export GCC_VERSION:=$(shell $(CROSS_COMPILE)gcc -dumpversion)
+
+  ifneq ($(GCC_VERSION),3.4.3)
+  $(warning You are using a different compiler from gcc 3.4.3. This board is known not to work with some newver versions (4.3))
+  endif
+endif
+
+# Set default C flags. If theese are set elsewhere (e.g. on a command
+# line), these default flags are not used.
+DEBUG ?= -g
+OPTIMIZE ?= -O2
+
+LPC_BAUD = 38400
+LPC_TTY ?= /dev/ttyUSB0
+LPC_XTAL = 10000
+TOLPC = $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils/tolpc --baud $(LPC_BAUD) --sdev $(LPC_TTY) -q $(LPC_XTAL) -v -L -f
+LOAD_CMD-ram = $(TOLPC) 
+LOAD_CMD-flash = load() { HEX=$(LOCAL_BUILD_DIR)/$$(basename $$1).hex; $(CROSS_COMPILE)objcopy -O ihex $$1 $$HEX; $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils/lpc21isp -control $$HEX $(LPC_TTY) $(LPC_BAUD) $(LPC_XTAL); }; load
+
+
+#LOAD_CMD-ramisp = $(TOLPC) 
+LOAD_CMD-mpram = $(TOLPC) 
+LOAD_CMD-mpflash = $(LOAD_CMD-flash)
+
+# $(CROSS_COMPILE)objcopy -O ihex in out
+# lpc21isp vstup.hex $(LPC_TTY) $(LPC_BAUD) $(LPC_XTAL)
+
+# This selects linker script
+LD_SCRIPT=lpc2364
+DEFAULT_LD_SCRIPT_VARIANT=ram flash
+
+#OUTPUT_FORMATS = bin hex srec
+
+###
+CONFIG_USB_BASE=
+CONFIG_USB_PDIUSB=
+CONFIG_USB_MORE=
+CONFIG_CMDPROC_TEST=n
+
+LN_HEADERS=y
diff --git a/board/lpc2364_addat/config.addat~ b/board/lpc2364_addat/config.addat~
new file mode 100644 (file)
index 0000000..aca27d2
--- /dev/null
@@ -0,0 +1,51 @@
+# -*- makefile -*-
+
+ARCH=arm
+MACH=lpc23xx
+BOARD=lpc2364_addat
+
+CROSS_COMPILE = arm-elf-
+TARGET_ARCH = -mcpu=arm7tdmi 
+
+
+ifndef GCC_VERSION
+  export GCC_VERSION:=$(shell $(CROSS_COMPILE)gcc -dumpversion)
+
+  ifneq ($(GCC_VERSION),3.4.3)
+  $(warning You are using a different compiler from gcc 3.4.3. This board is known not to work with some newver versions (4.3))
+  endif
+endif
+
+# Set default C flags. If theese are set elsewhere (e.g. on a command
+# line), these default flags are not used.
+DEBUG ?= -g
+OPTIMIZE ?= -O2
+
+LPC_BAUD = 38400
+LPC_TTY ?= /dev/ttyUSB0
+LPC_XTAL = 10000
+TOLPC = $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils/tolpc --baud $(LPC_BAUD) --sdev $(LPC_TTY) -q $(LPC_XTAL) -v -L -f
+LOAD_CMD-ram = $(TOLPC) 
+LOAD_CMD-flash = load() { HEX=$(LOCAL_BUILD_DIR)/$$(basename $$1).hex; $(CROSS_COMPILE)objcopy -O ihex $$1 $$HEX; $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils/lpc21isp -control $$HEX $(LPC_TTY) $(LPC_BAUD) $(LPC_XTAL); }; load
+
+
+#LOAD_CMD-ramisp = $(TOLPC) 
+LOAD_CMD-mpram = $(TOLPC) 
+LOAD_CMD-mpflash = $(LOAD_CMD-flash)
+
+# $(CROSS_COMPILE)objcopy -O ihex in out
+# lpc21isp vstup.hex $(LPC_TTY) $(LPC_BAUD) $(LPC_XTAL)
+
+# This selects linker script
+LD_SCRIPT=lpc2364
+DEFAULT_LD_SCRIPT_VARIANT=ram flash
+
+#OUTPUT_FORMATS = bin hex srec
+
+###
+CONFIG_USB_BASE=
+CONFIG_USB_PDIUSB=
+CONFIG_USB_MORE=
+CONFIG_CMDPROC_TEST=n
+
+LN_HEADERS=y
diff --git a/board/lpc2364_addat/defines/Makefile b/board/lpc2364_addat/defines/Makefile
new file mode 100644 (file)
index 0000000..76b56fd
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/board/lpc2364_addat/defines/Makefile.omk b/board/lpc2364_addat/defines/Makefile.omk
new file mode 100644 (file)
index 0000000..176b8a6
--- /dev/null
@@ -0,0 +1,2 @@
+# -*- makefile -*-
+include_HEADERS = $(notdir $(wildcard $(SOURCES_DIR)/*.h))
diff --git a/board/lpc2364_addat/defines/system_def.h b/board/lpc2364_addat/defines/system_def.h
new file mode 100644 (file)
index 0000000..369a421
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************
+  system_def.h 
+
+ *******************************************************************/
+
+#ifndef _SYSTEM_DEF_H_
+#define _SYSTEM_DEF_H_
+
+#include <types.h>
+
+#define WITH_SFI_SEL
+
+#define VER_CODE(major,minor,patch) (major*0x10000+minor*0x100+patch)
+/* Software version */
+#define SW_VER_ID      "LPCEUROBOT"
+#define SW_VER_MAJOR   0
+#define SW_VER_MINOR   1
+#define SW_VER_PATCH   0
+#define SW_VER_CODE    VER_CODE(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH)
+/* Hardware version */
+#define HW_VER_ID      "LPCEUROBOT"
+#define HW_VER_MAJOR   1
+#define HW_VER_MINOR   0
+#define HW_VER_PATCH   0
+#define HW_VER_CODE    VER_CODE(HW_VER_MAJOR,HW_VER_MINOR,HW_VER_PATCH)
+/* Version of mechanical  */
+#define MECH_VER_ID    "LPCEUROBOT"
+#define MECH_VER_MAJOR  0
+#define MECH_VER_MINOR  0
+#define MECH_VER_PATCH  0
+#define MECH_VER_CODE  VER_CODE(MECH_VER_MAJOR,MECH_VER_MINOR,MECH_VER_PATCH)
+
+#define BOARD_LPCEUROBOT
+
+#define CPU_REF_HZ 10000000l    /* reference clock */
+#define CPU_SYS_HZ (4*CPU_REF_HZ)/* system clock */
+#define CPU_APB_HZ (CPU_SYS_HZ/2)/* APB clock */
+#define CPU_VPB_HZ CPU_APB_HZ   /* VPB clock = APB clock, multiple definition */
+
+unsigned long cpu_ref_hz;      /* actual external XTAL reference */
+unsigned long cpu_sys_hz;      /* actual system clock frequency  */
+
+volatile unsigned long msec_time;
+
+#define SCI_RS232_CHAN_DEFAULT 1
+
+/* #define DEB_LED_INIT() \ */
+/*     do {\ */
+/*     *DIO_PEDR=0x00;\ */
+/*     SHADOW_REG_SET(DIO_PEDDR,0x0f); /\* set PJ.1, PJ.2, PJ.3 LED output *\/ \ */
+/*     } while (0) */
+       
+/* #define DEB_LED_OFF(num) \ */
+/*     (*DIO_PEDR |= PEDR_PE0DRm << (num)) */
+/* #define DEB_LED_ON(num) \ */
+/*     (*DIO_PEDR &=~(PEDR_PE0DRm << (num))) */
+
+
+#endif /* _SYSTEM_DEF_H_ */
diff --git a/board/lpc2364_addat/libs/Makefile b/board/lpc2364_addat/libs/Makefile
new file mode 100644 (file)
index 0000000..76b56fd
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/board/lpc2364_addat/libs/Makefile.omk b/board/lpc2364_addat/libs/Makefile.omk
new file mode 100644 (file)
index 0000000..63c5be3
--- /dev/null
@@ -0,0 +1,5 @@
+# -*- makefile -*-
+
+include_HEADERS = deb_led_board.h
+
+SUBDIRS = hwinit
diff --git a/board/lpc2364_addat/libs/deb_led_board.h b/board/lpc2364_addat/libs/deb_led_board.h
new file mode 100644 (file)
index 0000000..cafb88d
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef DEB_LED_BOARD_H
+#define DEB_LED_BOARD_H
+
+#include <lpc21xx.h>
+
+#define __LED_SHIFT 21
+#define __LED_MASK 0x0f
+
+#define LEDR (1<<0)            // LED R (1<<21)
+#define LEDG (1<<1)            // LED G (1<<22)
+#define LEDB (1<<2)            // LED B (1<<23)
+#define LEDY (1<<3)            // LED Y (1<<24)
+
+#define DEB_LED_ERROR LEDR     /* Error occured */
+#define DEB_LED_RUN   LEDG     /* Should blink when running */
+
+static inline unsigned
+__deb_led_get()
+{
+       return (IOPIN0 >> __LED_SHIFT) & __LED_MASK;
+}
+
+static inline void
+__deb_led_on(unsigned leds)
+{
+       IOSET0 = (leds & __LED_MASK) << __LED_SHIFT;
+}
+
+static inline void
+__deb_led_off(unsigned leds)
+{
+       IOCLR0 = (leds & __LED_MASK) << __LED_SHIFT;
+}
+
+static inline void
+__deb_led_set(unsigned leds)
+{
+       __deb_led_on(leds);
+       __deb_led_off(~leds);
+}
+
+static inline void
+__deb_led_change(unsigned leds)
+{
+       __deb_led_set(__deb_led_get() ^ leds);
+}
+
+static inline void
+__deb_led_init()
+{
+       IO0DIR |= (__LED_MASK << __LED_SHIFT);
+       __deb_led_set(0);
+}
+
+#endif
diff --git a/board/lpc2364_addat/libs/hwinit/Makefile b/board/lpc2364_addat/libs/hwinit/Makefile
new file mode 100644 (file)
index 0000000..76b56fd
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/board/lpc2364_addat/libs/hwinit/Makefile.omk b/board/lpc2364_addat/libs/hwinit/Makefile.omk
new file mode 100644 (file)
index 0000000..73ab720
--- /dev/null
@@ -0,0 +1,13 @@
+# -*- makefile -*-
+
+lib_LIBRARIES = eurobothw
+eurobothw_SOURCES = startcfg.c  error.c
+
+include_HEADERS = error.h
+
+test_PROGRAMS = hwinit_test
+hwinit_test_SOURCES = test.c
+
+lib_obj_SOURCES = hwinit.c
+
+lib_LDSCRIPTS = board.ld
diff --git a/board/lpc2364_addat/libs/hwinit/board.ld b/board/lpc2364_addat/libs/hwinit/board.ld
new file mode 100644 (file)
index 0000000..d76cd16
--- /dev/null
@@ -0,0 +1,2 @@
+/* Board specific objects linked with applications */
+INPUT(initarray.o hwinit.o)
diff --git a/board/lpc2364_addat/libs/hwinit/error.c b/board/lpc2364_addat/libs/hwinit/error.c
new file mode 100644 (file)
index 0000000..5f3a879
--- /dev/null
@@ -0,0 +1,33 @@
+#include <deb_led.h>
+#include <error.h>
+
+static void
+waitblink(int len)
+{
+       while (len--) {
+               unsigned int i =2000000;
+               while(--i);
+       }
+}
+
+void error(enum error err)
+{
+       if (err == SUCCESS)
+               return;
+       /* For case of unintetional rewrite of IO port setting. */
+       deb_led_init();
+       while (1) {
+               int i;
+               for (i=7; i>=0; i--) {
+                       deb_led_set(~0);
+                       if (err & (1<<i))
+                               waitblink(3); /* 1 */
+                       else
+                               waitblink(1); /* 0 */
+                       deb_led_set(DEB_LED_ERROR);
+                       waitblink(1);
+                               
+               }
+               waitblink(5);           
+       }
+}
diff --git a/board/lpc2364_addat/libs/hwinit/error.h b/board/lpc2364_addat/libs/hwinit/error.h
new file mode 100644 (file)
index 0000000..87de728
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef ERROR_H
+#define ERROR_H
+
+enum error {
+       SUCCESS = 0,
+       ERANGE = 11,
+};
+
+void error(enum error err);
+
+#endif
diff --git a/board/lpc2364_addat/libs/hwinit/hwinit.c b/board/lpc2364_addat/libs/hwinit/hwinit.c
new file mode 100644 (file)
index 0000000..df6a5b5
--- /dev/null
@@ -0,0 +1,32 @@
+#include <lpc21xx.h>                            /* LPC21xx definitions */\r
+#include <deb_led.h>\r
+#include "startcfg.h"\r
+#include <stdlib.h>\r
+#include <error.h>\r
+\r
+/* Called automatically from crt0.S before main() */\r
+/* void __hardware_init(void) __attribute__ ((used)); */\r
+void __hardware_init(void)\r
+{\r
+       int err = SUCCESS;\r
+\r
+       if ((void*)&__hardware_init > (void*)0x40000000) {\r
+               /* We are running from RAM */\r
+               MEMMAP = 0x2;   /* Remap interrupt vectors */\r
+       }\r
+\r
+       deb_led_init();\r
+       \r
+       err = init_PLL(PLL_MUL_4 ,PLL_DIV_2 ,PLL_MODE_ENABLE);   //58.98MHz\r
+       if (err) error(err);\r
+                                         \r
+       err = init_MAM(MAM_FULL);   //58.98MHz\r
+       if (err) error(err);\r
+\r
+       set_APB(APB_DIV_2);\r
+       
+\r
+}\r
+\r
+/* Put a pointer to this function in .init_array section */\r
+void (*fp) (void) __attribute__ ((section (".init_array"))) = __hardware_init;\r
diff --git a/board/lpc2364_addat/libs/hwinit/startcfg.c b/board/lpc2364_addat/libs/hwinit/startcfg.c
new file mode 100644 (file)
index 0000000..7d87f25
--- /dev/null
@@ -0,0 +1,202 @@
+#include "startcfg.h"\r
+#include <errno.h>             \r
+#include <lpc21xx.h>                            /* LPC21xx definitions */\r
+\r
+\r
+// -----------------   PLL part ------------------------\r
+#define PLL_OFF                        0               // fully disable PLL\r
+#define PLL_ACTIVE             1               // activate PLL \r
+#define PLL_CONNECT            3               // connect PLL to Cclk\r
+\r
+#define PLL_FEED_1             0xAA    // PLL feed sequence 1\r
+#define PLL_FEED_2             0x55    // PLL feed sequence 3                                                  \r
+#define PLL_LOCK_MASK  0x400   // PLL lock mask\r
+\r
+\r
+\r
+#define PLL_DIV_MASK_2 (0<<5)\r
+#define PLL_DIV_MASK_4 (1<<5)\r
+#define PLL_DIV_MASK_8 (2<<5)\r
+#define PLL_DIV_MASK_16        (3<<5)\r
+\r
+// -----------------   MAM part ------------------------\r
+\r
+#define MAM_1ST_BOUND  20000\r
+#define MAM_2ND_BOUND  40000\r
+#define MAM_TIM_1      1\r
+#define MAM_TIM_2      2\r
+#define MAM_TIM_3      3\r
+\r
+\r
+//------------------  code  ----------------------------\r
+\r
+void wait(void)\r
+{\r
+       unsigned int i =2000000;\r
+       while(--i);\r
+}\r
+\r
+\r
+void deb_led(char leds)\r
+{\r
+       IO0DIR |= ((1<<21) | (1<<22) | (1<<23) | (1<<24));\r
+\r
+       if (leds & 0x1) IOSET0 |=  (1<<21);\r
+               else IOCLR0 |= (1<<21);\r
+\r
+       if (leds & 0x2) IOSET0 |=  (1<<22);\r
+               else IOCLR0 |= (1<<22);\r
+\r
+       if (leds & 0x4) IOSET0 |=  (1<<23);\r
+               else IOCLR0 |= (1<<23);\r
+\r
+       if (leds & 0x8) IOSET0 |=  (1<<24);\r
+               else IOCLR0 |= (1<<24);\r
+}\r
+\r
+\r
+\r
+\r
+\r
+// setup procesor PLL\r
+unsigned char init_PLL(char mul,char div, char mode)\r
+{\r
+       \r
+       unsigned int fcco, cclk; \r
+\r
+\r
+       PLLCON = PLL_OFF;               // disable PLL          \r
+       PLLFEED = PLL_FEED_1;   // PLL change sequence\r
+       PLLFEED = PLL_FEED_2;\r
+       \r
+       if (mode == PLL_MODE_DISABLE)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       fcco = FOSC * 2 * (mul + 1) * div ;                     // count Fcco\r
+       if (( FCCO_MIN > fcco)|(fcco >  FCCO_MAX))      // check Fcco range\r
+       {\r
+               return   ERANGE;\r
+       }\r
+\r
+       cclk = (mul + 1) * FOSC;                                                        // count cclk\r
+       if (( CCLK_MIN > cclk)|(cclk >  CCLK_MAX))      // check cclk range\r
+       {\r
+               return   ERANGE;\r
+       }\r
+\r
+       switch(div)\r
+       {\r
+               case(PLL_DIV_2):        div = PLL_DIV_MASK_2;\r
+                                                       break;\r
+\r
+               case(PLL_DIV_4):        div = PLL_DIV_MASK_4;\r
+                                                       break;\r
+\r
+               case(PLL_DIV_8):        div = PLL_DIV_MASK_8;\r
+                                                       break;\r
+\r
+               case(PLL_DIV_16):       div = PLL_DIV_MASK_16;\r
+                                                       break;\r
+\r
+               default:                        return ERANGE;\r
+       }\r
+\r
+\r
+       PLLCFG = mul | div;             // write multiplicator and dividet to PLL config\r
+       PLLCON = PLL_ACTIVE;    // enable PLL           \r
+       PLLFEED = PLL_FEED_1;   // PLL change sequence\r
+       PLLFEED = PLL_FEED_2;\r
+\r
+       while( (PLLSTAT & PLL_LOCK_MASK) == 0);         // wait for PLL LOCK\r
+\r
+       PLLCON = PLL_CONNECT;   // connect PLL to Cclk\r
+       PLLFEED = PLL_FEED_1;   // PLL change sequence\r
+       PLLFEED = PLL_FEED_2;\r
+\r
+       return 0;\r
+}\r
+\r
+\r
+// get procesor speed\r
+unsigned int get_sys_speed(void)\r
+{\r
+       if( (PLLCON & PLL_CONNECT) == PLL_CONNECT) // if PLL is connected return PLL-Cclk speed\r
+       {\r
+       return( FOSC * ((PLLCFG & 0x1F) + 1));\r
+    }\r
+\r
+       return FOSC;    // if PLL is disabled return native Fosc\r
+\r
+}\r
+\r
+\r
+// setup MAM module\r
+\r
+unsigned char init_MAM(char mode)\r
+{\r
+       unsigned int clk;\r
+\r
+       MAMCR = MAM_OFF;\r
+\r
+       #ifdef MEM_RAM    // FIXME udelat pomoci linker scriptu\r
+               return 0;\r
+       #endif\r
+\r
+\r
+       if (mode == MAM_OFF) return 0;\r
+       \r
+\r
+       clk = get_sys_speed();\r
+\r
+       if(clk > MAM_2ND_BOUND)\r
+       {\r
+               MAMTIM = MAM_TIM_3; \r
+       } \r
+       else if (clk > MAM_1ST_BOUND) \r
+       {\r
+               MAMTIM = MAM_TIM_2;\r
+       }\r
+       else MAMTIM = MAM_TIM_1;\r
+\r
+       MAMCR = mode;\r
+\r
+       return 0;\r
+}\r
+\r
+// setup APB module\r
+unsigned char set_APB(char div)\r
+{\r
+       VPBDIV = div;\r
+       return 0;\r
+}\r
+\r
+\r
+unsigned int get_apb_speed(void)\r
+{\r
+       int sysClk,div;\r
+\r
+       switch( VPBDIV & 0x03)\r
+       {\r
+               case APB_DIV_1:  div = 1;\r
+                       break;\r
+\r
+               case APB_DIV_2:  div = 2;\r
+                       break;\r
+\r
+               case APB_DIV_4:  div = 4;\r
+                       break;\r
+\r
+               default:  return ERANGE;\r
+       }\r
+\r
+\r
+       sysClk = get_sys_speed();\r
+\r
+       return (sysClk / div);\r
+\r
+\r
+}\r
+\r
+\r
diff --git a/board/lpc2364_addat/libs/hwinit/startcfg.h b/board/lpc2364_addat/libs/hwinit/startcfg.h
new file mode 100644 (file)
index 0000000..2555079
--- /dev/null
@@ -0,0 +1,102 @@
+\r
+\r
+\r
+/** Fosc is crystal oscilator / resonator\r
+ *  If is not defined, is used  14,745MHz nominal oscilator (CTU DRAGONS LPC BOARD )\r
+ */\r
+#ifndef FOSC // FIXME: rename to CPU_REF_HZ\r
+  #define FOSC 14745\r
+#endif\r
+\r
+\r
+/** If memory is in RAM, it must be defined! Otherwise is defined MEM_FLASH\r
+ *  This is important for MAM module.\r
+ */\r
+#ifndef MEM_RAM\r
+  #define MEM_FLASH    \r
+#endif\r
+\r
+\r
+/// Absolute minimum and maximum ratings\r
+#define FCCO_MIN 156000                // internal minimal clock\r
+#define FCCO_MAX 320000                // internal maximal clock\r
+#define CCLK_MIN 10000         // processor minimal clock\r
+#define CCLK_MAX 60000         // processor maximal clock\r
+\r
+\r
+/// PLL Available multiplicators \r
+#define PLL_MUL_1      0\r
+#define PLL_MUL_2      1\r
+#define PLL_MUL_3      2\r
+#define PLL_MUL_4      3\r
+#define PLL_MUL_5      4\r
+#define PLL_MUL_6      5\r
+#define PLL_MUL_7      6\r
+\r
+/// PLL Available divisors\r
+#define PLL_DIV_2      2\r
+#define PLL_DIV_4      4\r
+#define PLL_DIV_8      8\r
+#define PLL_DIV_16     16\r
+\r
+/// PLL mode\r
+#define PLL_MODE_DISABLE       1\r
+#define PLL_MODE_ENABLE                0\r
+\r
+/// MAM definitions\r
+#define MAM_OFF        0       // MAM functions disabled\r
+#define MAM_PARTIAL 1  // MAM functions partially enabled\r
+#define MAM_FULL       2       // MAM functions fully enabled\r
+\r
+\r
+/// APB divider\r
+///@{\r
+#define APB_DIV_1      1\r
+#define APB_DIV_2      2\r
+#define APB_DIV_4      0\r
+///@}\r
+\r
+\r
+\r
+\r
+\r
+void wait(void);  // in future this should be deleted\r
+\r
+\r
+\r
+/** deb_led controls system debug leds\r
+ *  @param     leds    LED value\r
+ */\r
+void deb_led(char leds);\r
+\r
+/** Enables PLL for higher Fosc values\r
+ *  @return 0 or #ERANGE\r
+ *  @param     mul             PLL multiplicator\r
+ *  @param     div             PLL divider\r
+ *  @param     disable disables PLL\r
+ */\r
+unsigned char init_PLL(char mul,char div, char mode);\r
+\r
+/** get_sys_speed returns actual speed of Cclk (proc. frequency) in kHz\r
+ */\r
+unsigned int get_sys_speed(void);\r
+\r
+\r
+/** Setup MAM module\r
+ *  @return 0 or ERANGE\r
+ *  @param     mode    MAM mode\r
+ */\r
+unsigned char init_MAM(char mode);\r
+\r
+/** Sets APB divisor\r
+ *  @return 0 \r
+ *  @note VPB = APB   - name conflict FIXME\r
+ *  @param     div     divisor of APB\r
+ */\r
+unsigned char set_APB(char div);\r
+\r
+/** Returns actual speed of APB (peripheral frequency) in kHz\r
+ *  @note VPB = APB   - name conflict FIXME\r
+ */\r
+unsigned int get_apb_speed(void);\r
+\r
diff --git a/board/lpc2364_addat/libs/hwinit/test.c b/board/lpc2364_addat/libs/hwinit/test.c
new file mode 100644 (file)
index 0000000..85e6062
--- /dev/null
@@ -0,0 +1,22 @@
+#include <lpc21xx.h>                            /* LPC21xx definitions */
+#include <errno.h>
+#include "startcfg.h"
+#include <deb_led.h>
+
+extern unsigned int adc_val[4];
+
+#define LEDS 4
+
+int main (void)
+{
+       unsigned leds[] = {LEDR, LEDG, LEDB, LEDY};
+       int i=0;
+       while(1)
+       {
+               deb_led_set(leds[i]);
+               if (++i == LEDS) i=0;
+               wait();
+       
+       }
+       return 0;
+}