demo_thread.c 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <rtthread.h>
  2. #include "drv_led.h"
  3. #include "drv_uart.h"
  4. static void thread1_entry(void* parameter)
  5. {
  6. while(1)
  7. {
  8. Led_Control(0,1);
  9. rt_thread_delay(RT_TICK_PER_SECOND);
  10. Led_Control(0,0);
  11. rt_thread_delay(RT_TICK_PER_SECOND);
  12. }
  13. }
  14. static void thread2_entry(void* parameter)
  15. {
  16. while(1)
  17. {
  18. Led_Control(1,1);
  19. rt_thread_delay(RT_TICK_PER_SECOND);
  20. Led_Control(1,0);
  21. rt_thread_delay(RT_TICK_PER_SECOND);
  22. }
  23. }
  24. int demo_init(void)
  25. {
  26. rt_thread_t thread1 = RT_NULL;
  27. rt_thread_t thread2 = RT_NULL;
  28. rt_led_hw_init();
  29. thread1 = rt_thread_create("t1",thread1_entry, RT_NULL,512,10,5);
  30. if (thread1 != RT_NULL)
  31. rt_thread_startup(thread1);
  32. thread2 = rt_thread_create("t2",thread2_entry, RT_NULL,512,10,5);
  33. if (thread2 != RT_NULL)
  34. rt_thread_startup(thread2);
  35. return 0;
  36. }