sbl1_trdlspk_crcgeneration.c

来自「lte系统物理信道crc编码程序」· C语言 代码 · 共 129 行

C
129
字号
/* ==============================================================================
   Property of Freescale
   Freescale Confidential Proprietary
   Freescale Copyright (C) 2007 All rights reserved
   ------------------------------------------------------------------------------
   $RCSfile: SBL1_TRDLSPK_CRCGeneration.c.rca $
   $Revision: 1.5 $
   $Date: Thu Jul 17 07:36:11 2008 $
   ============================================================================== */ 


/*--------------------------------------------------------------------------*/
/**
 @file
 @brief   CRC Generation kernel
*/
/*--------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------*/
/*!
 @fn INT32  SBL1_TRDLSPK_CRCGeneration(  UINT8    *inp_ptr,
                           		         UINT8    *out_ptr,
                       		             INT32   tr_blk_size,
                       		             CUINT32  *lut_crc_24 );
 
 @brief   CRC Generation Kernel API
 
 @param   inp_ptr       Pointer to the beginning   of an array of bytes in
                        Packed Byte I/O data format. The starting (first)
                        element of the original bit array becomes the MSB
                        (7 th bit) of the byte and 8th element becomes the
                        0th bit.this convention is followed for packing
                        the remaining 8bit blocks of the original bit array
                        if the original bit array size is not a multiple of
                        8,the last byte of the byte array is formed from
                        whatever bits are remaining in the original bit
                        array as above and the rest of the bits are set to
                        zero.
                        
 @param   out_ptr        Pointer to beginning of output buffer.
 @param   tr_blk_size    Gives the number of bits in each Transport block.
 @param   lut_crc_24     A pointer to the beginning of the global CRC 24
                         bit look-up table crc_lookup_table24.

 @return  NULL
*/
/*--------------------------------------------------------------------------*/
#include "SBL_CM_Types.h"
#include "SBL1_SP_Defines.h"
#include "SBL1_SP_ErrorCodes.h"
#include "SBL1_TRDLSPK_CRCGeneration.h"


INT32  SBL1_TRDLSPK_CRCGeneration(UINT8    *inp_ptr,
                                  UINT8    *out_ptr,
                                  INT32   tr_blk_size,
                                  CUINT32  *lut_crc_24 )
{

   UINT8   input_data;          /* Input byte                           */
   UINT8   crc_reg_high;        /* Highest byte of CRC Reg              */
   UINT32  crc_register;        /* CRC register                         */
   INT32  num_of_bytes;        /* no of complete bytes in a TrBlk      */
   UINT16  remainder;           /* no of valid bits in the last byte in
                                /* a block of bytes                     */
   UINT16  crcLoopCount;        /* Intermediate loop count variable     */
   UINT16  crcI;                /* Loop variable                        */
   INT32   error = 0;
   
      
   if(tr_blk_size<MINI_CODEBLK_SIZE){
   		error = ERROR|SPK_CRCGENERATION|ERROR_INVALID_INPUT_BLOCK_SIZE;
    	APP_ASSERT(error);
   }
    
    

   crc_register=0;                              /* Initializing CRC Register*/
   num_of_bytes = (INT32)((tr_blk_size>>3));   /* No of complete bytes in the TrBlK*/
   remainder    = (UINT16)(tr_blk_size&0x7);    /* No of valid bits in the last byte
                                                   of the TrBlK*/

   for(crcI=0;crcI<num_of_bytes;crcI++)
   {
      input_data=(UINT8)*inp_ptr;
      *out_ptr++ = *inp_ptr++;                  /*Copying the data into output buffer*/
      crc_reg_high=(UINT8)(crc_register>>16);   /* >>CRC_LENGTH-8*/

      /* Highest byte of CRCReg */
      /* Updating CRC Register */
      crc_register=(crc_register<<8)^(lut_crc_24[crc_reg_high^input_data]);
   }

   /*Handling the case when the TrBlk Size is NOT a multiple of 8*/

   if (remainder>0)
   {
      input_data=(UINT8)*inp_ptr;               /*Copying a byte from the input*/
                                                /*buffer and making it unsigned*/
      crc_reg_high=(UINT8)(crc_register>>16);   /* >>CRC_LENGTH-8*/

      /* Highest byte of CRCReg */
      /* Updating CRC Register */
      crc_register = (crc_register<<(remainder))
                ^ (lut_crc_24[(crc_reg_high^input_data)>>(8-remainder)]);
   }

   crcLoopCount=remainder; /*Initializing LoopCount variable*/
   *out_ptr= (UINT8)(*inp_ptr &(0xff <<(8-remainder))); /*Ensuring that the vacant
                                                            positions in the last byte of
                                                            TrBlk are 0s*/

   /* Appending the CRC bits at the end of the Transport Block*/
   for(crcI=0;crcI<24;crcI++)
   {
     if(crcLoopCount==8)                /*One byte has been completed*/
     {
       *(++out_ptr)=0;                  /*Incrementing Output pointer and
                                          setting the location to zero*/
         crcLoopCount=0;                /*Re-initializing LoopCount variable*/
     }
     *out_ptr=  (UINT8)(*out_ptr | ((INT8)(crc_register&0x1)<<(7-crcLoopCount)));
     crc_register >>=1;
     crcLoopCount++;
   }
   
   return SUCCESS;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?