semaphore.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "base.h"
  3. #include "thread.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /// Attributes structure for semaphore.
  8. typedef struct {
  9. const char* name; ///< name of the semaphore
  10. uint32_t attr_bits; ///< attribute bits
  11. void* cb_mem; ///< memory for control block
  12. uint32_t cb_size; ///< size of provided memory for control block
  13. } osSemaphoreAttr_t;
  14. /// \details Semaphore ID identifies the semaphore.
  15. typedef void* osSemaphoreId_t;
  16. /// Create and Initialize a Semaphore object.
  17. /// \param[in] max_count maximum number of available tokens.
  18. /// \param[in] initial_count initial number of available tokens.
  19. /// \param[in] attr semaphore attributes; NULL: default values.
  20. /// \return semaphore ID for reference by other functions or NULL in case of error.
  21. osSemaphoreId_t
  22. osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t* attr);
  23. /// Get name of a Semaphore object.
  24. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  25. /// \return name as null-terminated string.
  26. const char* osSemaphoreGetName(osSemaphoreId_t semaphore_id);
  27. /// Acquire a Semaphore token or timeout if no tokens are available.
  28. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  29. /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  30. /// \return status code that indicates the execution status of the function.
  31. osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout);
  32. /// Release a Semaphore token up to the initial maximum count.
  33. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  34. /// \return status code that indicates the execution status of the function.
  35. osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id);
  36. /// Get current Semaphore token count.
  37. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  38. /// \return number of tokens available.
  39. uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id);
  40. /// Delete a Semaphore object.
  41. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  42. /// \return status code that indicates the execution status of the function.
  43. osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id);
  44. #ifdef __cplusplus
  45. }
  46. #endif