main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * File : main.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-09-14 Haley the first version
  23. */
  24. #include <rtthread.h>
  25. #ifdef RT_USING_FINSH
  26. #include <finsh.h>
  27. #include <shell.h>
  28. #endif
  29. #include "led.h"
  30. static rt_uint8_t led_stack[ 512 ];
  31. static struct rt_thread led_thread;
  32. static void led_thread_entry(void* parameter)
  33. {
  34. unsigned int count=0;
  35. while (1)
  36. {
  37. /* led1 on */
  38. #ifndef RT_USING_FINSH
  39. rt_kprintf("led on, count : %d\r\n",count);
  40. #endif
  41. count++;
  42. rt_hw_led_on(0);
  43. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  44. /* led1 off */
  45. #ifndef RT_USING_FINSH
  46. rt_kprintf("led off\r\n");
  47. #endif
  48. rt_hw_led_off(0);
  49. rt_thread_delay( RT_TICK_PER_SECOND/2 );
  50. }
  51. }
  52. int main(void)
  53. {
  54. rt_err_t result;
  55. /* init led thread */
  56. result = rt_thread_init(&led_thread,
  57. "led",
  58. led_thread_entry,
  59. RT_NULL,
  60. (rt_uint8_t*)&led_stack[0],
  61. sizeof(led_stack),
  62. RT_THREAD_PRIORITY_MAX/3,
  63. 5);
  64. if (result == RT_EOK)
  65. {
  66. rt_thread_startup(&led_thread);
  67. }
  68. return 0;
  69. }
  70. /*@}*/