diff --git a/platforms/lpc17xx/Makefile b/platforms/lpc17xx/Makefile index 172df5a..8975de9 100644 --- a/platforms/lpc17xx/Makefile +++ b/platforms/lpc17xx/Makefile @@ -8,8 +8,6 @@ ifeq ($(TEST_NAME),) TEST_NAME = kern1 endif - - CC = arm-none-eabi-gcc LN = arm-none-eabi-gcc AS = arm-none-eabi-gcc @@ -18,7 +16,7 @@ CFLAGS := $(CFLAGS) -O3 -Os -g3 -Wall -c -mcpu=cortex-m3 -mthumb AFLAGS := $(AFLAGS) -O3 -Os -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb LFLAGS := $(LFLAGS) -O3 -Os -Wall -mcpu=cortex-m3 -mthumb -Wl,-Map=system.map -Tsystem.ld -CDEFS := $(CDEFS) -DATOMTHREADS_TEST='"$(TEST_NAME)"' +CDEFS := $(CDEFS) -DATOMTHREADS_TEST='"$(TEST_NAME)"' -DBOARD_MBED_LP1768 ADEFS := $(ADEFS) -D__thumb2__ -DARM_RDI_MONITOR LLIBS := $(LLIBS) @@ -39,7 +37,8 @@ ASMS := $(ASMS) \ INCLUDES := $(INCLUDES) \ - -I./CMSISv2p00_LPC17xx/inc \ + -I$(ATOMTHREADS)/platforms/lpc17xx/CMSISv2p00_LPC17xx/inc \ + -I$(ATOMTHREADS)/platforms/lpc17xx \ -I$(ATOMTHREADS) include $(ATOMTHREADS)/ports/cortex_m/Makefile diff --git a/platforms/lpc17xx/README b/platforms/lpc17xx/README index d8055a3..8f69ee8 100644 --- a/platforms/lpc17xx/README +++ b/platforms/lpc17xx/README @@ -11,7 +11,14 @@ NXP LPC17xx Platform The "lpc17xx" platform contains sources for building the Atomthreads test suite for the NXP LPC17xx microcontroller. -The build was tested on the "mbed NXP LPC1768" board (http://www.mbed.org) -and the sources were compiled on Ubuntu 12.0.4 with the GNU ARM tool chain -using Newlib. +The build was tested on the "mbed NXP LPC1768" board (http://www.mbed.org) +but it should work on any LPC17xx development board where UART0 can be used +to monitor the output of the test. + +The NXP LPC17xx microcontrollers use the ARM Cortex M3 processor core. The +source code in this example uses the ARM CMSIS Cortex-M Access Library V2.01 +to initialize the platform and Newlib as the runtime library. Also it uses a +driver provided by NXP for the UART. The CMSIS library and the UART driver +are provided as source with the sample and Newlib is expected to be installed +together with the GNU ARM tool chain. diff --git a/platforms/lpc17xx/drivers/lpc17xx_uart.c b/platforms/lpc17xx/drivers/lpc17xx_uart.c index 3a0202f..fca71ec 100644 --- a/platforms/lpc17xx/drivers/lpc17xx_uart.c +++ b/platforms/lpc17xx/drivers/lpc17xx_uart.c @@ -143,6 +143,19 @@ void LPC17xx_UART_PutString (uint8_t *str) #endif } +/** + * @brief Write a buffer to UART0. + * + * @param buffer: buffer to be written + * @retval None + */ +void LPC17xx_UART_WriteBuffer (uint8_t *buffer, uint32_t len) +{ + while (len-- != 0) { + LPC17xx_UART_PutChar(*buffer++); + } + +} /** * @brief Print formatted string. This function takes variable length arguments. * diff --git a/platforms/lpc17xx/drivers/lpc17xx_uart.h b/platforms/lpc17xx/drivers/lpc17xx_uart.h index 9e7f045..400a089 100644 --- a/platforms/lpc17xx/drivers/lpc17xx_uart.h +++ b/platforms/lpc17xx/drivers/lpc17xx_uart.h @@ -29,8 +29,8 @@ void LPC17xx_UART_PutChar (uint8_t); uint8_t LPC17xx_UART_GetChar (void); void LPC17xx_UART_Init(uint32_t baudrate); -//void LPC17xx_UART_Printf (const uint8_t *format, ...); void LPC17xx_UART_PutString (uint8_t *str) ; +void LPC17xx_UART_WriteBuffer (uint8_t *buffer, uint32_t len) ; #endif // __LPC17xx_UART_H_ diff --git a/platforms/lpc17xx/main.c b/platforms/lpc17xx/main.c index 755f965..04d053f 100644 --- a/platforms/lpc17xx/main.c +++ b/platforms/lpc17xx/main.c @@ -27,31 +27,34 @@ * POSSIBILITY OF SUCH DAMAGE. */ - +#include #include "LPC17xx.h" #include "drivers/lpc17xx_uart.h" -#include #include "modules.h" #include "atom.h" #include "tests/atomtests.h" -// for mbed board -#define LED1_GPIO (1 << 18) -#define LED2_GPIO (1 << 20) -#define LED3_GPIO (1 << 21) -#define LED4_GPIO (1 << 23) - -#define LED_GET(led) (LPC_GPIO1->FIOSET & led) -#define LED_SET(led, on) { if (on) LPC_GPIO1->FIOSET = led ; else LPC_GPIO1->FIOCLR = led ; } -#define LED_TOGGLE(led) LED_SET(led, !LED_GET(led)) #ifndef ATOMTHREADS_TEST #define ATOMTHREADS_TEST "kern1" #endif -#define TEST_STACK_BYTE_SIZE 1024 -#define IDLE_STACK_BYTE_SIZE 512 +// for mbed board +#define MBED_LED1_GPIO (1 << 18) +#define MBED_LED2_GPIO (1 << 20) +#define MBED_LED3_GPIO (1 << 21) +#define MBED_LED4_GPIO (1 << 23) + +#define MBED_LED_GET(led) (LPC_GPIO1->FIOSET & led) +#define MBED_LED_SET(led, on) { if (on) LPC_GPIO1->FIOSET = led ; else LPC_GPIO1->FIOCLR = led ; } +#define MBED_LED_TOGGLE(led) MBED_LED_SET(led, !MBED_LED_GET(led)) +#define MBED_LED_COUNT(count) MBED_LED_SET(MBED_LED1_GPIO, count & 1) ; MBED_LED_SET(MBED_LED2_GPIO, count & 2) ; \ + MBED_LED_SET(MBED_LED3_GPIO, count & 4) ; MBED_LED_SET(MBED_LED4_GPIO, count & 8) ; + + +#define TEST_STACK_BYTE_SIZE 512 +#define IDLE_STACK_BYTE_SIZE 128 static unsigned char test_stack[TEST_STACK_BYTE_SIZE] ; static unsigned char idle_stack[IDLE_STACK_BYTE_SIZE] ; @@ -68,7 +71,6 @@ void test_thread (uint32_t param) { uint32_t failures ; - static volatile unsigned int i ; CRITICAL_STORE ; failures = test_start () ; @@ -79,18 +81,28 @@ test_thread (uint32_t param) CRITICAL_END() ; while(1) { - LED_TOGGLE(LED1_GPIO) ; - for (i=0; i<1000000; i++) ; +#ifdef BOARD_MBED_LP1768 + MBED_LED_TOGGLE(MBED_LED1_GPIO) ; +#endif + atomTimerDelay (65) ; } } -int main(void) { +/** + * \b main + * + * Initialize atomthreads and start a test_thread to run the Atomthreads test suite. + * + */ +int +main(void) +{ - static volatile unsigned int i ; - - // mbed board - LPC_GPIO1->FIODIR |= LED1_GPIO | LED2_GPIO | LED3_GPIO | LED4_GPIO ; +#ifdef BOARD_MBED_LP1768 + LPC_GPIO1->FIODIR |= MBED_LED1_GPIO | MBED_LED2_GPIO | MBED_LED3_GPIO | MBED_LED4_GPIO ; + MBED_LED_SET(MBED_LED1_GPIO | MBED_LED2_GPIO | MBED_LED3_GPIO | MBED_LED4_GPIO, 1); +#endif dbg_format_msg ("\r\nLPC17xx SystemCoreClock = %d\r\n",SystemCoreClock) ; @@ -99,18 +111,12 @@ int main(void) { dbg_format_msg ("Atomthreads starting %s... \r\n", ATOMTHREADS_TEST) ; atomOSInit(&idle_stack[0], IDLE_STACK_BYTE_SIZE, TRUE) ; - atomThreadCreate ((ATOM_TCB *)&test_tcb, TEST_THREAD_PRIO, test_thread, 0, &test_stack[0], TEST_STACK_BYTE_SIZE, TRUE); + atomThreadCreate ((ATOM_TCB *)&test_tcb, TEST_THREAD_PRIO, test_thread, 0, + &test_stack[0], TEST_STACK_BYTE_SIZE, TRUE); atomOSStart() ; + while(1) ; - - while(1) { - - LED_TOGGLE(LED1_GPIO) ; - for (i=0; i<1000000; i++) ; - - - } return 0 ; } diff --git a/platforms/lpc17xx/modules.c b/platforms/lpc17xx/modules.c index 7901bcd..95b55cf 100644 --- a/platforms/lpc17xx/modules.c +++ b/platforms/lpc17xx/modules.c @@ -50,7 +50,8 @@ dbg_format_msg (char *format, ...) va_start (args, format) ; //CRITICAL_START() ; - vsnprintf ((char*)msg, 256, (char*)format, args) ; + + vsniprintf ((char*)msg, 256, (char*)format, args) ; LPC17xx_UART_PutString (msg) ; //CRITICAL_END() ; diff --git a/platforms/lpc17xx/startup.c b/platforms/lpc17xx/startup.c index 87a90a5..14d104f 100644 --- a/platforms/lpc17xx/startup.c +++ b/platforms/lpc17xx/startup.c @@ -51,6 +51,8 @@ WEAK void IntDefault_Handler(void); //***************************************************************************** extern int main(void); +extern void low_level_init(void); + //***************************************************************************** // // External declaration for the pointer to the stack top from the Linker Script diff --git a/ports/cortex_m/atomport.h b/ports/cortex_m/atomport.h index 1a4cfd9..bc77588 100644 --- a/ports/cortex_m/atomport.h +++ b/ports/cortex_m/atomport.h @@ -39,7 +39,9 @@ * If stddef.h is available on the platform it is simplest to include it * from this header, otherwise define below. */ +#ifndef NULL #define NULL ((void *)(0)) +#endif /* Size of each stack entry / stack alignment size (e.g. 32 bits) */ #define STACK_ALIGN_SIZE sizeof(unsigned int) @@ -56,7 +58,9 @@ * Most of these are available from types.h on this platform, which is * included above. */ +#ifndef POINTER #define POINTER void * +#endif /* * * diff --git a/ports/cortex_m/types.h b/ports/cortex_m/types.h index e6f927d..ba0b9ee 100644 --- a/ports/cortex_m/types.h +++ b/ports/cortex_m/types.h @@ -51,9 +51,15 @@ typedef char int8_t ; #endif /* IO definitions (access restrictions to peripheral registers) */ +#ifndef __I #define __I volatile /*!< defines 'read only' permissions */ +#endif +#ifndef __O #define __O volatile /*!< defines 'write only' permissions */ +#endif +#ifndef __IO #define __IO volatile /*!< defines 'read / write' permissions */ +#endif #endif /* __TYPES_H__ */