application.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifdef RT_USING_COMPONENTS_INIT
  22. #include <components.h>
  23. #endif /* RT_USING_COMPONENTS_INIT */
  24. #include "led.h"
  25. /* led thread entry */
  26. static void led_thread_entry(void* parameter)
  27. {
  28. while(1)
  29. {
  30. rt_hw_led_on();
  31. rt_thread_delay(RT_TICK_PER_SECOND);
  32. rt_hw_led_off();
  33. rt_thread_delay(RT_TICK_PER_SECOND);
  34. }
  35. }
  36. static void rt_init_thread_entry(void* parameter)
  37. {
  38. rt_thread_t led_thread;
  39. /* Initialization RT-Thread Components */
  40. #ifdef RT_USING_COMPONENTS_INIT
  41. rt_components_init();
  42. #endif
  43. /* Set finsh device */
  44. #ifdef RT_USING_FINSH
  45. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  46. #endif /* RT_USING_FINSH */
  47. /* Create led thread */
  48. led_thread = rt_thread_create("led",
  49. led_thread_entry, RT_NULL,
  50. 128, 20, 20);
  51. if(led_thread != RT_NULL)
  52. rt_thread_startup(led_thread);
  53. }
  54. int rt_application_init()
  55. {
  56. rt_thread_t init_thread;
  57. #if (RT_THREAD_PRIORITY_MAX == 32)
  58. init_thread = rt_thread_create("init",
  59. rt_init_thread_entry, RT_NULL,
  60. 512, 8, 20);
  61. #else
  62. init_thread = rt_thread_create("init",
  63. rt_init_thread_entry, RT_NULL,
  64. 512, 80, 20);
  65. #endif
  66. if(init_thread != RT_NULL)
  67. rt_thread_startup(init_thread);
  68. return 0;
  69. }
  70. /*@}*/