application.c 1.8 KB

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