application.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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. * 2009-01-05 Bernard the first version
  13. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #include "led.h"
  20. char thread_led1_stack[512];
  21. struct rt_thread thread_led1;
  22. static void rt_thread_entry_led1(void* parameter)
  23. {
  24. /* init led configuration */
  25. rt_hw_led_init();
  26. while (1)
  27. {
  28. /* led on */
  29. rt_kprintf("led1 on\r\n");
  30. rt_hw_led_on(0);
  31. rt_thread_delay(50); /* sleep 0.5 second and switch to other thread */
  32. /* led off */
  33. rt_kprintf("led1 off\r\n");
  34. rt_hw_led_off(0);
  35. rt_thread_delay(50);
  36. }
  37. }
  38. char thread_led2_stack[512];
  39. struct rt_thread thread_led2;
  40. void rt_thread_entry_led2(void* parameter)
  41. {
  42. unsigned int count=0;
  43. while (1)
  44. {
  45. /* led on */
  46. rt_kprintf("led2 on,count : %d\r\n",count);
  47. count++;
  48. rt_hw_led_on(1);
  49. rt_thread_delay(RT_TICK_PER_SECOND);
  50. /* led off */
  51. rt_kprintf("led2 off\r\n");
  52. rt_hw_led_off(1);
  53. rt_thread_delay(RT_TICK_PER_SECOND);
  54. }
  55. }
  56. int rt_application_init()
  57. {
  58. /* init led1 thread */
  59. rt_thread_init(&thread_led1,
  60. "led1",
  61. rt_thread_entry_led1,
  62. RT_NULL,
  63. &thread_led1_stack[0],
  64. sizeof(thread_led1_stack),10,10);
  65. rt_thread_startup(&thread_led1);
  66. /* init led2 thread */
  67. rt_thread_init(&thread_led2,
  68. "led2",
  69. rt_thread_entry_led2,
  70. RT_NULL,
  71. &thread_led2_stack[0],
  72. sizeof(thread_led2_stack),10,10);
  73. rt_thread_startup(&thread_led2);
  74. return 0;
  75. }
  76. /*@}*/