1
0

application.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /** File : application.c
  2. * This file is part of RT-Thread RTOS
  3. * COPYRIGHT (C) 2006 - 2012, RT-Thread Develop Team
  4. *
  5. * The license and distribution terms for this file may be
  6. * found in the file LICENSE in this distribution or at
  7. * http://openlab.rt-thread.com/license/LICENSE
  8. *
  9. * Change Logs:
  10. * Date Author Notes
  11. * 2006-09-15 QiuYi the first version
  12. */
  13. /**
  14. * @addtogroup QEMU
  15. */
  16. /*@{*/
  17. #include <rtthread.h>
  18. ALIGN(RT_ALIGN_SIZE)
  19. static char thread_led1_stack[1024];
  20. struct rt_thread thread_led1;
  21. static void rt_thread_entry_led1(void *parameter)
  22. {
  23. unsigned int count=0;
  24. while (1)
  25. {
  26. /* led1 on */
  27. #ifndef RT_USING_FINSH
  28. rt_kprintf("led1 on,count : %d\r\n",count);
  29. #endif
  30. count ++;
  31. /* sleep 0.5 second and switch to other thread */
  32. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  33. /* led1 off */
  34. #ifndef RT_USING_FINSH
  35. rt_kprintf("led1 off\r\n");
  36. #endif
  37. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  38. }
  39. }
  40. ALIGN(RT_ALIGN_SIZE)
  41. static char thread_led2_stack[1024];
  42. struct rt_thread thread_led2;
  43. void rt_thread_entry_led2(void *parameter)
  44. {
  45. unsigned int count=0;
  46. while (1)
  47. {
  48. /* led2 on */
  49. #ifndef RT_USING_FINSH
  50. rt_kprintf("led2 on,count : %d\r\n",count);
  51. #endif
  52. count ++;
  53. rt_thread_delay(RT_TICK_PER_SECOND);
  54. /* led2 off */
  55. #ifndef RT_USING_FINSH
  56. rt_kprintf("led2 off\r\n");
  57. #endif
  58. rt_thread_delay(RT_TICK_PER_SECOND);
  59. }
  60. }
  61. /**
  62. * This function will be invoked to initalize user application when system
  63. * startup.
  64. */
  65. int rt_application_init(void)
  66. {
  67. // init led1 thread
  68. rt_thread_init(&thread_led1,
  69. "led1",
  70. rt_thread_entry_led1,
  71. RT_NULL,
  72. &thread_led1_stack[0],
  73. sizeof(thread_led1_stack),11,5);
  74. rt_thread_startup(&thread_led1);
  75. // init led2 thread
  76. rt_thread_init(&thread_led2,
  77. "led2",
  78. rt_thread_entry_led2,
  79. RT_NULL,
  80. &thread_led2_stack[0],
  81. sizeof(thread_led2_stack),12,5);
  82. rt_thread_startup(&thread_led2);
  83. return 0;
  84. }
  85. /*@}*/