application.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2015, 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. * 2017-09-14 Haley the first version
  13. */
  14. /**
  15. * @addtogroup APOLLO2
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #include <stdint.h>
  20. #ifdef RT_USING_FINSH
  21. #include <finsh.h>
  22. #include <shell.h>
  23. #endif
  24. #include "hw_led.h"
  25. ALIGN(RT_ALIGN_SIZE)
  26. static rt_uint8_t led_stack[ 512 ];
  27. static struct rt_thread led_thread;
  28. static void led_thread_entry(void* parameter)
  29. {
  30. unsigned int count=0;
  31. rt_hw_led_init(0);
  32. rt_hw_led_init(1);
  33. while (1)
  34. {
  35. /* led1 on */
  36. #ifndef RT_USING_FINSH
  37. rt_kprintf("led on, count : %d\r\n",count);
  38. #endif
  39. count++;
  40. rt_hw_led_on(0);
  41. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  42. /* led1 off */
  43. #ifndef RT_USING_FINSH
  44. rt_kprintf("led off\r\n");
  45. #endif
  46. rt_hw_led_off(0);
  47. rt_thread_delay( RT_TICK_PER_SECOND/2 );
  48. }
  49. }
  50. void rt_init_thread_entry(void* parameter)
  51. {
  52. #ifdef RT_USING_COMPONENTS_INIT
  53. /* initialization RT-Thread Components */
  54. rt_components_init();
  55. #endif
  56. }
  57. int rt_application_init(void)
  58. {
  59. rt_thread_t init_thread;
  60. rt_err_t result;
  61. /* init led thread */
  62. result = rt_thread_init(&led_thread,
  63. "led",
  64. led_thread_entry,
  65. RT_NULL,
  66. (rt_uint8_t*)&led_stack[0],
  67. sizeof(led_stack),
  68. 7,
  69. 5);
  70. if (result == RT_EOK)
  71. {
  72. rt_thread_startup(&led_thread);
  73. }
  74. init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024,
  75. RT_THREAD_PRIORITY_MAX / 3, 20);
  76. if (init_thread != RT_NULL)
  77. rt_thread_startup(init_thread);
  78. return 0;
  79. }
  80. /*@}*/