forked from richard-damon/FreeRTOScpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventCPP.h
executable file
·132 lines (117 loc) · 3.85 KB
/
EventCPP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* @file EventCPP.h
* @copyright (c) 2018-2019 Richard Damon
* @author Richard Damon <[email protected]>
* @parblock
* MIT License:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* It is requested (but not required by license) that any bugs found or
* improvements made be shared, preferably to the author.
* @endparblock
*
* @brief FreeRTOS Event Group Wrapper
*
* This file contains a set of lightweight wrappers for event groups using FreeRTOS
*
* @ingroup FreeRTOSCpp
*/
#ifndef EVENTCPP_H
#define EVENTCPP_H
#include "FreeRTOS.h"
#include "event_groups.h"
class EventGroup {
public:
EventGroup() {
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
eventHandle = xEventGroupCreateStatic(&eventBuffer);
#else
eventHandle = xEventGroupCreate();
#endif
}
~EventGroup() {
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
#else
vEventGroupDelete(eventHandle);
#endif
}
/**
* Get Event Bits
*
*/
EventBits_t get() {
return xEventGroupGetBits(eventHandle);
}
EventBits_t get_ISR() {
return xEventGroupGetBitsFromISR(eventHandle);
}
/**
* Set Event Bits
*
* Set Event bits and activate all tasks waiting for those bits.
*
* @param bits The Event Bits to Set.
*/
EventBits_t set(EventBits_t bits) {
return xEventGroupSetBits(eventHandle, bits);
}
EventBits_t set_ISR(EventBits_t bits, portBASE_TYPE& waswoken) {
return xEventGroupSetBitsFromISR(eventHandle, bits, &waswoken);
}
/**
* Clear Event Bits
*
* @param bits The Event Bits to Set.
*/
EventBits_t clear(EventBits_t bits) {
return xEventGroupClearBits(eventHandle, bits);
}
EventBits_t clear_ISR(EventBits_t bits) {
return xEventGroupClearBitsFromISR(eventHandle, bits);
}
/**
* Event Group Sync
*
* Sets the set bits than wait for all of the wait bits, and then clear all those bits.
*
* @returns the value of the event group befor clearing the bits.
*/
EventBits_t sync(EventBits_t set, EventBits_t wait, TickType_t ticks = portMAX_DELAY){
return xEventGroupSync(eventHandle, set, wait, ticks);
}
/**
* Wait for Event
*
* @param waitBits The bit(s) to wait for
* @param clear If true, then the bits are cleared after the wait.
* @param all If true, then wait for ALL the bits to be true, else for ANY of the bits
* @param ticks How long to wait for the bits to be set
* @returns The value of the event bits (before clearing) at the end of the wait.
*/
EventBits_t wait(EventBits_t waitBits, bool clear = true, bool all = false, TickType_t ticks = portMAX_DELAY) {
return xEventGroupWaitBits(eventHandle, waitBits, clear, all, ticks);
}
protected:
EventGroupHandle_t eventHandle;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
StaticEventGroup_t eventBuffer;
#endif
};
#endif