fork download
  1. #include <cstddef>
  2.  
  3. template<size_t stack_size> struct static_task{
  4.  
  5. TaskHandle_t handle; /// Task handle after initialization
  6. StaticTask_t state; /// Internal task state struct
  7. const char* const name; /// Task name
  8. const BaseType_t affinity; /// Task core
  9. const BaseType_t basic_priority; /// Task init priority
  10. const TaskFunction_t function; /// Task function pointer
  11. void* const ctx; /// Task context pointer
  12. struct stack{
  13. static constexpr size_t size = stack_size; /// Stack size
  14. StackType_t data[stack_size]; /// Stack data pointer
  15. };
  16. };
  17.  
  18. // Lib header
  19. template<size_t size> esp_err_t xTaskStaticInit(static_task<size>& task_struct);
  20.  
  21. // Lib CPP
  22. template<size_t size> esp_err_t xTaskStaticInit(static_task<size>& task_struct){
  23.  
  24.  
  25. task_struct.handle = xTaskCreateStaticPinnedToCore
  26. (
  27. task_struct->function,
  28. task_struct.name,
  29. task_struct.stack.size,
  30. task_struct.ctx,
  31. task_struct.basic_priority,
  32. task_struct.stack.data,
  33. &task_struct.state,
  34. task_struct.affinity
  35. );
  36.  
  37. if(task_struct.handle == nullptr) { return ESP_FAIL; }
  38. else { return ESP_OK; }
  39. };
  40.  
  41.  
  42. // Main CPP
  43.  
  44. static_task<2048> board_task = {
  45. .name = "board_task",
  46. .affinity = 1,
  47. .basic_priority = 5,
  48. .function = BoardTask,
  49. .ctx = nullptr,
  50. };
  51.  
  52. void main(void){
  53.  
  54. xTaskStaticInit(board_task);
  55. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:2: error: ‘TaskHandle_t’ does not name a type
  TaskHandle_t   handle;     /// Task handle after initialization
  ^~~~~~~~~~~~
prog.cpp:6:2: error: ‘StaticTask_t’ does not name a type; did you mean ‘static_task’?
  StaticTask_t   state;     /// Internal task state struct
  ^~~~~~~~~~~~
  static_task
prog.cpp:8:8: error: ‘BaseType_t’ does not name a type
  const BaseType_t  affinity;    /// Task core
        ^~~~~~~~~~
prog.cpp:9:8: error: ‘BaseType_t’ does not name a type
  const BaseType_t  basic_priority;   /// Task init priority
        ^~~~~~~~~~
prog.cpp:10:8: error: ‘TaskFunction_t’ does not name a type
  const TaskFunction_t function;    /// Task function pointer
        ^~~~~~~~~~~~~~
prog.cpp:14:3: error: ‘StackType_t’ does not name a type
   StackType_t    data[stack_size]; /// Stack data pointer
   ^~~~~~~~~~~
prog.cpp:19:23: error: ‘esp_err_t’ does not name a type
 template<size_t size> esp_err_t xTaskStaticInit(static_task<size>& task_struct);
                       ^~~~~~~~~
prog.cpp:22:23: error: ‘esp_err_t’ does not name a type
 template<size_t size> esp_err_t xTaskStaticInit(static_task<size>& task_struct){
                       ^~~~~~~~~
prog.cpp:48:14: error: ‘BoardTask’ was not declared in this scope
  .function = BoardTask,
              ^~~~~~~~~
prog.cpp:48:14: note: suggested alternative: ‘board_task’
  .function = BoardTask,
              ^~~~~~~~~
              board_task
prog.cpp:50:1: error: ‘static_task<2048>’ has no non-static data member named ‘affinity’
 };
 ^
prog.cpp:52:15: error: ‘::main’ must return ‘int’
 void main(void){
               ^
prog.cpp: In function ‘int main()’:
prog.cpp:54:5: error: ‘xTaskStaticInit’ was not declared in this scope
     xTaskStaticInit(board_task);
     ^~~~~~~~~~~~~~~
stdout
Standard output is empty