📄 errorhnd.c
字号:
/***********************************************************************************/
/* IS54 Baseband Simulation Software */
/* */
/* File Description : IS54 Receive CRC Error State Machine */
/* File Name : errorhnd.c */
/* Date : 12/30/93 */
/* : July, 20001 - Modified for TMS320C55x project */
/* */
/* This file contains the function "errorchk()" which verifies */
/* the CRC in the receive data. The CRC is verified by comparing */
/* the CRC extracted from the slot (after the viterbi), to the CRC */
/* generated from the VSELP parameters extracted from the slot. */
/* */
/* In the case that the CRC check passes, the VSELP parameters are */
/* stored. In the case that the CRC fails, the VSELP parameters are */
/* restored to that from the last CRC valid frame, and the R0 VSELP */
/* parameter is updated (reduced) accordingly. */
/* */
/* This fault state mechanism is a 7-state machine, where R0 is not */
/* decreased until at least 3 consecutive CRC-invalid frames ar received. */
/* */
/* Note that the current level of that state machine is not maintained in */
/* this file, but rather, it is passed as a parameter, and the updated state */
/* level is returned from this routine. */
/* */
/* Inputs : */
/* error_state : Previous CRC error state machine level. */
/* */
/* vselp : Pointer to current set of receive VSELP parameters. */
/* */
/* Outputs : */
/* vselp : Parameters are restored from last CRC valid frame */
/* if the current CRC is invalid. */
/* */
/* Return Value: */
/* This routine returns the updated CRC error-state */
/* level. If zero, the receive frame was CRC-valid. */
/* */
/***********************************************************************************/
/* Include Files */
#include <intrindefs.h>
#include "vselp.h"
/* Defines */
#define SAVE 0
#define RESTORE 1
#define FOUR_DB 0x32f5 /* Q15 format of ((float)0.3981) */
#define EIGHT_DB 0x1449 /* Q15 format of (FOUR_DB*FOUR_DB) */
#define TWELVE_DB 0x813 /* Q15 format of (FOUR_DB*FOUR_DB*FOUR_DB) */
/* Function Prototypes */
int errorchk( int, unsigned* );
void copy_vselp_data( int, unsigned* );
/* External Function Prototypes */
extern void crcgen( unsigned *); /* Defined in crcgen.c */
/* Data */
unsigned vselp_old[VSELP_SIZE];
int R0_multiplier[8] = { 0x7fff, 0x7fff, 0x7fff,
FOUR_DB, EIGHT_DB,TWELVE_DB,
0x0000, 0x0000 };
/* External Data */
/* Code */
int errorchk( int error_state, unsigned *vselp )
{
unsigned crcrcv, crcout;
crcrcv = vselp[ VSELP_CRC ];
crcgen( vselp );
crcout = vselp[ VSELP_CRC ];
if( crcrcv != crcout )
{
if( ++error_state >= 6 ) /* if state 6 is reached, 2 succesive */
error_state = 7; /* good frames are required to go to */
/* state 0. so go to state 7 first, then */
/* use state 6 as having received 1 good */
/* frame */
}
else
{
if( error_state == 0 )
copy_vselp_data( SAVE, vselp );
else
{
copy_vselp_data( RESTORE, vselp );
if( error_state == 7 ) error_state = 6;
else error_state = 0;
vselp[ VSELP_R0 ] = (unsigned)( _smpy(vselp[VSELP_R0], R0_multiplier[error_state]) );
}
}
return( error_state );
}
/**********************************************************/
/* Utility Function : copy_vselp_data() */
/* */
/* This function either stores or restores VSELP */
/* parameters based on the input "command". */
/* */
/* If ( command == RESTORE ) */
/* Set VSELP parameters to that of last valid frame */
/* Else ( command == SAVE ) */
/* Store current VSELP parameters */
/* */
/**********************************************************/
void copy_vselp_data( int command, unsigned *vselp )
{
unsigned *ptr_to, *ptr_from;
int i;
if( command == RESTORE )
{
ptr_to = vselp;
ptr_from = vselp_old;
}
else
{
ptr_to = vselp_old;
ptr_from = vselp;
}
for( i = 0; i < VSELP_SIZE; i++ )
*(ptr_to++) = *(ptr_from++);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -