From 959f6c695fdea80d6bbd9146770eda95e0a2dfa9 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Mon, 5 Jan 2015 11:19:42 +0800 Subject: [PATCH] lpc43xx: move the application code into its own space --- bsp/lpc43xx/M0/SConscript | 16 ++- bsp/lpc43xx/{ => M0}/applications/SConscript | 0 .../{ => M0}/applications/application.c | 5 +- bsp/lpc43xx/M0/applications/board.h | 59 +++++++++ bsp/lpc43xx/{ => M0}/applications/startup.c | 0 bsp/lpc43xx/M0/rtconfig.h | 4 +- bsp/lpc43xx/M4/SConscript | 16 ++- bsp/lpc43xx/M4/applications/SConscript | 13 ++ bsp/lpc43xx/M4/applications/application.c | 113 ++++++++++++++++++ .../{drivers => M4/applications}/board.h | 1 - bsp/lpc43xx/M4/applications/startup.c | 74 ++++++++++++ bsp/lpc43xx/M4/rtconfig.h | 3 +- 12 files changed, 287 insertions(+), 17 deletions(-) rename bsp/lpc43xx/{ => M0}/applications/SConscript (100%) rename bsp/lpc43xx/{ => M0}/applications/application.c (95%) create mode 100644 bsp/lpc43xx/M0/applications/board.h rename bsp/lpc43xx/{ => M0}/applications/startup.c (100%) create mode 100644 bsp/lpc43xx/M4/applications/SConscript create mode 100644 bsp/lpc43xx/M4/applications/application.c rename bsp/lpc43xx/{drivers => M4/applications}/board.h (98%) create mode 100644 bsp/lpc43xx/M4/applications/startup.c diff --git a/bsp/lpc43xx/M0/SConscript b/bsp/lpc43xx/M0/SConscript index e2c31c0755..285e5c295f 100644 --- a/bsp/lpc43xx/M0/SConscript +++ b/bsp/lpc43xx/M0/SConscript @@ -2,12 +2,16 @@ from building import * cwd = GetCurrentDir() objs = [] -list = os.listdir(os.path.join(cwd, '..')) -for d in list: - if (d != 'M4' and d != 'M0'): - path = os.path.join(cwd, '..', d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(path, 'SConscript')) +for d in os.listdir(os.path.join(cwd, '..')): + if d not in ('M0', 'M4'): + path = os.path.join(cwd, '..', d, 'SConscript') + if os.path.isfile(path): + objs = objs + SConscript(path) + +for d in os.listdir(cwd): + p = os.path.join(cwd, d, 'SConscript'); + if os.path.isfile(p): + objs = objs + SConscript(p) Return('objs') diff --git a/bsp/lpc43xx/applications/SConscript b/bsp/lpc43xx/M0/applications/SConscript similarity index 100% rename from bsp/lpc43xx/applications/SConscript rename to bsp/lpc43xx/M0/applications/SConscript diff --git a/bsp/lpc43xx/applications/application.c b/bsp/lpc43xx/M0/applications/application.c similarity index 95% rename from bsp/lpc43xx/applications/application.c rename to bsp/lpc43xx/M0/applications/application.c index e40ad02e48..e49f1dd767 100644 --- a/bsp/lpc43xx/applications/application.c +++ b/bsp/lpc43xx/M0/applications/application.c @@ -49,12 +49,12 @@ static void led_thread_entry(void *parameter) { /* led0 on */ led_value = 1; - led_dev->write(led_dev, 0, &led_value, 1); + led_dev->write(led_dev, 1, &led_value, 1); rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */ /* led0 off */ led_value = 0; - led_dev->write(led_dev, 0, &led_value, 1); + led_dev->write(led_dev, 1, &led_value, 1); rt_thread_delay(RT_TICK_PER_SECOND / 2); } } @@ -82,3 +82,4 @@ int rt_application_init(void) } return 0; } + diff --git a/bsp/lpc43xx/M0/applications/board.h b/bsp/lpc43xx/M0/applications/board.h new file mode 100644 index 0000000000..c19d0dc4ba --- /dev/null +++ b/bsp/lpc43xx/M0/applications/board.h @@ -0,0 +1,59 @@ +/* + * File : board.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-09-22 Bernard add board.h to this bsp + * 2010-02-04 Magicoe add board.h to LPC176x bsp + * 2013-12-18 Bernard porting to LPC4088 bsp + */ + +#ifndef __BOARD_H__ +#define __BOARD_H__ + +#include "LPC43xx.h" +#include + +/* disable SDRAM in default */ +#ifndef LPC_EXT_SDRAM +#define LPC_EXT_SDRAM 0 +#endif + +// + +// +#define LPC_EXT_SDRAM_BEGIN 0xA0000000 +// +#define LPC_EXT_SDRAM_END 0xA2000000 + +// +// +//#define RT_USING_UART1 +// +//#define RT_USING_UART2 + +// + +#ifdef __CC_ARM +extern int Image$$RW_IRAM2$$ZI$$Limit; +#define HEAP_BEGIN ((void *)&Image$$RW_IRAM2$$ZI$$Limit) +#elif __ICCARM__ +#pragma section="HEAP" +#define HEAP_BEGIN (__segment_end("HEAP")) +#else +extern int __bss_end; +#define HEAP_BEGIN ((void *)&__bss_end) +#endif +#define HEAP_END (void*)(0x10080000 + 0x8000) + +void rt_hw_board_init(void); +int rt_hw_board_heap_init(void); + + +#endif diff --git a/bsp/lpc43xx/applications/startup.c b/bsp/lpc43xx/M0/applications/startup.c similarity index 100% rename from bsp/lpc43xx/applications/startup.c rename to bsp/lpc43xx/M0/applications/startup.c diff --git a/bsp/lpc43xx/M0/rtconfig.h b/bsp/lpc43xx/M0/rtconfig.h index 84fc28028c..a1ac5509ab 100644 --- a/bsp/lpc43xx/M0/rtconfig.h +++ b/bsp/lpc43xx/M0/rtconfig.h @@ -24,6 +24,7 @@ #define RT_DEBUG // #define RT_DEBUG_INIT 0 +//#define RT_DEBUG_SCHEDULER 1 // // #define RT_THREAD_DEBUG // @@ -33,7 +34,7 @@ // #define RT_USING_HOOK //
-#define RT_USING_TIMER_SOFT +//#define RT_USING_TIMER_SOFT // #define RT_TIMER_THREAD_PRIO 4 // @@ -96,6 +97,7 @@ #define RT_CONSOLEBUF_SIZE 128 // #define RT_CONSOLE_DEVICE_NAME "uart0" +#define RT_USING_UART0 //
// diff --git a/bsp/lpc43xx/M4/SConscript b/bsp/lpc43xx/M4/SConscript index e2c31c0755..285e5c295f 100644 --- a/bsp/lpc43xx/M4/SConscript +++ b/bsp/lpc43xx/M4/SConscript @@ -2,12 +2,16 @@ from building import * cwd = GetCurrentDir() objs = [] -list = os.listdir(os.path.join(cwd, '..')) -for d in list: - if (d != 'M4' and d != 'M0'): - path = os.path.join(cwd, '..', d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(path, 'SConscript')) +for d in os.listdir(os.path.join(cwd, '..')): + if d not in ('M0', 'M4'): + path = os.path.join(cwd, '..', d, 'SConscript') + if os.path.isfile(path): + objs = objs + SConscript(path) + +for d in os.listdir(cwd): + p = os.path.join(cwd, d, 'SConscript'); + if os.path.isfile(p): + objs = objs + SConscript(p) Return('objs') diff --git a/bsp/lpc43xx/M4/applications/SConscript b/bsp/lpc43xx/M4/applications/SConscript new file mode 100644 index 0000000000..773b8d0422 --- /dev/null +++ b/bsp/lpc43xx/M4/applications/SConscript @@ -0,0 +1,13 @@ +Import('RTT_ROOT') +Import('rtconfig') +from building import * + +cwd = os.path.join(str(Dir('#')), 'applications') +src = Glob('*.c') +CPPPATH = [cwd, str(Dir('#'))] + +group = DefineGroup('Applications', src, + depend = [''], CPPPATH = CPPPATH, + CPPDEFINES = ['BOOT_PROCESSOR']) + +Return('group') diff --git a/bsp/lpc43xx/M4/applications/application.c b/bsp/lpc43xx/M4/applications/application.c new file mode 100644 index 0000000000..72e0234d85 --- /dev/null +++ b/bsp/lpc43xx/M4/applications/application.c @@ -0,0 +1,113 @@ +/* + * File : application.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2014, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2014-07-13 xiaonong port for lpc43xx + */ + +#include +#include +#include +#include "drv_led.h" + +#ifdef RT_USING_FINSH +#include +#include +#endif + +static const unsigned char _M0_CODE[] SECTION("M0_CODE") = { +#include "M0_CODE.h" +}; + +static void _boot_M0(void) +{ + volatile uint32_t u32REG, u32Val; + + LPC_CREG->M0APPMEMMAP = (uint32_t)&_M0_CODE[0]; + + // Release Slave from reset, first read status + u32REG = LPC_RGU->RESET_ACTIVE_STATUS1; + + // If the M0 is being held in reset, release it... + // 1 = no reset, 0 = reset + while(!(u32REG & (1u << 24))) + { + u32Val = (~(u32REG) & (~(1 << 24))); + LPC_RGU->RESET_CTRL1 = u32Val; + u32REG = LPC_RGU->RESET_ACTIVE_STATUS1; + } + + rt_kprintf("M0 boot to %p\n", &_M0_CODE[0]); +} + +/* thread phase init */ +void rt_init_thread_entry(void *parameter) +{ +#ifdef RT_USING_FINSH + /* initialize finsh */ + finsh_system_init(); + finsh_set_device(RT_CONSOLE_DEVICE_NAME); +#endif + + _boot_M0(); +} + +/*the led thread*/ +ALIGN(RT_ALIGN_SIZE) +static rt_uint8_t led_stack[ 512 ]; +static struct rt_thread led_thread; +static void led_thread_entry(void *parameter) +{ + rt_uint8_t led_value = 0; + rt_device_t led_dev; + rt_led_hw_init(); + led_dev = rt_device_find("led"); + if (led_dev == RT_NULL) + { + rt_kprintf("can not find the led device!\n"); + return; + } + while (1) + { + /* led0 on */ + led_value = 1; + led_dev->write(led_dev, 0, &led_value, 1); + rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */ + + /* led0 off */ + led_value = 0; + led_dev->write(led_dev, 0, &led_value, 1); + rt_thread_delay(RT_TICK_PER_SECOND / 2); + } +} + +int rt_application_init(void) +{ + rt_thread_t tid; + rt_err_t result; + tid = rt_thread_create("init", + rt_init_thread_entry, RT_NULL, + 2048, RT_THREAD_PRIORITY_MAX / 3, 20); + if (tid != RT_NULL) rt_thread_startup(tid); + /* init led thread */ + result = rt_thread_init(&led_thread, + "led", + led_thread_entry, + RT_NULL, + (rt_uint8_t *)&led_stack[0], + sizeof(led_stack), + 20, + 5); + if (result == RT_EOK) + { + rt_thread_startup(&led_thread); + } + return 0; +} diff --git a/bsp/lpc43xx/drivers/board.h b/bsp/lpc43xx/M4/applications/board.h similarity index 98% rename from bsp/lpc43xx/drivers/board.h rename to bsp/lpc43xx/M4/applications/board.h index 393dc30c91..465ccef2cc 100644 --- a/bsp/lpc43xx/drivers/board.h +++ b/bsp/lpc43xx/M4/applications/board.h @@ -33,7 +33,6 @@ #define LPC_EXT_SDRAM_END 0xA2000000 // -#define RT_USING_UART0 // //#define RT_USING_UART1 // diff --git a/bsp/lpc43xx/M4/applications/startup.c b/bsp/lpc43xx/M4/applications/startup.c new file mode 100644 index 0000000000..f6cf534b03 --- /dev/null +++ b/bsp/lpc43xx/M4/applications/startup.c @@ -0,0 +1,74 @@ +/* + * File : startup.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-01-05 Bernard first implementation + * 2014-07-13 xiaonong for LPC43xx + */ + +#include +#include + +#include "board.h" + +extern int rt_application_init(void); + +/** + * This function will startup RT-Thread RTOS. + */ +void rtthread_startup(void) +{ + /* initialize board */ + rt_hw_board_init(); + + /* show version */ + rt_show_version(); + +#ifdef RT_USING_HEAP +#if LPC_EXT_SDRAM + rt_system_heap_init((void *)LPC_EXT_SDRAM_BEGIN, (void *)LPC_EXT_SDRAM_END); + sram_init(); +#else + rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); +#endif +#endif + + /* initialize scheduler system */ + rt_system_scheduler_init(); + + /* initialize system timer*/ + rt_system_timer_init(); + + /* initialize application */ + rt_application_init(); + + /* initialize timer thread */ + rt_system_timer_thread_init(); + + /* initialize idle thread */ + rt_thread_idle_init(); + + /* start scheduler */ + rt_system_scheduler_start(); + + /* never reach here */ + return ; +} + +int main(void) +{ + /* disable interrupt first */ + rt_hw_interrupt_disable(); + + /* startup RT-Thread RTOS */ + rtthread_startup(); + + return 0; +} diff --git a/bsp/lpc43xx/M4/rtconfig.h b/bsp/lpc43xx/M4/rtconfig.h index 84fc28028c..fb65f5bf3d 100644 --- a/bsp/lpc43xx/M4/rtconfig.h +++ b/bsp/lpc43xx/M4/rtconfig.h @@ -95,7 +95,8 @@ // #define RT_CONSOLEBUF_SIZE 128 // -#define RT_CONSOLE_DEVICE_NAME "uart0" +#define RT_CONSOLE_DEVICE_NAME "uart3" +#define RT_USING_UART3 // // -- GitLab