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