userled.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * File : userled.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. * 2012-09-20 heyuanjie first version
  23. * 2012-09-29 lgnq re-fromat the coding style
  24. */
  25. #include <rtthread.h>
  26. #include "drv_led.h"
  27. #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
  28. #include <finsh.h>
  29. #endif
  30. static rt_thread_t tid;
  31. /**
  32. * This function is the entry of the led thread
  33. *
  34. * @param param parameter of the led thread
  35. */
  36. static void rt_userled_thread_init(void *param)
  37. {
  38. led_init();
  39. led_set(1);
  40. /* leds blink */
  41. while (1)
  42. {
  43. led_set(0);
  44. rt_thread_delay(RT_TICK_PER_SECOND / 100);
  45. led_clear(0);
  46. rt_thread_delay(RT_TICK_PER_SECOND);
  47. }
  48. }
  49. /**
  50. * This function will create and start a led thread
  51. */
  52. void rt_hw_userled_init(void)
  53. {
  54. tid = rt_thread_create("userled",
  55. rt_userled_thread_init,
  56. RT_NULL,
  57. 512,
  58. 8,
  59. 1);
  60. if (tid != RT_NULL)
  61. rt_thread_startup(tid);
  62. }
  63. void rt_hw_userled_cleanup(void)
  64. {
  65. rt_enter_critical();
  66. led_clear(0);
  67. if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
  68. {
  69. rt_kprintf("delete led thread success\n");
  70. rt_thread_delete(tid);
  71. }
  72. else
  73. {
  74. rt_kprintf("delete led thread faild\n");
  75. if (tid == RT_NULL)
  76. rt_kprintf("tid is null\n");
  77. else
  78. rt_kprintf("tid stat is %d\n", tid->stat);
  79. }
  80. rt_exit_critical();
  81. }
  82. #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
  83. MSH_CMD_EXPORT_ALIAS(rt_hw_userled_cleanup, led_cleanup, delete led task);
  84. #endif
  85. void rt_hw_userled_input(void)
  86. {
  87. led_deinit();
  88. }
  89. #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
  90. MSH_CMD_EXPORT_ALIAS(rt_hw_userled_input, led_as_input, delete led task);
  91. #endif