application.c 3.1 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 "led.h"
24 25 26 27 28

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

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

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

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

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

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

A
 
aganhx@gmail.com 已提交
77 78
#ifdef RT_USING_RTGUI
	{
qiuyiuestc's avatar
qiuyiuestc 已提交
79
		rtgui_startup();
A
 
aganhx@gmail.com 已提交
80 81 82
	}
#endif

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

B
bernard.xiong 已提交
89 90
		/* register ethernetif device */
		rt_hw_dm9000_init();
91

B
bernard.xiong 已提交
92 93
		/* re-init device driver */
		rt_device_init_all();
94

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

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

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

	}
}

A
 
aganhx@gmail.com 已提交
119

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

#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 已提交
129 130 131 132

	led_thread = rt_thread_create("led",
								rt_led_thread_entry, RT_NULL,
								512, 20, 20);
B
bernard.xiong 已提交
133 134 135 136
#else
	init_thread = rt_thread_create("init",
								rt_init_thread_entry, RT_NULL,
								2048, 80, 20);
A
 
aganhx@gmail.com 已提交
137 138 139 140

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

B
bernard.xiong 已提交
143 144
	if (init_thread != RT_NULL)
		rt_thread_startup(init_thread);
145

A
 
aganhx@gmail.com 已提交
146 147 148
	if(led_thread != RT_NULL)
		rt_thread_startup(led_thread);

B
bernard.xiong 已提交
149
	return 0;
150
}
B
bernard.xiong 已提交
151 152

/*@}*/