⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsip_data.c

📁 dsp tms320c6486的csl例程
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  ============================================================================
 *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2006
 *
 *   Use of this software is controlled by the terms and conditions found
 *   in the license agreement under which this software has been supplied.
 *  ============================================================================
 */
#include <csl_types.h>
//#include <edma_data.h>
//#include <csl_idma.h>
//#include "edma_common.h"
#include <csl_psc.h>
#include <cslr_psc.h>
#include <soc.h>

/*****************************************************************************\
* Init Memory:- 
******************************************************************************/
#define	ALAWCHAN	(0x55)
#define	ULAWCHAN	(0x7f)
#define	SIGN		(0x80)
#define	BIAS		(0x21)
#define	EXPONENT	(0x70)	
#define	MANTISSA	(0x0f)	
//For PSC
CSL_PscHandle 	hPsc;
CSL_PscObj    	pscObj;
CSL_Status    	psc_status;

Uint8 ALawCompress(Uint16 InputData);	/* 2's complement (16-bit range) */
Uint16 ALawExpand( int i);
Uint8 ULawCompress(Uint16 InputData);	/* 2's complement (16-bit range) */
Uint16 ULawExpand( Uint8 i);
void Init_Mem(Uint8* Addr, Uint32 NoofArrays, Uint32 Count, Uint8 IncrData)
{
   	Uint32 i;
        Uint32 Data = 0x1; 

     	for (i=0; i < Count * NoofArrays; i++)
     	{
          	*(Uint8*)(Addr + i) = Data;
          	Data += IncrData;
     	}

}	

/*****************************************************************************\
* Verifies TSIP CFG A transfer
******************************************************************************/
Bool Verify_Transfer(Uint32 FrameCnt, Uint32 FrameSize, Uint32 srcBuff,Uint32 dstBuff)
{
        Uint8* ExpArrayPtr = (Uint8*)(srcBuff );
        Uint8* dstArrayPtr = (Uint8*)(dstBuff );

        int i,j;
        dstArrayPtr = dstArrayPtr + FrameSize;
#if 0
        for (i = 0; i < FrameCnt + 1; i++)
        {
                for (j = 0; j < FrameSize;j++)
                {
                         VAL_TRACE(j);
                         VAL_TRACE(0xDA05);
                         VAL_TRACE(ExpArrayPtr[j]);
                         VAL_TRACE(dstArrayPtr[j]);
                }
                        ExpArrayPtr = ExpArrayPtr + FrameSize ;
                        dstArrayPtr = dstArrayPtr + FrameSize ;
        }
#endif
        ExpArrayPtr = (Uint8*)(srcBuff );
        dstArrayPtr = (Uint8*)(dstBuff );
        dstArrayPtr = dstArrayPtr + FrameSize ;
        for (i = 0; i < FrameCnt + 1 ; i++)
        {
                for (j = 0; j < FrameSize;j++)
                {
                         if (j >= (FrameSize - 4) )
                         {

                         if(dstArrayPtr[j] != ((i+1)>> ((j - FrameSize - 4) * 8)))
                         {
                             return (1);
                         }
                         }
                    else
                    {
                    if (j > 3)
                    {
                       if(ExpArrayPtr[j] != dstArrayPtr[j])
                       {
                         return (1);
                      }
                    }
                    else
                    {
                         if(dstArrayPtr[j] != ((i+1)>> (j * 8)))
                         {
                         return (1);
                         }

                    }
                }
            }
                        ExpArrayPtr = ExpArrayPtr + FrameSize ;
                        dstArrayPtr = dstArrayPtr + FrameSize ;
        }
        return (0);
}

