31 #include <oc_stdlib.h> 39 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 44 oC_Semaphore_Type_t Type;
48 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 55 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 57 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 64 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 76 semaphore->Type = Type;
77 semaphore->Value = InitialValue;
86 bool oC_Semaphore_Delete(
oC_Semaphore_t * Semaphore , AllocationFlags_t Flags )
90 if(oC_Semaphore_IsCorrect(*Semaphore))
92 oC_IntMan_EnterCriticalSection();
93 (*Semaphore)->ObjectControl = 0;
94 oC_ThreadMan_UnblockAllBlockedBy(&(*Semaphore)->Value,
false);
96 if(!ksmartfree(*Semaphore,
sizeof(
struct Semaphore_t),Flags))
98 oC_SaveError(
"Semaphore" , oC_ErrorCode_ReleaseError);
105 oC_IntMan_ExitCriticalSection();
124 if(oC_Semaphore_IsCorrect(Semaphore))
126 oC_IntMan_EnterCriticalSection();
128 if(Semaphore->Value < Semaphore->Type)
132 oC_IntMan_ExitCriticalSection();
141 bool oC_Semaphore_GiveCounting(
oC_Semaphore_t Semaphore , uint32_t Count )
145 if(oC_Semaphore_IsCorrect(Semaphore))
147 oC_IntMan_EnterCriticalSection();
148 Semaphore->Value += Count;
150 if(Semaphore->Value > Semaphore->Type)
152 Semaphore->Value = Semaphore->Type;
155 oC_IntMan_ExitCriticalSection();
164 bool oC_Semaphore_Take(
oC_Semaphore_t Semaphore , oC_Time_t Timeout )
168 if(oC_Semaphore_IsCorrect(Semaphore))
170 if(Semaphore->Value == 0)
172 oC_Thread_t thread = oC_ThreadMan_GetCurrentThread();
174 if(oC_Thread_SetBlocked(thread,&Semaphore->Value,oC_Thread_Unblock_WhenGreaterOrEqual,1,oC_Thread_UnblockMask_All,Timeout))
176 while(oC_Thread_IsBlocked(thread));
178 oC_Thread_SetUnblocked(thread);
180 oC_IntMan_EnterCriticalSection();
181 if(oC_Semaphore_IsCorrect(Semaphore) && (Semaphore->Value >= 1))
183 Semaphore->Value = 0;
186 oC_IntMan_ExitCriticalSection();
191 oC_IntMan_EnterCriticalSection();
192 Semaphore->Value = 0;
194 oC_IntMan_ExitCriticalSection();
204 bool oC_Semaphore_TakeCounting(
oC_Semaphore_t Semaphore , uint32_t Count , oC_Time_t Timeout )
208 if(oC_Semaphore_IsCorrect(Semaphore) && Count <= Semaphore->Type)
210 oC_IntMan_EnterCriticalSection();
211 if(Semaphore->Value < Count)
213 oC_IntMan_ExitCriticalSection();
214 oC_Thread_t thread = oC_ThreadMan_GetCurrentThread();
216 if(oC_Thread_SetBlocked(thread,&Semaphore->Value, oC_Thread_Unblock_WhenGreaterOrEqual , Count , oC_Thread_UnblockMask_All , Timeout))
218 while(oC_Thread_IsBlocked(thread));
220 oC_Thread_SetUnblocked(thread);
222 oC_IntMan_EnterCriticalSection();
223 if(oC_Semaphore_IsCorrect(Semaphore) && (Semaphore->Value >= Count))
225 Semaphore->Value -= Count;
228 oC_IntMan_ExitCriticalSection();
233 Semaphore->Value -= Count;
235 oC_IntMan_ExitCriticalSection();
244 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 252 #define _________________________________________LOCAL_SECTION______________________________________________________________________________ 255 #undef _________________________________________LOCAL_SECTION______________________________________________________________________________
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.
uint32_t oC_ObjectControl_t
stores object control value
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 semaphores.
The file with interface for Thread Manager.
#define NULL
pointer to a zero