1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2011-01-13 weety first version
9 */
10
11 /**
12 * @addtogroup at91sam9260
13 */
14 /*@{*/
15
16 #include <rtthread.h>
17 #include <rtdevice.h>
18
19 #ifdef RT_USING_DFS
20 /* dfs Filesystem APIs */
21 #include <dfs_fs.h>
22 #endif
23
24 #ifdef RT_USING_SDIO
25 #include <drivers/dev_mmcsd_core.h>
26 #include "at91_mci.h"
27 #endif
28
29 #ifdef RT_USING_LED
30 #include "led.h"
31 #endif
32
33 static int rt_led_app_init(void);
34
main(void)35 int main(void)
36 {
37 int timeout = 0;
38
39 /* Filesystem Initialization */
40 #ifdef RT_USING_DFS
41 {
42 #if defined(RT_USING_DFS_ROMFS)
43 if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
44 {
45 rt_kprintf("ROM File System initialized!\n");
46 }
47 else
48 rt_kprintf("ROM File System initialzation failed!\n");
49 #endif
50
51 #if defined(RT_USING_DFS_UFFS)
52 {
53 /* mount flash device as flash directory */
54 if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
55 rt_kprintf("UFFS File System initialized!\n");
56 else
57 rt_kprintf("UFFS File System initialzation failed!\n");
58 }
59 #endif
60
61 #ifdef RT_USING_SDIO
62 timeout = 0;
63 while ((rt_device_find("sd0") == RT_NULL) && (timeout++ < RT_TICK_PER_SECOND*2))
64 {
65 rt_thread_delay(1);
66 }
67
68 if (timeout < RT_TICK_PER_SECOND*2)
69 {
70 /* mount sd card fat partition 1 as root directory */
71 if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
72 {
73 rt_kprintf("File System initialized!\n");
74 }
75 else
76 rt_kprintf("File System initialzation failed!%d\n", rt_get_errno());
77 }
78 else
79 {
80 rt_kprintf("No SD card found.\n");
81 }
82 #endif
83 }
84 #endif
85
86 #ifdef RT_USING_LED
87 rt_led_app_init();
88 #endif
89 }
90
91 #ifdef RT_USING_LED
rt_led_thread_entry(void * parameter)92 void rt_led_thread_entry(void* parameter)
93 {
94 rt_uint8_t cnt = 0;
95 led_init();
96 while(1)
97 {
98 /* light on leds for one second */
99 rt_thread_delay(40);
100 cnt++;
101 if (cnt&0x01)
102 led_on(1);
103 else
104 led_off(1);
105 if (cnt&0x02)
106 led_on(2);
107 else
108 led_off(2);
109 if (cnt&0x04)
110 led_on(3);
111 else
112 led_off(3);
113 }
114 }
115 #endif
116
rt_led_app_init(void)117 static int rt_led_app_init(void)
118 {
119 #ifdef RT_USING_LED
120 rt_thread_t led_thread;
121
122 #if (RT_THREAD_PRIORITY_MAX == 32)
123 led_thread = rt_thread_create("led",
124 rt_led_thread_entry, RT_NULL,
125 512, 20, 20);
126 #else
127 led_thread = rt_thread_create("led",
128 rt_led_thread_entry, RT_NULL,
129 512, 200, 20);
130 #endif
131
132 if(led_thread != RT_NULL)
133 rt_thread_startup(led_thread);
134 #endif
135
136 return 0;
137 }
138
139 /* NFSv3 Initialization */
140 #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
141 #include <dfs_nfs.h>
nfs_start(void)142 void nfs_start(void)
143 {
144 nfs_init();
145
146 if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
147 {
148 rt_kprintf("NFSv3 File System initialized!\n");
149 }
150 else
151 rt_kprintf("NFSv3 File System initialzation failed!\n");
152 }
153
154 #include "finsh.h"
155 FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
156 #endif
157
158 /*@}*/
159