application.c 3.2 KB

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