application.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. static void rt_thread_entry_led1(void* parameter)
  21. {
  22. /* init led configuration */
  23. rt_hw_led_init();
  24. while (1)
  25. {
  26. /* led on */
  27. rt_kprintf("led1 on\r\n");
  28. rt_hw_led_on(0);
  29. rt_thread_delay(50); /* sleep 0.5 second and switch to other thread */
  30. /* led off */
  31. rt_kprintf("led1 off\r\n");
  32. rt_hw_led_off(0);
  33. rt_thread_delay(50);
  34. }
  35. }
  36. char thread_led2_stack[1024];
  37. struct rt_thread thread_led2;
  38. void rt_thread_entry_led2(void* parameter)
  39. {
  40. unsigned int count=0;
  41. while (1)
  42. {
  43. /* led on */
  44. rt_kprintf("led2 on,count : %d\r\n",count);
  45. count++;
  46. rt_hw_led_on(1);
  47. rt_thread_delay(RT_TICK_PER_SECOND);
  48. /* led off */
  49. rt_kprintf("led2 off\r\n");
  50. rt_hw_led_off(1);
  51. rt_thread_delay(RT_TICK_PER_SECOND);
  52. }
  53. }
  54. int rt_application_init()
  55. {
  56. rt_thread_t thread;
  57. /* create led1 thread */
  58. thread = rt_thread_create("led1",
  59. rt_thread_entry_led1, RT_NULL,
  60. 512,
  61. 20, 5);
  62. if (thread != RT_NULL)
  63. rt_thread_startup(thread);
  64. //------- init led2 thread
  65. rt_thread_init(&thread_led2,
  66. "led2",
  67. rt_thread_entry_led2,
  68. RT_NULL,
  69. &thread_led2_stack[0],
  70. sizeof(thread_led2_stack),10,10);
  71. rt_thread_startup(&thread_led2);
  72. return 0;
  73. }
  74. /*@}*/