| /***************************************************************************** |
| * Copyright Statement: |
| * -------------------- |
| * This software is protected by Copyright and the information contained |
| * herein is confidential. The software may not be copied and the information |
| * contained herein may not be used or disclosed except with the written |
| * permission of MediaTek Inc. (C) 2005 |
| * |
| * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| * |
| * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| * |
| * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| * |
| *****************************************************************************/ |
| |
| /***************************************************************************** |
| * |
| * Filename: |
| * --------- |
| * bf.c |
| * |
| * Project: |
| * -------- |
| * Maui_Software |
| * |
| * Description: |
| * ------------ |
| * This Module defines the ring-buffer API |
| * |
| * Author: |
| * ------- |
| * ------- |
| * |
| *============================================================================ |
| * HISTORY |
| * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| *------------------------------------------------------------------------------ |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| *------------------------------------------------------------------------------ |
| * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| *============================================================================ |
| ****************************************************************************/ |
| #include "drv_comm.h" |
| #include "bmd.h" |
| |
| |
| /* |
| * FUNCTION |
| * Buff_init |
| * |
| * DESCRIPTION |
| * This function is to let a memory area become a ring-buffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * Buffaddr: the start addr of memory area |
| * uTotalSize: the size of the memory area |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| void Buff_init(BUFFER_INFO *Buf,kal_uint8 *Buffaddr, kal_uint16 uTotalSize) |
| { |
| Buf->Read = 0; |
| Buf->Write = 0; |
| Buf->Length = uTotalSize; |
| Buf->CharBuffer = Buffaddr; |
| } |
| |
| /* |
| * FUNCTION |
| * Buff_Push |
| * |
| * DESCRIPTION |
| * This function is to put a data to ring-buffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * *pushData: the data will be put into ring-buffer |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| void Buff_Push(BUFFER_INFO *Buf,kal_uint8 *pushData) |
| { |
| *BuffWrite(Buf) = *pushData; |
| BWrite(Buf)++; |
| if (BWrite(Buf) >= BLength(Buf)) |
| { |
| BWrite(Buf) -= BLength(Buf); |
| } |
| } |
| |
| /* |
| * FUNCTION |
| * Buff_Pop |
| * |
| * DESCRIPTION |
| * This function is to pop a data from ring-buffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * *popData: the data will be pop from ring-buffer |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| void Buff_Pop(BUFFER_INFO *Buf,kal_uint8 *popData) |
| { |
| *popData= *BuffRead(Buf); |
| BRead(Buf)++; |
| if (BRead(Buf) >= BLength(Buf)) |
| { |
| BRead(Buf) -= BLength(Buf); |
| } |
| |
| } |
| |
| void Buff_look(BUFFER_INFO *Buf,kal_uint8 *popData,kal_uint8 num) |
| { |
| kal_uint8 index; |
| kal_uint16 tmp; |
| |
| tmp = BRead(Buf); |
| for(index=0;index<num;index++) |
| { |
| *popData= *(Buf->CharBuffer+tmp); |
| |
| tmp++; |
| if (tmp >= BLength(Buf)) |
| { |
| tmp -= BLength(Buf); |
| } |
| } |
| } |
| /* |
| * FUNCTION |
| * Buff_IsEmpty |
| * |
| * DESCRIPTION |
| * This function is check whether ring-buffer is empty |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| kal_uint8 Buff_IsEmpty(BUFFER_INFO *Buf) |
| { |
| kal_uint8 status; |
| if ( BRead(Buf) == BWrite(Buf) ) |
| { |
| status = Buff_isEmpty; |
| } |
| else |
| { |
| status = Buff_notEmpty; |
| } |
| return status; |
| } |
| |
| /* |
| * FUNCTION |
| * Buff_IsFull |
| * |
| * DESCRIPTION |
| * This function is check whether ring-buffer is full |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| kal_uint8 Buff_IsFull (BUFFER_INFO *Buf) |
| { |
| kal_uint8 status; |
| kal_uint16 tmp = BRead(Buf); |
| if (tmp == 0) |
| tmp = BLength(Buf); |
| |
| if ( (tmp-BWrite(Buf)) == 1) |
| { |
| status = Buff_isFull; |
| } |
| else |
| { |
| status = Buff_notFull; |
| } |
| return status; |
| } |
| |
| /* |
| * FUNCTION |
| * Buff_GetRoomLeft |
| * |
| * DESCRIPTION |
| * This function is obtain the size of the residual space |
| * in ring-buffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * |
| * RETURNS |
| * the size of the residual space |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| kal_uint16 Buff_GetRoomLeft (BUFFER_INFO *Buf) |
| { |
| kal_uint16 RoomLeft = 0; |
| if ( BRead(Buf) <= BWrite(Buf) ) |
| { |
| RoomLeft = BLength(Buf) - BWrite(Buf) + BRead(Buf) - 1; |
| } |
| else |
| { |
| RoomLeft = BRead(Buf) - BWrite(Buf) - 1; |
| } |
| |
| return RoomLeft; |
| } |
| |
| /* |
| * FUNCTION |
| * Buff_GetBytesAvail |
| * |
| * DESCRIPTION |
| * This function is obtain the size of the used space |
| * in ring-buffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * |
| * RETURNS |
| * the size of the used space |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| kal_uint16 Buff_GetBytesAvail (BUFFER_INFO *Buf) |
| { |
| kal_uint16 BytesAvail = 0; |
| if (BWrite(Buf) >= BRead(Buf)) |
| BytesAvail = BWrite(Buf) - BRead(Buf); |
| else |
| BytesAvail = BLength(Buf) - BRead(Buf) + BWrite(Buf); |
| |
| return BytesAvail; |
| } |
| |
| /* |
| * FUNCTION |
| * Buff_GetLength |
| * |
| * DESCRIPTION |
| * This function is to obtain the total size of the ring-buffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * |
| * RETURNS |
| * the total size of the ring-buffer |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| kal_uint16 Buff_GetLength(BUFFER_INFO *Buf) |
| { |
| return Buf->Length; |
| } |
| |
| /* |
| * FUNCTION |
| * Buff_Flush |
| * |
| * DESCRIPTION |
| * This function is to reset the ring-buffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| void Buff_Flush (BUFFER_INFO *Buf) |
| { |
| Buf->Write = Buf->Read = 0; |
| } |
| |
| /* |
| * FUNCTION |
| * Get32FromBuff |
| * |
| * DESCRIPTION |
| * This function is to obtain a 32bit data from ringbuffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * *DATA: the data will be obtain from ringbuffer |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| void Get32FromBuff(BUFFER_INFO *Buf,kal_uint32 *DATA) |
| { |
| kal_uint8 tmp,index; |
| kal_uint32 tmp32; |
| *DATA =0; |
| for (index =0;index < 4;index++) |
| { |
| Buff_Pop(Buf,&tmp); |
| tmp32 = (kal_uint32)tmp; |
| //(*DATA) |= (tmp32 << (24-8*index)); |
| (*DATA) |= (tmp32 << (8*index)); |
| } |
| } |
| |
| /* |
| * FUNCTION |
| * Put32toBuff |
| * |
| * DESCRIPTION |
| * This function is to put a 32bit data to ringbuffer |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * *Buf: struct of BUFFER_INFO |
| * *DATA: the data will be put into ringbuffer |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| void Put32toBuff(BUFFER_INFO *Buf,kal_uint32 *DATA) |
| { |
| kal_uint8 tmp,index; |
| kal_uint32 tmp32; |
| for (index =0;index < 4;index++) |
| { |
| //tmp32 = ((*DATA) >> (24-8*index)); |
| tmp32 = ((*DATA) >> (8*index)); |
| tmp = (kal_uint8)tmp32; |
| Buff_Push(Buf,&tmp); |
| } |
| } |
| |
| /* |
| * FUNCTION |
| * MemCPY |
| * |
| * DESCRIPTION |
| * This function is to copy memory block |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * dst: destination address. |
| * src: source address. |
| * len: copy length |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| void MemCPY(kal_uint8 *dst,kal_uint8 *src,kal_uint32 len) |
| { |
| kal_uint32 index; |
| for (index = 0; index < len; index++) |
| *dst++ = *src++; |
| } |
| |
| /* |
| * FUNCTION |
| * MemSET |
| * |
| * DESCRIPTION |
| * This function is to set a value to a memory blcok |
| * |
| * CALLS |
| * |
| * PARAMETERS |
| * dst: destination address. |
| * len: copy length |
| * data: the value |
| * |
| * RETURNS |
| * None |
| * |
| * GLOBALS AFFECTED |
| * external_global |
| */ |
| void MemSET(kal_uint8 *dst,kal_uint8 data,kal_uint32 len) |
| { |
| kal_uint32 index; |
| for (index = 0; index < len; index++) |
| *dst++ = data; |
| } |
| |