platform_thread.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-23 19:26:27
  5. * @LastEditTime: 2020-09-23 08:53:43
  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. BaseType_t err;
  18. platform_thread_t *thread;
  19. thread = platform_memory_alloc(sizeof(platform_thread_t));
  20. (void)tick;
  21. err = xTaskCreate(entry, name, stack_size, param, priority, &thread->thread);
  22. if(pdPASS != err) {
  23. platform_memory_free(thread);
  24. return NULL;
  25. }
  26. return thread;
  27. }
  28. void platform_thread_startup(platform_thread_t* thread)
  29. {
  30. (void)thread;
  31. }
  32. void platform_thread_stop(platform_thread_t* thread)
  33. {
  34. vTaskSuspend(thread->thread);
  35. }
  36. void platform_thread_start(platform_thread_t* thread)
  37. {
  38. vTaskResume(thread->thread);
  39. }
  40. void platform_thread_destroy(platform_thread_t* thread)
  41. {
  42. if (NULL != thread)
  43. vTaskDelete(thread->thread);
  44. platform_memory_free(thread);
  45. }