platform_thread.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-23 19:26:27
  5. * @LastEditTime : 2020-02-15 23:32:25
  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. k_err_t err;
  19. k_stack_t *thread_stack;
  20. thread = platform_memory_alloc(sizeof(platform_thread_t));
  21. thread_stack = (k_stack_t*) platform_memory_alloc(stack_size);
  22. err = tos_task_create(&(thread->thread),
  23. (char*)name,
  24. entry,
  25. param,
  26. priority,
  27. thread_stack,
  28. stack_size,
  29. tick);
  30. if(err != K_ERR_NONE) {
  31. platform_memory_free(thread);
  32. platform_memory_free(thread_stack);
  33. }
  34. return thread;
  35. }
  36. void platform_thread_startup(platform_thread_t* thread)
  37. {
  38. (void)thread;
  39. }
  40. void platform_thread_stop(platform_thread_t* thread)
  41. {
  42. tos_task_suspend(&(thread->thread));
  43. }
  44. void platform_thread_start(platform_thread_t* thread)
  45. {
  46. tos_task_resume(&(thread->thread));
  47. }
  48. void platform_thread_destroy(platform_thread_t* thread)
  49. {
  50. if (NULL != thread)
  51. tos_task_destroy(&(thread->thread));
  52. platform_memory_free(&(thread->thread));
  53. platform_memory_free(&(thread->thread.stk_size));
  54. }