applications.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <rtthread.h>
  2. static void rt_init_thread_entry(void* parameter)
  3. {
  4. #ifdef RT_USING_COMPONENTS_INIT
  5. /* initialization RT-Thread Components */
  6. rt_components_init();
  7. #endif
  8. rt_thread_delay( RT_TIMER_TICK_PER_SECOND*2 ); /* sleep 0.5 second and switch to other thread */
  9. }
  10. static void led_thread_entry(void* parameter)
  11. {
  12. unsigned int count=0;
  13. rt_hw_led_init();
  14. while (1)
  15. {
  16. /* led1 on */
  17. #ifndef RT_USING_FINSH
  18. /* rt_kprintf("led on, count : %d\r\n",count);*/
  19. #endif
  20. count++;
  21. rt_hw_led_on(0);
  22. rt_thread_delay( RT_TIMER_TICK_PER_SECOND*2 ); /* sleep 0.5 second and switch to other thread */
  23. /* led1 off */
  24. #ifndef RT_USING_FINSH
  25. /* rt_kprintf("led off\r\n");*/
  26. #endif
  27. rt_hw_led_off(0);
  28. rt_thread_delay( RT_TIMER_TICK_PER_SECOND*2);
  29. }
  30. }
  31. static rt_uint8_t led_stack[ 512 ];
  32. static struct rt_thread led_thread;
  33. void rt_application_init()
  34. {
  35. rt_thread_t init_thread;
  36. rt_err_t result;
  37. /* init led thread */
  38. result = rt_thread_init(&led_thread,
  39. "led",
  40. led_thread_entry,
  41. RT_NULL,
  42. (rt_uint8_t*)&led_stack[0],
  43. sizeof(led_stack),
  44. 20,
  45. 5);
  46. if (result == RT_EOK)
  47. {
  48. rt_thread_startup(&led_thread);
  49. }
  50. init_thread = rt_thread_create("init",
  51. rt_init_thread_entry, RT_NULL,
  52. 2048, 8, 20);
  53. if (init_thread != RT_NULL)
  54. rt_thread_startup(init_thread);
  55. return;
  56. }