application.c 4.0 KB

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