FreeRTOS C++ Wrappers
SemaphoreCPP.h
Go to the documentation of this file.
1 
36 #ifndef SEMAPHORE_CPP_H
37 #define SEMAPHORE_CPP_H
38 
39 #include "FreeRTOS.h"
40 #include "semphr.h"
41 
48 class Semaphore {
49 public:
54  Semaphore(char const* name) {
55  vSemaphoreCreateBinary(sema);
56 #if configQUEUE_REGISTRY_SIZE > 0
57  vQueueAddToRegistry(sema, name);
58 #endif
59  }
66  vQueueDelete(sema);
67  }
71  signed portBASE_TYPE give() {
72  return xSemaphoreGive(sema);
73  }
74 
80  signed portBASE_TYPE take(TickType_t delay = portMAX_DELAY){
81  return xSemaphoreTake(sema, delay);
82  }
83 
84 // void start_ISR(portBASE_TYPE& flag) {
85 // waswoken = &flag;
86 // }
87 
94  signed portBASE_TYPE give_ISR(portBASE_TYPE& waswoken) {
95  return xSemaphoreGiveFromISR(sema, &waswoken);
96  }
97 private:
98  xSemaphoreHandle sema;
99 // portBASE_TYPE* waswoken;
100 
101 #if __cplusplus < 201101L
102  Semaphore(Semaphore const&);
103  void operator =(Semaphore const&);
104 #else
105  Semaphore(Semaphore const&) = delete;
106  void operator =(Semaphore const&) = delete;
107 #endif // __cplusplus
108 
109 };
110 #endif
signed portBASE_TYPE take(TickType_t delay=portMAX_DELAY)
Take the semaphore.
Definition: SemaphoreCPP.h:80
signed portBASE_TYPE give_ISR(portBASE_TYPE &waswoken)
Give the Semaphore inside an ISR.
Definition: SemaphoreCPP.h:94
Semaphore(char const *name)
Constructor.
Definition: SemaphoreCPP.h:54
signed portBASE_TYPE give()
Give the Semaphore.
Definition: SemaphoreCPP.h:71
Binary Semaphore Wrapper.
Definition: SemaphoreCPP.h:48
~Semaphore()
Destructor.
Definition: SemaphoreCPP.h:65