From dd5ac17fc8dc2c9dd166833b31ff08e7d9b316fb Mon Sep 17 00:00:00 2001 From: weety Date: Thu, 19 Oct 2017 19:14:06 +0800 Subject: [PATCH] [bsp][dm365] Using component initial; [drv][mmcsd] Add component initial. --- bsp/dm365/applications/application.c | 126 +-------------- bsp/dm365/applications/board.c | 26 ++- bsp/dm365/applications/startup.c | 148 ------------------ bsp/dm365/dm365_ram.ld | 8 + bsp/dm365/drivers/davinci_emac.c | 2 + bsp/dm365/drivers/davinci_serial.c | 5 +- bsp/dm365/drivers/i2c-davinci.c | 6 + bsp/dm365/rtconfig.h | 3 + .../drivers/include/drivers/mmcsd_core.h | 4 +- components/drivers/sdio/block_dev.c | 6 +- components/drivers/sdio/mmcsd_core.c | 7 +- components/drivers/sdio/sdio.c | 7 +- 12 files changed, 69 insertions(+), 279 deletions(-) delete mode 100644 bsp/dm365/applications/startup.c diff --git a/bsp/dm365/applications/application.c b/bsp/dm365/applications/application.c index 656083ad11..507e1d9592 100644 --- a/bsp/dm365/applications/application.c +++ b/bsp/dm365/applications/application.c @@ -29,63 +29,29 @@ /*@{*/ #include -//#include #ifdef RT_USING_DFS -/* dfs filesystem:ELM FatFs filesystem init */ -#include /* dfs Filesystem APIs */ #include -#ifdef RT_USING_DFS_UFFS -/* dfs filesystem:UFFS filesystem init */ -#include -#endif -#endif - -#if defined(RT_USING_DFS_DEVFS) -#include #endif #ifdef RT_USING_SDIO #include - -#endif - -#ifdef RT_USING_LWIP -#include #endif #ifdef RT_USING_SPI #include #endif -#ifdef RT_USING_LED -#include "led.h" -#endif - -#define RT_INIT_THREAD_STACK_SIZE (2*1024) - -#ifdef RT_USING_DFS_ROMFS -#include -#endif - -void rt_init_thread_entry(void* parameter) +int main(void) { platform_init(); /* Filesystem Initialization */ #ifdef RT_USING_DFS { - /* init the device filesystem */ - dfs_init(); - -#if defined(RT_USING_DFS_ELMFAT) - /* init the elm chan FatFs filesystam*/ - elm_init(); -#endif #if defined(RT_USING_DFS_ROMFS) - dfs_romfs_init(); if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0) { rt_kprintf("ROM File System initialized!\n"); @@ -94,24 +60,8 @@ void rt_init_thread_entry(void* parameter) rt_kprintf("ROM File System initialzation failed!\n"); #endif -#if defined(RT_USING_DFS_DEVFS) - devfs_init(); - if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0) - rt_kprintf("Device File System initialized!\n"); - else - rt_kprintf("Device File System initialzation failed!\n"); - - #ifdef RT_USING_NEWLIB - /* init libc */ - libc_system_init(RT_CONSOLE_DEVICE_NAME); - #endif -#endif - #if defined(RT_USING_DFS_UFFS) { - /* init the uffs filesystem */ - dfs_uffs_init(); - /* mount flash device as flash directory */ if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0) rt_kprintf("UFFS File System initialized!\n"); @@ -120,13 +70,6 @@ void rt_init_thread_entry(void* parameter) } #endif -#ifdef RT_USING_I2C - { - rt_i2c_core_init(); - davinci_i2c_init("I2C1"); - } -#endif - #ifdef RT_USING_SPI { rt_hw_spi_init(); @@ -134,83 +77,26 @@ void rt_init_thread_entry(void* parameter) #endif #ifdef RT_USING_SDIO - rt_mmcsd_core_init(); - rt_mmcsd_blk_init(); rt_hw_mmcsd_init(); - rt_thread_delay(RT_TICK_PER_SECOND*2); - /* mount sd card fat partition 1 as root directory */ + if (MMCSD_HOST_PLUGED == mmcsd_wait_cd_changed(RT_TICK_PER_SECOND*2)) + { + /* mount sd card fat partition 1 as root directory */ if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) { rt_kprintf("File System initialized!\n"); } else rt_kprintf("File System initialzation failed!%d\n", rt_get_errno()); + } #endif } #endif -#ifdef RT_USING_LWIP - { - /* register ethernetif device */ - eth_system_device_init(); - rt_hw_davinci_emac_init(); - /* init lwip system */ - lwip_system_init(); - } -#endif + /* put user application code here */ } -void rt_led_thread_entry(void* parameter) -{ - while(1) - { - /* light on leds for one second */ - rt_thread_delay(100); - - /* light off leds for one second */ - rt_thread_delay(100); - } -} - -int rt_application_init() -{ - rt_thread_t init_thread; -#ifdef RT_USING_LED - rt_thread_t led_thread; -#endif - -#if (RT_THREAD_PRIORITY_MAX == 32) - init_thread = rt_thread_create("init", - rt_init_thread_entry, RT_NULL, - RT_INIT_THREAD_STACK_SIZE, 8, 20); -#ifdef RT_USING_LED - led_thread = rt_thread_create("led", - rt_led_thread_entry, RT_NULL, - 512, 20, 20); -#endif -#else - init_thread = rt_thread_create("init", - rt_init_thread_entry, RT_NULL, - RT_INIT_THREAD_STACK_SIZE, 80, 20); -#ifdef RT_USING_LED - led_thread = rt_thread_create("led", - rt_led_thread_entry, RT_NULL, - 512, 200, 20); -#endif -#endif - - if (init_thread != RT_NULL) - rt_thread_startup(init_thread); -#ifdef RT_USING_LED - if(led_thread != RT_NULL) - rt_thread_startup(led_thread); -#endif - - return 0; -} - /* NFSv3 Initialization */ #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS) #include diff --git a/bsp/dm365/applications/board.c b/bsp/dm365/applications/board.c index 779217c8d0..cd66ae0588 100644 --- a/bsp/dm365/applications/board.c +++ b/bsp/dm365/applications/board.c @@ -32,6 +32,19 @@ * @addtogroup dm365 */ /*@{*/ +#if defined(__CC_ARM) + extern int Image$$ER_ZI$$ZI$$Base; + extern int Image$$ER_ZI$$ZI$$Length; + extern int Image$$ER_ZI$$ZI$$Limit; +#elif (defined (__GNUC__)) + rt_uint8_t _irq_stack_start[1024]; + rt_uint8_t _fiq_stack_start[1024]; + rt_uint8_t _undefined_stack_start[512]; + rt_uint8_t _abort_stack_start[512]; + rt_uint8_t _svc_stack_start[1024] SECTION(".nobss"); + extern unsigned char __bss_start; + extern unsigned char __bss_end; +#endif extern void rt_hw_clock_init(void); extern void rt_hw_uart_init(void); @@ -99,8 +112,10 @@ void rt_hw_board_init() //rt_hw_clock_init(); davinci_clk_init(); - /* initialize uart */ - rt_hw_uart_init(); + /* initialize early device */ +#ifdef RT_USING_COMPONENTS_INIT + rt_components_board_init(); +#endif #ifdef RT_USING_CONSOLE rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif @@ -108,6 +123,13 @@ void rt_hw_board_init() /* initialize mmu */ rt_hw_mmu_init(dm365_mem_desc, sizeof(dm365_mem_desc)/sizeof(dm365_mem_desc[0])); + /* initialize heap memory system */ +#ifdef __CC_ARM + rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x88000000); +#else + rt_system_heap_init((void*)&__bss_end, (void*)0x88000000); +#endif + /* initialize timer0 */ rt_hw_timer_init(); diff --git a/bsp/dm365/applications/startup.c b/bsp/dm365/applications/startup.c deleted file mode 100644 index 8aacc3073c..0000000000 --- a/bsp/dm365/applications/startup.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * File : startup.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2011-01-13 weety first version - */ - -#include -#include - -#include -#ifdef RT_USING_FINSH -#include -#endif - -extern void rt_hw_interrupt_init(void); -extern void rt_hw_board_init(void); -extern void rt_serial_init(void); -extern void rt_system_timer_init(void); -extern void rt_system_scheduler_init(void); -extern void rt_thread_idle_init(void); -extern void rt_hw_cpu_icache_enable(void); -extern void rt_show_version(void); -extern void rt_system_heap_init(void*, void*); -extern void rt_hw_finsh_init(void); -extern void rt_application_init(void); - -/** - * @addtogroup dm365 - */ - -/*@{*/ -#if defined(__CC_ARM) - extern int Image$$ER_ZI$$ZI$$Base; - extern int Image$$ER_ZI$$ZI$$Length; - extern int Image$$ER_ZI$$ZI$$Limit; -#elif (defined (__GNUC__)) - rt_uint8_t _irq_stack_start[1024]; - rt_uint8_t _fiq_stack_start[1024]; - rt_uint8_t _undefined_stack_start[512]; - rt_uint8_t _abort_stack_start[512]; - rt_uint8_t _svc_stack_start[1024] SECTION(".nobss"); - extern unsigned char __bss_start; - extern unsigned char __bss_end; -#endif - -#ifdef RT_USING_FINSH -extern int finsh_system_init(void); -#endif - - -/** - * This function will startup RT-Thread RTOS. - */ -void rtthread_startup(void) -{ - /* enable cpu cache */ - //rt_hw_cpu_icache_enable(); - //rt_hw_cpu_dcache_enable(); - - /* initialize hardware interrupt */ - rt_hw_interrupt_init(); - - /* initialize board */ - rt_hw_board_init(); - - /* show version */ - rt_show_version(); - - /* initialize tick */ - rt_system_tick_init(); - - /* initialize kernel object */ - rt_system_object_init(); - - /* initialize timer system */ - rt_system_timer_init(); - - /* initialize heap memory system */ -#ifdef __CC_ARM - rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x88000000); -#else - rt_system_heap_init((void*)&__bss_end, (void*)0x88000000); -#endif - -#ifdef RT_USING_MODULE - /* initialize module system*/ - rt_system_module_init(); -#endif - - /* initialize scheduler system */ - rt_system_scheduler_init(); - - /* initialize application */ - rt_application_init(); - -#ifdef RT_USING_FINSH - /* initialize finsh */ - finsh_system_init(); -#ifdef RT_USING_DEVICE - finsh_set_device(RT_CONSOLE_DEVICE_NAME); -#endif -#endif - - /* initialize system 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) -{ - rt_uint32_t RT_UNUSED level; - - /* disable interrupt first */ - level = rt_hw_interrupt_disable(); - - /* startup RT-Thread RTOS */ - rtthread_startup(); - - return 0; -} - -/*@}*/ diff --git a/bsp/dm365/dm365_ram.ld b/bsp/dm365/dm365_ram.ld index 2a47d3a189..7715a53b0d 100644 --- a/bsp/dm365/dm365_ram.ld +++ b/bsp/dm365/dm365_ram.ld @@ -28,6 +28,14 @@ SECTIONS __rtmsymtab_start = .; KEEP(*(RTMSymTab)) __rtmsymtab_end = .; + . = ALIGN(4); + + /* section information for initial. */ + . = ALIGN(4); + __rt_init_start = .; + KEEP(*(SORT(.rti_fn*))) + __rt_init_end = .; + . = ALIGN(4); } . = ALIGN(4); diff --git a/bsp/dm365/drivers/davinci_emac.c b/bsp/dm365/drivers/davinci_emac.c index 312f79bc66..8db49a7c67 100644 --- a/bsp/dm365/drivers/davinci_emac.c +++ b/bsp/dm365/drivers/davinci_emac.c @@ -1698,6 +1698,8 @@ void rt_hw_davinci_emac_init() } +INIT_DEVICE_EXPORT(rt_hw_davinci_emac_init); + #ifdef RT_USING_FINSH #include diff --git a/bsp/dm365/drivers/davinci_serial.c b/bsp/dm365/drivers/davinci_serial.c index 9340befbcd..0671cb4e49 100644 --- a/bsp/dm365/drivers/davinci_serial.c +++ b/bsp/dm365/drivers/davinci_serial.c @@ -223,7 +223,7 @@ void davinci_uart1_init(void) /** * This function will handle init uart */ -void rt_hw_uart_init(void) +int rt_hw_uart_init(void) { davinci_serial_dev0.ops = &davinci_uart_ops; //davinci_serial_dev0.config = RT_SERIAL_CONFIG_DEFAULT; @@ -257,5 +257,8 @@ void rt_hw_uart_init(void) UART1); davinci_uart1_init(); + return 0; } +INIT_BOARD_EXPORT(rt_hw_uart_init); + diff --git a/bsp/dm365/drivers/i2c-davinci.c b/bsp/dm365/drivers/i2c-davinci.c index d77c31f69c..c1d8a07ba4 100644 --- a/bsp/dm365/drivers/i2c-davinci.c +++ b/bsp/dm365/drivers/i2c-davinci.c @@ -647,4 +647,10 @@ err: return r; } +int rt_hw_iic_init(void) +{ + davinci_i2c_init("I2C1"); +} + +INIT_DEVICE_EXPORT(rt_hw_iic_init); diff --git a/bsp/dm365/rtconfig.h b/bsp/dm365/rtconfig.h index 08843c77d0..bc6f728ab3 100644 --- a/bsp/dm365/rtconfig.h +++ b/bsp/dm365/rtconfig.h @@ -267,4 +267,7 @@ * #define RT_DFS_ELM_MAX_LFN 128 */ +#define RT_USING_COMPONENTS_INIT +#define RT_USING_USER_MAIN + #endif diff --git a/components/drivers/include/drivers/mmcsd_core.h b/components/drivers/include/drivers/mmcsd_core.h index e474fa28a8..36d71efeb2 100644 --- a/components/drivers/include/drivers/mmcsd_core.h +++ b/components/drivers/include/drivers/mmcsd_core.h @@ -247,9 +247,9 @@ void mmcsd_change(struct rt_mmcsd_host *host); void mmcsd_detect(void *param); struct rt_mmcsd_host *mmcsd_alloc_host(void); void mmcsd_free_host(struct rt_mmcsd_host *host); -void rt_mmcsd_core_init(void); +int rt_mmcsd_core_init(void); -void rt_mmcsd_blk_init(void); +int rt_mmcsd_blk_init(void); rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card); void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card); diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c index 3e142ee6e4..e6998f4fe3 100644 --- a/components/drivers/sdio/block_dev.c +++ b/components/drivers/sdio/block_dev.c @@ -479,7 +479,11 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card) * @deprecated since 2.1.0, this function does not need to be invoked * in the system initialization. */ -void rt_mmcsd_blk_init(void) +int rt_mmcsd_blk_init(void) { /* nothing */ + return 0; } + +INIT_PREV_EXPORT(rt_mmcsd_blk_init); + diff --git a/components/drivers/sdio/mmcsd_core.c b/components/drivers/sdio/mmcsd_core.c index 02063efdd2..3e98444b71 100644 --- a/components/drivers/sdio/mmcsd_core.c +++ b/components/drivers/sdio/mmcsd_core.c @@ -655,6 +655,7 @@ void mmcsd_detect(void *param) if (init_sd(host, ocr)) mmcsd_power_off(host); mmcsd_host_unlock(host); + rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host); continue; } @@ -726,7 +727,7 @@ void mmcsd_free_host(struct rt_mmcsd_host *host) rt_free(host); } -void rt_mmcsd_core_init(void) +int rt_mmcsd_core_init(void) { rt_err_t ret; @@ -749,5 +750,9 @@ void rt_mmcsd_core_init(void) } rt_sdio_init(); + + return 0; } +INIT_PREV_EXPORT(rt_mmcsd_core_init); + diff --git a/components/drivers/sdio/sdio.c b/components/drivers/sdio/sdio.c index 496765854e..dc0cd1eb96 100644 --- a/components/drivers/sdio/sdio.c +++ b/components/drivers/sdio/sdio.c @@ -33,8 +33,8 @@ #define RT_SDIO_THREAD_PRIORITY 0x40 #endif -static rt_list_t sdio_cards; -static rt_list_t sdio_drivers; +static rt_list_t sdio_cards = RT_LIST_OBJECT_INIT(sdio_cards); +static rt_list_t sdio_drivers = RT_LIST_OBJECT_INIT(sdio_drivers); struct sdio_card { @@ -1397,7 +1397,6 @@ rt_int32_t sdio_unregister_driver(struct rt_sdio_driver *driver) void rt_sdio_init(void) { - rt_list_init(&sdio_cards); - rt_list_init(&sdio_drivers); + }