thread.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <cmsis_os2.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /** FuriThreadState */
  9. typedef enum {
  10. FuriThreadStateStopped,
  11. FuriThreadStateStarting,
  12. FuriThreadStateRunning,
  13. } FuriThreadState;
  14. /** FuriThread anonymous structure */
  15. typedef struct FuriThread FuriThread;
  16. /** FuriThreadCallback
  17. * Your callback to run in new thread
  18. * @warning don't use osThreadExit
  19. */
  20. typedef int32_t (*FuriThreadCallback)(void* context);
  21. /** FuriThread state change calback
  22. * called upon thread state change
  23. * @param state - new thread state
  24. * @param context - callback context
  25. */
  26. typedef void (*FuriThreadStateCallback)(FuriThreadState state, void* context);
  27. /** Allocate FuriThread
  28. * @return FuriThread instance
  29. */
  30. FuriThread* furi_thread_alloc();
  31. /** Release FuriThread
  32. * @param thread - FuriThread instance
  33. */
  34. void furi_thread_free(FuriThread* thread);
  35. /** Set FuriThread name
  36. * @param thread - FuriThread instance
  37. * @param name - string
  38. */
  39. void furi_thread_set_name(FuriThread* thread, const char* name);
  40. /** Set FuriThread stack size
  41. * @param thread - FuriThread instance
  42. * @param stack_size - stack size in bytes
  43. */
  44. void furi_thread_set_stack_size(FuriThread* thread, size_t stack_size);
  45. /** Set FuriThread callback
  46. * @param thread - FuriThread instance
  47. * @param callback - FuriThreadCallback, called upon thread run
  48. */
  49. void furi_thread_set_callback(FuriThread* thread, FuriThreadCallback callback);
  50. /** Set FuriThread context
  51. * @param thread - FuriThread instance
  52. * @param context - pointer to context for thread callback
  53. */
  54. void furi_thread_set_context(FuriThread* thread, void* context);
  55. /** Set FuriThread state change callback
  56. * @param thread - FuriThread instance
  57. * @param callack - state change callback
  58. */
  59. void furi_thread_set_state_callback(FuriThread* thread, FuriThreadStateCallback callback);
  60. /** Set FuriThread state change context
  61. * @param thread - FuriThread instance
  62. * @param context - pointer to context
  63. */
  64. void furi_thread_set_state_context(FuriThread* thread, void* context);
  65. /** Get FuriThread state
  66. * @param thread - FuriThread instance
  67. * @return thread state from FuriThreadState
  68. */
  69. FuriThreadState furi_thread_get_state(FuriThread* thread);
  70. /** Start FuriThread
  71. * @param thread - FuriThread instance
  72. * @return true on success
  73. */
  74. bool furi_thread_start(FuriThread* thread);
  75. /** Treminate FuriThread
  76. * @param thread - FuriThread instance
  77. * @return osStatus_t
  78. * @warning terminating statefull thread is dangerous
  79. * use only if you know what you doing
  80. */
  81. osStatus_t furi_thread_terminate(FuriThread* thread);
  82. /** Join FuriThread
  83. * @param thread - FuriThread instance
  84. * @return osStatus_t
  85. */
  86. osStatus_t furi_thread_join(FuriThread* thread);
  87. /** Get CMSIS Thread ID
  88. * @param thread - FuriThread instance
  89. * @return osThreadId_t or NULL
  90. */
  91. osThreadId_t furi_thread_get_thread_id(FuriThread* thread);
  92. /** Enable heap tracing
  93. * @param thread - FuriThread instance
  94. */
  95. void furi_thread_enable_heap_trace(FuriThread* thread);
  96. /** Disable heap tracing
  97. * @param thread - FuriThread instance
  98. */
  99. void furi_thread_disable_heap_trace(FuriThread* thread);
  100. /** Get thread heap size
  101. * @param thread - FuriThread instance
  102. */
  103. size_t furi_thread_get_heap_size(FuriThread* thread);
  104. #ifdef __cplusplus
  105. }
  106. #endif