29 #include <oc_stdlib.h> 39 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 45 oC_Event_Protect_t Protection;
48 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 55 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 65 event->State = InitState;
67 event->Protection = oC_Event_Protect_NotProtected;
71 oC_SaveError(
"Event: Creating new event" , oC_ErrorCode_AllocationError);
80 bool oC_Event_Delete(
oC_Event_t * Event , AllocationFlags_t Flags )
84 if(oC_Event_IsCorrect(*Event))
86 if((*Event)->Protection == oC_Event_Protect_NotProtected)
88 oC_IntMan_EnterCriticalSection();
90 oC_ThreadMan_UnblockAllBlockedBy(&(*Event)->State ,
false);
91 (*Event)->ObjectControl = 0;
93 if(ksmartfree(*Event,
sizeof(
struct Event_t),Flags))
100 oC_SaveError(
"Event: Delete" , oC_ErrorCode_ReleaseError);
103 oC_IntMan_ExitCriticalSection();
107 oC_SaveError(
"Event: Delete - " , oC_ErrorCode_ObjectProtected);
112 oC_SaveError(
"Event: Delete - " , oC_ErrorCode_ObjectNotCorrect);
120 bool oC_Event_ProtectDelete(
oC_Event_t Event ,
Allocator_t Allocator , oC_Event_Protect_t Protection )
122 bool success =
false;
124 if(oC_Event_IsCorrect(Event))
126 if(isaddresscorrect(Allocator))
130 oC_IntMan_EnterCriticalSection();
132 Event->Protection = Protection;
136 oC_IntMan_ExitCriticalSection();
140 oC_SaveError(
"Event: Protect delete - Allocator not correct (you are not owner of this event)" , oC_ErrorCode_WrongAddress );
145 oC_SaveError(
"Event: Protect delete - Allocator not correct " , oC_ErrorCode_WrongAddress );
150 oC_SaveError(
"Event: Protect delete - " , oC_ErrorCode_ObjectNotCorrect);
165 oC_Event_State_t oC_Event_GetState(
oC_Event_t Event )
167 return oC_Event_IsCorrect(Event) ? Event->State : 0;
172 bool oC_Event_SetState(
oC_Event_t Event , oC_Event_State_t State )
176 if(oC_Event_IsCorrect(Event))
178 oC_IntMan_EnterCriticalSection();
179 Event->State = State;
186 oC_IntMan_ExitCriticalSection();
190 oC_SaveError(
"Event: set state" , oC_ErrorCode_ObjectNotCorrect);
199 bool oC_Event_ClearStateBits(
oC_Event_t Event , uint32_t StateMask )
201 bool cleared =
false;
203 if(oC_Event_IsCorrect(Event))
205 oC_IntMan_EnterCriticalSection();
206 Event->State &= ~StateMask;
208 oC_IntMan_ExitCriticalSection();
216 bool oC_Event_ReadState(
oC_Event_t Event , oC_Event_State_t * outState )
220 if(oC_Event_IsCorrect(Event))
222 oC_IntMan_EnterCriticalSection();
223 *outState = Event->State;
225 oC_IntMan_ExitCriticalSection();
229 oC_SaveError(
"Event: read state" , oC_ErrorCode_ObjectNotCorrect);
247 bool stateOk =
false;
249 if(oC_Event_IsCorrect(Event))
251 oC_Thread_t thread = oC_ThreadMan_GetCurrentThread();
253 if(StateMask != oC_Event_StateMask_DifferentThan)
255 oC_Thread_SetBlocked(thread, &Event->State , oC_Thread_Unblock_WhenEqual , State , StateMask , Timeout);
259 oC_Thread_SetBlocked(thread, &Event->State , oC_Thread_Unblock_WhenNotEqual , State , oC_Event_StateMask_Full , Timeout);
262 while(oC_Thread_IsBlocked(thread));
264 oC_Thread_SetUnblocked(thread);
266 oC_IntMan_EnterCriticalSection();
268 if(oC_Event_IsCorrect(Event))
270 if(StateMask != oC_Event_StateMask_DifferentThan)
272 if((Event->State & StateMask) == (State & StateMask))
279 stateOk = (Event->State & oC_Event_StateMask_Full) != (State & oC_Event_StateMask_Full);
282 oC_IntMan_ExitCriticalSection();
286 oC_SaveError(
"Event: wait for state" , oC_ErrorCode_ObjectNotCorrect);
294 bool oC_Event_WaitForValue(
oC_Event_t Event , oC_Event_State_t Value , oC_Event_CompareType_t CompareType, oC_Time_t Timeout )
296 bool stateOk =
false;
298 if(oC_Event_IsCorrect(Event) && CompareType < oC_Event_CompareType_NumberOfElements)
300 oC_Thread_t thread = oC_ThreadMan_GetCurrentThread();
302 if(CompareType == oC_Event_CompareType_Equal)
304 oC_Thread_SetBlocked(thread, &Event->State , oC_Thread_Unblock_WhenEqual , Value, oC_Event_StateMask_Full, Timeout);
306 else if(CompareType == oC_Event_CompareType_Greater)
308 oC_Thread_SetBlocked(thread, &Event->State , oC_Thread_Unblock_WhenGreater, Value, oC_Event_StateMask_Full, Timeout);
310 else if(CompareType == oC_Event_CompareType_GreaterOrEqual)
312 oC_Thread_SetBlocked(thread, &Event->State , oC_Thread_Unblock_WhenGreaterOrEqual, Value, oC_Event_StateMask_Full, Timeout);
314 else if(CompareType == oC_Event_CompareType_Less)
316 oC_Thread_SetBlocked(thread, &Event->State , oC_Thread_Unblock_WhenSmaller, Value, oC_Event_StateMask_Full, Timeout);
318 else if(CompareType == oC_Event_CompareType_LessOrEqual)
320 oC_Thread_SetBlocked(thread, &Event->State , oC_Thread_Unblock_WhenSmallerOrEqual, Value, oC_Event_StateMask_Full, Timeout);
323 while(oC_Thread_IsBlocked(thread));
325 oC_Thread_SetUnblocked(thread);
327 oC_IntMan_EnterCriticalSection();
329 if(oC_Event_IsCorrect(Event))
331 if(CompareType == oC_Event_CompareType_Equal)
333 stateOk = Event->State == Value;
335 else if(CompareType == oC_Event_CompareType_Greater)
337 stateOk = Event->State > Value;
339 else if(CompareType == oC_Event_CompareType_GreaterOrEqual)
341 stateOk = Event->State >= Value;
343 else if(CompareType == oC_Event_CompareType_Less)
345 stateOk = Event->State < Value;
347 else if(CompareType == oC_Event_CompareType_LessOrEqual)
349 stateOk = Event->State <= Value;
352 oC_IntMan_ExitCriticalSection();
356 oC_SaveError(
"Event: wait for state" , oC_ErrorCode_ObjectNotCorrect);
362 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
bool oC_Event_WaitForState(oC_Event_t Event, oC_Event_State_t State, oC_Event_StateMask_t StateMask, oC_Time_t Timeout)
bool oC_MemMan_IsRamAddress(const void *Address)
checks if address is in ram section
identifier for allocations
The file with helper macros for managing objects.
Allocator_t oC_MemMan_GetAllocatorOfAddress(const void *Address)
returns allocator of address
uint32_t oC_ObjectControl_t
stores object control value
The file with interface for event module.
The file with interface for interrupt manager.
static oC_ObjectControl_t oC_CountObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId)
counts object control for object
static bool oC_CheckObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId, oC_ObjectControl_t ObjectControl)
checks if object control is correct
Definition of the null pointer.
static const oC_Allocator_t Allocator
The file with interface for Thread Manager.
#define NULL
pointer to a zero