application.c 3.2 KB

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