main.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-09-14 Haley the first version
  9. */
  10. #include <rtthread.h>
  11. #ifdef RT_USING_FINSH
  12. #include <finsh.h>
  13. #include <shell.h>
  14. #endif
  15. #include "led.h"
  16. static rt_uint8_t led_stack[ 512 ];
  17. static struct rt_thread led_thread;
  18. static void led_thread_entry(void* parameter)
  19. {
  20. unsigned int count=0;
  21. while (1)
  22. {
  23. /* led1 on */
  24. #ifndef RT_USING_FINSH
  25. rt_kprintf("led on, count : %d\r\n",count);
  26. #endif
  27. count++;
  28. rt_hw_led_on(0);
  29. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  30. /* led1 off */
  31. #ifndef RT_USING_FINSH
  32. rt_kprintf("led off\r\n");
  33. #endif
  34. rt_hw_led_off(0);
  35. rt_thread_delay( RT_TICK_PER_SECOND/2 );
  36. }
  37. }
  38. int main(void)
  39. {
  40. rt_err_t result;
  41. /* init led thread */
  42. result = rt_thread_init(&led_thread,
  43. "led",
  44. led_thread_entry,
  45. RT_NULL,
  46. (rt_uint8_t*)&led_stack[0],
  47. sizeof(led_stack),
  48. RT_THREAD_PRIORITY_MAX/3,
  49. 5);
  50. if (result == RT_EOK)
  51. {
  52. rt_thread_startup(&led_thread);
  53. }
  54. return 0;
  55. }
  56. /*@}*/