From 98c8a23e9456b6a03f285245fbe9432b825e4f45 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 23 Jun 2013 07:48:42 +0800 Subject: [PATCH] Add component initialization. --- bsp/lpc176x/drivers/emac.c | 4 +- bsp/lpc176x/drivers/emac.h | 2 +- components/dfs/filesystems/devfs/devfs.c | 1 + components/dfs/filesystems/elmfat/dfs_elm.c | 1 + components/dfs/filesystems/jffs2/dfs_jffs2.c | 2 + components/dfs/filesystems/nfs/dfs_nfs.c | 1 + components/dfs/filesystems/romfs/dfs_romfs.c | 1 + components/dfs/filesystems/uffs/dfs_uffs.c | 1 + components/dfs/src/dfs.c | 3 +- components/dfs/src/dfs_posix.c | 2 +- components/drivers/usb/usbhost/core/usbhost.c | 2 +- components/finsh/shell.c | 7 +- components/finsh/shell.h | 2 +- components/init/components.c | 119 ++++++++---------- components/init/components.h | 7 +- components/net/lwip-1.4.1/src/arch/sys_arch.c | 7 +- components/net/lwip-1.4.1/src/lwipopts.h | 8 +- .../net/lwip-1.4.1/src/netif/ethernetif.c | 1 + components/net/lwip/src/arch/sys_arch.c | 8 +- .../net/lwip/src/include/netif/ethernetif.h | 2 +- components/net/lwip/src/netif/ethernetif.c | 5 +- include/rtdef.h | 4 + src/module.c | 1 + 23 files changed, 105 insertions(+), 86 deletions(-) diff --git a/bsp/lpc176x/drivers/emac.c b/bsp/lpc176x/drivers/emac.c index 632b55f1a7..41c979e309 100644 --- a/bsp/lpc176x/drivers/emac.c +++ b/bsp/lpc176x/drivers/emac.c @@ -458,7 +458,7 @@ struct pbuf *lpc17xx_emac_rx(rt_device_t dev) return p; } -void lpc17xx_emac_hw_init(void) +int lpc17xx_emac_hw_init(void) { rt_event_init(&tx_event, "tx_event", RT_IPC_FLAG_FIFO); rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); @@ -487,4 +487,6 @@ void lpc17xx_emac_hw_init(void) lpc17xx_emac_device.parent.eth_tx = lpc17xx_emac_tx; eth_device_init(&(lpc17xx_emac_device.parent), "e0"); + return 0; } +INIT_DEVICE_EXPORT(lpc17xx_emac_hw_init); diff --git a/bsp/lpc176x/drivers/emac.h b/bsp/lpc176x/drivers/emac.h index 0554fb2873..d0edd25d63 100644 --- a/bsp/lpc176x/drivers/emac.h +++ b/bsp/lpc176x/drivers/emac.h @@ -290,6 +290,6 @@ #define DP83848C_DEF_ADR 0x0100 /* Default PHY device address */ #define DP83848C_ID 0x20005C90 /* PHY Identifier */ -void lpc17xx_emac_hw_init(void); +int lpc17xx_emac_hw_init(void); #endif diff --git a/components/dfs/filesystems/devfs/devfs.c b/components/dfs/filesystems/devfs/devfs.c index f5d469fd5f..4d23f78bb6 100644 --- a/components/dfs/filesystems/devfs/devfs.c +++ b/components/dfs/filesystems/devfs/devfs.c @@ -277,4 +277,5 @@ int devfs_init(void) return 0; } +INIT_FS_EXPORT(devfs_init); diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 4f24a0cd72..1a0eeb731f 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -783,6 +783,7 @@ int elm_init(void) return 0; } +INIT_FS_EXPORT(elm_init); /* * RT-Thread Device Interface for ELM FatFs diff --git a/components/dfs/filesystems/jffs2/dfs_jffs2.c b/components/dfs/filesystems/jffs2/dfs_jffs2.c index 04022f4cc7..3b96295c76 100644 --- a/components/dfs/filesystems/jffs2/dfs_jffs2.c +++ b/components/dfs/filesystems/jffs2/dfs_jffs2.c @@ -726,3 +726,5 @@ int dfs_jffs2_init(void) rt_kprintf("init jffs2 lock mutex okay\n"); return 0; } +INIT_FS_EXPORT(dfs_jffs2_init); + diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c index a7aa1cb208..7e8ceeb99f 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/filesystems/nfs/dfs_nfs.c @@ -1106,3 +1106,4 @@ int nfs_init(void) return RT_EOK; } +INIT_FS_EXPORT(nfs_init); diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index d21c336f19..0cfe4d5361 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -289,4 +289,5 @@ int dfs_romfs_init(void) dfs_register(&_romfs); return 0; } +INIT_FS_EXPORT(dfs_romfs_init); diff --git a/components/dfs/filesystems/uffs/dfs_uffs.c b/components/dfs/filesystems/uffs/dfs_uffs.c index 6072910058..f9c314622b 100644 --- a/components/dfs/filesystems/uffs/dfs_uffs.c +++ b/components/dfs/filesystems/uffs/dfs_uffs.c @@ -654,3 +654,4 @@ int dfs_uffs_init(void) } return -RT_ERROR; } +INIT_FS_EXPORT(dfs_uffs_init); diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index e1d78d398c..0cccddb0f7 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -16,7 +16,7 @@ #include #include -#define NO_WORKING_DIR "system does not support working dir\n" +#define NO_WORKING_DIR "system does not support working directory\n" /* Global variables */ const struct dfs_filesystem_operation *filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; @@ -62,6 +62,7 @@ void dfs_init(void) working_directory[0] = '/'; #endif } +INIT_COMPONENT_EXPORT(dfs_init); /** * this function will lock device file system. diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 7b650a48fa..5cb3b8ffaa 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -757,7 +757,7 @@ char *getcwd(char *buf, size_t size) rt_strncpy(buf, working_directory, size); rt_exit_critical(); #else - rt_kprintf("WARNING: not support working directory\n"); + rt_kprintf(NO_WORKING_DIR); #endif return buf; diff --git a/components/drivers/usb/usbhost/core/usbhost.c b/components/drivers/usb/usbhost/core/usbhost.c index 572da8bd67..649fa0b20c 100644 --- a/components/drivers/usb/usbhost/core/usbhost.c +++ b/components/drivers/usb/usbhost/core/usbhost.c @@ -71,4 +71,4 @@ void rt_usb_host_init(void) drv = rt_usb_class_driver_hub(); rt_usb_class_driver_register(drv); } - +INIT_COMPONENT_EXPORT(rt_usb_host_init); diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 08dfc2b21a..7ace0c34fc 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -511,7 +511,7 @@ __declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end = * * This function will initialize finsh shell */ -void finsh_system_init(void) +int finsh_system_init(void) { rt_err_t result; @@ -561,7 +561,7 @@ void finsh_system_init(void) if (shell == RT_NULL) { rt_kprintf("no memory for shell\n"); - return; + return -1; } memset(shell, 0, sizeof(struct finsh_shell)); @@ -575,4 +575,7 @@ void finsh_system_init(void) if (result == RT_EOK) rt_thread_startup(&finsh_thread); + return 0; } +INIT_COMPONENT_EXPORT(finsh_system_init); + diff --git a/components/finsh/shell.h b/components/finsh/shell.h index ff768d4c66..4aedb6d96f 100644 --- a/components/finsh/shell.h +++ b/components/finsh/shell.h @@ -89,7 +89,7 @@ struct finsh_shell void finsh_set_echo(rt_uint32_t echo); rt_uint32_t finsh_get_echo(void); -void finsh_system_init(void); +int finsh_system_init(void); void finsh_set_device(const char* device_name); const char* finsh_get_device(void); diff --git a/components/init/components.c b/components/init/components.c index b8dae7ce1a..8fe774708e 100644 --- a/components/init/components.c +++ b/components/init/components.c @@ -12,86 +12,71 @@ * 2012-09-20 Bernard Change the name to components.c * And all components related header files. * 2012-12-23 Bernard fix the pthread initialization issue. + * 2013-06-23 Bernard Add the init_call for components initialization. */ #include "components.h" -/** - * RT-Thread Components Initialization - */ -void rt_components_init(void) +static int rti_start(void) { -#ifdef RT_USING_MODULE - rt_system_module_init(); -#endif - -#ifdef RT_USING_FINSH - /* initialize finsh */ - finsh_system_init(); - finsh_set_device(RT_CONSOLE_DEVICE_NAME); -#endif - -#ifdef RT_USING_LWIP - /* initialize lwip stack */ - /* register ethernetif device */ - eth_system_device_init(); - - /* initialize lwip system */ - lwip_system_init(); - rt_kprintf("TCP/IP initialized!\n"); -#endif - -#ifdef RT_USING_DFS - /* initialize the device file system */ - dfs_init(); - - #ifdef RT_USING_DFS_ELMFAT - /* initialize the elm chan FatFS file system*/ - elm_init(); - #endif - - #if defined(RT_USING_DFS_NFS) && defined(RT_USING_LWIP) - /* initialize NFSv3 client file system */ - nfs_init(); - #endif - - #ifdef RT_USING_DFS_YAFFS2 - dfs_yaffs2_init(); - #endif + return 0; +} +INIT_EXPORT(rti_start, "0"); - #ifdef RT_USING_DFS_UFFS - dfs_uffs_init(); - #endif +static int rti_board_end(void) +{ + return 0; +} +INIT_EXPORT(rti_board_end, "1.post"); - #ifdef RT_USING_DFS_JFFS2 - dfs_jffs2_init(); - #endif +static int rti_end(void) +{ + return 0; +} +INIT_EXPORT(rti_end,"7"); - #ifdef RT_USING_DFS_ROMFS - dfs_romfs_init(); - #endif +#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) +/* fixed for MSC_VC and x86_64 in GNU GCC */ +#define NEXT_COMPONENT_FN(fn_ptr, end) fn_ptr = _next_component_fn(fn_ptr, end) - #ifdef RT_USING_DFS_DEVFS - devfs_init(); - #endif -#endif /* end of RT_USING_DFS */ +const init_fn_t* _next_component_fn(const init_fn_t* fn, const init_fn_t* end) +{ + unsigned int *ptr; + ptr = (unsigned int*) (fn + 1); + while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*)end)) + ptr ++; -#ifdef RT_USING_NEWLIB - libc_system_init(RT_CONSOLE_DEVICE_NAME); + return (const init_fn_t*)ptr; +} #else - /* the pthread system initialization will be initiallized in libc */ - #ifdef RT_USING_PTHREADS - pthread_system_init(); - #endif +#define NEXT_COMPONENT_FN(fn_ptr, end) fn_ptr++ #endif -#ifdef RT_USING_RTGUI - rtgui_system_server_init(); -#endif +/** + * RT-Thread Components Initialization for board + */ +void rt_components_board_init(void) +{ + const init_fn_t* fn_ptr; -#ifdef RT_USING_USB_HOST - rt_usb_host_init(); -#endif + for (fn_ptr = &__rt_init_rti_start; fn_ptr < &__rt_init_rti_board_end; ) + { + (*fn_ptr)(); + NEXT_COMPONENT_FN(fn_ptr, __rt_init_rti_board_end); + } +} + +/** + * RT-Thread Components Initialization + */ +void rt_components_init(void) +{ + const init_fn_t* fn_ptr; - return; + for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; ) + { + (*fn_ptr)(); + NEXT_COMPONENT_FN(fn_ptr, __rt_init_rti_end); + } } + diff --git a/components/init/components.h b/components/init/components.h index c19813da3a..60fd139884 100644 --- a/components/init/components.h +++ b/components/init/components.h @@ -77,9 +77,14 @@ extern void lwip_system_init(void); extern "C" { #endif +/** + * Initializes board routine in RT-Thread. + */ +void rt_components_board_init(void); + /** * Initializes components in RT-Thread - * notes: this function must be invoked in thread + * notes: this function must be invoked in Init Thread */ void rt_components_init(void); diff --git a/components/net/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip-1.4.1/src/arch/sys_arch.c index bb7eb99e8d..e18ed91345 100644 --- a/components/net/lwip-1.4.1/src/arch/sys_arch.c +++ b/components/net/lwip-1.4.1/src/arch/sys_arch.c @@ -25,6 +25,7 @@ #include "lwip/tcpip.h" #include "netif/ethernetif.h" #include "lwip/sio.h" +#include #include @@ -124,7 +125,7 @@ static void tcpip_init_done_callback(void *arg) /** * LwIP system initialization */ -void lwip_system_init(void) +int lwip_system_init(void) { rt_err_t rc; struct rt_semaphore done_sem; @@ -165,7 +166,11 @@ void lwip_system_init(void) netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw); } #endif + rt_kprintf("lwIP-%d.%d.%d initialized!\n", LWIP_VERSION_MAJOR, LWIP_VERSION_MINOR, LWIP_VERSION_REVISION); + + return 0; } +INIT_COMPONENT_EXPORT(lwip_system_init); void sys_init(void) { diff --git a/components/net/lwip-1.4.1/src/lwipopts.h b/components/net/lwip-1.4.1/src/lwipopts.h index 24cba48ea6..7dc8af0ae0 100644 --- a/components/net/lwip-1.4.1/src/lwipopts.h +++ b/components/net/lwip-1.4.1/src/lwipopts.h @@ -82,11 +82,7 @@ #define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) /* ---------- Memory options ---------- */ -#ifdef RT_LWIP_ALIGN_SIZE -#define MEM_ALIGNMENT RT_LWIP_ALIGN_SIZE -#else #define MEM_ALIGNMENT 4 -#endif #define MEM_LIBC_MALLOC 1 #define mem_malloc rt_malloc @@ -179,7 +175,11 @@ #define TCP_MSS 1460 /* TCP sender buffer space (bytes). */ +#ifdef RT_LWIP_TCP_SND_BUF +#define TCP_SND_BUF RT_LWIP_TCP_SND_BUF +#else #define TCP_SND_BUF (TCP_MSS * 2) +#endif /* TCP sender buffer space (pbufs). This must be at least = 2 * TCP_SND_BUF/TCP_MSS for things to work. */ diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 3f0fd21e59..4757981fa0 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -383,6 +383,7 @@ void eth_system_device_init() result = rt_thread_startup(ð_tx_thread); RT_ASSERT(result == RT_EOK); } +INIT_DEVICE_EXPORT(eth_system_device_init); #ifdef RT_USING_FINSH #include diff --git a/components/net/lwip/src/arch/sys_arch.c b/components/net/lwip/src/arch/sys_arch.c index bb7eb99e8d..6e488a31b5 100644 --- a/components/net/lwip/src/arch/sys_arch.c +++ b/components/net/lwip/src/arch/sys_arch.c @@ -124,7 +124,7 @@ static void tcpip_init_done_callback(void *arg) /** * LwIP system initialization */ -void lwip_system_init(void) +int lwip_system_init(void) { rt_err_t rc; struct rt_semaphore done_sem; @@ -138,7 +138,7 @@ void lwip_system_init(void) { LWIP_ASSERT("Failed to create semaphore", 0); - return; + return -1; } tcpip_init(tcpip_init_done_callback, (void *)&done_sem); @@ -148,7 +148,7 @@ void lwip_system_init(void) { rt_sem_detach(&done_sem); - return; + return -1; } rt_sem_detach(&done_sem); @@ -165,7 +165,9 @@ void lwip_system_init(void) netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw); } #endif + return 0; } +INIT_COMPONENT_EXPORT(lwip_system_init); void sys_init(void) { diff --git a/components/net/lwip/src/include/netif/ethernetif.h b/components/net/lwip/src/include/netif/ethernetif.h index 4aa4525ce2..53dacf2270 100644 --- a/components/net/lwip/src/include/netif/ethernetif.h +++ b/components/net/lwip/src/include/netif/ethernetif.h @@ -30,6 +30,6 @@ rt_err_t eth_device_init(struct eth_device * dev, char *name); rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flag); rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up); -void eth_system_device_init(void); +int eth_system_device_init(void); #endif /* __NETIF_ETHERNETIF_H__ */ diff --git a/components/net/lwip/src/netif/ethernetif.c b/components/net/lwip/src/netif/ethernetif.c index 3f0fd21e59..52a6831ebf 100644 --- a/components/net/lwip/src/netif/ethernetif.c +++ b/components/net/lwip/src/netif/ethernetif.c @@ -350,7 +350,7 @@ static void eth_rx_thread_entry(void* parameter) } } -void eth_system_device_init() +int eth_system_device_init(void) { rt_err_t result = RT_EOK; @@ -382,7 +382,10 @@ void eth_system_device_init() result = rt_thread_startup(ð_tx_thread); RT_ASSERT(result == RT_EOK); + + return 0; } +INIT_DEVICE_EXPORT(eth_system_device_init); #ifdef RT_USING_FINSH #include diff --git a/include/rtdef.h b/include/rtdef.h index ec4e8179c9..cfcde6d929 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -97,6 +97,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #include #define SECTION(x) @ x #define UNUSED + #define USED #define PRAGMA(x) _Pragma(#x) #define ALIGN(n) PRAGMA(data_alignment=n) #define rt_inline static inline @@ -137,6 +138,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #include #define SECTION(x) __attribute__((section(x))) #define UNUSED __attribute__((unused)) + #define USED __attribute__((used)) #define ALIGN(n) __attribute__((aligned(n))) #define rt_inline static inline #define RTT_API @@ -144,6 +146,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #include #define SECTION(x) #define UNUSED + #define USED #define ALIGN(n) __declspec(align(n)) #define rt_inline static __inline #define RTT_API @@ -153,6 +156,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ * details. */ #define SECTION(x) #define UNUSED + #define USED #define ALIGN(n) #define rt_inline static inline #define RTT_API diff --git a/src/module.c b/src/module.c index ca885a8e99..303b33cc26 100644 --- a/src/module.c +++ b/src/module.c @@ -91,6 +91,7 @@ void rt_system_module_init(void) rt_sem_init(&mod_sem, "module", 1, RT_IPC_FLAG_FIFO); #endif } +INIT_COMPONENT_EXPORT(rt_system_module_init); static rt_uint32_t rt_module_symbol_find(const char *sym_str) { -- GitLab