PIC24 Support Libraries
esos_cb.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2013 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30 
31 /**
32  * \addtogroup ESOS_Circular_Buffers
33  * @{
34  */
35 
36 
37 /** \file
38  * This file contains macros, prototypes, and definitions for
39  * circular buffers used by many ESOS services.
40  *
41  * \todo Reconcile circular buffer routines to be used in tasks and ISRs!
42  */
43 
44 
45 #ifndef ESOS_CB_H
46 #define ESOS_CB_H
47 
48 /* I N C L U D E S **********************************************************/
49 #include "esos.h"
50 
51 /* D E F I N E S ************************************************************/
52 
53 /* S T R U C T U R E S ******************************************************/
54 
55 /**
56 * structure to contain a set of descriptors about the buffers used
57 * to implement ESOS task mailboxes
58 **/
59 typedef struct __stCIRCBUFF {
60  uint16_t u16_Length; // maximum number of elements
61  uint16_t u16_Start; // index of oldest element
62  uint16_t u16_Count; // number of elements in use
63  uint8_t* pau8_Data; // ptr to data area (SHOULD THIS BE A void* ?)
64 } CBUFFER;
65 
66 typedef CBUFFER* CBUFF_HANDLE;
67 
68 /* M A C R O S ************************************************************/
69 #define __ESOS_CB_FLUSH(pstCB) (pstCB)->u16_Count = 0
70 #define __ESOS_CB_IS_EMPTY(pstCB) ((pstCB)->u16_Count == 0)
71 #define __ESOS_CB_IS_NOT_EMPTY(pstCB) ((pstCB)->u16_Count != 0)
72 #define __ESOS_CB_IS_FULL(pstCB) ((pstCB)->u16_Length == (pstCB)->u16_Count)
73 #define __ESOS_CB_GET_LENGTH(pstCB) ((pstCB)->u16_Length)
74 #define __ESOS_CB_GET_COUNT(pstCB) ((pstCB)->u16_Count)
75 #define __ESOS_CB_GET_AVAILABLE(pstCB) (__ESOS_CB_GET_LENGTH(pstCB)-__ESOS_CB_GET_COUNT(pstCB))
76 #define __ESOS_CB_IS_AVAILABLE_AT_LEAST(pstCB, x) (__ESOS_CB_GOT_AVAILABLE((pstCB))>=(x))
77 #define __ESOS_CB_IS_AVAILABLE_EXACTLY(pstCB, x) (__ESOS_CB_GOT_AVAILABLE((pstCB))==(x))
78 
79 #define ESOS_TASK_WAIT_WHILE_CB_IS_EMPTY(pstCB) ESOS_TASK_WAIT_WHILE(__ESOS_CB_IS_EMPTY((pstCB)))
80 #define ESOS_TASK_WAIT_WHILE_CB_IS_FULL(pstCB) ESOS_TASK_WAIT_WHILE(__ESOS_CB_IS_FULL((pstCB)))
81 #define ESOS_TASK_WAIT_UNTIL_CB_HAS_AVAILABLE_AT_LEAST(pstCB,x) ESOS_TASK_WAIT_UNTIL(__ESOS_CB_IS_AVAILABLE_AT_LEAST((pstCB),x))
82 
83 
84 /* E X T E R N S ************************************************************/
85 
86 /* P U B L I C P R O T O T Y P E S *****************************************/
87 
88 
89 /* P R I V A T E P R O T O T Y P E S ***********************************/
90 void __esos_CB_Init(CBUFFER* pst_CBuffer, uint8_t* pau8_ptr, uint16_t u16_Length);
91 void __esos_CB_WriteUINT8(CBUFFER* pst_CBuffer, uint8_t u8_x);
92 void __esos_CB_WriteUINT16(CBUFFER* pst_CBuffer, uint16_t u16_x);
93 void __esos_CB_WriteUINT32(CBUFFER* pst_CBuffer, uint32_t u32_x);
94 void __esos_CB_WriteUINT8Buffer(CBUFFER* pst_CBuffer, uint8_t* pu8_x, uint16_t u16_size );
95 void __esos_CB_OverwriteUINT8(CBUFFER *pst_CBuffer, uint8_t u8_x);
96 
97 
98 uint8_t __esos_CB_ReadUINT8(CBUFFER* pst_CBuffer);
99 uint16_t __esos_CB_ReadUINT16(CBUFFER* pst_CBuffer);
100 uint32_t __esos_CB_ReadUINT32(CBUFFER* pst_CBuffer);
101 void __esos_CB_ReadUINT8Buffer(CBUFFER* pst_CBuffer, uint8_t* pu8_x, uint16_t u16_size );
102 
103 /**
104 void __esos_CB_Init(MAILBOX* pst_Mailbox);
105 void __esos_WriteMailboxUINT8(MAILBOX* pst_Mailbox, uint8_t u8_x );
106 void __esos_WriteMailboxUINT16(MAILBOX* pst_Mailbox, uint16_t u16_x );
107 void __esos_WriteMailboxUINT32(MAILBOX* pst_Mailbox, uint32_t u32_x );
108 uint8_t __esos_ReadMailboxUINT8(MAILBOX* pst_Mailbox );
109 uint16_t __esos_ReadMailboxUINT16(MAILBOX* pst_Mailbox );
110 uint32_t __esos_ReadMailboxUINT32(MAILBOX* pst_Mailbox );
111 void __esos_SendMailUint8(ESOS_TASK_HANDLE pst_Task, MAILBOX* pst_Mailbox, uint8_t* pau8_data, uint8_t u8_len );
112 **/
113 
114 /** @} */
115 
116 #endif // ESOS_CB_H
void __esos_CB_WriteUINT8(CBUFFER *pst_CBuffer, uint8_t u8_x)
Definition: esos_cb.c:90
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194