application.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, 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. * 2009-01-05 Bernard the first version
  13. * 2010-03-04 Magicoe for LPC1766 version
  14. * 2010-05-02 Aozima add led function
  15. * 2010-05-24 Bernard add filesystem initialization and move led function to led.c
  16. */
  17. /**
  18. * @addtogroup LPC1700
  19. */
  20. /*@{*/
  21. #include <rtthread.h>
  22. #include <board.h>
  23. #ifdef RT_USING_DFS
  24. /* dfs init */
  25. #include <dfs_init.h>
  26. /* dfs filesystem:ELM FatFs filesystem init */
  27. #include <dfs_elm.h>
  28. /* dfs Filesystem APIs */
  29. #include <dfs_fs.h>
  30. #endif
  31. #ifdef RT_USING_LWIP
  32. #include <lwip/sys.h>
  33. #include <lwip/api.h>
  34. #include <netif/ethernetif.h>
  35. #endif
  36. /* thread phase init */
  37. void rt_init_thread_entry(void *parameter)
  38. {
  39. /* Filesystem Initialization */
  40. #ifdef RT_USING_DFS
  41. {
  42. /* init the device filesystem */
  43. dfs_init();
  44. /* init the elm FAT filesystam*/
  45. elm_init();
  46. /* mount sd card fat partition 1 as root directory */
  47. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  48. rt_kprintf("File System initialized!\n");
  49. else
  50. rt_kprintf("File System init failed!\n");
  51. }
  52. #endif
  53. /* LwIP Initialization */
  54. #ifdef RT_USING_LWIP
  55. {
  56. extern void lwip_sys_init(void);
  57. extern void lpc17xx_emac_hw_init(void);
  58. eth_system_device_init();
  59. /* register ethernetif device */
  60. lpc17xx_emac_hw_init();
  61. /* init all device */
  62. rt_device_init_all();
  63. /* init lwip system */
  64. lwip_sys_init();
  65. rt_kprintf("TCP/IP initialized!\n");
  66. }
  67. #endif
  68. }
  69. // init led
  70. #define rt_hw_led_init() LPC_GPIO2->DIR |= 1<<25;
  71. // trun on led n
  72. #define rt_hw_led_on(n) LPC_GPIO2->CLR |= 1<<25;
  73. // trun off led n
  74. #define rt_hw_led_off(n) LPC_GPIO2->SET |= 1<<25;
  75. ALIGN(RT_ALIGN_SIZE)
  76. static char thread_led_stack[1024];
  77. struct rt_thread thread_led;
  78. static void rt_thread_entry_led(void* parameter)
  79. {
  80. unsigned int count=0;
  81. rt_hw_led_init();
  82. while (1)
  83. {
  84. /* led on */
  85. #ifndef RT_USING_FINSH
  86. rt_kprintf("led on,count : %d\r\n",count);
  87. #endif
  88. count++;
  89. rt_hw_led_on(1);
  90. /* sleep 0.5 second and switch to other thread */
  91. rt_thread_delay(RT_TICK_PER_SECOND/2);
  92. /* led off */
  93. #ifndef RT_USING_FINSH
  94. rt_kprintf("led off\r\n");
  95. #endif
  96. rt_hw_led_off(1);
  97. rt_thread_delay(RT_TICK_PER_SECOND/2);
  98. }
  99. }
  100. int rt_application_init()
  101. {
  102. rt_thread_t init_thread;
  103. //------- init led thread
  104. rt_thread_init(&thread_led,
  105. "led",
  106. rt_thread_entry_led,
  107. RT_NULL,
  108. &thread_led_stack[0],
  109. sizeof(thread_led_stack),11,5);
  110. rt_thread_startup(&thread_led);
  111. #if (RT_THREAD_PRIORITY_MAX == 32)
  112. init_thread = rt_thread_create("init",
  113. rt_init_thread_entry, RT_NULL,
  114. 2048, 8, 20);
  115. #else
  116. init_thread = rt_thread_create("init",
  117. rt_init_thread_entry, RT_NULL,
  118. 2048, 80, 20);
  119. #endif
  120. if (init_thread != RT_NULL) rt_thread_startup(init_thread);
  121. return 0;
  122. }
  123. /*@}*/