ESOS32
ESOSOn32-bitProcessors
esos_cb.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2019 J. W. Bruce ("AUTHOR(S)")"
3  * All rights reserved.
4  * (J. W. Bruce, jwbruce_AT_tntech.edu, Tennessee Tech University)
5  *
6  * Permission to use, copy, modify, and distribute this software and its
7  * documentation for any purpose, without fee, and without written agreement is
8  * hereby granted, provided that the above copyright notice, the following
9  * two paragraphs and the authors appear in all copies of this software.
10  *
11  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
12  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
13  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
14  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15  *
16  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
17  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
19  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
20  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
21  *
22  * Please maintain this header in its entirety when copying/modifying
23  * these files.
24  *
25  *
26  */
27 
42 #ifndef ESOS_CB_H
43 #define ESOS_CB_H
44 
45 /* I N C L U D E S **********************************************************/
46 #include "esos.h"
47 
48 /* D E F I N E S ************************************************************/
49 
50 /* S T R U C T U R E S ******************************************************/
51 
56 typedef struct __stCIRCBUFF {
57  uint16_t u16_Length; // maximum number of elements
58  uint16_t u16_Start; // index of oldest element
59  uint16_t u16_Count; // number of elements in use
60  uint8_t* pau8_Data; // ptr to data area (SHOULD THIS BE A void* ?)
61 } CBUFFER;
62 
63 typedef CBUFFER* CBUFF_HANDLE;
64 
65 /* M A C R O S ************************************************************/
66 #define __ESOS_CB_FLUSH(pstCB) (pstCB)->u16_Count = 0
67 #define __ESOS_CB_IS_EMPTY(pstCB) ((pstCB)->u16_Count == 0)
68 #define __ESOS_CB_IS_NOT_EMPTY(pstCB) ((pstCB)->u16_Count != 0)
69 #define __ESOS_CB_IS_FULL(pstCB) ((pstCB)->u16_Length == (pstCB)->u16_Count)
70 #define __ESOS_CB_GET_LENGTH(pstCB) ((pstCB)->u16_Length)
71 #define __ESOS_CB_GET_COUNT(pstCB) ((pstCB)->u16_Count)
72 #define __ESOS_CB_GET_AVAILABLE(pstCB) (__ESOS_CB_GET_LENGTH(pstCB)-__ESOS_CB_GET_COUNT(pstCB))
73 #define __ESOS_CB_IS_AVAILABLE_AT_LEAST(pstCB, x) (__ESOS_CB_GET_AVAILABLE((pstCB))>=(x))
74 #define __ESOS_CB_IS_AVAILABLE_EXACTLY(pstCB, x) (__ESOS_CB_GET_AVAILABLE((pstCB))==(x))
75 
76 #define ESOS_TASK_WAIT_WHILE_CB_IS_EMPTY(pstCB) ESOS_TASK_WAIT_WHILE(__ESOS_CB_IS_EMPTY((pstCB)))
77 #define ESOS_TASK_WAIT_WHILE_CB_IS_FULL(pstCB) ESOS_TASK_WAIT_WHILE(__ESOS_CB_IS_FULL((pstCB)))
78 #define ESOS_TASK_WAIT_UNTIL_CB_HAS_AVAILABLE_AT_LEAST(pstCB,x) ESOS_TASK_WAIT_UNTIL(__ESOS_CB_IS_AVAILABLE_AT_LEAST((pstCB),(x)))
79 
80 
81 /* E X T E R N S ************************************************************/
82 
83 /* P U B L I C P R O T O T Y P E S *****************************************/
84 
85 
86 /* P R I V A T E P R O T O T Y P E S ***********************************/
87 void __esos_CB_Init(CBUFFER* pst_CBuffer, uint8_t* pau8_ptr, uint16_t u16_Length);
88 void __esos_CB_WriteUINT8(CBUFFER* pst_CBuffer, uint8_t u8_x);
89 void __esos_CB_WriteUINT16(CBUFFER* pst_CBuffer, uint16_t u16_x);
90 void __esos_CB_WriteUINT32(CBUFFER* pst_CBuffer, uint32_t u32_x);
91 void __esos_CB_WriteUINT8Buffer(CBUFFER* pst_CBuffer, uint8_t* pu8_x, uint16_t u16_size );
92 void __esos_CB_OverwriteUINT8(CBUFFER *pst_CBuffer, uint8_t u8_x);
93 
94 
95 uint8_t __esos_CB_ReadUINT8(CBUFFER* pst_CBuffer);
96 uint16_t __esos_CB_ReadUINT16(CBUFFER* pst_CBuffer);
97 uint32_t __esos_CB_ReadUINT32(CBUFFER* pst_CBuffer);
98 void __esos_CB_ReadUINT8Buffer(CBUFFER* pst_CBuffer, uint8_t* pu8_x, uint16_t u16_size );
99 
113 #endif // ESOS_CB_H
CBUFFER
struct __stCIRCBUFF CBUFFER
__stCIRCBUFF
Definition: esos_cb.h:56
esos.h
__esos_CB_WriteUINT8
void __esos_CB_WriteUINT8(CBUFFER *pst_CBuffer, uint8_t u8_x)
Definition: esos_cb.c:95