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 rt_weak int main(void)
36 {
37 #ifdef RT_USING_SDIO
38 int timeout = 0;
39 #endif
40
41 /* Filesystem Initialization */
42 #ifdef RT_USING_DFS
43 {
44 #if defined(RT_USING_DFS_ROMFS)
45 if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
46 {
47 rt_kprintf("ROM File System initialized!\n");
48 }
49 else
50 rt_kprintf("ROM File System initialzation failed!\n");
51 #endif
52
53 #if defined(RT_USING_DFS_UFFS)
54 {
55 /* mount flash device as flash directory */
56 if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
57 rt_kprintf("UFFS File System initialized!\n");
58 else
59 rt_kprintf("UFFS File System initialzation failed!\n");
60 }
61 #endif
62
63 #ifdef RT_USING_SDIO
64 timeout = 0;
65 while ((rt_device_find("sd0") == RT_NULL) && (timeout++ < RT_TICK_PER_SECOND*2))
66 {
67 rt_thread_delay(1);
68 }
69
70 if (timeout < RT_TICK_PER_SECOND*2)
71 {
72 /* mount sd card fat partition 1 as root directory */
73 if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
74 {
75 rt_kprintf("File System initialized!\n");
76 }
77 else
78 rt_kprintf("File System initialzation failed!%d\n", rt_get_errno());
79 }
80 else
81 {
82 rt_kprintf("No SD card found.\n");
83 }
84 #endif
85 }
86 #endif
87
88 rt_led_app_init();
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 }
116 #endif
117
rt_led_app_init(void)118 static int rt_led_app_init(void)
119 {
120 #ifdef RT_USING_LED
121 rt_thread_t led_thread;
122
123 #if (RT_THREAD_PRIORITY_MAX == 32)
124 led_thread = rt_thread_create("led",
125 rt_led_thread_entry, RT_NULL,
126 512, 20, 20);
127 #else
128 led_thread = rt_thread_create("led",
129 rt_led_thread_entry, RT_NULL,
130 512, 200, 20);
131 #endif
132
133 if(led_thread != RT_NULL)
134 rt_thread_startup(led_thread);
135 #endif
136
137 return 0;
138 }
139
140 /* NFSv3 Initialization */
141 #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
142 #include <dfs_nfs.h>
nfs_start(void)143 void nfs_start(void)
144 {
145 nfs_init();
146
147 if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
148 {
149 rt_kprintf("NFSv3 File System initialized!\n");
150 }
151 else
152 rt_kprintf("NFSv3 File System initialzation failed!\n");
153 }
154
155 #include "finsh.h"
156 FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
157 #endif
158
159 /*@}*/
160