2009-09-29 21:23:27 +08:00
|
|
|
/*
|
|
|
|
* File : application.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
2010-03-18 13:51:39 +08:00
|
|
|
* COPYRIGHT (C) 2006, RT-Thread Development Team
|
2009-09-29 21:23:27 +08:00
|
|
|
*
|
|
|
|
* 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 the first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup STM32
|
|
|
|
*/
|
|
|
|
/*@{*/
|
|
|
|
|
2010-04-02 14:17:40 +08:00
|
|
|
#include <board.h>
|
2009-09-29 21:23:27 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
|
2010-04-02 14:17:40 +08:00
|
|
|
#ifdef RT_USING_DFS
|
|
|
|
/* dfs init */
|
|
|
|
#include <dfs_init.h>
|
|
|
|
/* dfs filesystem:ELM filesystem init */
|
|
|
|
#include <dfs_elm.h>
|
|
|
|
/* dfs Filesystem APIs */
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
#endif
|
2009-12-13 23:28:33 +08:00
|
|
|
|
2010-04-02 14:17:40 +08:00
|
|
|
#ifdef RT_USING_LWIP
|
|
|
|
#include <lwip/sys.h>
|
|
|
|
#include <lwip/api.h>
|
|
|
|
#include <netif/ethernetif.h>
|
|
|
|
#endif
|
|
|
|
|
2011-06-23 23:24:10 +08:00
|
|
|
#include "led.h"
|
|
|
|
|
|
|
|
ALIGN(RT_ALIGN_SIZE)
|
2011-07-03 21:21:32 +08:00
|
|
|
static rt_uint8_t led_stack[ 512 ];
|
2011-06-23 23:24:10 +08:00
|
|
|
static struct rt_thread led_thread;
|
|
|
|
static void led_thread_entry(void* parameter)
|
|
|
|
{
|
|
|
|
unsigned int count=0;
|
|
|
|
|
|
|
|
rt_hw_led_init();
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* led1 on */
|
|
|
|
#ifndef RT_USING_FINSH
|
|
|
|
rt_kprintf("led on, count : %d\r\n",count);
|
|
|
|
#endif
|
|
|
|
count++;
|
|
|
|
rt_hw_led_on(0);
|
|
|
|
rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
|
|
|
|
|
|
|
|
/* led1 off */
|
|
|
|
#ifndef RT_USING_FINSH
|
2011-07-03 21:21:32 +08:00
|
|
|
rt_kprintf("led off\r\n");
|
2011-06-23 23:24:10 +08:00
|
|
|
#endif
|
|
|
|
rt_hw_led_off(0);
|
|
|
|
rt_thread_delay( RT_TICK_PER_SECOND/2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 14:17:40 +08:00
|
|
|
void rt_init_thread_entry(void* parameter)
|
2010-03-18 13:51:39 +08:00
|
|
|
{
|
2010-04-02 14:17:40 +08:00
|
|
|
/* Filesystem Initialization */
|
|
|
|
#ifdef RT_USING_DFS
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
/* LwIP Initialization */
|
|
|
|
#ifdef RT_USING_LWIP
|
|
|
|
{
|
|
|
|
extern void lwip_sys_init(void);
|
|
|
|
|
|
|
|
/* register ethernetif device */
|
|
|
|
eth_system_device_init();
|
|
|
|
|
|
|
|
#ifdef STM32F10X_CL
|
|
|
|
rt_hw_stm32_eth_init();
|
|
|
|
#else
|
|
|
|
/* STM32F103 */
|
|
|
|
#if STM32_ETH_IF == 0
|
|
|
|
rt_hw_enc28j60_init();
|
|
|
|
#elif STM32_ETH_IF == 1
|
|
|
|
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
|
2011-07-04 15:39:49 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_RTGUI
|
|
|
|
{
|
|
|
|
rt_device_t lcd;
|
|
|
|
|
|
|
|
/* init lcd */
|
|
|
|
rt_hw_lcd_init();
|
|
|
|
|
|
|
|
/* init touch panel */
|
|
|
|
rtgui_touch_hw_init();
|
|
|
|
|
|
|
|
/* init keypad */
|
|
|
|
rt_hw_key_init();
|
|
|
|
|
|
|
|
/* re-init device driver */
|
|
|
|
rt_device_init_all();
|
|
|
|
|
|
|
|
/* find lcd device */
|
|
|
|
lcd = rt_device_find("lcd");
|
|
|
|
|
|
|
|
/* set lcd device as rtgui graphic driver */
|
|
|
|
rtgui_graphic_set_device(lcd);
|
|
|
|
|
|
|
|
/* startup rtgui */
|
|
|
|
rtgui_startup();
|
|
|
|
}
|
|
|
|
#endif /* #ifdef RT_USING_RTGUI */
|
2009-09-29 21:23:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int rt_application_init()
|
|
|
|
{
|
2010-04-02 14:17:40 +08:00
|
|
|
rt_thread_t init_thread;
|
|
|
|
|
2011-06-23 23:24:10 +08:00
|
|
|
rt_err_t result;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2010-04-02 14:17:40 +08:00
|
|
|
#if (RT_THREAD_PRIORITY_MAX == 32)
|
|
|
|
init_thread = rt_thread_create("init",
|
|
|
|
rt_init_thread_entry, RT_NULL,
|
|
|
|
2048, 8, 20);
|
|
|
|
#else
|
|
|
|
init_thread = rt_thread_create("init",
|
|
|
|
rt_init_thread_entry, RT_NULL,
|
|
|
|
2048, 80, 20);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (init_thread != RT_NULL)
|
|
|
|
rt_thread_startup(init_thread);
|
|
|
|
|
|
|
|
return 0;
|
2009-09-29 21:23:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|