yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2005 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /***************************************************************************** |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * bmd.h |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * Maui_Software |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * This file is intends for ring-buffer API. |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================ |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * removed! |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * removed! |
| 89 | * |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * removed! |
| 93 | * |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * removed! |
| 97 | * |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * removed! |
| 101 | * |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * removed! |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * removed! |
| 109 | * removed! |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * removed! |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * removed! |
| 116 | * removed! |
| 117 | * removed! |
| 118 | * removed! |
| 119 | *------------------------------------------------------------------------------ |
| 120 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 121 | *============================================================================ |
| 122 | ****************************************************************************/ |
| 123 | #ifndef BMD_H |
| 124 | #define BMD_H |
| 125 | |
| 126 | #include "drv_comm.h" |
| 127 | |
| 128 | typedef struct __BUFFER_INFO |
| 129 | { |
| 130 | volatile kal_uint16 Read; /* @field Current Read index. */ |
| 131 | volatile kal_uint16 Write; /* @field Current Write index. */ |
| 132 | volatile kal_uint16 Length; /* @field Length of buffer */ |
| 133 | volatile kal_uint8 *CharBuffer; /* @field Start of buffer */ |
| 134 | }BUFFER_INFO; |
| 135 | |
| 136 | #define ResetFifo(Buffer) (Buffer.Write = Buffer.Read = 0) |
| 137 | #define BWrite(Buffer) (Buffer->Write) |
| 138 | #define BRead(Buffer) (Buffer->Read) |
| 139 | #define BLength(Buffer) (Buffer->Length) |
| 140 | #define BStartAddr(Buffer) (Buffer->CharBuffer) |
| 141 | #define BuffWrite(Buffer) (Buffer->CharBuffer+Buffer->Write) |
| 142 | #define BuffRead(Buffer) (Buffer->CharBuffer+Buffer->Read) |
| 143 | |
| 144 | #define BWrite_addr(Buffer) (Buffer.Write) |
| 145 | #define BRead_addr(Buffer) (Buffer.Read) |
| 146 | #define BLength_addr(Buffer) (Buffer.Length) |
| 147 | #define BuffWrite_addr(Buffer) (Buffer.CharBuffer+Buffer.Write) |
| 148 | #define BuffRead_addr(Buffer) (Buffer.CharBuffer+Buffer.Read) |
| 149 | #define Buff_EndAddr(Buffer) (Buffer.CharBuffer+Buffer.Length-1) |
| 150 | #define Buff_StartAddr(Buffer) (Buffer.CharBuffer) |
| 151 | |
| 152 | #define Buff_isEmpty 1 |
| 153 | #define Buff_notEmpty 0 |
| 154 | #define Buff_isFull 1 |
| 155 | #define Buff_notFull 0 |
| 156 | #define Buff_PushOK 0 |
| 157 | #define Buff_PushErr 1 |
| 158 | #define Buff_PopOK 0 |
| 159 | #define Buff_PopErr 1 |
| 160 | |
| 161 | #define Buf_init(_Buffer,_Buffaddr,_uTotalSize) \ |
| 162 | {\ |
| 163 | BUFFER_INFO *_Buf=_Buffer;\ |
| 164 | _Buf->Read = 0;\ |
| 165 | _Buf->Write = 0;\ |
| 166 | _Buf->Length = _uTotalSize;\ |
| 167 | _Buf->CharBuffer = _Buffaddr;\ |
| 168 | }\ |
| 169 | |
| 170 | #define Buf_IsFull(_Buffer,_result) \ |
| 171 | {\ |
| 172 | BUFFER_INFO *_Buf=_Buffer;\ |
| 173 | kal_uint16 _tmp = BRead(_Buf);\ |
| 174 | if (_tmp == 0)\ |
| 175 | _tmp = BLength(_Buf);\ |
| 176 | if ( (_tmp-BWrite(_Buf)) == 1)\ |
| 177 | {\ |
| 178 | _result = Buff_isFull;\ |
| 179 | }\ |
| 180 | else\ |
| 181 | {\ |
| 182 | _result = Buff_notFull;\ |
| 183 | }\ |
| 184 | }\ |
| 185 | |
| 186 | #define Buf_GetRoomLeft(_Buffer,_RoomLeft) \ |
| 187 | {\ |
| 188 | BUFFER_INFO *_Buf=_Buffer;\ |
| 189 | if ( BRead(_Buf) <= BWrite(_Buf) ) \ |
| 190 | {\ |
| 191 | _RoomLeft = BLength(_Buf) - BWrite(_Buf) + BRead(_Buf) - 1;\ |
| 192 | }\ |
| 193 | else\ |
| 194 | {\ |
| 195 | _RoomLeft = BRead(_Buf) - BWrite(_Buf) - 1;\ |
| 196 | }\ |
| 197 | }\ |
| 198 | |
| 199 | #define Buf_Push_Multi(_Buffer,_pushDataPointer,_multi,offset) \ |
| 200 | {\ |
| 201 | BUFFER_INFO *_Buf=_Buffer;\ |
| 202 | if( (BWrite(_Buf) + _multi) >= BLength(_Buf) ){\ |
| 203 | kal_mem_cpy(BuffWrite(_Buf), _pushDataPointer + offset, (BLength(_Buf) - BWrite(_Buf))*sizeof(kal_uint8));\ |
| 204 | kal_mem_cpy(BStartAddr(_Buf) , _pushDataPointer + offset + (BLength(_Buf) - BWrite(_Buf)), (_multi- (BLength(_Buf) - BWrite(_Buf)))*sizeof(kal_uint8));\ |
| 205 | BWrite(_Buf) = (BWrite(_Buf) + _multi) - BLength(_Buf);\ |
| 206 | }\ |
| 207 | else{\ |
| 208 | kal_mem_cpy(BuffWrite(_Buf), _pushDataPointer + offset, _multi*sizeof(kal_uint8));\ |
| 209 | BWrite(_Buf) += _multi;\ |
| 210 | }\ |
| 211 | }\ |
| 212 | |
| 213 | #define Buf_Push(_Buffer,_pushData) \ |
| 214 | {\ |
| 215 | BUFFER_INFO *_Buf=_Buffer;\ |
| 216 | *BuffWrite(_Buf) = _pushData;\ |
| 217 | if(BWrite(_Buf) >= (BLength(_Buf) - 1))\ |
| 218 | {\ |
| 219 | BWrite(_Buf) = 0;\ |
| 220 | }\ |
| 221 | else\ |
| 222 | {\ |
| 223 | BWrite(_Buf)++;\ |
| 224 | }\ |
| 225 | }\ |
| 226 | |
| 227 | #define Buf_GetBytesAvail(_Buffer,_BytesAvail) \ |
| 228 | {\ |
| 229 | BUFFER_INFO *_Buf = _Buffer;\ |
| 230 | _BytesAvail = 0;\ |
| 231 | if (BWrite(_Buf) >= BRead(_Buf))\ |
| 232 | _BytesAvail = BWrite(_Buf) - BRead(_Buf);\ |
| 233 | else\ |
| 234 | _BytesAvail = BLength(_Buf) - BRead(_Buf) + BWrite(_Buf); \ |
| 235 | }\ |
| 236 | |
| 237 | #define Buf_GetBytesAvail_DMA(_Buffer,_BytesAvail) \ |
| 238 | {\ |
| 239 | BUFFER_INFO *_Buf = _Buffer;\ |
| 240 | _BytesAvail = 0;\ |
| 241 | if (BWrite(_Buf) >= BRead(_Buf))\ |
| 242 | _BytesAvail = BWrite(_Buf) - BRead(_Buf);\ |
| 243 | else\ |
| 244 | _BytesAvail = BLength(_Buf) - BRead(_Buf); \ |
| 245 | }\ |
| 246 | |
| 247 | #define Buf_Pop_Multi(_Buffer,_popDataPointer,_multi,offset) \ |
| 248 | {\ |
| 249 | BUFFER_INFO *_Buf=_Buffer;\ |
| 250 | if( (BRead(_Buf) + _multi) >= BLength(_Buf) ){\ |
| 251 | kal_mem_cpy(_popDataPointer + offset, BuffRead(_Buf), (BLength(_Buf) - BRead(_Buf))*sizeof(kal_uint8));\ |
| 252 | kal_mem_cpy(_popDataPointer + offset + (BLength(_Buf) - BRead(_Buf)), BStartAddr(_Buf), (_multi- (BLength(_Buf) - BRead(_Buf)))*sizeof(kal_uint8));\ |
| 253 | BRead(_Buf) = BRead(_Buf) + _multi - BLength(_Buf) ;)\ |
| 254 | else{\ |
| 255 | kal_mem_cpy(_popDataPointer + offset, BuffRead(_Buf), _multi);\ |
| 256 | BRead(_Buf) += _multi;}\ |
| 257 | }\ |
| 258 | |
| 259 | #define Buf_Pop(_Buffer,_popData) \ |
| 260 | {\ |
| 261 | BUFFER_INFO *_Buf = _Buffer;\ |
| 262 | _popData= *BuffRead(_Buf);\ |
| 263 | BRead(_Buf)++;\ |
| 264 | if (BRead(_Buf) >= BLength(_Buf))\ |
| 265 | {\ |
| 266 | BRead(_Buf) -= BLength(_Buf);\ |
| 267 | }\ |
| 268 | }\ |
| 269 | |
| 270 | /* should be deleted */ |
| 271 | #define Buf_IsEmpty(_Buffer,_result) \ |
| 272 | {\ |
| 273 | BUFFER_INFO *_Buf = _Buffer;\ |
| 274 | if ( BRead(_Buf) == BWrite(_Buf) ) \ |
| 275 | {\ |
| 276 | _result = Buff_isEmpty;\ |
| 277 | }\ |
| 278 | else\ |
| 279 | {\ |
| 280 | _result = Buff_notEmpty;\ |
| 281 | }\ |
| 282 | }\ |
| 283 | |
| 284 | /* void Get32FromBuff(BUFFER_INFO *Buf,kal_uint32 DATA) */ |
| 285 | #define Get32FromBuf(_Buffer,_DATA) \ |
| 286 | {\ |
| 287 | BUFFER_INFO *_Buf = _Buffer;\ |
| 288 | kal_uint8 _tmp,_index;\ |
| 289 | kal_uint32 _tmp32;\ |
| 290 | _DATA =0;\ |
| 291 | for (_index =0;_index < 4;_index++)\ |
| 292 | {\ |
| 293 | Buff_Pop(_Buf,&_tmp);\ |
| 294 | _tmp32 = (kal_uint32)_tmp;\ |
| 295 | (_DATA) |= (_tmp32 << (8*_index));\ |
| 296 | }\ |
| 297 | }\ |
| 298 | |
| 299 | /*void Put32toBuff(BUFFER_INFO *Buf,kal_uint32 *DATA)*/ |
| 300 | #define Put32toBuf(_Buffer,_DATA) \ |
| 301 | {\ |
| 302 | BUFFER_INFO *_Buf = _Buffer;\ |
| 303 | kal_uint8 _tmp,_index;\ |
| 304 | kal_uint32 _tmp32;\ |
| 305 | for (_index =0;_index < 4;_index++)\ |
| 306 | {\ |
| 307 | _tmp32 = ((*_DATA) >> (8*_index));\ |
| 308 | _tmp = (kal_uint8)_tmp32;\ |
| 309 | Buff_Push(_Buf,&_tmp);\ |
| 310 | }\ |
| 311 | }\ |
| 312 | |
| 313 | #define Buf_Flush(_Buffer) \ |
| 314 | {\ |
| 315 | BUFFER_INFO *_Buf = _Buffer;\ |
| 316 | _Buf->Write = _Buf->Read = 0;\ |
| 317 | } |
| 318 | |
| 319 | #define Buf_look(_Buffer,_popData,_num) \ |
| 320 | {\ |
| 321 | BUFFER_INFO *_Buf = _Buffer;\ |
| 322 | kal_uint8 _index;\ |
| 323 | kal_uint16 _tmp;\ |
| 324 | _tmp = BRead(Buf);\ |
| 325 | for(_index=0;_index<_num;_index++)\ |
| 326 | {\ |
| 327 | *_popData= *(Buf->CharBuffer+_tmp);\ |
| 328 | _tmp++;\ |
| 329 | if (_tmp >= BLength(Buf))\ |
| 330 | {\ |
| 331 | _tmp -= BLength(Buf);\ |
| 332 | }\ |
| 333 | }\ |
| 334 | } |
| 335 | |
| 336 | // MoDIS parser skip start |
| 337 | #if 1 |
| 338 | extern void Buff_init(BUFFER_INFO *Buf,kal_uint8 *Buffaddr, kal_uint16 uTotalSize); |
| 339 | extern void Buff_Push(BUFFER_INFO *Buf,kal_uint8 *pushData); |
| 340 | extern void Buff_Pop(BUFFER_INFO *Buf,kal_uint8 *popData); |
| 341 | extern kal_uint8 Buff_IsEmpty(BUFFER_INFO *Buf); |
| 342 | extern kal_uint8 Buff_IsFull (BUFFER_INFO *Buf); |
| 343 | extern kal_uint16 Buff_GetRoomLeft (BUFFER_INFO *Buf); |
| 344 | extern kal_uint16 Buff_GetBytesAvail (BUFFER_INFO *Buf); |
| 345 | extern kal_uint16 Buff_GetLength(BUFFER_INFO *Buf); |
| 346 | extern void Buff_Flush (BUFFER_INFO *Buf); |
| 347 | extern void Buff_look(BUFFER_INFO *Buf,kal_uint8 *popData,kal_uint8 num); |
| 348 | extern void Get32FromBuff(BUFFER_INFO *Buf,kal_uint32 *DATA); |
| 349 | extern void Put32toBuff(BUFFER_INFO *Buf,kal_uint32 *DATA); |
| 350 | extern void MemCPY(kal_uint8 *dst,kal_uint8 *src,kal_uint32 len); |
| 351 | extern void MemSET(kal_uint8 *dst,kal_uint8 data,kal_uint32 len); |
| 352 | #endif |
| 353 | // MoDIS parser skip end |
| 354 | |
| 355 | #endif |
| 356 | |