support auto initial.

This commit is contained in:
aozima 2013-07-12 23:08:46 +08:00
parent 8890e83aa9
commit c44b02f08c
4 changed files with 158 additions and 185 deletions

View File

@ -1,4 +1,3 @@
/* /*
* File : application.c * File : application.c
* This file is part of RT-Thread RTOS * This file is part of RT-Thread RTOS
@ -11,6 +10,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2009-01-05 Bernard the first version * 2009-01-05 Bernard the first version
* 2013-07-12 aozima update for auto initial.
*/ */
/** /**
@ -21,21 +21,17 @@
#include <board.h> #include <board.h>
#include <rtthread.h> #include <rtthread.h>
#ifdef RT_USING_COMPONENTS_INIT
#include <components.h>
#endif /* RT_USING_COMPONENTS_INIT */
#ifdef RT_USING_DFS #ifdef RT_USING_DFS
/* dfs init */
#include <dfs_init.h>
/* dfs filesystem:ELM filesystem init */ /* dfs filesystem:ELM filesystem init */
#include <dfs_elm.h> #include <dfs_elm.h>
/* dfs Filesystem APIs */ /* dfs Filesystem APIs */
#include <dfs_fs.h> #include <dfs_fs.h>
#endif #endif
#ifdef RT_USING_LWIP
#include <lwip/sys.h>
#include <lwip/api.h>
#include <netif/ethernetif.h>
#endif
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h> #include <rtgui/rtgui.h>
#include <rtgui/rtgui_server.h> #include <rtgui/rtgui_server.h>
@ -84,127 +80,102 @@ rt_bool_t cali_setup(void)
void cali_store(struct calibration_data *data) void cali_store(struct calibration_data *data)
{ {
rt_kprintf("cali finished (%d, %d), (%d, %d)\n", rt_kprintf("cali finished (%d, %d), (%d, %d)\n",
data->min_x, data->min_x,
data->max_x, data->max_x,
data->min_y, data->min_y,
data->max_y); data->max_y);
} }
#endif #endif /* RT_USING_RTGUI */
void rt_init_thread_entry(void* parameter) void rt_init_thread_entry(void* parameter)
{ {
/* Filesystem Initialization */ #ifdef RT_USING_COMPONENTS_INIT
#ifdef RT_USING_DFS /* initialization RT-Thread Components */
{ rt_components_init();
/* init the device filesystem */
dfs_init();
#ifdef RT_USING_DFS_ELMFAT
/* init the elm chan FatFs filesystam*/
elm_init();
/* 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!\n");
#endif
}
#endif #endif
/* LwIP Initialization */ #ifdef RT_USING_FINSH
#ifdef RT_USING_LWIP finsh_set_device(RT_CONSOLE_DEVICE_NAME);
{ #endif /* RT_USING_FINSH */
extern void lwip_sys_init(void);
/* register ethernetif device */ /* Filesystem Initialization */
eth_system_device_init(); #if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
/* mount sd card fat partition 1 as root directory */
#ifdef STM32F10X_CL if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
rt_hw_stm32_eth_init(); {
#else rt_kprintf("File System initialized!\n");
/* STM32F103 */ }
#if STM32_ETH_IF == 0 else
rt_hw_enc28j60_init(); rt_kprintf("File System initialzation failed!\n");
#elif STM32_ETH_IF == 1 #endif /* RT_USING_DFS */
rt_hw_dm9000_init();
#endif
#endif
/* re-init device driver */
rt_device_init_all();
/* init lwip system */
lwip_sys_init();
rt_kprintf("TCP/IP initialized!\n");
}
#endif
#ifdef RT_USING_RTGUI #ifdef RT_USING_RTGUI
{ {
extern void rtgui_system_server_init(void); extern void rtgui_system_server_init(void);
extern void rt_hw_lcd_init(); extern void rt_hw_lcd_init();
extern void rtgui_touch_hw_init(void); extern void rtgui_touch_hw_init(void);
rt_device_t lcd; rt_device_t lcd;
/* init lcd */ /* init lcd */
rt_hw_lcd_init(); rt_hw_lcd_init();
/* init touch panel */ /* init touch panel */
rtgui_touch_hw_init(); rtgui_touch_hw_init();
/* re-init device driver */ /* re-init device driver */
rt_device_init_all(); rt_device_init_all();
/* find lcd device */ /* find lcd device */
lcd = rt_device_find("lcd"); lcd = rt_device_find("lcd");
/* set lcd device as rtgui graphic driver */ /* set lcd device as rtgui graphic driver */
rtgui_graphic_set_device(lcd); rtgui_graphic_set_device(lcd);
/* init rtgui system server */ /* init rtgui system server */
rtgui_system_server_init(); rtgui_system_server_init();
calibration_set_restore(cali_setup); calibration_set_restore(cali_setup);
calibration_set_after(cali_store); calibration_set_after(cali_store);
calibration_init(); calibration_init();
} }
#endif /* #ifdef RT_USING_RTGUI */ #endif /* #ifdef RT_USING_RTGUI */
} }
int rt_application_init() int rt_application_init(void)
{ {
rt_thread_t init_thread; rt_thread_t init_thread;
rt_err_t result; rt_err_t result;
/* init led thread */ /* init led thread */
result = rt_thread_init(&led_thread, result = rt_thread_init(&led_thread,
"led", "led",
led_thread_entry, RT_NULL, led_thread_entry,
(rt_uint8_t*)&led_stack[0], sizeof(led_stack), 20, 5); RT_NULL,
if (result == RT_EOK) (rt_uint8_t*)&led_stack[0],
{ sizeof(led_stack),
20,
5);
if (result == RT_EOK)
{
rt_thread_startup(&led_thread); rt_thread_startup(&led_thread);
} }
#if (RT_THREAD_PRIORITY_MAX == 32) #if (RT_THREAD_PRIORITY_MAX == 32)
init_thread = rt_thread_create("init", init_thread = rt_thread_create("init",
rt_init_thread_entry, RT_NULL, rt_init_thread_entry, RT_NULL,
2048, 8, 20); 2048, 8, 20);
#else #else
init_thread = rt_thread_create("init", init_thread = rt_thread_create("init",
rt_init_thread_entry, RT_NULL, rt_init_thread_entry, RT_NULL,
2048, 80, 20); 2048, 80, 20);
#endif #endif
if (init_thread != RT_NULL) if (init_thread != RT_NULL)
rt_thread_startup(init_thread); rt_thread_startup(init_thread);
return 0; return 0;
} }
/*@}*/ /*@}*/

View File

@ -24,10 +24,6 @@
/*@{*/ /*@{*/
extern int rt_application_init(void); extern int rt_application_init(void);
#ifdef RT_USING_FINSH
extern void finsh_system_init(void);
extern void finsh_set_device(const char* device);
#endif
#ifdef __CC_ARM #ifdef __CC_ARM
extern int Image$$RW_IRAM1$$ZI$$Limit; extern int Image$$RW_IRAM1$$ZI$$Limit;
@ -48,11 +44,11 @@ extern int __bss_end;
*******************************************************************************/ *******************************************************************************/
void assert_failed(u8* file, u32 line) void assert_failed(u8* file, u32 line)
{ {
rt_kprintf("\n\r Wrong parameter value detected on\r\n"); rt_kprintf("\n\r Wrong parameter value detected on\r\n");
rt_kprintf(" file %s\r\n", file); rt_kprintf(" file %s\r\n", file);
rt_kprintf(" line %d\r\n", line); rt_kprintf(" line %d\r\n", line);
while (1) ; while (1) ;
} }
/** /**
@ -60,67 +56,61 @@ void assert_failed(u8* file, u32 line)
*/ */
void rtthread_startup(void) void rtthread_startup(void)
{ {
/* init board */ /* init board */
rt_hw_board_init(); rt_hw_board_init();
/* show version */ /* show version */
rt_show_version(); rt_show_version();
/* init kernel object */ /* init kernel object */
rt_system_object_init(); rt_system_object_init();
/* init timer system */ /* init timer system */
rt_system_timer_init(); rt_system_timer_init();
#ifdef RT_USING_HEAP #ifdef RT_USING_HEAP
#if STM32_EXT_SRAM #if STM32_EXT_SRAM
rt_system_heap_init((void*)STM32_EXT_SRAM_BEGIN, (void*)STM32_EXT_SRAM_END); rt_system_heap_init((void*)STM32_EXT_SRAM_BEGIN, (void*)STM32_EXT_SRAM_END);
#else #else
#ifdef __CC_ARM #ifdef __CC_ARM
rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)STM32_SRAM_END); rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)STM32_SRAM_END);
#elif __ICCARM__ #elif __ICCARM__
rt_system_heap_init(__segment_end("HEAP"), (void*)STM32_SRAM_END); rt_system_heap_init(__segment_end("HEAP"), (void*)STM32_SRAM_END);
#else #else
/* init memory system */ /* init memory system */
rt_system_heap_init((void*)&__bss_end, (void*)STM32_SRAM_END); rt_system_heap_init((void*)&__bss_end, (void*)STM32_SRAM_END);
#endif #endif
#endif /* STM32_EXT_SRAM */ #endif /* STM32_EXT_SRAM */
#endif /* RT_USING_HEAP */ #endif /* RT_USING_HEAP */
/* init scheduler system */ /* init scheduler system */
rt_system_scheduler_init(); rt_system_scheduler_init();
/* init timer thread */ /* init timer thread */
rt_system_timer_thread_init(); rt_system_timer_thread_init();
/* init application */ /* init application */
rt_application_init(); rt_application_init();
#ifdef RT_USING_FINSH /* init idle thread */
/* init finsh */ rt_thread_idle_init();
finsh_system_init();
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
/* init idle thread */ /* start scheduler */
rt_thread_idle_init(); rt_system_scheduler_start();
/* start scheduler */ /* never reach here */
rt_system_scheduler_start(); return ;
/* never reach here */
return ;
} }
int main(void) int main(void)
{ {
/* disable interrupt first */ /* disable interrupt first */
rt_hw_interrupt_disable(); rt_hw_interrupt_disable();
/* startup RT-Thread RTOS */ /* startup RT-Thread RTOS */
rtthread_startup(); rtthread_startup();
return 0; return 0;
} }
/*@}*/ /*@}*/

