You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1 KiB

1 year ago
  1. #pragma once
  2. #include <functional>
  3. extern "C" {
  4. #include "cmsis_os.h"
  5. }
  6. namespace iflytop {
  7. using namespace std;
  8. typedef function<void()> zosthread_cb_t;
  9. class ZThread {
  10. public:
  11. typedef enum {
  12. kidle,
  13. kworking,
  14. kdead,
  15. } status_t;
  16. const char* m_name;
  17. uint32_t m_stacksize;
  18. osPriority m_uxPriority;
  19. status_t m_status = kidle;
  20. bool m_threadisworkingFlagCallSide = false;
  21. zosthread_cb_t m_taskfunction;
  22. zosthread_cb_t m_taskfunction_exitcb;
  23. EventGroupHandle_t m_zthreadstartworkevent;
  24. osThreadId m_defaultTaskHandle;
  25. SemaphoreHandle_t m_lock;
  26. public:
  27. /**
  28. * @brief init in zos.cpp, called by zos_init
  29. */
  30. static void zthread_module_init();
  31. void init(const char* threadname, int stack_size = 512, osPriority priority = osPriorityNormal);
  32. void start(zosthread_cb_t cb);
  33. void start(zosthread_cb_t cb, zosthread_cb_t exitcb);
  34. void stop();
  35. bool getExitFlag() { return !m_threadisworkingFlagCallSide; }
  36. bool isworking() { return m_status == kworking; }
  37. void wake();
  38. static void sleep(uint32_t ms);
  39. public:
  40. void threadcb();
  41. };
  42. } // namespace iflytop