thread_static.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 static 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_kprintf("thread staticly inited ok\n");
  19. rt_thread_delay(10);
  20. rt_kprintf("thread exit\n");
  21. tc_done(TC_STAT_PASSED);
  22. }
  23. rt_err_t thread_static_init()
  24. {
  25. rt_err_t result;
  26. result = rt_thread_init(&thread,
  27. "test",
  28. thread_entry, RT_NULL,
  29. &thread_stack[0], sizeof(thread_stack),
  30. THREAD_PRIORITY, 10);
  31. if (result == RT_EOK)
  32. rt_thread_startup(&thread);
  33. else
  34. tc_stat(TC_STAT_END | TC_STAT_FAILED);
  35. return result;
  36. }
  37. #ifdef RT_USING_TC
  38. int _tc_thread_static()
  39. {
  40. thread_static_init();
  41. return 20;
  42. }
  43. FINSH_FUNCTION_EXPORT(_tc_thread_static, a static thread test);
  44. #else
  45. int rt_application_init()
  46. {
  47. thread_static_init();
  48. return 0;
  49. }
  50. #endif