thread_delay.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. *
  8. */
  9. #include <rtthread.h>
  10. #include "tc_comm.h"
  11. /*
  12. * This is an example for delay thread
  13. */
  14. static struct rt_thread thread;
  15. static char thread_stack[THREAD_STACK_SIZE];
  16. static void thread_entry(void* parameter)
  17. {
  18. rt_tick_t tick;
  19. rt_kprintf("thread inited ok\n");
  20. rt_kprintf("thread delay 10 tick\n");
  21. tick = rt_tick_get();
  22. rt_thread_delay(10);
  23. if (rt_tick_get() - tick > 11)
  24. {
  25. tc_done(TC_STAT_FAILED);
  26. return;
  27. }
  28. rt_kprintf("thread delay 15 tick\n");
  29. tick = rt_tick_get();
  30. rt_thread_delay(15);
  31. if (rt_tick_get() - tick > 16)
  32. {
  33. tc_done(TC_STAT_FAILED);
  34. return;
  35. }
  36. rt_kprintf("thread exit\n");
  37. tc_done(TC_STAT_PASSED);
  38. }
  39. rt_err_t thread_delay_init()
  40. {
  41. rt_err_t result;
  42. result = rt_thread_init(&thread,
  43. "test",
  44. thread_entry, RT_NULL,
  45. &thread_stack[0], sizeof(thread_stack),
  46. THREAD_PRIORITY, 10);
  47. if (result == RT_EOK)
  48. rt_thread_startup(&thread);
  49. else
  50. tc_stat(TC_STAT_END | TC_STAT_FAILED);
  51. return result;
  52. }
  53. #ifdef RT_USING_TC
  54. int _tc_thread_delay()
  55. {
  56. thread_delay_init();
  57. return 30;
  58. }
  59. FINSH_FUNCTION_EXPORT(_tc_thread_delay, a thread delay test);
  60. #else
  61. int rt_application_init()
  62. {
  63. thread_delay_init();
  64. return 0;
  65. }
  66. #endif