platform_thread.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-23 19:26:27
  5. * @LastEditTime: 2020-09-20 14:30:08
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #include "platform_thread.h"
  9. #include "platform_memory.h"
  10. platform_thread_t *platform_thread_init( const char *name,
  11. void (*entry)(void *),
  12. void * const param,
  13. unsigned int stack_size,
  14. unsigned int priority,
  15. unsigned int tick)
  16. {
  17. platform_thread_t *thread;
  18. thread = platform_memory_alloc(sizeof(platform_thread_t));
  19. if(RT_NULL == thread)
  20. {
  21. return RT_NULL;
  22. }
  23. /*modify thread creation method is dynamic creation, so thread exit rtos can recylcle the resource!*/
  24. thread->thread = rt_thread_create((const char *)name,
  25. entry, param,
  26. stack_size, priority, tick);
  27. if (thread->thread == RT_NULL)
  28. {
  29. return RT_NULL;
  30. }
  31. else
  32. {
  33. return thread;
  34. }
  35. }
  36. void platform_thread_startup(platform_thread_t* thread)
  37. {
  38. rt_thread_startup(thread->thread);
  39. }
  40. void platform_thread_stop(platform_thread_t* thread)
  41. {
  42. rt_thread_suspend(thread->thread);
  43. }
  44. void platform_thread_start(platform_thread_t* thread)
  45. {
  46. rt_thread_resume(thread->thread);
  47. }
  48. void platform_thread_destroy(platform_thread_t* thread)
  49. {
  50. platform_memory_free(thread);
  51. }