View File

@ -10,6 +10,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2009-01-05 Bernard first implementation * 2009-01-05 Bernard first implementation
* 2013-07-12 aozima update for auto initial.
*/ */
#include <rthw.h> #include <rthw.h>
@ -19,6 +20,10 @@
#include "stm32f10x_fsmc.h" #include "stm32f10x_fsmc.h"
#include "board.h" #include "board.h"
#ifdef RT_USING_COMPONENTS_INIT
#include <components.h>
#endif /* RT_USING_COMPONENTS_INIT */
/** /**
* @addtogroup STM32 * @addtogroup STM32
*/ */
@ -35,19 +40,19 @@
void NVIC_Configuration(void) void NVIC_Configuration(void)
{ {
#ifdef VECT_TAB_RAM #ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */ /* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */ #else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */ /* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif #endif
} }
#if STM32_EXT_SRAM #if STM32_EXT_SRAM
void EXT_SRAM_Configuration(void) void EXT_SRAM_Configuration(void)
{ {
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p; FSMC_NORSRAMTimingInitTypeDef p;
/* FSMC GPIO configure */ /* FSMC GPIO configure */
{ {
@ -117,35 +122,35 @@ void EXT_SRAM_Configuration(void)
} }
/* FSMC GPIO configure */ /* FSMC GPIO configure */
/*-- FSMC Configuration ------------------------------------------------------*/ /*-- FSMC Configuration ------------------------------------------------------*/
p.FSMC_AddressSetupTime = 0; p.FSMC_AddressSetupTime = 0;
p.FSMC_AddressHoldTime = 0; p.FSMC_AddressHoldTime = 0;
p.FSMC_DataSetupTime = 2; p.FSMC_DataSetupTime = 2;
p.FSMC_BusTurnAroundDuration = 0; p.FSMC_BusTurnAroundDuration = 0;
p.FSMC_CLKDivision = 0; p.FSMC_CLKDivision = 0;
p.FSMC_DataLatency = 0; p.FSMC_DataLatency = 0;
p.FSMC_AccessMode = FSMC_AccessMode_A; p.FSMC_AccessMode = FSMC_AccessMode_A;
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/* Enable FSMC Bank1_SRAM Bank */ /* Enable FSMC Bank1_SRAM Bank */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
} }
#endif #endif
@ -155,13 +160,13 @@ void EXT_SRAM_Configuration(void)
*/ */
void SysTick_Handler(void) void SysTick_Handler(void)
{ {
/* enter interrupt */ /* enter interrupt */
rt_interrupt_enter(); rt_interrupt_enter();
rt_tick_increase(); rt_tick_increase();
/* leave interrupt */ /* leave interrupt */
rt_interrupt_leave(); rt_interrupt_leave();
} }
/** /**
@ -169,18 +174,22 @@ void SysTick_Handler(void)
*/ */
void rt_hw_board_init(void) void rt_hw_board_init(void)
{ {
/* NVIC Configuration */ /* NVIC Configuration */
NVIC_Configuration(); NVIC_Configuration();
/* Configure the SysTick */ /* Configure the SysTick */
SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND ); SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND );
#if STM32_EXT_SRAM #if STM32_EXT_SRAM
EXT_SRAM_Configuration(); EXT_SRAM_Configuration();
#endif #endif
rt_hw_usart_init(); rt_hw_usart_init();
rt_console_set_device(RT_CONSOLE_DEVICE_NAME); rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
} }
/*@}*/ /*@}*/

