application.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2009-01-05 Bernard the first version
  9. * 2013-11-15 bright add init thread and components initial
  10. */
  11. /**
  12. * @addtogroup STM32
  13. */
  14. /*@{*/
  15. #include <stdio.h>
  16. #include <board.h>
  17. #include <rtthread.h>
  18. #include "led.h"
  19. /* led thread entry */
  20. static void led_thread_entry(void* parameter)
  21. {
  22. while(1)
  23. {
  24. rt_hw_led_on();
  25. rt_thread_delay(RT_TICK_PER_SECOND);
  26. rt_hw_led_off();
  27. rt_thread_delay(RT_TICK_PER_SECOND);
  28. }
  29. }
  30. static void rt_init_thread_entry(void* parameter)
  31. {
  32. rt_thread_t led_thread;
  33. /* Initialization RT-Thread Components */
  34. #ifdef RT_USING_COMPONENTS_INIT
  35. rt_components_init();
  36. #endif
  37. /* Set finsh device */
  38. #ifdef RT_USING_FINSH
  39. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  40. #endif /* RT_USING_FINSH */
  41. /* Create led thread */
  42. led_thread = rt_thread_create("led",
  43. led_thread_entry, RT_NULL,
  44. 256, 20, 20);
  45. if(led_thread != RT_NULL)
  46. rt_thread_startup(led_thread);
  47. }
  48. int rt_application_init()
  49. {
  50. rt_thread_t init_thread;
  51. #if (RT_THREAD_PRIORITY_MAX == 32)
  52. init_thread = rt_thread_create("init",
  53. rt_init_thread_entry, RT_NULL,
  54. 512, 8, 20);
  55. #else
  56. init_thread = rt_thread_create("init",
  57. rt_init_thread_entry, RT_NULL,
  58. 512, 80, 20);
  59. #endif
  60. if(init_thread != RT_NULL)
  61. rt_thread_startup(init_thread);
  62. return 0;
  63. }
  64. /*@}*/