blink.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * File : blink.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 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-11-8 Tangyuxin first version
  23. */
  24. #include <rtthread.h>
  25. #include <board.h>
  26. #include <drv_gpio.h>
  27. void blink_task(void* param)
  28. {
  29. rt_uint8_t cnt = 0;
  30. while(1)
  31. {
  32. rt_thread_delay(RT_TICK_PER_SECOND / 4);
  33. if(cnt & 0x01)
  34. gpio_set_value(BLINK_LED0_PORT,BLINK_LED0_PIN,0);
  35. else
  36. gpio_set_value(BLINK_LED0_PORT,BLINK_LED0_PIN,1);
  37. if(cnt & 0x02)
  38. gpio_set_value(BLINK_LED1_PORT,BLINK_LED1_PIN,0);
  39. else
  40. gpio_set_value(BLINK_LED1_PORT,BLINK_LED1_PIN,1);
  41. if(cnt & 0x04)
  42. gpio_set_value(BLINK_LED2_PORT,BLINK_LED2_PIN,0);
  43. else
  44. gpio_set_value(BLINK_LED2_PORT,BLINK_LED2_PIN,1);
  45. if(cnt & 0x08)
  46. gpio_set_value(BLINK_LED3_PORT,BLINK_LED3_PIN,0);
  47. else
  48. gpio_set_value(BLINK_LED3_PORT,BLINK_LED3_PIN,1);
  49. cnt ++;
  50. }
  51. }
  52. int blink_init(void)
  53. {
  54. rt_thread_t tid;
  55. tid = rt_thread_create("blink",
  56. blink_task, RT_NULL,
  57. 512,
  58. RT_THREAD_PRIORITY_MAX - 2,
  59. 10);
  60. if (tid != RT_NULL)
  61. rt_thread_startup(tid);
  62. }
  63. INIT_APP_EXPORT(blink_init);