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.

54 lines
1.0 KiB

11 months 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. void init(const char* threadname, int stack_size = 512, osPriority priority = osPriorityNormal);
  28. void start(zosthread_cb_t cb);
  29. void start(zosthread_cb_t cb, zosthread_cb_t exitcb);
  30. void stop();
  31. bool getExitFlag() { return !m_threadisworkingFlagCallSide; }
  32. bool isworking() { return m_status == kworking; }
  33. void wake();
  34. static void sleep(uint32_t ms);
  35. public:
  36. void threadcb();
  37. };
  38. } // namespace iflytop