SYS/BIOS  7.00
Semaphore.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Texas Instruments Incorporated - https://www.ti.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
137 /*
138  * ======== Semaphore.h ========
139  */
140 
141 #ifndef ti_sysbios_knl_Semaphore__include
142 #define ti_sysbios_knl_Semaphore__include
143 
144 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
146 #include <xdc/std.h>
149 #include <stdbool.h>
150 #include <stddef.h>
151 #include <stdint.h>
152 
153 #include <ti/sysbios/knl/Queue.h>
154 #include <ti/sysbios/knl/Task.h>
155 #include <ti/sysbios/knl/Clock.h>
156 #include <ti/sysbios/knl/Event.h>
157 
159 
160 /* @cond NODOC */
161 #define ti_sysbios_knl_Semaphore_long_names
162 #include "Semaphore_defs.h"
165 #ifdef __cplusplus
166 extern "C" {
167 #endif
168 
169 /*
170  * Error and Assert Ids
171  */
172 
177 #define Semaphore_A_badContext "bad calling context - must be called from a Task"
178 
183 #define Semaphore_A_noEvents "the Semaphore.supportsEvents flag is disabled"
184 
189 #define Semaphore_A_overflow "count has exceeded 65535 and rolled over"
190 
195 #define Semaphore_A_pendTaskDisabled "cannot call Semaphore_pend() while the Task or Swi scheduler is disabled"
196 
198 typedef struct Semaphore_PendElem Semaphore_PendElem;
206 
244 };
245 
267 
269 enum Semaphore_PendState {
270  Semaphore_PendState_TIMEOUT = 0,
271  Semaphore_PendState_POSTED = 1,
272  Semaphore_PendState_CLOCK_WAIT = 2,
273  Semaphore_PendState_WAIT_FOREVER = 3
274 };
275 typedef enum Semaphore_PendState Semaphore_PendState;
276 
277 struct Semaphore_PendElem {
278  Task_PendElem tpElem;
279  Semaphore_PendState pendState;
280 };
293  Semaphore_Mode mode;
309  unsigned int eventId;
310 };
311 
314  Queue_Elem objElem;
324  Event_Handle event;
330  unsigned int eventId;
340  Semaphore_Mode mode;
341  volatile uint16_t count;
342  Queue_Elem pendQ;
344 };
345 
347 typedef struct {
348  Queue_Struct objQ;
349 } Semaphore_Module_State;
362 extern const bool Semaphore_supportsEvents;
363 
374 extern const bool Semaphore_supportsPriority;
375 
377 typedef void (*Semaphore_EventPost)(Event_Handle arg1, unsigned int arg2);
378 extern const Semaphore_EventPost Semaphore_eventPost;
379 
380 typedef void (*Semaphore_EventSync)(Event_Handle arg1, unsigned int arg2, unsigned int arg3);
381 extern const Semaphore_EventSync Semaphore_eventSync;
382 
383 extern void Semaphore_Instance_init(Semaphore_Object *obj, int count, const Semaphore_Params *prms);
384 
385 extern void Semaphore_Instance_finalize(Semaphore_Object *obj);
403 extern Semaphore_Handle Semaphore_create(int count, const Semaphore_Params *prms, Error_Block *eb);
404 
418 extern Semaphore_Handle Semaphore_construct(Semaphore_Struct *obj, int count, const Semaphore_Params *prms);
419 
429 extern void Semaphore_delete(Semaphore_Handle *semaphore);
430 
438 extern void Semaphore_destruct(Semaphore_Struct *obj);
439 
451 extern void Semaphore_Params_init(Semaphore_Params *prms);
452 
461 extern Semaphore_Handle Semaphore_Object_first(void);
462 
473 extern Semaphore_Handle Semaphore_Object_next(Semaphore_Handle semaphore);
474 
497 extern int Semaphore_getCount(Semaphore_Handle semaphore);
498 
525 extern bool Semaphore_pend(Semaphore_Handle semaphore, uint32_t timeout);
526 
537 extern void Semaphore_post(Semaphore_Handle semaphore);
538 
561 extern void Semaphore_registerEvent(Semaphore_Handle semaphore, Event_Handle event, unsigned int eventId);
562 
579 extern void Semaphore_reset(Semaphore_Handle semaphore, int count);
580 
586 extern void Semaphore_pendTimeout(uintptr_t arg);
587 
588 static inline Semaphore_Handle Semaphore_handle(Semaphore_Struct *str)
589 {
590  return ((Semaphore_Handle)str);
591 }
592 
593 static inline Semaphore_Struct * Semaphore_struct(Semaphore_Handle handle)
594 {
595  return ((Semaphore_Struct *)handle);
596 }
597 
600 #ifdef __cplusplus
601 }
602 #endif
603 #endif /* ti_sysbios_knl_Semaphore__include */
604 
605 /* @cond NODOC */
606 #undef ti_sysbios_knl_Semaphore_long_names
607 #include "Semaphore_defs.h"
Definition: Semaphore.h:312
void Semaphore_delete(Semaphore_Handle *semaphore)
Delete a semaphore.
Semaphore_Mode mode
Semaphore mode.
Definition: Semaphore.h:293
Opaque queue element.
Definition: Queue.h:204
System Clock Manager.
Definition: Event.h:310
const bool Semaphore_supportsPriority
Support Task priority pend queuing?
Runtime error manager.
void Semaphore_destruct(Semaphore_Struct *obj)
Destruct a semaphore.
void Semaphore_post(Semaphore_Handle semaphore)
Signal a semaphore.
Queue Manager.
void Semaphore_registerEvent(Semaphore_Handle semaphore, Event_Handle event, unsigned int eventId)
Register an Event Object with a semaphore.
Semaphore_Struct * Semaphore_Handle
Definition: Semaphore.h:204
Semaphore_Handle Semaphore_Object_next(Semaphore_Handle semaphore)
return handle of the next Semaphore on Semaphore list
Binary (FIFO)
Definition: Semaphore.h:235
Error block.
Definition: Error.h:152
unsigned int eventId
eventId if using Events
Definition: Semaphore.h:309
Definition: Semaphore.h:283
bool Semaphore_pend(Semaphore_Handle semaphore, uint32_t timeout)
Wait for a semaphore.
Counting (FIFO)
Definition: Semaphore.h:231
Semaphore_Handle Semaphore_Object_first(void)
return handle of the first Semaphore on Semaphore list
Event Manager.
const bool Semaphore_supportsEvents
Support Semaphores with Events?
int Semaphore_getCount(Semaphore_Handle semaphore)
Get current semaphore count.
Semaphore_Mode
Semaphore types.
Definition: Semaphore.h:227
void Semaphore_Params_init(Semaphore_Params *prms)
Initialize the Semaphore_Params structure with default values.
Event_Handle event
Event instance to use if non-NULL.
Definition: Semaphore.h:303
Task Manager.
Semaphore_Handle Semaphore_create(int count, const Semaphore_Params *prms, Error_Block *eb)
Create a Semaphore object.
Binary (priority-based)
Definition: Semaphore.h:243
void Semaphore_reset(Semaphore_Handle semaphore, int count)
Reset semaphore count.
Counting (priority-based)
Definition: Semaphore.h:239
Semaphore_Struct * Semaphore_Instance
Definition: Semaphore.h:205
Semaphore_Handle Semaphore_construct(Semaphore_Struct *obj, int count, const Semaphore_Params *prms)
Construct a semaphore.
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale