application.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. * 2006-06-05 Bernard the first version
  9. */
  10. #include <rtthread.h>
  11. /**
  12. * @addtogroup LPC2148
  13. */
  14. /*@{*/
  15. #ifdef RT_USING_FINSH
  16. #include <shell.h>
  17. #include <finsh.h>
  18. #endif
  19. #ifdef RT_USING_DFS
  20. /* dfs init */
  21. #include <dfs.h>
  22. /* dfs filesystem:FAT filesystem init */
  23. #include <dfs_fat.h>
  24. /* dfs filesystem:EFS filesystem init */
  25. #include <dfs_efs.h>
  26. /* dfs Filesystem APIs */
  27. #include <dfs_fs.h>
  28. #endif
  29. #ifdef RT_USING_LWIP
  30. #include <lwip/sys.h>
  31. #endif
  32. #ifdef RT_USING_RTGUI
  33. #include <rtgui/rtgui.h>
  34. #endif
  35. /* thread phase init */
  36. void rt_init_thread_entry(void *parameter)
  37. {
  38. #ifdef RT_USING_DEVICE
  39. #ifdef RT_USING_DFS
  40. /* init sd card */
  41. rt_hw_sdcard_init();
  42. #endif
  43. #ifdef RT_USING_LWIP
  44. eth_system_device_init();
  45. /* init ethernetif device */
  46. rt_hw_dm9000_init();
  47. #endif
  48. /* init hardware serial device */
  49. rt_hw_serial_init();
  50. #endif
  51. /* Filesystem Initialization */
  52. #ifdef RT_USING_DFS
  53. {
  54. /* init the device filesystem */
  55. dfs_init();
  56. elm_init();
  57. /* mount sd card fat partition 1 as root directory */
  58. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  59. rt_kprintf("File System initialized!\n");
  60. else
  61. rt_kprintf("File System init failed!\n");
  62. }
  63. #endif
  64. /* LwIP Initialization */
  65. #ifdef RT_USING_LWIP
  66. {
  67. extern void lwip_sys_init(void);
  68. /* init lwip system */
  69. lwip_sys_init();
  70. rt_kprintf("TCP/IP initialized!\n");
  71. }
  72. #endif
  73. #ifdef RT_USING_FINSH
  74. finsh_system_init();
  75. #endif
  76. }
  77. /************** LED BLINK *******************/
  78. #include "lpc214x.h"
  79. #define LED1 (1<<16) //P1
  80. #define LED2 (1<<17) //P1
  81. #define LED3 (1<<18) //P1
  82. #define LED4 (1<<19) //P1
  83. rt_align(4) char thread_led1_stack[512];
  84. struct rt_thread thread_led1;
  85. void thread_led1_entry(void *parameter)
  86. {
  87. unsigned int count = 0;
  88. IO1DIR |= LED1;
  89. while (1)
  90. {
  91. /* led1 on */
  92. IO1CLR = LED1;
  93. #ifndef RT_USING_FINSH
  94. rt_kprintf("led1 on, count : %d\r\n", count);
  95. #endif
  96. count++;
  97. rt_thread_delay(RT_TICK_PER_SECOND / 3); /* delay 0.3s */
  98. /* led1 off */
  99. IO1SET = LED1;
  100. #ifndef RT_USING_FINSH
  101. rt_kprintf("led1 off\r\n");
  102. #endif
  103. rt_thread_delay(RT_TICK_PER_SECOND / 3);
  104. }
  105. }
  106. rt_align(4) char thread_led2_stack[512];
  107. struct rt_thread thread_led2;
  108. void thread_led2_entry(void *parameter)
  109. {
  110. unsigned int count = 0;
  111. IO1DIR |= LED2;
  112. while (1)
  113. {
  114. /* led2 on */
  115. IO1CLR = LED2;
  116. #ifndef RT_USING_FINSH
  117. rt_kprintf("led2 on, count : %d\r\n", count);
  118. #endif
  119. count++;
  120. rt_thread_delay(RT_TICK_PER_SECOND / 2); /* delay 0.5s */
  121. /* led2 off */
  122. IO1SET = LED2;
  123. #ifndef RT_USING_FINSH
  124. rt_kprintf("led1 off\r\n");
  125. #endif
  126. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  127. }
  128. }
  129. /************** LED BLINK *******************/
  130. int rt_application_init()
  131. {
  132. rt_thread_init(&thread_led1,
  133. "led1",
  134. thread_led1_entry, RT_NULL,
  135. &thread_led1_stack[0], sizeof(thread_led1_stack),
  136. 20, 10);
  137. rt_thread_init(&thread_led2,
  138. "led2",
  139. thread_led2_entry, RT_NULL,
  140. &thread_led2_stack[0], sizeof(thread_led2_stack),
  141. 25, 8);
  142. rt_thread_startup(&thread_led1);
  143. rt_thread_startup(&thread_led2);
  144. /* inint SD-crad and dm9000 */
  145. {
  146. rt_thread_t init_thread;
  147. init_thread = rt_thread_create("init",
  148. rt_init_thread_entry, RT_NULL,
  149. 1024, 8, 5);
  150. rt_thread_startup(init_thread);
  151. }
  152. return 0;
  153. }
  154. /*@}*/