SYS/BIOS  7.00
Mailbox.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022, Texas Instruments Incorporated - http://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  */
132 #ifndef ti_sysbios_knl_Mailbox__include
133 #define ti_sysbios_knl_Mailbox__include
134 
135 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
137 #include <xdc/std.h>
140 #include <ti/sysbios/knl/Event.h>
141 #include <ti/sysbios/knl/Queue.h>
143 
145 
146 /* @cond NODOC */
147 #define ti_sysbios_knl_Mailbox_long_names
148 #include "Mailbox_defs.h"
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154 
161 #define Mailbox_A_invalidBufSize "Mailbox_create's bufSize parameter is invalid (too small)"
162 
171 struct Mailbox_MbxElem {
172  Queue_Elem elem;
173 };
174 
182 typedef struct Mailbox_MbxElem Mailbox_MbxElem;
183 
184 #define Mailbox_maxTypeAlign (sizeof (long long))
185 
194  IHeap_Handle heap;
210  unsigned int readerEventId;
226  unsigned int writerEventId;
251  void * buf;
257  unsigned int bufSize;
258 };
260 
261 /* Struct */
264  Queue_Elem objElem;
271  IHeap_Handle heap;
272  size_t msgSize;
273  unsigned int numMsgs;
305  void * buf;
306  unsigned int numFreeMsgs;
307  void * allocBuf;
308  Queue_Struct dataQue;
309  Queue_Struct freeQue;
310  Semaphore_Struct dataSem;
311  Semaphore_Struct freeSem;
313 };
317 
319 typedef struct {
320  Queue_Struct objQ;
321 } Mailbox_Module_State;
337 extern Mailbox_Handle Mailbox_create(size_t msgSize, unsigned int numMsgs, const Mailbox_Params *prms, Error_Block *eb);
338 
354 extern Mailbox_Handle Mailbox_construct(Mailbox_Struct *obj, size_t msgSize, unsigned int numMsgs, const Mailbox_Params *prms, Error_Block *eb);
355 
365 extern void Mailbox_delete(Mailbox_Handle *mailbox);
366 
374 extern void Mailbox_destruct(Mailbox_Struct *obj);
375 
383 extern size_t Mailbox_getMsgSize(Mailbox_Handle mailbox);
384 
392 extern int Mailbox_getNumFreeMsgs(Mailbox_Handle mailbox);
393 
401 extern int Mailbox_getNumPendingMsgs(Mailbox_Handle mailbox);
402 
444 extern bool Mailbox_pend(Mailbox_Handle mailbox, void * msg, uint32_t timeout);
445 
488 extern bool Mailbox_peek(Mailbox_Handle mailbox, void * msg, uint32_t timeout);
489 
533 extern bool Mailbox_post(Mailbox_Handle mailbox, void * msg, uint32_t timeout);
534 
578 extern bool Mailbox_putHead(Mailbox_Handle mailbox, void * msg, uint32_t timeout);
579 
591 extern void Mailbox_Params_init(Mailbox_Params *prms);
592 
601 extern Mailbox_Handle Mailbox_Object_first(void);
602 
613 extern Mailbox_Handle Mailbox_Object_next(Mailbox_Handle mbx);
614 
616 static inline Mailbox_Handle Mailbox_handle(Mailbox_Struct *str)
617 {
618  return ((Mailbox_Handle)str);
619 }
620 
621 static inline Mailbox_Struct * Mailbox_struct(Mailbox_Handle h)
622 {
623  return ((Mailbox_Struct *)h);
624 }
625 
626 #define Mailbox_module ((Mailbox_Module_State *) &(Mailbox_Module_state))
627 
629 #ifdef __cplusplus
630 }
631 #endif
632 
633 #endif /* ti_sysbios_knl_Mailbox__include */
634 
635 /* @cond NODOC */
636 #undef ti_sysbios_knl_Mailbox_long_names
637 #include "Mailbox_defs.h"
bool Mailbox_post(Mailbox_Handle mailbox, void *msg, uint32_t timeout)
Post a message to mailbox.
Event_Handle readerEvent
Mailbox not empty event if using Events. Default is null.
Definition: Mailbox.h:202
Mailbox_Handle Mailbox_construct(Mailbox_Struct *obj, size_t msgSize, unsigned int numMsgs, const Mailbox_Params *prms, Error_Block *eb)
Construct a task.
Definition: Semaphore.h:312
unsigned int writerEventId
Mailbox not full event Id if using Events.
Definition: Mailbox.h:226
unsigned int bufSize
The size of the buffer that &#39;buf&#39; references.
Definition: Mailbox.h:257
size_t Mailbox_getMsgSize(Mailbox_Handle mailbox)
Get the message size.
Mailbox_Handle Mailbox_Object_first(void)
return handle of the first Mailbox on Mailbox list
void Mailbox_Params_init(Mailbox_Params *prms)
Initialize the Mailbox_Params structure with default values.
int Mailbox_getNumFreeMsgs(Mailbox_Handle mailbox)
Get the number messages available for use.
Opaque queue element.
Definition: Queue.h:204
Definition: Event.h:310
Runtime error manager.
bool Mailbox_peek(Mailbox_Handle mailbox, void *msg, uint32_t timeout)
Peek a message from the mailbox.
Definition: Mailbox.h:187
Queue Manager.
unsigned int readerEventId
Mailbox not empty event Id if using Events. Default is 1.
Definition: Mailbox.h:210
bool Mailbox_putHead(Mailbox_Handle mailbox, void *msg, uint32_t timeout)
Post a message to mailbox.
Error block.
Definition: Error.h:152
int Mailbox_getNumPendingMsgs(Mailbox_Handle mailbox)
Get the number of messages that are ready to be read.
Event_Handle writerEvent
Mailbox not full event if using Events. Default is null.
Definition: Mailbox.h:218
IHeap_Handle heap
The IHeap instance used for dynamic creates.
Definition: Mailbox.h:194
void Mailbox_delete(Mailbox_Handle *mailbox)
Delete a mailbox.
bool Mailbox_pend(Mailbox_Handle mailbox, void *msg, uint32_t timeout)
Wait for a message from mailbox.
Event Manager.
Definition: Mailbox.h:262
void * buf
The address of the buffer used for creating messages.
Definition: Mailbox.h:251
struct Mailbox_Struct * Mailbox_Handle
Definition: Mailbox.h:316
Mailbox_Handle Mailbox_create(size_t msgSize, unsigned int numMsgs, const Mailbox_Params *prms, Error_Block *eb)
Create a mailbox.
void Mailbox_destruct(Mailbox_Struct *obj)
Destruct a mailbox.
Mailbox_Handle Mailbox_Object_next(Mailbox_Handle mbx)
return handle of the next Mailbox on Mailbox list
Semaphore Manager.
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale