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>
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 40 41 42 43
#ifdef RT_USING_RTGUI
extern void rt_hw_lcd_init(void);
extern void rt_hw_key_init(void);
#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 69 70 71 72 73 74
#ifdef RT_USING_RTGUI
	{
		rtgui_touch_hw_init();
		
		rtgui_startup();
	}
#endif

B
bernard.xiong 已提交
75
/* LwIP Initialization */
76
#ifdef RT_USING_LWIP
B
bernard.xiong 已提交
77 78 79
	{
		extern void lwip_sys_init(void);
		eth_system_device_init();
80

B
bernard.xiong 已提交
81 82
		/* register ethernetif device */
		rt_hw_dm9000_init();
83

B
bernard.xiong 已提交
84 85
		/* re-init device driver */
		rt_device_init_all();
86

B
bernard.xiong 已提交
87 88 89 90
		/* init lwip system */
		lwip_sys_init();
		rt_kprintf("TCP/IP initialized!\n");
	}
91
#endif
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106
/* NFSv3 Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
	{
		extern void nfs_init(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");
	}
#endif
B
bernard.xiong 已提交
107
}
108

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

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

	}
}

B
bernard.xiong 已提交
126 127 128
int rt_application_init()
{
	rt_thread_t init_thread;
A
 
aganhx@gmail.com 已提交
129
	rt_thread_t led_thread;
B
bernard.xiong 已提交
130 131 132 133 134

#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 已提交
135 136 137 138

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

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

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

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

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

/*@}*/