/*****************************************************************************\
* Verifies TSIP CFG A BigEndian transfer
******************************************************************************/
Bool Verify_Transfer_BigEnd(Uint32 FrameCnt, Uint32 FrameSize, Uint32 srcBuff,Uint32 dstBuff)
{
        Uint8* ExpArrayPtr = (Uint8*)(srcBuff );
        Uint8* dstArrayPtr = (Uint8*)(dstBuff );

        int i,j;
        dstArrayPtr = dstArrayPtr + FrameSize;
#if 0
        for (i = 0; i < FrameCnt + 1; i++)
        {
                VAL_TRACE(0xDA04);
                VAL_TRACE(i);
                for (j = 0; j < FrameSize;j++)
                {
                         VAL_TRACE(j);
                         VAL_TRACE(0xDA05);
                         VAL_TRACE(ExpArrayPtr[j]);
                         VAL_TRACE(dstArrayPtr[j]);
                }
                        ExpArrayPtr = ExpArrayPtr + FrameSize ;
                        dstArrayPtr = dstArrayPtr + FrameSize ;
        }
#endif
        ExpArrayPtr = (Uint8*)(srcBuff );
        dstArrayPtr = (Uint8*)(dstBuff );
        dstArrayPtr = dstArrayPtr + FrameSize ;
        for (i = 0; i < FrameCnt + 1 ; i++)
        {
                for (j = 0; j < FrameSize;j++)
                {
                         if (j >= (FrameSize - 4) )
                         {

                         if(dstArrayPtr[(j/4 * 4) + (3 - (j%4))] != ((i+1)>> ((j - FrameSize - 4) * 8)))
                         {
                         return (1);
                         }
                         }
                    else
                    {
                    if (j > 3)
                    {
                       if(ExpArrayPtr[j] != dstArrayPtr[j])
                       {
                         return (1);
                      }
                    }
                    else
                    {
                         if(dstArrayPtr[(3 - (j%4))] != ((i+1)>> (j * 8)))
                         {
                         return (1);
                         }

                    }
                }
            }
                        ExpArrayPtr = ExpArrayPtr + FrameSize ;
                        dstArrayPtr = dstArrayPtr + FrameSize ;
        }
        return (0);
}

/*****************************************************************************\
* Verifies TSIP CFG B transfer
******************************************************************************/
Bool Verify_Transfer_CFG_B(Uint32 StartFrame_Count, Uint32 FrameCnt, Uint32 FrameSize, Uint32 srcBuff,Uint32 dstBuff)
{
        Uint8* ExpArrayPtr = (Uint8*)(srcBuff );
        Uint8* dstArrayPtr = (Uint8*)(dstBuff );

        int i,j;
        dstArrayPtr = dstArrayPtr + FrameSize;
#if 0
        for (i = 0; i < FrameCnt  + 1; i++)
        {
                VAL_TRACE(0xDA04);
                VAL_TRACE(i);
                for (j = 0; j < FrameSize;j++)
                {
                         VAL_TRACE(j);
                         VAL_TRACE(0xDA05);
                         VAL_TRACE(ExpArrayPtr[j]);
                         VAL_TRACE(dstArrayPtr[j]);
                }
                        ExpArrayPtr = ExpArrayPtr + FrameSize ;
                        dstArrayPtr = dstArrayPtr + FrameSize ;
        }
#endif
        ExpArrayPtr = (Uint8*)(srcBuff );
        dstArrayPtr = (Uint8*)(dstBuff );
        dstArrayPtr = dstArrayPtr + FrameSize ;
        for (i = StartFrame_Count + 2; i < StartFrame_Count + FrameCnt + 1; i++)
        {
                for (j = 0; j < FrameSize;j++)
                {
                         if (j >= (FrameSize - 4) )
                         {

                         if(dstArrayPtr[j] != (((i+1 + 0x1000000)>> ((j - FrameSize - 4) * 8))  & 0xFF))
                         {
                         return (1);
                         }
                         }
                    else
                    {
                    if (j > 3)
                    {
                       if(ExpArrayPtr[j] != dstArrayPtr[j])
                       {
                         return (1);
                      }
                    }
                    else
                    {
                         if(dstArrayPtr[j] != ((i+1 + 0x1000000)>> ((j * 8)) & 0xFF))
                         {
                         return (1);
                         }

                    }
                }
            }
                        ExpArrayPtr = ExpArrayPtr + FrameSize ;
                        dstArrayPtr = dstArrayPtr + FrameSize ;
        }
        return (0);
}
/*****************************************************************************\
* Verifies TSIP CFG A transfer starting from a particular frame number
******************************************************************************/
Bool Verify_Transfer_Frame_Start_Count(Uint32 FrameNumber, Uint32 FrameCnt, Uint32 FrameSize, Uint32 srcBuff,Uint32 dstBuff)
{
        Uint8* ExpArrayPtr = (Uint8*)(srcBuff );
        Uint8* dstArrayPtr = (Uint8*)(dstBuff );

        int i,j;
        dstArrayPtr = dstArrayPtr + FrameSize ;
        for (i = (FrameNumber - 1); i < FrameCnt + 1 ; i++)
        {
                for (j = 0; j < FrameSize;j++)
                {
                         if (j >= (FrameSize - 4) )
                         {

                         if(dstArrayPtr[j] != ((i+1)>> ((j - FrameSize - 4) * 8)))
                         {
                             return (1);
                         }
                         }
                    else
                    {
                    if (j > 3)
                    {
                       if(ExpArrayPtr[j] != dstArrayPtr[j])
                       {
                         return (1);
                      }
                    }
                    else
                    {
                         if(dstArrayPtr[j] != ((i+1)>> (j * 8)))
                         {
                             return (1);
                         }

                    }
                }
            }
                        ExpArrayPtr = ExpArrayPtr + FrameSize ;
                        dstArrayPtr = dstArrayPtr + FrameSize ;
        }
        return (0);
}

