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 | * bf.c |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * Maui_Software |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * This Module defines the 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 | * removed! |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * removed! |
| 74 | * removed! |
| 75 | *------------------------------------------------------------------------------ |
| 76 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 77 | *============================================================================ |
| 78 | ****************************************************************************/ |
| 79 | #include "drv_comm.h" |
| 80 | #include "bmd.h" |
| 81 | |
| 82 | |
| 83 | /* |
| 84 | * FUNCTION |
| 85 | * Buff_init |
| 86 | * |
| 87 | * DESCRIPTION |
| 88 | * This function is to let a memory area become a ring-buffer |
| 89 | * |
| 90 | * CALLS |
| 91 | * |
| 92 | * PARAMETERS |
| 93 | * *Buf: struct of BUFFER_INFO |
| 94 | * Buffaddr: the start addr of memory area |
| 95 | * uTotalSize: the size of the memory area |
| 96 | * |
| 97 | * RETURNS |
| 98 | * None |
| 99 | * |
| 100 | * GLOBALS AFFECTED |
| 101 | * external_global |
| 102 | */ |
| 103 | void Buff_init(BUFFER_INFO *Buf,kal_uint8 *Buffaddr, kal_uint16 uTotalSize) |
| 104 | { |
| 105 | Buf->Read = 0; |
| 106 | Buf->Write = 0; |
| 107 | Buf->Length = uTotalSize; |
| 108 | Buf->CharBuffer = Buffaddr; |
| 109 | } |
| 110 | |
| 111 | /* |
| 112 | * FUNCTION |
| 113 | * Buff_Push |
| 114 | * |
| 115 | * DESCRIPTION |
| 116 | * This function is to put a data to ring-buffer |
| 117 | * |
| 118 | * CALLS |
| 119 | * |
| 120 | * PARAMETERS |
| 121 | * *Buf: struct of BUFFER_INFO |
| 122 | * *pushData: the data will be put into ring-buffer |
| 123 | * |
| 124 | * RETURNS |
| 125 | * None |
| 126 | * |
| 127 | * GLOBALS AFFECTED |
| 128 | * external_global |
| 129 | */ |
| 130 | void Buff_Push(BUFFER_INFO *Buf,kal_uint8 *pushData) |
| 131 | { |
| 132 | *BuffWrite(Buf) = *pushData; |
| 133 | BWrite(Buf)++; |
| 134 | if (BWrite(Buf) >= BLength(Buf)) |
| 135 | { |
| 136 | BWrite(Buf) -= BLength(Buf); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * FUNCTION |
| 142 | * Buff_Pop |
| 143 | * |
| 144 | * DESCRIPTION |
| 145 | * This function is to pop a data from ring-buffer |
| 146 | * |
| 147 | * CALLS |
| 148 | * |
| 149 | * PARAMETERS |
| 150 | * *Buf: struct of BUFFER_INFO |
| 151 | * *popData: the data will be pop from ring-buffer |
| 152 | * |
| 153 | * RETURNS |
| 154 | * None |
| 155 | * |
| 156 | * GLOBALS AFFECTED |
| 157 | * external_global |
| 158 | */ |
| 159 | void Buff_Pop(BUFFER_INFO *Buf,kal_uint8 *popData) |
| 160 | { |
| 161 | *popData= *BuffRead(Buf); |
| 162 | BRead(Buf)++; |
| 163 | if (BRead(Buf) >= BLength(Buf)) |
| 164 | { |
| 165 | BRead(Buf) -= BLength(Buf); |
| 166 | } |
| 167 | |
| 168 | } |
| 169 | |
| 170 | void Buff_look(BUFFER_INFO *Buf,kal_uint8 *popData,kal_uint8 num) |
| 171 | { |
| 172 | kal_uint8 index; |
| 173 | kal_uint16 tmp; |
| 174 | |
| 175 | tmp = BRead(Buf); |
| 176 | for(index=0;index<num;index++) |
| 177 | { |
| 178 | *popData= *(Buf->CharBuffer+tmp); |
| 179 | |
| 180 | tmp++; |
| 181 | if (tmp >= BLength(Buf)) |
| 182 | { |
| 183 | tmp -= BLength(Buf); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | /* |
| 188 | * FUNCTION |
| 189 | * Buff_IsEmpty |
| 190 | * |
| 191 | * DESCRIPTION |
| 192 | * This function is check whether ring-buffer is empty |
| 193 | * |
| 194 | * CALLS |
| 195 | * |
| 196 | * PARAMETERS |
| 197 | * *Buf: struct of BUFFER_INFO |
| 198 | * |
| 199 | * RETURNS |
| 200 | * None |
| 201 | * |
| 202 | * GLOBALS AFFECTED |
| 203 | * external_global |
| 204 | */ |
| 205 | kal_uint8 Buff_IsEmpty(BUFFER_INFO *Buf) |
| 206 | { |
| 207 | kal_uint8 status; |
| 208 | if ( BRead(Buf) == BWrite(Buf) ) |
| 209 | { |
| 210 | status = Buff_isEmpty; |
| 211 | } |
| 212 | else |
| 213 | { |
| 214 | status = Buff_notEmpty; |
| 215 | } |
| 216 | return status; |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * FUNCTION |
| 221 | * Buff_IsFull |
| 222 | * |
| 223 | * DESCRIPTION |
| 224 | * This function is check whether ring-buffer is full |
| 225 | * |
| 226 | * CALLS |
| 227 | * |
| 228 | * PARAMETERS |
| 229 | * *Buf: struct of BUFFER_INFO |
| 230 | * |
| 231 | * RETURNS |
| 232 | * None |
| 233 | * |
| 234 | * GLOBALS AFFECTED |
| 235 | * external_global |
| 236 | */ |
| 237 | kal_uint8 Buff_IsFull (BUFFER_INFO *Buf) |
| 238 | { |
| 239 | kal_uint8 status; |
| 240 | kal_uint16 tmp = BRead(Buf); |
| 241 | if (tmp == 0) |
| 242 | tmp = BLength(Buf); |
| 243 | |
| 244 | if ( (tmp-BWrite(Buf)) == 1) |
| 245 | { |
| 246 | status = Buff_isFull; |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | status = Buff_notFull; |
| 251 | } |
| 252 | return status; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * FUNCTION |
| 257 | * Buff_GetRoomLeft |
| 258 | * |
| 259 | * DESCRIPTION |
| 260 | * This function is obtain the size of the residual space |
| 261 | * in ring-buffer |
| 262 | * |
| 263 | * CALLS |
| 264 | * |
| 265 | * PARAMETERS |
| 266 | * *Buf: struct of BUFFER_INFO |
| 267 | * |
| 268 | * RETURNS |
| 269 | * the size of the residual space |
| 270 | * |
| 271 | * GLOBALS AFFECTED |
| 272 | * external_global |
| 273 | */ |
| 274 | kal_uint16 Buff_GetRoomLeft (BUFFER_INFO *Buf) |
| 275 | { |
| 276 | kal_uint16 RoomLeft = 0; |
| 277 | if ( BRead(Buf) <= BWrite(Buf) ) |
| 278 | { |
| 279 | RoomLeft = BLength(Buf) - BWrite(Buf) + BRead(Buf) - 1; |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | RoomLeft = BRead(Buf) - BWrite(Buf) - 1; |
| 284 | } |
| 285 | |
| 286 | return RoomLeft; |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * FUNCTION |
| 291 | * Buff_GetBytesAvail |
| 292 | * |
| 293 | * DESCRIPTION |
| 294 | * This function is obtain the size of the used space |
| 295 | * in ring-buffer |
| 296 | * |
| 297 | * CALLS |
| 298 | * |
| 299 | * PARAMETERS |
| 300 | * *Buf: struct of BUFFER_INFO |
| 301 | * |
| 302 | * RETURNS |
| 303 | * the size of the used space |
| 304 | * |
| 305 | * GLOBALS AFFECTED |
| 306 | * external_global |
| 307 | */ |
| 308 | kal_uint16 Buff_GetBytesAvail (BUFFER_INFO *Buf) |
| 309 | { |
| 310 | kal_uint16 BytesAvail = 0; |
| 311 | if (BWrite(Buf) >= BRead(Buf)) |
| 312 | BytesAvail = BWrite(Buf) - BRead(Buf); |
| 313 | else |
| 314 | BytesAvail = BLength(Buf) - BRead(Buf) + BWrite(Buf); |
| 315 | |
| 316 | return BytesAvail; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * FUNCTION |
| 321 | * Buff_GetLength |
| 322 | * |
| 323 | * DESCRIPTION |
| 324 | * This function is to obtain the total size of the ring-buffer |
| 325 | * |
| 326 | * CALLS |
| 327 | * |
| 328 | * PARAMETERS |
| 329 | * *Buf: struct of BUFFER_INFO |
| 330 | * |
| 331 | * RETURNS |
| 332 | * the total size of the ring-buffer |
| 333 | * |
| 334 | * GLOBALS AFFECTED |
| 335 | * external_global |
| 336 | */ |
| 337 | kal_uint16 Buff_GetLength(BUFFER_INFO *Buf) |
| 338 | { |
| 339 | return Buf->Length; |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | * FUNCTION |
| 344 | * Buff_Flush |
| 345 | * |
| 346 | * DESCRIPTION |
| 347 | * This function is to reset the ring-buffer |
| 348 | * |
| 349 | * CALLS |
| 350 | * |
| 351 | * PARAMETERS |
| 352 | * *Buf: struct of BUFFER_INFO |
| 353 | * |
| 354 | * RETURNS |
| 355 | * None |
| 356 | * |
| 357 | * GLOBALS AFFECTED |
| 358 | * external_global |
| 359 | */ |
| 360 | void Buff_Flush (BUFFER_INFO *Buf) |
| 361 | { |
| 362 | Buf->Write = Buf->Read = 0; |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * FUNCTION |
| 367 | * Get32FromBuff |
| 368 | * |
| 369 | * DESCRIPTION |
| 370 | * This function is to obtain a 32bit data from ringbuffer |
| 371 | * |
| 372 | * CALLS |
| 373 | * |
| 374 | * PARAMETERS |
| 375 | * *Buf: struct of BUFFER_INFO |
| 376 | * *DATA: the data will be obtain from ringbuffer |
| 377 | * |
| 378 | * RETURNS |
| 379 | * None |
| 380 | * |
| 381 | * GLOBALS AFFECTED |
| 382 | * external_global |
| 383 | */ |
| 384 | void Get32FromBuff(BUFFER_INFO *Buf,kal_uint32 *DATA) |
| 385 | { |
| 386 | kal_uint8 tmp,index; |
| 387 | kal_uint32 tmp32; |
| 388 | *DATA =0; |
| 389 | for (index =0;index < 4;index++) |
| 390 | { |
| 391 | Buff_Pop(Buf,&tmp); |
| 392 | tmp32 = (kal_uint32)tmp; |
| 393 | //(*DATA) |= (tmp32 << (24-8*index)); |
| 394 | (*DATA) |= (tmp32 << (8*index)); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | * FUNCTION |
| 400 | * Put32toBuff |
| 401 | * |
| 402 | * DESCRIPTION |
| 403 | * This function is to put a 32bit data to ringbuffer |
| 404 | * |
| 405 | * CALLS |
| 406 | * |
| 407 | * PARAMETERS |
| 408 | * *Buf: struct of BUFFER_INFO |
| 409 | * *DATA: the data will be put into ringbuffer |
| 410 | * |
| 411 | * RETURNS |
| 412 | * None |
| 413 | * |
| 414 | * GLOBALS AFFECTED |
| 415 | * external_global |
| 416 | */ |
| 417 | void Put32toBuff(BUFFER_INFO *Buf,kal_uint32 *DATA) |
| 418 | { |
| 419 | kal_uint8 tmp,index; |
| 420 | kal_uint32 tmp32; |
| 421 | for (index =0;index < 4;index++) |
| 422 | { |
| 423 | //tmp32 = ((*DATA) >> (24-8*index)); |
| 424 | tmp32 = ((*DATA) >> (8*index)); |
| 425 | tmp = (kal_uint8)tmp32; |
| 426 | Buff_Push(Buf,&tmp); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | /* |
| 431 | * FUNCTION |
| 432 | * MemCPY |
| 433 | * |
| 434 | * DESCRIPTION |
| 435 | * This function is to copy memory block |
| 436 | * |
| 437 | * CALLS |
| 438 | * |
| 439 | * PARAMETERS |
| 440 | * dst: destination address. |
| 441 | * src: source address. |
| 442 | * len: copy length |
| 443 | * |
| 444 | * RETURNS |
| 445 | * None |
| 446 | * |
| 447 | * GLOBALS AFFECTED |
| 448 | * external_global |
| 449 | */ |
| 450 | void MemCPY(kal_uint8 *dst,kal_uint8 *src,kal_uint32 len) |
| 451 | { |
| 452 | kal_uint32 index; |
| 453 | for (index = 0; index < len; index++) |
| 454 | *dst++ = *src++; |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * FUNCTION |
| 459 | * MemSET |
| 460 | * |
| 461 | * DESCRIPTION |
| 462 | * This function is to set a value to a memory blcok |
| 463 | * |
| 464 | * CALLS |
| 465 | * |
| 466 | * PARAMETERS |
| 467 | * dst: destination address. |
| 468 | * len: copy length |
| 469 | * data: the value |
| 470 | * |
| 471 | * RETURNS |
| 472 | * None |
| 473 | * |
| 474 | * GLOBALS AFFECTED |
| 475 | * external_global |
| 476 | */ |
| 477 | void MemSET(kal_uint8 *dst,kal_uint8 data,kal_uint32 len) |
| 478 | { |
| 479 | kal_uint32 index; |
| 480 | for (index = 0; index < len; index++) |
| 481 | *dst++ = data; |
| 482 | } |
| 483 | |