summaryrefslogtreecommitdiff
path: root/bsp/mini4020/applications/application.c
blob: 65295e4c4765ee0b075fc37b74e35f8285be919f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * File      : application.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author		Notes
 * 2007-11-20     Yi.Qiu		add rtgui application
 * 2008-6-28      Bernard		no rtgui init
 */

/**
 * @addtogroup mini4020
 */
 
/*@{*/

#include <board.h>
#include <rtthread.h>

#ifdef RT_USING_DFS
#include <dfs_init.h>
#include <dfs_elm.h>
#include <dfs_fs.h>
#include <dfs_posix.h>
#endif

#ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h>
extern void radio_rtgui_init(void);
#endif

#define RT_INIT_THREAD_STACK_SIZE (2*1024)

void rt_init_thread_entry(void *parameter)
{
	int fd;
	rt_uint32_t sz;
	char buffer[20];
#ifdef RT_USING_DFS
	dfs_init();
#ifdef RT_USING_DFS_ELMFAT
	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");

		/*Open a file*/
		fd = open("/fattest.txt", O_RDWR|O_CREAT, 0);
		if (fd < 0)
		{
			rt_kprintf("open file for write failed\n");
			return;
		}

		sz = write(fd,"Hello RT-Thread!",sizeof("Hello RT-Thread!"));

		if (sz != 0)
		{
			rt_kprintf("written %d\n",sz);
		}
		else
			rt_kprintf("haven't written\n");

		lseek(fd, 0, SEEK_SET);
		
		sz = read(fd, buffer, sizeof(buffer));

		if (sz != 0)
		{
			rt_kprintf("READ %d:",sz);
			while (sz--)
				rt_kprintf("%c",buffer[sz]);//opposite
			rt_kprintf("\n");
		}
		else
			rt_kprintf("haven't read\n");

		close(fd);
	}
	else
		rt_kprintf("File System initialzation failed!\n");
#endif	
#endif
}

void rt_led_thread_entry(void *parameter)
{
/*
    while (1)
    {
        count++;
        *(RP)GPIO_PORTE_DATA |= 0x1<<4;
        rt_thread_delay(RT_TICK_PER_SECOND*2);

        *(RP)GPIO_PORTE_DATA &= ~(0x1<<4);
        rt_thread_delay(RT_TICK_PER_SECOND*2);

    }
*/
}


int rt_application_init(void)
{
	rt_thread_t init_thread;
	rt_thread_t led_thread;

	init_thread = rt_thread_create("init",
								rt_init_thread_entry, RT_NULL,
								RT_INIT_THREAD_STACK_SIZE, 8, 20);
	led_thread = rt_thread_create("led",
								rt_led_thread_entry, RT_NULL,
								512, 200, 20);

	if (init_thread != RT_NULL)
		rt_thread_startup(init_thread);

	if (led_thread != RT_NULL)
		rt_thread_startup(led_thread);
	
	return 0;
}

/*@}*/