/*****************************************************************************\
* Verifies TSIP CFG B transfer
******************************************************************************/
#if 0
/* Function to determine the expected value in case of U-law expansion at the receiver end */
Uint16 ExpectedValue_Ulaw_Expand(Uint32 xmt_data)
{
	Uint32 word_length;
	Uint32 wd_len;
	Uint32 shift_amt, bit_mask; 
	
        wd_len = 8;
	/* Calculate word lengths */
	word_length = wd_len*2;  // naturally 8, 16 because of compand mode
	
	xmt_data = ULawExpand(xmt_data); 

	/* Calculate shift amount  */
	shift_amt = 32 - word_length;
	
	bit_mask = (Uint32)
		((Uint32)(0x80000000) >> (word_length - 1)) >> shift_amt;
		
	/* Simulate receive justify modes */
	xmt_data &= bit_mask; 

	return xmt_data;
}

/* Function to determine the expected value in case of U-law compression at the transmitter end */
Uint16 ExpectedValue_Ulaw_Compress(Uint16 xmt_data)
{
	Uint32 word_length;
	Uint32 shift_amt, bit_mask; 
	
        wd_len = 8;
	/* Calculate word lengths */
	word_length = wd_len;  
	
	xmt_data = ULawCompress(xmt_data & 0xFFFF); 

	/* Calculate shift amount  */
	shift_amt = 32 - word_length;
	
	bit_mask = (Uint32)
		((Uint32)(0x80000000) >> (word_length - 1)) >> shift_amt;
		
	/* Simulate receive justify modes */
	xmt_data &= bit_mask; 

	return xmt_data;
}

#endif

/* Function to simulate U-law Expansion */ 
Uint16 ULawExpand(Uint8 i)
{
   Uint16 j;
   Int16 k;
   Uint16 exp, mant, sign;
   
   j = i ^ ULAWCHAN; 
   sign = (j & SIGN) >> 7;
   exp = (j & EXPONENT) >> 4;
   mant = j & MANTISSA;
   k = ((((mant|0x10)<<1)+1)<<exp)-BIAS;
   if(sign == 0) k = -k;
   k = k << 2;
   if (i == 0x7f) k = -1;
        
   return (k);
}

/* Function to simulate U-law compression */
Uint8 ULawCompress(Uint16 InputData)
{

   Uint16 i, j, k;
   Uint16 exp, mant, sign;

        if (InputData >= 0x8000) i = (InputData >> 2) | 0xC000;
        else i = InputData >> 2;
    
        sign = 1;
        if (i >= 0x8000)
        {

           sign = 0;
           i = -i;
        }
        i = i + BIAS;
        if (i > 0x1fff) i = 0x1fff;
        exp = 7;
        while ((i < 0x1000) || (i >= 0x8000))       
        {
            i = i << 1;
            exp = exp - 1;
        }
        if (i >= 0x8000) i = (i >> 8) | 0xFE00;
        else i = (i >> 8);
        mant = i &MANTISSA; 
        j = (sign<<7)+(exp<<4)+mant;
        k = j ^ ULAWCHAN;
        if (InputData == 0xffff) k = 0x7f;
	return (k);
}

⌨️ 快捷键说明

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