application.c 3.4 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
#include <rtthread.h>
qiuyiuestc's avatar
qiuyiuestc 已提交
22
#include "dm9000.h"
23
#include "touch.h"
A
 
aganhx@gmail.com 已提交
24
#include "led.h"
25 26 27 28

#ifdef RT_USING_DFS
/* dfs init */
#include <dfs_init.h>
B
bernard.xiong 已提交
29 30
/* dfs filesystem:ELM FatFs filesystem init */
#include <dfs_elm.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
#ifdef RT_USING_RTGUI
qiuyiuestc's avatar
qiuyiuestc 已提交
40
#include <rtgui/rtgui.h>
qiuyiuestc's avatar
qiuyiuestc 已提交
41
extern void rt_hw_touch_init(void);
A
 
aganhx@gmail.com 已提交
42 43
#endif

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

B
bernard.xiong 已提交
52
#if defined(RT_USING_DFS_ELMFAT)
B
bernard.xiong 已提交
53 54 55 56 57 58 59 60 61 62
		/* 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");
63
#endif
B
bernard.xiong 已提交
64
	}
65 66
#endif

67 68
#ifdef RT_USING_RTGUI
	{
qiuyiuestc's avatar
qiuyiuestc 已提交
69 70 71
		/* init touch panel */
		rtgui_touch_hw_init();	

qiuyiuestc's avatar
qiuyiuestc 已提交
72 73 74
		/* re-init device driver */
		rt_device_init_all();		
		
qiuyiuestc's avatar
qiuyiuestc 已提交
75
		/* startup rtgui */
76 77 78 79
		rtgui_startup();
	}
#endif

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

B
bernard.xiong 已提交
86 87
		/* register ethernetif device */
		rt_hw_dm9000_init();
88

B
bernard.xiong 已提交
89 90
		/* re-init device driver */
		rt_device_init_all();
91

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

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

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

	}
}

B
bernard.xiong 已提交
116 117 118
int rt_application_init()
{
	rt_thread_t init_thread;
A
 
aganhx@gmail.com 已提交
119
	rt_thread_t led_thread;
B
bernard.xiong 已提交
120 121 122 123 124

#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 已提交
125 126 127 128

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

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

B
bernard.xiong 已提交
139 140
	if (init_thread != RT_NULL)
		rt_thread_startup(init_thread);
141

A
 
aganhx@gmail.com 已提交
142 143 144
	if(led_thread != RT_NULL)
		rt_thread_startup(led_thread);

B
bernard.xiong 已提交
145
	return 0;
146
}
B
bernard.xiong 已提交
147

qiuyiuestc's avatar
qiuyiuestc 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
/* NFSv3 Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
#include <dfs_nfs.h>
void nfs_start(void)
{
	nfs_init();

	if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
	{
		rt_kprintf("NFSv3 File System initialized!\n");
	}
	else
		rt_kprintf("NFSv3 File System initialzation failed!\n");
}

#include "finsh.h"
FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
#endif

B
bernard.xiong 已提交
167
/*@}*/