thread.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /* Start FuriThread
  66. * @param thread - FuriThread instance
  67. * @return true on success
  68. */
  69. bool furi_thread_start(FuriThread* thread);
  70. /* Treminate FuriThread
  71. * @param thread - FuriThread instance
  72. * @return osStatus_t
  73. * @warning terminating statefull thread is dangerous
  74. * use only if you know what you doing
  75. */
  76. osStatus_t furi_thread_terminate(FuriThread* thread);
  77. /* Join FuriThread
  78. * @param thread - FuriThread instance
  79. * @return osStatus_t
  80. */
  81. osStatus_t furi_thread_join(FuriThread* thread);
  82. #ifdef __cplusplus
  83. }
  84. #endif