added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / staging / meilhaus / mecirc_buf.h
blobe9b591eaa3490b0be589ee2601612d6bacadfd09
1 /**
2 * @file mecirc_buf.h
4 * @brief Meilhaus circular buffer implementation.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 * @author Krzysztof Gantzke (k.gantzke@meilhaus.de)
8 */
11 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
13 * This file is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #ifndef _MECIRC_BUF_H_
29 #define _MECIRC_BUF_H_
31 # ifdef __KERNEL__
33 # ifdef BOSCH
35 typedef struct me_circ_buf {
36 unsigned int mask;
37 // unsigned int count;
38 uint32_t *buf;
39 int volatile head;
40 int volatile tail;
41 } me_circ_buf_t;
43 static int inline me_circ_buf_values(me_circ_buf_t * buf)
45 // return ((buf->head - buf->tail) & (buf->count - 1));
46 return ((buf->head - buf->tail) & (buf->mask));
49 static int inline me_circ_buf_space(me_circ_buf_t * buf)
51 // return ((buf->tail - (buf->head + 1)) & (buf->count - 1));
52 return ((buf->tail - (buf->head + 1)) & (buf->mask));
55 static int inline me_circ_buf_values_to_end(me_circ_buf_t * buf)
57 int end;
58 int n;
59 // end = buf->count - buf->tail;
60 // n = (buf->head + end) & (buf->count - 1);
61 end = buf->mask + 1 - buf->tail;
62 n = (buf->head + end) & (buf->mask);
63 return (n < end) ? n : end;
66 static int inline me_circ_buf_space_to_end(me_circ_buf_t * buf)
68 int end;
69 int n;
71 // end = buf->count - 1 - buf->head;
72 // n = (end + buf->tail) & (buf->count - 1);
73 end = buf->mask - buf->head;
74 n = (end + buf->tail) & (buf->mask);
75 return (n <= end) ? n : (end + 1);
78 #define _CBUFF_32b_t
80 # else //~BOSCH
81 /// @note buf->mask = buf->count-1 = ME4600_AI_CIRC_BUF_COUNT-1
83 # ifdef _CBUFF_32b_t
84 //32 bit
85 typedef struct me_circ_buf_32b {
86 int volatile head;
87 int volatile tail;
88 unsigned int mask; //buffor size-1 must be 2^n-1 to work
89 uint32_t *buf;
90 } me_circ_buf_t;
91 # else
92 //16 bit
93 typedef struct me_circ_buf_16b {
94 int volatile head;
95 int volatile tail;
96 unsigned int mask; //buffor size-1 must be 2^n-1 to work
97 uint16_t *buf;
98 } me_circ_buf_t;
99 # endif //_CBUFF_32b_t
101 /** How many values is in buffer */
102 static int inline me_circ_buf_values(me_circ_buf_t * buf)
104 return ((buf->head - buf->tail) & (buf->mask));
107 /** How many space left */
108 static int inline me_circ_buf_space(me_circ_buf_t * buf)
110 return ((buf->tail - (buf->head + 1)) & (buf->mask));
113 /** How many values can be read from buffor in one chunck. */
114 static int inline me_circ_buf_values_to_end(me_circ_buf_t * buf)
116 return (buf->tail <=
117 buf->head) ? (buf->head - buf->tail) : (buf->mask - buf->tail +
121 /** How many values can be write to buffer in one chunck. */
122 static int inline me_circ_buf_space_to_end(me_circ_buf_t * buf)
124 return (buf->tail <=
125 buf->head) ? (buf->mask - buf->head + 1) : (buf->tail -
126 buf->head - 1);
129 # endif //BOSCH
130 # endif //__KERNEL__
131 #endif //_MECIRC_BUF_H_