application.c 2.8 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

#ifdef RT_USING_DFS
/* dfs init */
#include <dfs_init.h>
B
bernard.xiong 已提交
28 29
/* dfs filesystem:ELM FatFs filesystem init */
#include <dfs_elm.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
#ifdef defined(RT_USING_DFS_ELMFAT)
B
bernard.xiong 已提交
52 53 54 55 56 57 58 59 60 61
		/* 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");
62
#endif
B
bernard.xiong 已提交
63
	}
64 65
#endif

B
bernard.xiong 已提交
66
/* LwIP Initialization */
67
#ifdef RT_USING_LWIP
B
bernard.xiong 已提交
68 69 70
	{
		extern void lwip_sys_init(void);
		eth_system_device_init();
71

B
bernard.xiong 已提交
72 73
		/* register ethernetif device */
		rt_hw_dm9000_init();
74

B
bernard.xiong 已提交
75 76
		/* re-init device driver */
		rt_device_init_all();
77

B
bernard.xiong 已提交
78 79 80 81
		/* init lwip system */
		lwip_sys_init();
		rt_kprintf("TCP/IP initialized!\n");
	}
82
#endif
83 84 85 86 87 88 89

#ifdef RT_USING_RTGUI
	{
		rt_hw_touch_init();
		rtgui_startup();
	}
#endif
B
bernard.xiong 已提交
90
}
91

A
 
aganhx@gmail.com 已提交
92 93 94 95
void rt_led_thread_entry(void* parameter)
{
	while(1)
	{
A
 
aganhx@gmail.com 已提交
96
		/* light on leds for one second */
A
 
aganhx@gmail.com 已提交
97
		rt_hw_led_on(LED2|LED3);
A
 
aganhx@gmail.com 已提交
98
		rt_hw_led_off(LED1|LED4);
A
 
aganhx@gmail.com 已提交
99 100
		rt_thread_delay(100);

A
 
aganhx@gmail.com 已提交
101
		/* light off leds for one second */
A
 
aganhx@gmail.com 已提交
102
		rt_hw_led_off(LED2|LED3);
A
 
aganhx@gmail.com 已提交
103
		rt_hw_led_on(LED1|LED4);
A
 
aganhx@gmail.com 已提交
104 105 106 107 108
		rt_thread_delay(100);

	}
}

A
 
aganhx@gmail.com 已提交
109

B
bernard.xiong 已提交
110 111 112
int rt_application_init()
{
	rt_thread_t init_thread;
A
 
aganhx@gmail.com 已提交
113
	rt_thread_t led_thread;
B
bernard.xiong 已提交
114 115 116 117 118

#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 已提交
119 120 121 122

	led_thread = rt_thread_create("led",
								rt_led_thread_entry, RT_NULL,
								512, 20, 20);
B
bernard.xiong 已提交
123 124 125 126
#else
	init_thread = rt_thread_create("init",
								rt_init_thread_entry, RT_NULL,
								2048, 80, 20);
A
 
aganhx@gmail.com 已提交
127 128 129 130

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

B
bernard.xiong 已提交
133 134
	if (init_thread != RT_NULL)
		rt_thread_startup(init_thread);
135

A
 
aganhx@gmail.com 已提交
136 137 138
	if(led_thread != RT_NULL)
		rt_thread_startup(led_thread);

B
bernard.xiong 已提交
139
	return 0;
140
}
B
bernard.xiong 已提交
141 142

/*@}*/