application.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2011-01-13 weety first version
  23. */
  24. /**
  25. * @addtogroup dm365
  26. */
  27. /*@{*/
  28. #include <rtthread.h>
  29. //#include <rtdevice.h>
  30. #ifdef RT_USING_DFS
  31. /* dfs filesystem:ELM FatFs filesystem init */
  32. #include <dfs_elm.h>
  33. /* dfs Filesystem APIs */
  34. #include <dfs_fs.h>
  35. #ifdef RT_USING_DFS_UFFS
  36. /* dfs filesystem:UFFS filesystem init */
  37. #include <dfs_uffs.h>
  38. #endif
  39. #endif
  40. #if defined(RT_USING_DFS_DEVFS)
  41. #include <devfs.h>
  42. #endif
  43. #ifdef RT_USING_SDIO
  44. #include <drivers/mmcsd_core.h>
  45. #endif
  46. #ifdef RT_USING_LWIP
  47. #include <netif/ethernetif.h>
  48. #endif
  49. #ifdef RT_USING_SPI
  50. #include <spi-davinci.h>
  51. #endif
  52. #ifdef RT_USING_LED
  53. #include "led.h"
  54. #endif
  55. #define RT_INIT_THREAD_STACK_SIZE (2*1024)
  56. #ifdef RT_USING_DFS_ROMFS
  57. #include <dfs_romfs.h>
  58. #endif
  59. void rt_init_thread_entry(void* parameter)
  60. {
  61. platform_init();
  62. /* Filesystem Initialization */
  63. #ifdef RT_USING_DFS
  64. {
  65. /* init the device filesystem */
  66. dfs_init();
  67. #if defined(RT_USING_DFS_ELMFAT)
  68. /* init the elm chan FatFs filesystam*/
  69. elm_init();
  70. #endif
  71. #if defined(RT_USING_DFS_ROMFS)
  72. dfs_romfs_init();
  73. if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
  74. {
  75. rt_kprintf("ROM File System initialized!\n");
  76. }
  77. else
  78. rt_kprintf("ROM File System initialzation failed!\n");
  79. #endif
  80. #if defined(RT_USING_DFS_DEVFS)
  81. devfs_init();
  82. if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
  83. rt_kprintf("Device File System initialized!\n");
  84. else
  85. rt_kprintf("Device File System initialzation failed!\n");
  86. #ifdef RT_USING_NEWLIB
  87. /* init libc */
  88. libc_system_init(RT_CONSOLE_DEVICE_NAME);
  89. #endif
  90. #endif
  91. #if defined(RT_USING_DFS_UFFS)
  92. {
  93. /* init the uffs filesystem */
  94. dfs_uffs_init();
  95. /* mount flash device as flash directory */
  96. if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
  97. rt_kprintf("UFFS File System initialized!\n");
  98. else
  99. rt_kprintf("UFFS File System initialzation failed!\n");
  100. }
  101. #endif
  102. #ifdef RT_USING_I2C
  103. {
  104. rt_i2c_core_init();
  105. davinci_i2c_init("I2C1");
  106. }
  107. #endif
  108. #ifdef RT_USING_SPI
  109. {
  110. rt_hw_spi_init();
  111. }
  112. #endif
  113. #ifdef RT_USING_SDIO
  114. rt_mmcsd_core_init();
  115. rt_mmcsd_blk_init();
  116. rt_hw_mmcsd_init();
  117. rt_thread_delay(RT_TICK_PER_SECOND*2);
  118. /* mount sd card fat partition 1 as root directory */
  119. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  120. {
  121. rt_kprintf("File System initialized!\n");
  122. }
  123. else
  124. rt_kprintf("File System initialzation failed!%d\n", rt_get_errno());
  125. #endif
  126. }
  127. #endif
  128. #ifdef RT_USING_LWIP
  129. {
  130. /* register ethernetif device */
  131. eth_system_device_init();
  132. rt_hw_davinci_emac_init();
  133. /* init lwip system */
  134. lwip_system_init();
  135. }
  136. #endif
  137. }
  138. void rt_led_thread_entry(void* parameter)
  139. {
  140. while(1)
  141. {
  142. /* light on leds for one second */
  143. rt_thread_delay(100);
  144. /* light off leds for one second */
  145. rt_thread_delay(100);
  146. }
  147. }
  148. int rt_application_init()
  149. {
  150. rt_thread_t init_thread;
  151. #ifdef RT_USING_LED
  152. rt_thread_t led_thread;
  153. #endif
  154. #if (RT_THREAD_PRIORITY_MAX == 32)
  155. init_thread = rt_thread_create("init",
  156. rt_init_thread_entry, RT_NULL,
  157. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  158. #ifdef RT_USING_LED
  159. led_thread = rt_thread_create("led",
  160. rt_led_thread_entry, RT_NULL,
  161. 512, 20, 20);
  162. #endif
  163. #else
  164. init_thread = rt_thread_create("init",
  165. rt_init_thread_entry, RT_NULL,
  166. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  167. #ifdef RT_USING_LED
  168. led_thread = rt_thread_create("led",
  169. rt_led_thread_entry, RT_NULL,
  170. 512, 200, 20);
  171. #endif
  172. #endif
  173. if (init_thread != RT_NULL)
  174. rt_thread_startup(init_thread);
  175. #ifdef RT_USING_LED
  176. if(led_thread != RT_NULL)
  177. rt_thread_startup(led_thread);
  178. #endif
  179. return 0;
  180. }
  181. /* NFSv3 Initialization */
  182. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  183. #include <dfs_nfs.h>
  184. void nfs_start(void)
  185. {
  186. nfs_init();
  187. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  188. {
  189. rt_kprintf("NFSv3 File System initialized!\n");
  190. }
  191. else
  192. rt_kprintf("NFSv3 File System initialzation failed!\n");
  193. }
  194. #include "finsh.h"
  195. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  196. #endif
  197. /*@}*/