application.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_DFS
  20. /* dfs init */
  21. #include <dfs_init.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. /* Filesystem Initialization */
  39. #ifdef RT_USING_DFS
  40. {
  41. /* init the device filesystem */
  42. dfs_init();
  43. /* init the efsl filesystam*/
  44. efsl_init();
  45. /* mount sd card fat partition 1 as root directory */
  46. if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
  47. rt_kprintf("File System initialized!\n");
  48. else
  49. rt_kprintf("File System init failed!\n");
  50. }
  51. #endif
  52. /* LwIP Initialization */
  53. #ifdef RT_USING_LWIP
  54. {
  55. extern void lwip_sys_init(void);
  56. /* init lwip system */
  57. lwip_sys_init();
  58. rt_kprintf("TCP/IP initialized!\n");
  59. }
  60. #endif
  61. }
  62. /************** LED BLINK *******************/
  63. #include "lpc214x.h"
  64. #define LED1 (1<<16) //P1
  65. #define LED2 (1<<17) //P1
  66. #define LED3 (1<<18) //P1
  67. #define LED4 (1<<19) //P1
  68. ALIGN(4) char thread_led1_stack[512];
  69. struct rt_thread thread_led1;
  70. void thread_led1_entry(void* parameter)
  71. {
  72. unsigned int count=0;
  73. IO1DIR |= LED1;
  74. while(1)
  75. {
  76. /* led1 on */
  77. IO1CLR = LED1;
  78. #ifndef RT_USING_FINSH
  79. rt_kprintf("led1 on, count : %d\r\n",count);
  80. #endif
  81. count++;
  82. rt_thread_delay( RT_TICK_PER_SECOND/3 ); /* delay 0.3s */
  83. /* led1 off */
  84. IO1SET = LED1;
  85. #ifndef RT_USING_FINSH
  86. rt_kprintf("led1 off\r\n");
  87. #endif
  88. rt_thread_delay( RT_TICK_PER_SECOND/3 );
  89. }
  90. }
  91. ALIGN(4) char thread_led2_stack[512];
  92. struct rt_thread thread_led2;
  93. void thread_led2_entry(void* parameter)
  94. {
  95. unsigned int count=0;
  96. IO1DIR |= LED2;
  97. while(1)
  98. {
  99. /* led2 on */
  100. IO1CLR = LED2;
  101. #ifndef RT_USING_FINSH
  102. rt_kprintf("led2 on, count : %d\r\n",count);
  103. #endif
  104. count++;
  105. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* delay 0.5s */
  106. /* led2 off */
  107. IO1SET = LED2;
  108. #ifndef RT_USING_FINSH
  109. rt_kprintf("led1 off\r\n");
  110. #endif
  111. rt_thread_delay( RT_TICK_PER_SECOND/2 );
  112. }
  113. }
  114. /************** LED BLINK *******************/
  115. int rt_application_init()
  116. {
  117. rt_thread_init(&thread_led1,
  118. "led1",
  119. thread_led1_entry, RT_NULL,
  120. &thread_led1_stack[0], sizeof(thread_led1_stack),
  121. 20, 10);
  122. rt_thread_init(&thread_led2,
  123. "led2",
  124. thread_led2_entry, RT_NULL,
  125. &thread_led2_stack[0], sizeof(thread_led2_stack),
  126. 25, 8);
  127. rt_thread_startup(&thread_led1);
  128. rt_thread_startup(&thread_led2);
  129. /* inint SD-crad and dm9000 */
  130. {
  131. rt_thread_t init_thread;
  132. init_thread = rt_thread_create("init",
  133. rt_init_thread_entry, RT_NULL,
  134. 1024, 8, 5);
  135. rt_thread_startup(init_thread);
  136. }
  137. return 0;
  138. }
  139. /*@}*/