mutex.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include "base.h"
  3. #include "thread.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. // Mutex attributes (attr_bits in \ref osMutexAttr_t).
  8. #define osMutexRecursive 0x00000001U ///< Recursive mutex.
  9. #define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol.
  10. #define osMutexRobust 0x00000008U ///< Robust mutex.
  11. /// Attributes structure for mutex.
  12. typedef struct {
  13. const char* name; ///< name of the mutex
  14. uint32_t attr_bits; ///< attribute bits
  15. void* cb_mem; ///< memory for control block
  16. uint32_t cb_size; ///< size of provided memory for control block
  17. } osMutexAttr_t;
  18. /// \details Mutex ID identifies the mutex.
  19. typedef void* osMutexId_t;
  20. /// Create and Initialize a Mutex object.
  21. /// \param[in] attr mutex attributes; NULL: default values.
  22. /// \return mutex ID for reference by other functions or NULL in case of error.
  23. osMutexId_t osMutexNew(const osMutexAttr_t* attr);
  24. /// Get name of a Mutex object.
  25. /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
  26. /// \return name as null-terminated string.
  27. const char* osMutexGetName(osMutexId_t mutex_id);
  28. /// Acquire a Mutex or timeout if it is locked.
  29. /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
  30. /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  31. /// \return status code that indicates the execution status of the function.
  32. osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout);
  33. /// Release a Mutex that was acquired by \ref osMutexAcquire.
  34. /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
  35. /// \return status code that indicates the execution status of the function.
  36. osStatus_t osMutexRelease(osMutexId_t mutex_id);
  37. /// Delete a Mutex object.
  38. /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
  39. /// \return status code that indicates the execution status of the function.
  40. osStatus_t osMutexDelete(osMutexId_t mutex_id);
  41. FuriThreadId osMutexGetOwner(osMutexId_t mutex_id);
  42. #ifdef __cplusplus
  43. }
  44. #endif