application.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2014, 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. * 2014-11-23 Bright first implementation
  13. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include <stdio.h>
  19. #include <board.h>
  20. #include <rtthread.h>
  21. #include "led.h"
  22. /* led thread entry */
  23. static void led_thread_entry(void* parameter)
  24. {
  25. while(1)
  26. {
  27. rt_hw_led_on();
  28. rt_thread_delay(RT_TICK_PER_SECOND);
  29. rt_hw_led_off();
  30. rt_thread_delay(RT_TICK_PER_SECOND);
  31. }
  32. }
  33. static void rt_init_thread_entry(void* parameter)
  34. {
  35. rt_thread_t led_thread;
  36. /* Initialization RT-Thread Components */
  37. #ifdef RT_USING_COMPONENTS_INIT
  38. rt_components_init();
  39. #endif
  40. /* Set finsh device */
  41. #ifdef RT_USING_FINSH
  42. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  43. #endif /* RT_USING_FINSH */
  44. /* Create led thread */
  45. led_thread = rt_thread_create("led",
  46. led_thread_entry, RT_NULL,
  47. 128, 20, 20);
  48. if(led_thread != RT_NULL)
  49. rt_thread_startup(led_thread);
  50. }
  51. int rt_application_init()
  52. {
  53. rt_thread_t init_thread;
  54. #if (RT_THREAD_PRIORITY_MAX == 32)
  55. init_thread = rt_thread_create("init",
  56. rt_init_thread_entry, RT_NULL,
  57. 512, 8, 20);
  58. #else
  59. init_thread = rt_thread_create("init",
  60. rt_init_thread_entry, RT_NULL,
  61. 512, 80, 20);
  62. #endif
  63. if(init_thread != RT_NULL)
  64. rt_thread_startup(init_thread);
  65. return 0;
  66. }
  67. /*@}*/