application.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. * 2010-05-02 Aozima add led function
  13. */
  14. #include <rtthread.h>
  15. #include <board.h>
  16. #ifdef RT_USING_DFS
  17. /* dfs init */
  18. #include <dfs_init.h>
  19. /* dfs filesystem:ELM FatFs filesystem init */
  20. #include <dfs_elm.h>
  21. /* dfs Filesystem APIs */
  22. #include <dfs_fs.h>
  23. #endif
  24. #ifdef RT_USING_LWIP
  25. #include <lwip/sys.h>
  26. #include <lwip/api.h>
  27. #include <netif/ethernetif.h>
  28. #endif
  29. #ifdef RT_USING_RTGUI
  30. #include <rtgui/driver.h>
  31. #endif
  32. /* thread phase init */
  33. void rt_init_thread_entry(void *parameter)
  34. {
  35. /* Filesystem Initialization */
  36. #ifdef RT_USING_DFS
  37. {
  38. /* init the device filesystem */
  39. dfs_init();
  40. /* init the elm FAT filesystam*/
  41. elm_init();
  42. /* mount sd card fat partition 1 as root directory */
  43. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  44. rt_kprintf("File System initialized!\n");
  45. else
  46. rt_kprintf("File System init failed!\n");
  47. }
  48. #endif
  49. /* LwIP Initialization */
  50. #ifdef RT_USING_LWIP
  51. {
  52. extern void lwip_sys_init(void);
  53. extern void lpc17xx_emac_hw_init(void);
  54. eth_system_device_init();
  55. /* register ethernetif device */
  56. lpc17xx_emac_hw_init();
  57. /* init lwip system */
  58. lwip_sys_init();
  59. rt_kprintf("TCP/IP initialized!\n");
  60. }
  61. #endif
  62. #ifdef RT_USING_RTGUI
  63. {
  64. extern void rtgui_system_server_init(void);
  65. extern void application_init(void);
  66. rt_device_t lcd;
  67. /* init lcd */
  68. rt_hw_lcd_init();
  69. /* find lcd device */
  70. lcd = rt_device_find("lcd");
  71. if (lcd != RT_NULL)
  72. {
  73. /* set lcd device as rtgui graphic driver */
  74. rtgui_graphic_set_device(lcd);
  75. /* init rtgui system server */
  76. rtgui_system_server_init();
  77. /* startup rtgui in demo of RT-Thread/GUI examples */
  78. application_init();
  79. }
  80. }
  81. #endif
  82. }
  83. // init led
  84. #define rt_hw_led_init() LPC_GPIO2->DIR |= 1<<25;
  85. // trun on led n
  86. #define rt_hw_led_on(n) LPC_GPIO2->CLR |= 1<<25;
  87. // trun off led n
  88. #define rt_hw_led_off(n) LPC_GPIO2->SET |= 1<<25;
  89. ALIGN(RT_ALIGN_SIZE)
  90. static char thread_led_stack[1024];
  91. struct rt_thread thread_led;
  92. static void rt_thread_entry_led(void* parameter)
  93. {
  94. unsigned int count=0;
  95. rt_hw_led_init();
  96. while (1)
  97. {
  98. /* led on */
  99. #ifndef RT_USING_FINSH
  100. rt_kprintf("led on,count : %d\r\n",count);
  101. #endif
  102. count++;
  103. rt_hw_led_on(1);
  104. /* sleep 0.5 second and switch to other thread */
  105. rt_thread_delay(RT_TICK_PER_SECOND/2);
  106. /* led off */
  107. #ifndef RT_USING_FINSH
  108. rt_kprintf("led off\r\n");
  109. #endif
  110. rt_hw_led_off(1);
  111. rt_thread_delay(RT_TICK_PER_SECOND/2);
  112. }
  113. }
  114. int rt_application_init(void)
  115. {
  116. rt_thread_t tid;
  117. rt_thread_init(&thread_led,
  118. "led",
  119. rt_thread_entry_led,
  120. RT_NULL,
  121. &thread_led_stack[0],
  122. sizeof(thread_led_stack),11,5);
  123. rt_thread_startup(&thread_led);
  124. tid = rt_thread_create("init",
  125. rt_init_thread_entry, RT_NULL,
  126. 2048, RT_THREAD_PRIORITY_MAX/3, 20);
  127. if (tid != RT_NULL) rt_thread_startup(tid);
  128. return 0;
  129. }
  130. #if defined(RT_USING_RTGUI) && defined(RT_USING_FINSH)
  131. #include <rtgui/rtgui_server.h>
  132. #include <rtgui/event.h>
  133. #include <rtgui/kbddef.h>
  134. #include <finsh.h>
  135. void key(rt_uint32_t key)
  136. {
  137. struct rtgui_event_kbd ekbd;
  138. RTGUI_EVENT_KBD_INIT(&ekbd);
  139. ekbd.mod = RTGUI_KMOD_NONE;
  140. ekbd.unicode = 0;
  141. ekbd.key = key;
  142. ekbd.type = RTGUI_KEYDOWN;
  143. rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd));
  144. rt_thread_delay(2);
  145. ekbd.type = RTGUI_KEYUP;
  146. rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd));
  147. }
  148. FINSH_FUNCTION_EXPORT(key, send a key to gui server);
  149. #endif