application.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. * 2010-05-02 Aozima add led function
  9. */
  10. #include <rtthread.h>
  11. #include <board.h>
  12. #ifdef RT_USING_DFS
  13. /* dfs init */
  14. #include <dfs.h>
  15. /* dfs filesystem:ELM FatFs filesystem init */
  16. #include <dfs_elm.h>
  17. /* dfs Filesystem APIs */
  18. #include <dfs_fs.h>
  19. #endif
  20. #ifdef RT_USING_LWIP
  21. #include <lwip/sys.h>
  22. #include <lwip/api.h>
  23. #include <netif/ethernetif.h>
  24. #endif
  25. #ifdef RT_USING_RTGUI
  26. #include <rtgui/driver.h>
  27. #endif
  28. #ifdef RT_USING_FINSH
  29. #include <shell.h>
  30. #include <finsh.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. #ifdef RT_USING_FINSH
  83. /* initialize finsh */
  84. finsh_system_init();
  85. #endif
  86. }
  87. // init led
  88. #define rt_hw_led_init() LPC_GPIO2->DIR |= 1<<25;
  89. // trun on led n
  90. #define rt_hw_led_on(n) LPC_GPIO2->CLR |= 1<<25;
  91. // trun off led n
  92. #define rt_hw_led_off(n) LPC_GPIO2->SET |= 1<<25;
  93. rt_align(RT_ALIGN_SIZE)
  94. static char thread_led_stack[1024];
  95. struct rt_thread thread_led;
  96. static void rt_thread_entry_led(void* parameter)
  97. {
  98. unsigned int count=0;
  99. rt_hw_led_init();
  100. while (1)
  101. {
  102. /* led on */
  103. #ifndef RT_USING_FINSH
  104. rt_kprintf("led on,count : %d\r\n",count);
  105. #endif
  106. count++;
  107. rt_hw_led_on(1);
  108. /* sleep 0.5 second and switch to other thread */
  109. rt_thread_delay(RT_TICK_PER_SECOND/2);
  110. /* led off */
  111. #ifndef RT_USING_FINSH
  112. rt_kprintf("led off\r\n");
  113. #endif
  114. rt_hw_led_off(1);
  115. rt_thread_delay(RT_TICK_PER_SECOND/2);
  116. }
  117. }
  118. int rt_application_init(void)
  119. {
  120. rt_thread_t tid;
  121. rt_thread_init(&thread_led,
  122. "led",
  123. rt_thread_entry_led,
  124. RT_NULL,
  125. &thread_led_stack[0],
  126. sizeof(thread_led_stack),11,5);
  127. rt_thread_startup(&thread_led);
  128. tid = rt_thread_create("init",
  129. rt_init_thread_entry, RT_NULL,
  130. 2048, RT_THREAD_PRIORITY_MAX/3, 20);
  131. if (tid != RT_NULL) rt_thread_startup(tid);
  132. return 0;
  133. }
  134. #if defined(RT_USING_RTGUI) && defined(RT_USING_FINSH)
  135. #include <rtgui/rtgui_server.h>
  136. #include <rtgui/event.h>
  137. #include <rtgui/kbddef.h>
  138. #include <finsh.h>
  139. void key(rt_uint32_t key)
  140. {
  141. struct rtgui_event_kbd ekbd;
  142. RTGUI_EVENT_KBD_INIT(&ekbd);
  143. ekbd.mod = RTGUI_KMOD_NONE;
  144. ekbd.unicode = 0;
  145. ekbd.key = key;
  146. ekbd.type = RTGUI_KEYDOWN;
  147. rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd));
  148. rt_thread_delay(2);
  149. ekbd.type = RTGUI_KEYUP;
  150. rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd));
  151. }
  152. FINSH_FUNCTION_EXPORT(key, send a key to gui server);
  153. #endif