📄 fcs.c
字号:
/*****************************************************************************
* 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:
* ---------
* fcs.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* This file is for FCS driver.
*
* 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!
* 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 "..\..\l1\l1c\csd_def.h"
#ifdef RA_UNIT_TEST
#include "sw_types.h"
#else
#include "kal_release.h"
#endif
#include "reg_base.h"
#include "fcs.h"
#ifdef RA_UNIT_TEST
#define FCS_SIM
#endif
#ifdef L1C_TEST_SIM
#define FCS_SIM
#endif
#ifdef FCS_SIM
kal_bool FCS_ERR;
#endif
#ifdef MT6205B
#define SW_FCS
#endif
#ifdef SW_FCS
#define POLY 0x00bba1b5
kal_uint32 sw_parity;
kal_uint32 fcs_table[256]= {
0x000000 , 0x76A7D6 , 0x5745F6 , 0x21E220 , 0x1581B7 , 0x632661 , 0x42C441 , 0x346397 ,
0x910934 , 0xE7AEE2 , 0xC64CC2 , 0xB0EB14 , 0x848883 , 0xF22F55 , 0xD3CD75 , 0xA56AA3 ,
0x221368 , 0x54B4BE , 0x75569E , 0x3F148 , 0x3792DF , 0x413509 , 0x60D729 , 0x1670FF ,
0xB31A5C , 0xC5BD8A , 0xE45FAA , 0x92F87C , 0xA69BEB , 0xD03C3D , 0xF1DE1D , 0x8779CB ,
0x4426D0 , 0x328106 , 0x136326 , 0x65C4F0 , 0x51A767 , 0x2700B1 , 0x6E291 , 0x704547 ,
0xD52FE4 , 0xA38832 , 0x826A12 , 0xF4CDC4 , 0xC0AE53 , 0xB60985 , 0x97EBA5 , 0xE14C73 ,
0x6635B8 , 0x10926E , 0x31704E , 0x47D798 , 0x73B40F , 0x513D9 , 0x24F1F9 , 0x52562F ,
0xF73C8C , 0x819B5A , 0xA0797A , 0xD6DEAC , 0xE2BD3B , 0x941AED , 0xB5F8CD , 0xC35F1B ,
0x3347FB , 0x45E02D , 0x64020D , 0x12A5DB , 0x26C64C , 0x50619A , 0x7183BA , 0x7246C ,
0xA24ECF , 0xD4E919 , 0xF50B39 , 0x83ACEF , 0xB7CF78 , 0xC168AE , 0xE08A8E , 0x962D58 ,
0x115493 , 0x67F345 , 0x461165 , 0x30B6B3 , 0x4D524 , 0x7272F2 , 0x5390D2 , 0x253704 ,
0x805DA7 , 0xF6FA71 , 0xD71851 , 0xA1BF87 , 0x95DC10 , 0xE37BC6 , 0xC299E6 , 0xB43E30 ,
0x77612B , 0x1C6FD , 0x2024DD , 0x56830B , 0x62E09C , 0x14474A , 0x35A56A , 0x4302BC ,
0xE6681F , 0x90CFC9 , 0xB12DE9 , 0xC78A3F , 0xF3E9A8 , 0x854E7E , 0xA4AC5E , 0xD20B88 ,
0x557243 , 0x23D595 , 0x237B5 , 0x749063 , 0x40F3F4 , 0x365422 , 0x17B602 , 0x6111D4 ,
0xC47B77 , 0xB2DCA1 , 0x933E81 , 0xE59957 , 0xD1FAC0 , 0xA75D16 , 0x86BF36 , 0xF018E0 ,
0xDD85AD , 0xAB227B , 0x8AC05B , 0xFC678D , 0xC8041A , 0xBEA3CC , 0x9F41EC , 0xE9E63A ,
0x4C8C99 , 0x3A2B4F , 0x1BC96F , 0x6D6EB9 , 0x590D2E , 0x2FAAF8 , 0xE48D8 , 0x78EF0E ,
0xFF96C5 , 0x893113 , 0xA8D333 , 0xDE74E5 , 0xEA1772 , 0x9CB0A4 , 0xBD5284 , 0xCBF552 ,
0x6E9FF1 , 0x183827 , 0x39DA07 , 0x4F7DD1 , 0x7B1E46 , 0xDB990 , 0x2C5BB0 , 0x5AFC66 ,
0x99A37D , 0xEF04AB , 0xCEE68B , 0xB8415D , 0x8C22CA , 0xFA851C , 0xDB673C , 0xADC0EA ,
0x8AA49 , 0x7E0D9F , 0x5FEFBF , 0x294869 , 0x1D2BFE , 0x6B8C28 , 0x4A6E08 , 0x3CC9DE ,
0xBBB015 , 0xCD17C3 , 0xECF5E3 , 0x9A5235 , 0xAE31A2 , 0xD89674 , 0xF97454 , 0x8FD382 ,
0x2AB921 , 0x5C1EF7 , 0x7DFCD7 , 0xB5B01 , 0x3F3896 , 0x499F40 , 0x687D60 , 0x1EDAB6 ,
0xEEC256 , 0x986580 , 0xB987A0 , 0xCF2076 , 0xFB43E1 , 0x8DE437 , 0xAC0617 , 0xDAA1C1 ,
0x7FCB62 , 0x96CB4 , 0x288E94 , 0x5E2942 , 0x6A4AD5 , 0x1CED03 , 0x3D0F23 , 0x4BA8F5 ,
0xCCD13E , 0xBA76E8 , 0x9B94C8 , 0xED331E , 0xD95089 , 0xAFF75F , 0x8E157F , 0xF8B2A9 ,
0x5DD80A , 0x2B7FDC , 0xA9DFC , 0x7C3A2A , 0x4859BD , 0x3EFE6B , 0x1F1C4B , 0x69BB9D ,
0xAAE486 , 0xDC4350 , 0xFDA170 , 0x8B06A6 , 0xBF6531 , 0xC9C2E7 , 0xE820C7 , 0x9E8711 ,
0x3BEDB2 , 0x4D4A64 , 0x6CA844 , 0x1A0F92 , 0x2E6C05 , 0x58CBD3 , 0x7929F3 , 0xF8E25 ,
0x88F7EE , 0xFE5038 , 0xDFB218 , 0xA915CE , 0x9D7659 , 0xEBD18F , 0xCA33AF , 0xBC9479 ,
0x19FEDA , 0x6F590C , 0x4EBB2C , 0x381CFA , 0xC7F6D , 0x7AD8BB , 0x5B3A9B , 0x2D9D4D
};
kal_uint32 fcs_codec(kal_uint32 enc_dec, kal_uint32 count, kal_uint32 *table, kal_uint8 *data)
{
kal_uint32 temp_data, remainder, parity;
kal_uint32 i;
temp_data=((*data)<<16)^((*(data+1))<<8)^(*(data+2));
i=count;
while(i)
{
remainder=*(table+(temp_data>>16));
temp_data=(((temp_data<<16)>>8)^(*(data+count-i+3)))^remainder;
i--;
}
temp_data=~temp_data^((count==69) ? 0x00fa4aaa : 0x00e6a836);
temp_data=(temp_data<<8)>>8;
if(enc_dec)
return ((temp_data==0) ? 0 : 1);
else
return temp_data;
}
void fcs_feed_stream_sw(kal_uint8* data,kal_uint16 len,kal_uint8 BIT_ORDER,kal_uint8 PAR_ORDER,kal_uint8 EN_DEC)
{
if(EN_DEC==0) /* Encode */
{
data[len]=0;
data[len+1]=0;
data[len+2]=0;
sw_parity=fcs_codec((kal_uint32)EN_DEC,(kal_uint32)len,fcs_table,data);
}
else /* Decode */
sw_parity=fcs_codec((kal_uint32)EN_DEC,(kal_uint32)len-3,fcs_table,data);
}
void get_fcs_parity_sw(kal_uint8* parity)
{
parity[0]=(kal_uint8)(sw_parity>>16);
parity[1]=(kal_uint8)(sw_parity>>8);
parity[2]=(kal_uint8)(sw_parity);
}
kal_bool get_fcs_result_sw(void)
{
return (sw_parity==0) ? 1 : 0 ;
}
#endif
/********************************************************
* FUNCTION
* fcs_feed_stream
*
* DESCRIPTION
* This function is to write byte streams
into FCS codec register.
*
* CALLS
*
*
* PARAMETERS
* data: pointer to the byte streams to be encoded/decoded.
* len: length of the byte stream.
* BIT_ORDER: bit order to be fed into shift register for information field.
* PAR_ORDER: bit order to be fed into shift register for parity field.
* EN_DEC: 0 for encode, 1 for decode mode.
*
* RETURNS
* void
*
* GLOBALS AFFECTED
* external_global
* len execludes the 3-byte parity field for encoding, including for decoding.
*********************************************************/
#ifndef SW_FCS
void fcs_feed_stream_hw(kal_uint8* data,kal_uint16 len,kal_uint8 BIT_ORDER,kal_uint8 PAR_ORDER,kal_uint8 EN_DEC)
{
kal_uint16 len_16;
kal_uint16 data_16,rst;
rst=0;
if(BIT_ORDER)
rst|=0x02;
if(PAR_ORDER)
rst|=0x04;
if(EN_DEC)
rst|=0x08;
*FCS_RST= rst;
len_16=(len/2)+(len%2);
*FCS_DLEN= (len*8);
while(len_16)
{
data_16=(*data<<8)|*(data+1);
while((*FCS_STAT)&0x0004)
{}
*FCS_DATA=data_16;
data+=2;
len_16--;
/* No need to poll BUSY flag, the timing is enough to finish data write. */
}
}
#endif
/********************************************************
* FUNCTION
* get_fcs_parity
*
* DESCRIPTION
* This function is to get the 3-byte parity field.
*
* CALLS
*
*
* PARAMETERS
* parity: This is the 3-byte parity field for the
* latest encoded information streams.
*
* RETURNS
* parity
*
* GLOBALS AFFECTED
* external_global
* This function should be called after fcs_gen()
* is executed.
*********************************************************/
#ifndef SW_FCS
void get_fcs_parity_hw(kal_uint8* parity)
{
kal_uint8* src;
kal_uint16 *src_16,temp;
while(!((*FCS_STAT)&0x0001))
{}
src= (kal_uint8*)FCS_PAR2;
parity[0]=*src;
src_16=(kal_uint16*)FCS_PAR1;
temp=*src_16;
parity[1]=(kal_uint8)((temp>>8)&0x00FF);
parity[2]=(kal_uint8)(temp&0x00FF);
}
#endif
/********************************************************
* FUNCTION
* get_fcs_result
*
* DESCRIPTION
* This function is to return the decoded result
* of FCS codec.
*
* CALLS
*
*
* PARAMETERS
*
*
* RETURNS
* bool result:
* TRUE if decoder result is correct.
* FALSE if decoder result is incorrect.
*
* GLOBALS AFFECTED
* external_global
*********************************************************/
#ifndef SW_FCS
kal_bool get_fcs_result_hw(void)
{
kal_uint16 stat;
while(1)
{
stat=*FCS_STAT;
if((stat&0x0001))
return !(stat&0x0002);
}
}
#endif
/********************************/
#ifndef FCS_SIM
void fcs_feed_stream(kal_uint8* data,kal_uint16 len,kal_uint8 BIT_ORDER,kal_uint8 PAR_ORDER,kal_uint8 EN_DEC)
{
#ifdef SW_FCS
fcs_feed_stream_sw(data,len,BIT_ORDER,PAR_ORDER,EN_DEC);
#else
*(volatile kal_uint16 *)0x80000308 &= ~0x0040;
fcs_feed_stream_hw(data,len,BIT_ORDER,PAR_ORDER,EN_DEC);
#endif
}
void get_fcs_parity(kal_uint8* parity)
{
#ifdef SW_FCS
get_fcs_parity_sw(parity);
#else
get_fcs_parity_hw(parity);
*(volatile kal_uint16 *)0x80000308 |= 0x0040;
#endif
}
kal_bool get_fcs_result(void)
{
kal_bool result;
#ifdef SW_FCS
result=get_fcs_result_sw();
#else
result=get_fcs_result_hw();
*(volatile kal_uint16 *)0x80000308 |= 0x0040;
#endif
return result;
}
#else
void fcs_feed_stream(kal_uint8* data,kal_uint16 len,kal_uint8 BIT_ORDER,kal_uint8 PAR_ORDER,kal_uint8 EN_DEC)
{
if(((data[0]==0x00)&&(data[1]==0x00)&&(data[2]==0x00))||((data[0]==0xFF)&&(data[1]==0xFF)&&(data[2]==0xFF)))
FCS_ERR=KAL_TRUE;
else
FCS_ERR=KAL_FALSE;
return ;
}
void get_fcs_parity(kal_uint8* parity)
{
parity[0]=0x01;
parity[1]=0x02;
parity[2]=0x03;
}
kal_uint8 fcs_dbg=0;
kal_bool get_fcs_result(void)
{
#if 1
fcs_dbg++;
if(fcs_dbg==10)
{
fcs_dbg=0;
return FCS_ERR;
}
else if(fcs_dbg==5)
return FCS_ERR;
#endif
return !FCS_ERR;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -