application.c 3.5 KB

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