application.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifdef RT_USING_RTGUI
  41. extern void rtgui_system_server_init(void);
  42. /* find lcd device */
  43. lcd = rt_device_find("lcd");
  44. /* set lcd device as rtgui graphic driver */
  45. rtgui_graphic_set_device(lcd);
  46. /* init rtgui system server */
  47. rtgui_system_server_init();
  48. /* startup rtgui */
  49. rtgui_startup();
  50. #else
  51. {
  52. char buf[20] = {'\0'};
  53. struct lcd_msg msg;
  54. rt_device_t device;
  55. device = rt_device_find("lcd");
  56. rt_device_control(device, RT_DEVICE_CTRL_LCD_CLEAR_SCR, RT_NULL);
  57. x = 1;
  58. y = 1;
  59. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "ADC");
  60. x = 1;
  61. y = 20;
  62. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "CPU");
  63. x = 1;
  64. y = 40;
  65. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "KEY");
  66. while(1)
  67. {
  68. if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK)
  69. {
  70. switch(msg.type)
  71. {
  72. case ADC_MSG:
  73. x = 40;
  74. y = 1;
  75. rt_memset(buf, 0, sizeof(buf));
  76. rt_sprintf(buf, "%04d", msg.adc_value);
  77. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  78. break;
  79. case CPU_MSG:
  80. x = 40;
  81. y = 20;
  82. rt_memset(buf, 0, sizeof(buf));
  83. rt_sprintf(buf, "%03d %03d", msg.major, msg.minor);
  84. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  85. break;
  86. case KEY_MSG:
  87. x = 40;
  88. y = 40;
  89. rt_memset(buf, 0, sizeof(buf));
  90. switch(msg.key)
  91. {
  92. case KEY_DOWN:
  93. rt_sprintf(buf, "DOWN KEY ");
  94. break;
  95. case KEY_UP:
  96. rt_sprintf(buf, "UP KEY ");
  97. break;
  98. case KEY_RIGHT:
  99. rt_sprintf(buf, "RIGHT KEY");
  100. break;
  101. case KEY_LEFT:
  102. rt_sprintf(buf, "LEFT KEY ");
  103. break;
  104. case KEY_ENTER:
  105. rt_sprintf(buf, "ENTER KEY");
  106. break;
  107. default:
  108. rt_sprintf(buf, "NO KEY ");
  109. break;
  110. }
  111. rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf);
  112. break;
  113. }
  114. }
  115. }
  116. }
  117. #endif
  118. }
  119. int rt_application_init(void)
  120. {
  121. rt_thread_t init_thread;
  122. rt_mq_init(&mq, "mqt", &msg_pool[0], 128 - sizeof(void*), sizeof(msg_pool), RT_IPC_FLAG_FIFO);
  123. init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024, 21, 20);
  124. if(init_thread != RT_NULL)
  125. rt_thread_startup(init_thread);
  126. return 0;
  127. }
  128. /*@}*/