application.c 3.2 KB
Newer Older
1
/*
2
 * File      : application.c
3 4 5 6 7
 * 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
8
 * http://www.rt-thread.org/license/LICENSE
9 10 11 12 13 14 15 16
 *
 * Change Logs:
 * Date           Author		Notes
 * 2007-11-20     Yi.Qiu		add rtgui application
 * 2008-6-28      Bernard		no rtgui init
 */

/**
B
bernard.xiong 已提交
17 18
 * @addtogroup mini2440
 */
19 20
/*@{*/

B
bernard.xiong 已提交
21 22
#include <board.h>
#include <rtthread.h>
A
 
aganhx@gmail.com 已提交
23
#include <rtgui/rtgui.h>
A
 
aganhx@gmail.com 已提交
24
#include "led.h"
25 26 27 28 29

#ifdef RT_USING_DFS
/* dfs init */
#include <dfs_init.h>
/* dfs filesystem:EFS filesystem init */
B
bernard.xiong 已提交
30
#include <dfs_efs.h>
31 32 33 34 35
/* dfs Filesystem APIs */
#include <dfs_fs.h>
#endif

#ifdef RT_USING_LWIP
B
bernard.xiong 已提交
36
#include <netif/ethernetif.h>
37 38
#endif

A
 
aganhx@gmail.com 已提交
39 40 41
#ifdef RT_USING_RTGUI
extern void rt_hw_lcd_init(void);
extern void rt_hw_key_init(void);
A
 
aganhx@gmail.com 已提交
42
extern void radio_rtgui_init(void);
A
 
aganhx@gmail.com 已提交
43 44
#endif

B
bernard.xiong 已提交
45
void rt_init_thread_entry(void* parameter)
46
{
B
bernard.xiong 已提交
47 48 49 50 51
/* Filesystem Initialization */
#ifdef RT_USING_DFS
	{
		/* init the device filesystem */
		dfs_init();
52

B
bernard.xiong 已提交
53 54 55
#ifdef RT_USING_DFS_EFSL
		/* init the efsl filesystam*/
		efsl_init();
56

B
bernard.xiong 已提交
57 58
		/* mount sd card fat partition 1 as root directory */
		if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
59
		{
B
bernard.xiong 已提交
60
			rt_kprintf("File System initialized!\n");
61
		}
B
bernard.xiong 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74
		else
			rt_kprintf("File System initialzation failed!\n");
#elif defined(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");
75
#endif
B
bernard.xiong 已提交
76
	}
77 78
#endif

A
 
aganhx@gmail.com 已提交
79 80
#ifdef RT_USING_RTGUI
	{
A
 
aganhx@gmail.com 已提交
81
		radio_rtgui_init();
A
 
aganhx@gmail.com 已提交
82 83 84 85
		rt_hw_key_init();
	}
#endif

B
bernard.xiong 已提交
86
/* LwIP Initialization */
87
#ifdef RT_USING_LWIP
B
bernard.xiong 已提交
88 89 90
	{
		extern void lwip_sys_init(void);
		eth_system_device_init();
91

B
bernard.xiong 已提交
92 93
		/* register ethernetif device */
		rt_hw_dm9000_init();
94

B
bernard.xiong 已提交
95 96
		/* re-init device driver */
		rt_device_init_all();
97

B
bernard.xiong 已提交
98 99 100 101
		/* init lwip system */
		lwip_sys_init();
		rt_kprintf("TCP/IP initialized!\n");
	}
102
#endif
B
bernard.xiong 已提交
103
}
104

A
 
aganhx@gmail.com 已提交
105 106 107 108
void rt_led_thread_entry(void* parameter)
{
	while(1)
	{
A
 
aganhx@gmail.com 已提交
109
		/* light on leds for one second */
A
 
aganhx@gmail.com 已提交
110
		rt_hw_led_on(LED2|LED3);
A
 
aganhx@gmail.com 已提交
111
		rt_hw_led_off(LED1|LED4);
A
 
aganhx@gmail.com 已提交
112 113
		rt_thread_delay(100);

A
 
aganhx@gmail.com 已提交
114
		/* light off leds for one second */
A
 
aganhx@gmail.com 已提交
115
		rt_hw_led_off(LED2|LED3);
A
 
aganhx@gmail.com 已提交
116
		rt_hw_led_on(LED1|LED4);
A
 
aganhx@gmail.com 已提交
117 118 119 120 121
		rt_thread_delay(100);

	}
}

A
 
aganhx@gmail.com 已提交
122

B
bernard.xiong 已提交
123 124 125
int rt_application_init()
{
	rt_thread_t init_thread;
A
 
aganhx@gmail.com 已提交
126
	rt_thread_t led_thread;
B
bernard.xiong 已提交
127

A
 
aganhx@gmail.com 已提交
128 129 130 131
#ifdef RT_USING_RTGUI
	rt_hw_lcd_init();
#endif

B
bernard.xiong 已提交
132 133 134 135
#if (RT_THREAD_PRIORITY_MAX == 32)
	init_thread = rt_thread_create("init",
								rt_init_thread_entry, RT_NULL,
								2048, 8, 20);
A
 
aganhx@gmail.com 已提交
136 137 138 139

	led_thread = rt_thread_create("led",
								rt_led_thread_entry, RT_NULL,
								512, 20, 20);
B
bernard.xiong 已提交
140 141 142 143
#else
	init_thread = rt_thread_create("init",
								rt_init_thread_entry, RT_NULL,
								2048, 80, 20);
A
 
aganhx@gmail.com 已提交
144 145 146 147

	led_thread = rt_thread_create("led",
								rt_led_thread_entry, RT_NULL,
								512, 200, 20);
B
bernard.xiong 已提交
148
#endif
149

B
bernard.xiong 已提交
150 151
	if (init_thread != RT_NULL)
		rt_thread_startup(init_thread);
152

A
 
aganhx@gmail.com 已提交
153 154 155
	if(led_thread != RT_NULL)
		rt_thread_startup(led_thread);

B
bernard.xiong 已提交
156
	return 0;
157
}
B
bernard.xiong 已提交
158 159

/*@}*/