提交 98c8a23e 编写于 作者: B Bernard Xiong

Add component initialization.

上级 c5927f51
......@@ -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);
......@@ -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
......@@ -277,4 +277,5 @@ int devfs_init(void)
return 0;
}
INIT_FS_EXPORT(devfs_init);
......@@ -783,6 +783,7 @@ int elm_init(void)
return 0;
}
INIT_FS_EXPORT(elm_init);
/*
* RT-Thread Device Interface for ELM FatFs
......
......@@ -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);
......@@ -1106,3 +1106,4 @@ int nfs_init(void)
return RT_EOK;
}
INIT_FS_EXPORT(nfs_init);
......@@ -289,4 +289,5 @@ int dfs_romfs_init(void)
dfs_register(&_romfs);
return 0;
}
INIT_FS_EXPORT(dfs_romfs_init);
......@@ -654,3 +654,4 @@ int dfs_uffs_init(void)
}
return -RT_ERROR;
}
INIT_FS_EXPORT(dfs_uffs_init);
......@@ -16,7 +16,7 @@
#include <dfs_fs.h>
#include <dfs_file.h>
#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.
......
......@@ -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;
......
......@@ -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);
......@@ -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);
......@@ -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);
......
......@@ -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);
}
}
......@@ -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);
......
......@@ -25,6 +25,7 @@
#include "lwip/tcpip.h"
#include "netif/ethernetif.h"
#include "lwip/sio.h"
#include <lwip/init.h>
#include <string.h>
......@@ -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)
{
......
......@@ -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. */
......
......@@ -383,6 +383,7 @@ void eth_system_device_init()
result = rt_thread_startup(&eth_tx_thread);
RT_ASSERT(result == RT_EOK);
}
INIT_DEVICE_EXPORT(eth_system_device_init);
#ifdef RT_USING_FINSH
#include <finsh.h>
......
......@@ -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)
{
......
......@@ -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__ */
......@@ -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(&eth_tx_thread);
RT_ASSERT(result == RT_EOK);
return 0;
}
INIT_DEVICE_EXPORT(eth_system_device_init);
#ifdef RT_USING_FINSH
#include <finsh.h>
......
......@@ -97,6 +97,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
#include <stdarg.h>
#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 <stdarg.h>
#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 <stdarg.h>
#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
......
......@@ -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)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册