本帖最后由 stm32boy 于 2012-1-12 21:57 编辑
再来改改application.c的内容——
/*
* File : application.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006, RT-Thread Development Team
*
* 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
*/
/*@{*/
#include <board.h>
#include <rtthread.h>
#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
#ifdef RT_USING_LWIP
#include <lwip/sys.h>
#include <lwip/api.h>
#include <netif/ethernetif.h>
#endif
#ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/driver.h>
#endif
#include "led.h"
void led2_thread_entry(void* parameter)
{
unsigned int count;
rt_hw_led_init();
while (1)
{
/* led1-3 on */
#ifndef RT_USING_FINSH
rt_kprintf("led on, count : %d\r\n",count);
#endif
for(count=0;count<3;count++)
{
rt_hw_led_on(count);
rt_thread_delay( RT_TICK_PER_SECOND/4 ); /* sleep 0.25 second and switch to other thread */
/* led1-3 off */
#ifndef RT_USING_FINSH
rt_kprintf("led off\r\n");
#endif
rt_hw_led_off(count);
rt_thread_delay( RT_TICK_PER_SECOND*3 );
}
}
}
void led1_thread_entry(void* parameter)
{
unsigned int count;
rt_hw_led_init();
while (1)
{
/* led1-3 on */
#ifndef RT_USING_FINSH
rt_kprintf("led on, count : %d\r\n",count);
#endif
for(count=0;count<3;count++)
{
rt_hw_led_on(count);
rt_thread_delay( RT_TICK_PER_SECOND*2 ); /* sleep 2 second and switch to other thread */
/* led1-3 off */
#ifndef RT_USING_FINSH
rt_kprintf("led off\r\n");
#endif
rt_hw_led_off(count);
rt_thread_delay( RT_TICK_PER_SECOND );
}
}
}
ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t led_stack[ 512 ];
static struct rt_thread led_thread;
static void led_thread_entry(void* parameter)
{
unsigned int count;
rt_hw_led_init();
while (1)
{
/* led4-5 on */
#ifndef RT_USING_FINSH
rt_kprintf("led on, count : %d\r\n",count);
#endif
for(count=3;count<5;count++)
{
rt_hw_led_on(count);
rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
/* led4-5 off */
#ifndef RT_USING_FINSH
rt_kprintf("led off\r\n");
#endif
rt_hw_led_off(count);
rt_thread_delay( RT_TICK_PER_SECOND/2 );
}
}
}
void rt_init_thread_entry(void* parameter)
{
/* 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
#ifdef RT_USING_RTGUI
{
extern void rtgui_startup();
extern void rt_hw_lcd_init();
extern void rtgui_touch_hw_init(void);
rt_device_t lcd;
/* init lcd */
rt_hw_lcd_init();
/* init touch panel */
rtgui_touch_hw_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 */
}
int rt_application_init()
{
rt_thread_t init_thread;
rt_thread_t led1_thread;
rt_thread_t led2_thread;
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);
}
#if (RT_THREAD_PRIORITY_MAX == 32)
init_thread = rt_thread_create("init",
rt_init_thread_entry, RT_NULL,
2048, 8, 20);
led1_thread = rt_thread_create("led1",
led1_thread_entry, RT_NULL,
2048, 15, 5);
led2_thread = rt_thread_create("led2",
led2_thread_entry, RT_NULL,
2048, 16, 5);
#else
init_thread = rt_thread_create("init",
rt_init_thread_entry, RT_NULL,
2048, 80, 20);
led1_thread = rt_thread_create("led1",
led1_thread_entry, RT_NULL,
2048, 150, 5);
led2_thread = rt_thread_create("led2",
led2_thread_entry, RT_NULL,
2048, 160, 5);
#endif
if (init_thread != RT_NULL|led1_thread != RT_NULL|led2_thread != RT_NULL)
rt_thread_startup(init_thread);
rt_thread_startup(led1_thread);
rt_thread_startup(led2_thread);
return 0;
}
/*@}*/
红色部分为改动很大的地方。 |