application.c 3.5 KB

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