blink.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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-11-8 Tangyuxin first version
  9. */
  10. #include <rtthread.h>
  11. #include <board.h>
  12. #include <drv_gpio.h>
  13. void blink_task(void* param)
  14. {
  15. rt_uint8_t cnt = 0;
  16. while(1)
  17. {
  18. rt_thread_delay(RT_TICK_PER_SECOND / 4);
  19. if(cnt & 0x01)
  20. gpio_set_value(BLINK_LED0_PORT,BLINK_LED0_PIN,0);
  21. else
  22. gpio_set_value(BLINK_LED0_PORT,BLINK_LED0_PIN,1);
  23. if(cnt & 0x02)
  24. gpio_set_value(BLINK_LED1_PORT,BLINK_LED1_PIN,0);
  25. else
  26. gpio_set_value(BLINK_LED1_PORT,BLINK_LED1_PIN,1);
  27. if(cnt & 0x04)
  28. gpio_set_value(BLINK_LED2_PORT,BLINK_LED2_PIN,0);
  29. else
  30. gpio_set_value(BLINK_LED2_PORT,BLINK_LED2_PIN,1);
  31. if(cnt & 0x08)
  32. gpio_set_value(BLINK_LED3_PORT,BLINK_LED3_PIN,0);
  33. else
  34. gpio_set_value(BLINK_LED3_PORT,BLINK_LED3_PIN,1);
  35. cnt ++;
  36. }
  37. }
  38. int blink_init(void)
  39. {
  40. rt_thread_t tid;
  41. tid = rt_thread_create("blink",
  42. blink_task, RT_NULL,
  43. 512,
  44. RT_THREAD_PRIORITY_MAX - 2,
  45. 10);
  46. if (tid != RT_NULL)
  47. rt_thread_startup(tid);
  48. }
  49. INIT_APP_EXPORT(blink_init);