yfifo.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yfifo.h 24872 2016-06-20 13:29:48Z seb $
4  *
5  * Declaration of a generic fifo queue
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 #ifndef YFIFO_H
40 #define YFIFO_H
41 #include "ydef.h"
42 
43 #ifndef MICROCHIP_API
44 #define YFIFO_USE_MUTEX
45 #endif
46 
47 //#define DEBUG_FIFO
48 
49 #if defined(WINDOWS_API) && defined(YFIFO_USE_MUTEX)
50 #if defined(__BORLANDC__)
51 #pragma warn -8019
52 #include <windows.h>
53 #pragma warn +8019
54 #else
55 #include <windows.h>
56 #endif
57 #endif
58 
59 typedef struct {
60  u16 buffsize;
61  u16 datasize;
62  u8 *buff;
63  u8 *head;
64  u8 *tail;
65 #ifdef YFIFO_USE_MUTEX
67 #endif
68 #ifdef DEBUG_FIFO
69  const char* fileid;
70  int line;
71  u32 totalPushed;
72  u32 totalPopded;
73 #endif
74 } yFifoBuf;
75 
76 #define YFIFOEND(fifobuf) ((fifobuf)->buff + (fifobuf)->buffsize)
77 
78 
79 #ifdef DEBUG_FIFO
80 void yFifoInitEx(const char* fileid,int line, yFifoBuf *buf, u8 *buffer, u16 bufflen);
81 #define yFifoInit(fifo,buffer,len) yFifoInitEx(__FILE_ID__,__LINE__,fifo,buffer,len);
82 #else
83 void yFifoInitEx(yFifoBuf *buf, u8 *buffer, u16 bufflen);
84 #define yFifoInit(fifo,buffer,len) yFifoInitEx(fifo,buffer,len);
85 #endif
86 
87 #ifdef MICROCHIP_API
88 #define yFifoCleanup(fifo) memset(fifo, 0, sizeof(yFifoBuf))
89 #else
90 void yFifoCleanup(yFifoBuf *buf);
91 #endif
92 
93 // Ex version do not have muxtex
94 void yFifoEmptyEx(yFifoBuf *buf);
95 u16 yPushFifoEx(yFifoBuf *buf, const u8 *data, u16 datalen);
96 u16 yPopFifoEx(yFifoBuf *buf, u8 *data, u16 datalen);
97 u16 yPeekFifoEx(yFifoBuf *buf, u8 *data, u16 datalen, u16 startofs);
98 u16 yPeekContinuousFifoEx(yFifoBuf *buf, u8 **ptr, u16 startofs);
99 u16 ySeekFifoEx(yFifoBuf *buf, const u8* pattern, u16 patlen, u16 startofs, u16 searchlen, u8 bTextCompare);
100 u16 yFifoGetUsedEx(yFifoBuf *buf);
101 u16 yFifoGetFreeEx(yFifoBuf *buf);
102 u16 yForceFifo(yFifoBuf *buf, const u8 *data, u16 datalen, u32 *absCounter);
103 
104 #ifdef YFIFO_USE_MUTEX
105 // mutex non-Ex function call yFifoEnterCs and yFifoLeaveCs
106 // before calling Ex version
107 
108 void yFifoEnterCS(yFifoBuf *buf);
109 void yFifoLeaveCS(yFifoBuf *buf);
110 void yFifoEmpty(yFifoBuf *buf);
111 u16 yPushFifo(yFifoBuf *buf, const u8 *data, u16 datalen);
112 u16 yPopFifo(yFifoBuf *buf, u8 *data, u16 datalen);
113 u16 yPeekFifo(yFifoBuf *buf, u8 *data, u16 datalen, u16 startofs);
114 u16 yPeekContinuousFifo(yFifoBuf *buf, u8 **ptr,u16 startofs);
115 u16 ySeekFifo(yFifoBuf *buf, const u8* pattern, u16 patlen, u16 startofs, u16 searchlen, u8 bTextCompare);
116 u16 yFifoGetUsed(yFifoBuf *buf);
117 u16 yFifoGetFree(yFifoBuf *buf);
118 
119 #else
120 // no mutex -> map function to Ex version
121 #define yFifoEnterCS(buf)
122 #define yFifoLeaveCS(buf)
123 #define yFifoEmpty(buf) yFifoEmptyEx(buf)
124 #define yPushFifo(buf,data, datalen) yPushFifoEx(buf,data,datalen)
125 #define yPopFifo(buf, data, datalen) yPopFifoEx(buf,data,datalen)
126 #define yPeekFifo(buf, data, datalen, startofs) yPeekFifoEx(buf,data,datalen,startofs)
127 #define yPeekContinuousFifo(buf,ptr,startofs) yPeekContinuousFifoEx(buf,ptr,startofs)
128 #define ySeekFifo(buf, pattern, patlen, startofs, searchlen, bTextCompare) ySeekFifoEx(buf,pattern,patlen,startofs,searchlen,bTextCompare)
129 #define yFifoGetUsed(buf) yFifoGetUsedEx(buf)
130 #define yFifoGetFree(buf) yFifoGetFreeEx(buf)
131 #endif
132 
133 // Misc functions needed in yapi, hubs and devices
134 void yxtoa(u32 x, char *buf, u16 len);
135 void decodePubVal(Notification_funydx funInfo, const char *funcval, char *buffer);
136 
137 #endif
u16 yPushFifoEx(yFifoBuf *buf, const u8 *data, u16 datalen)
Definition: yfifo.c:108
void yFifoCleanup(yFifoBuf *buf)
Definition: yfifo.c:70
void * yCRITICAL_SECTION
Definition: ydef.h:366
u16 yPopFifoEx(yFifoBuf *buf, u8 *data, u16 datalen)
Definition: yfifo.c:153
u16 yFifoGetUsed(yFifoBuf *buf)
Definition: yfifo.c:385
u16 yFifoGetFree(yFifoBuf *buf)
Definition: yfifo.c:401
u16 buffsize
Definition: yfifo.h:60
void yFifoEnterCS(yFifoBuf *buf)
Definition: yfifo.c:81
u8 * head
Definition: yfifo.h:63
u16 yPeekContinuousFifoEx(yFifoBuf *buf, u8 **ptr, u16 startofs)
Definition: yfifo.c:274
yCRITICAL_SECTION cs
Definition: yfifo.h:66
u16 yFifoGetFreeEx(yFifoBuf *buf)
Definition: yfifo.c:395
void yFifoEmptyEx(yFifoBuf *buf)
Definition: yfifo.c:92
Definition: yfifo.h:59
void decodePubVal(Notification_funydx funInfo, const char *funcval, char *buffer)
Definition: yfifo.c:429
u16 yPopFifo(yFifoBuf *buf, u8 *data, u16 datalen)
Definition: yfifo.c:187
void yFifoInitEx(yFifoBuf *buf, u8 *buffer, u16 bufflen)
Definition: yfifo.c:50
void yFifoLeaveCS(yFifoBuf *buf)
Definition: yfifo.c:86
u8 * buff
Definition: yfifo.h:62
void yFifoEmpty(yFifoBuf *buf)
Definition: yfifo.c:100
u16 yPushFifo(yFifoBuf *buf, const u8 *data, u16 datalen)
Definition: yfifo.c:143
u16 yPeekFifoEx(yFifoBuf *buf, u8 *data, u16 datalen, u16 startofs)
Definition: yfifo.c:232
u16 yPeekFifo(yFifoBuf *buf, u8 *data, u16 datalen, u16 startofs)
Definition: yfifo.c:263
u16 ySeekFifo(yFifoBuf *buf, const u8 *pattern, u16 patlen, u16 startofs, u16 searchlen, u8 bTextCompare)
Definition: yfifo.c:367
u16 yFifoGetUsedEx(yFifoBuf *buf)
Definition: yfifo.c:378
u16 ySeekFifoEx(yFifoBuf *buf, const u8 *pattern, u16 patlen, u16 startofs, u16 searchlen, u8 bTextCompare)
Definition: yfifo.c:314
u8 * tail
Definition: yfifo.h:64
void yxtoa(u32 x, char *buf, u16 len)
Definition: yfifo.c:413
u16 yPeekContinuousFifo(yFifoBuf *buf, u8 **ptr, u16 startofs)
Definition: yfifo.c:303
u16 yForceFifo(yFifoBuf *buf, const u8 *data, u16 datalen, u32 *absCounter)
Definition: yfifo.c:214
u16 datasize
Definition: yfifo.h:61


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:10