View File

@ -56,6 +56,9 @@
/* Using Small MM */ /* Using Small MM */
#define RT_USING_SMALL_MEM #define RT_USING_SMALL_MEM
// <bool name="RT_USING_COMPONENTS_INIT" description="Using RT-Thread components initialization" default="true" />
#define RT_USING_COMPONENTS_INIT
/* SECTION: Device System */ /* SECTION: Device System */
/* Using Device System */ /* Using Device System */
#define RT_USING_DEVICE #define RT_USING_DEVICE
@ -78,12 +81,12 @@
/* #define RT_USING_DFS */ /* #define RT_USING_DFS */
#define RT_USING_DFS_ELMFAT #define RT_USING_DFS_ELMFAT
#define RT_DFS_ELM_WORD_ACCESS
/* Reentrancy (thread safe) of the FatFs module. */ /* Reentrancy (thread safe) of the FatFs module. */
#define RT_DFS_ELM_REENTRANT #define RT_DFS_ELM_REENTRANT
/* Number of volumes (logical drives) to be used. */ /* Number of volumes (logical drives) to be used. */
#define RT_DFS_ELM_DRIVES 2 #define RT_DFS_ELM_DRIVES 2
/* #define RT_DFS_ELM_USE_LFN 1 */ /* #define RT_DFS_ELM_USE_LFN 1 */
/* #define RT_DFS_ELM_CODE_PAGE 936 */
#define RT_DFS_ELM_MAX_LFN 255 #define RT_DFS_ELM_MAX_LFN 255
/* Maximum sector size to be handled. */ /* Maximum sector size to be handled. */
#define RT_DFS_ELM_MAX_SECTOR_SIZE 512 #define RT_DFS_ELM_MAX_SECTOR_SIZE 512