application.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-09-15 QiuYi the first version
  13. */
  14. /**
  15. * @addtogroup QEMU
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. ALIGN(RT_ALIGN_SIZE)
  20. static char thread_led1_stack[1024];
  21. struct rt_thread thread_led1;
  22. static void rt_thread_entry_led1(void* parameter)
  23. {
  24. unsigned int count=0;
  25. while (1)
  26. {
  27. /* led1 on */
  28. #ifndef RT_USING_FINSH
  29. rt_kprintf("led1 on,count : %d\r\n",count);
  30. #endif
  31. count++;
  32. /* sleep 0.5 second and switch to other thread */
  33. rt_thread_delay(RT_TICK_PER_SECOND/2);
  34. /* led1 off */
  35. #ifndef RT_USING_FINSH
  36. rt_kprintf("led1 off\r\n");
  37. #endif
  38. rt_thread_delay(RT_TICK_PER_SECOND/2);
  39. }
  40. }
  41. ALIGN(RT_ALIGN_SIZE)
  42. static char thread_led2_stack[1024];
  43. struct rt_thread thread_led2;
  44. void rt_thread_entry_led2(void* parameter)
  45. {
  46. unsigned int count=0;
  47. while (1)
  48. {
  49. /* led2 on */
  50. #ifndef RT_USING_FINSH
  51. rt_kprintf("led2 on,count : %d\r\n",count);
  52. #endif
  53. count++;
  54. rt_thread_delay(RT_TICK_PER_SECOND);
  55. /* led2 off */
  56. #ifndef RT_USING_FINSH
  57. rt_kprintf("led2 off\r\n");
  58. #endif
  59. rt_thread_delay(RT_TICK_PER_SECOND);
  60. }
  61. }
  62. /**
  63. * This function will be invoked to initalize user application when system startup.
  64. */
  65. int rt_application_init()
  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; /* empty */
  84. }
  85. /*@}*/