application.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 - 2012, 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. * 2011-02-24 Bernard the first version
  13. */
  14. /**
  15. * @addtogroup FM3
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #include "board.h"
  20. #include "led.h"
  21. #include "key.h"
  22. #include "adc.h"
  23. #include "lcd.h"
  24. #include "cpuusage.h"
  25. #ifdef RT_USING_RTGUI
  26. #include <rtgui/rtgui.h>
  27. #include <rtgui/driver.h>
  28. extern void rtgui_startup();
  29. #endif
  30. struct rt_messagequeue mq;
  31. static char msg_pool[2048];
  32. void rt_init_thread_entry(void *parameter)
  33. {
  34. rt_device_t lcd;
  35. rt_hw_led_init();
  36. rt_hw_key_init();
  37. rt_hw_adc_init();
  38. rt_hw_lcd_init();
  39. rt_hw_cpu_init();
  40. /* re-init device driver */
  41. rt_device_init_all();
  42. #ifdef RT_USING_RTGUI
  43. extern void rtgui_system_server_init(void);
  44. /* find lcd device */
  45. lcd = rt_device_find("lcd");
  46. /* set lcd device as rtgui graphic driver */
  47. rtgui_graphic_set_device(lcd);
  48. /* init rtgui system server */
  49. rtgui_system_server_init();
  50. /* startup rtgui */
  51. rtgui_startup();
  52. #else
  53. {
  54. char buf[20] = {'\0'};
  55. struct lcd_msg msg;
  56. rt_device_t device;
  57. device = rt_device_find("lcd");
  58. rt_device_control(device, RT_DEVICE_CTRL_LCD_CLEAR_SCR, RT_NULL);
  59. x = 1;
  60. y = 1;
  61. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "ADC");
  62. x = 1;
  63. y = 20;
  64. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "CPU");
  65. x = 1;
  66. y = 40;
  67. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "KEY");
  68. while(1)
  69. {
  70. if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK)
  71. {
  72. switch(msg.type)
  73. {
  74. case ADC_MSG:
  75. x = 40;
  76. y = 1;
  77. rt_memset(buf, 0, sizeof(buf));
  78. rt_sprintf(buf, "%04d", msg.adc_value);
  79. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  80. break;
  81. case CPU_MSG:
  82. x = 40;
  83. y = 20;
  84. rt_memset(buf, 0, sizeof(buf));
  85. rt_sprintf(buf, "%03d %03d", msg.major, msg.minor);
  86. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  87. break;
  88. case KEY_MSG:
  89. x = 40;
  90. y = 40;
  91. rt_memset(buf, 0, sizeof(buf));
  92. switch(msg.key)
  93. {
  94. case KEY_DOWN:
  95. rt_sprintf(buf, "DOWN KEY ");
  96. break;
  97. case KEY_UP:
  98. rt_sprintf(buf, "UP KEY ");
  99. break;
  100. case KEY_RIGHT:
  101. rt_sprintf(buf, "RIGHT KEY");
  102. break;
  103. case KEY_LEFT:
  104. rt_sprintf(buf, "LEFT KEY ");
  105. break;
  106. case KEY_ENTER:
  107. rt_sprintf(buf, "ENTER KEY");
  108. break;
  109. default:
  110. rt_sprintf(buf, "NO KEY ");
  111. break;
  112. }
  113. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  114. break;
  115. }
  116. }
  117. }
  118. }
  119. #endif
  120. }
  121. int rt_application_init(void)
  122. {
  123. rt_thread_t init_thread;
  124. rt_mq_init(&mq, "mqt", &msg_pool[0], 128 - sizeof(void*), sizeof(msg_pool), RT_IPC_FLAG_FIFO);
  125. init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024, 21, 20);
  126. if(init_thread != RT_NULL)
  127. rt_thread_startup(init_thread);
  128. return 0;
  129. }
  130. /*@}*/