application.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-01-13 weety first version
  13. */
  14. /**
  15. * @addtogroup at91sam9260
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #ifdef RT_USING_DFS
  20. /* dfs init */
  21. #include <dfs_init.h>
  22. /* dfs filesystem:ELM FatFs filesystem init */
  23. #include <dfs_elm.h>
  24. /* dfs Filesystem APIs */
  25. #include <dfs_fs.h>
  26. #ifdef RT_USING_DFS_UFFS
  27. /* dfs filesystem:UFFS filesystem init */
  28. #include <dfs_uffs.h>
  29. #endif
  30. #endif
  31. #if defined(RT_USING_DFS_DEVFS)
  32. #include <devfs.h>
  33. #endif
  34. #ifdef RT_USING_SDIO
  35. #include <mmcsd_core.h>
  36. #include "at91_mci.h"
  37. #endif
  38. #ifdef RT_USING_LWIP
  39. #include <netif/ethernetif.h>
  40. //#include <arch/sys_arch_init.h>
  41. #include "macb.h"
  42. #endif
  43. #ifdef RT_USING_LED
  44. #include "led.h"
  45. #endif
  46. #define RT_INIT_THREAD_STACK_SIZE (2*1024)
  47. #ifdef RT_USING_DFS_ROMFS
  48. #include <dfs_romfs.h>
  49. #endif
  50. #ifdef RT_USING_I2C
  51. #include <i2c.h>
  52. static struct rt_i2c_hardware_info hw_info[] = {
  53. { RT_I2C_HARDWARE_INFO("pcf8563", 0, 0xA2 >> 1, 0), },
  54. };
  55. #endif
  56. void rt_init_thread_entry(void* parameter)
  57. {
  58. /* Filesystem Initialization */
  59. #ifdef RT_USING_DFS
  60. {
  61. /* init the device filesystem */
  62. dfs_init();
  63. #if defined(RT_USING_DFS_ELMFAT)
  64. /* init the elm chan FatFs filesystam*/
  65. elm_init();
  66. #endif
  67. #if defined(RT_USING_DFS_ROMFS)
  68. dfs_romfs_init();
  69. if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
  70. {
  71. rt_kprintf("ROM File System initialized!\n");
  72. }
  73. else
  74. rt_kprintf("ROM File System initialzation failed!\n");
  75. #endif
  76. #if defined(RT_USING_DFS_DEVFS)
  77. devfs_init();
  78. if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
  79. rt_kprintf("Device File System initialized!\n");
  80. else
  81. rt_kprintf("Device File System initialzation failed!\n");
  82. #ifdef RT_USING_NEWLIB
  83. /* init libc */
  84. libc_system_init("uart0");
  85. #endif
  86. #endif
  87. #if defined(RT_USING_DFS_UFFS)
  88. {
  89. /* init the uffs filesystem */
  90. dfs_uffs_init();
  91. /* mount flash device as flash directory */
  92. if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
  93. rt_kprintf("UFFS File System initialized!\n");
  94. else
  95. rt_kprintf("UFFS File System initialzation failed!\n");
  96. }
  97. #endif
  98. #ifdef RT_USING_SDIO
  99. rt_mmcsd_core_init();
  100. rt_mmcsd_blk_init();
  101. at91_mci_init();
  102. rt_thread_delay(RT_TICK_PER_SECOND*2);
  103. /* mount sd card fat partition 1 as root directory */
  104. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  105. {
  106. rt_kprintf("File System initialized!\n");
  107. }
  108. else
  109. rt_kprintf("File System initialzation failed!\n");
  110. #endif
  111. }
  112. #endif
  113. #ifdef RT_USING_LWIP
  114. {
  115. /* register ethernetif device */
  116. eth_system_device_init();
  117. rt_hw_macb_init();
  118. /* re-init device driver */
  119. rt_device_init_all();
  120. /* init lwip system */
  121. lwip_sys_init();
  122. }
  123. #endif
  124. #ifdef RT_USING_I2C
  125. {
  126. rt_i2c_core_init();
  127. rt_i2c_hw_info_register(hw_info, 1);
  128. at91_i2c_init();
  129. }
  130. #endif
  131. }
  132. #ifdef RT_USING_LED
  133. void rt_led_thread_entry(void* parameter)
  134. {
  135. rt_uint8_t cnt = 0;
  136. led_init();
  137. while(1)
  138. {
  139. /* light on leds for one second */
  140. rt_thread_delay(40);
  141. cnt++;
  142. if (cnt&0x01)
  143. led_on(1);
  144. else
  145. led_off(1);
  146. if (cnt&0x02)
  147. led_on(2);
  148. else
  149. led_off(2);
  150. if (cnt&0x04)
  151. led_on(3);
  152. else
  153. led_off(3);
  154. }
  155. }
  156. #endif
  157. int rt_application_init()
  158. {
  159. rt_thread_t init_thread;
  160. #ifdef RT_USING_LED
  161. rt_thread_t led_thread;
  162. #endif
  163. #if (RT_THREAD_PRIORITY_MAX == 32)
  164. init_thread = rt_thread_create("init",
  165. rt_init_thread_entry, RT_NULL,
  166. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  167. #ifdef RT_USING_LED
  168. led_thread = rt_thread_create("led",
  169. rt_led_thread_entry, RT_NULL,
  170. 512, 20, 20);
  171. #endif
  172. #else
  173. init_thread = rt_thread_create("init",
  174. rt_init_thread_entry, RT_NULL,
  175. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  176. #ifdef RT_USING_LED
  177. led_thread = rt_thread_create("led",
  178. rt_led_thread_entry, RT_NULL,
  179. 512, 200, 20);
  180. #endif
  181. #endif
  182. if (init_thread != RT_NULL)
  183. rt_thread_startup(init_thread);
  184. #ifdef RT_USING_LED
  185. if(led_thread != RT_NULL)
  186. rt_thread_startup(led_thread);
  187. #endif
  188. return 0;
  189. }
  190. /* NFSv3 Initialization */
  191. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  192. #include <dfs_nfs.h>
  193. void nfs_start(void)
  194. {
  195. nfs_init();
  196. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  197. {
  198. rt_kprintf("NFSv3 File System initialized!\n");
  199. }
  200. else
  201. rt_kprintf("NFSv3 File System initialzation failed!\n");
  202. }
  203. #include "finsh.h"
  204. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  205. #endif
  206. /*@}*/