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

📄 280xsciloopback.c

📁 TMS320F2808的完整驱动测试程序源码
💻 C
字号:
/*H*****************************************************************************
*
* $Archive::                                                                   $
* $Revision::                                                                  $
* $Date::                                                                      $
* $Author::                                                                    $
*
* DESCRIPTION: R2808 Post
*
* GLOBALS 
*
* PUBLIC FUNCTIONS:
*                              
* PRIVATE FUNCTIONS:
*
* USAGE/LIMITATIONS:
*
* NOTES:  
*     
* (C) Copyright 2004 by Spectrum Digital Incorporated
* All rights reserved
*
*H*****************************************************************************/

#include "DSP280x_Device.h"
#include "r2808cfg.h"


// Prototype statements for functions found within this file.
void scia_reset();
void scia_loopback_init(void);
void scia_fifo_init(void);	
void scia_xmit(int a);

void scib_reset();
void scib_loopback_init(void);
void scib_fifo_init(void);	
void scib_xmit(int a);


#define BAUD_115200  115200UL
#define BAUD_57600    57600UL
#define BAUD_38400    38400UL
#define BAUD_19200    19200UL
#define BAUD_9600      9600UL
#define BAUD_4800      4800UL
#define BAUD_2400      2400UL
#define BAUD_1200      1200UL

#define BAUD_RATE   BAUD_115200
                
#define LOSPCK     25000000UL
#define BRR        (LOSPCK/(BAUD_RATE*8) ) -1

#define BIT_TIME   (1000000UL/BAUD_RATE)

#define MAX_WAIT   16   // Wait up to N bit times

volatile unsigned Error_TxAToRxB  = 0;		// The memory errors
volatile unsigned Error_TxBToRxA  = 0;

int SCI_LoopBack(void)
{
    Uint16 SendChar;
    volatile Uint16 ReceivedChar;
    Uint16 NotSendChar;

    int    Loop;
    long   Timeout;
    int    Xrdy;
    
    scia_reset();
    scib_reset();
 
    scia_fifo_init();	   // Initialize the SCI FIFO
    scib_fifo_init();	   // Initialize the SCI FIFO
    
    scia_loopback_init();  // Initalize SCI for digital loop back 
    scib_loopback_init();  // Initalize SCI for digital loop back 

    SendChar = 0;								

	for(Loop=0; Loop<256; Loop++)
    { 
		// Send on A recv on B
		scia_xmit(SendChar);
		Timeout = MAX_WAIT;
		do{
		
			Xrdy = (ScibRegs.SCIFFRX.bit.RXFFST !=1 ) ?0:1;	// wait for XRDY =1 for empty state
			DELAY_US(BIT_TIME);
		}while( ( Timeout-- > 0) && (!Xrdy) );
		
		if( Timeout <= 0 ) {
		    Error_TxBToRxA = Error_TxAToRxB = (unsigned)-1;
			return( -1 );
		}
		
		// Check received character
		ReceivedChar = ScibRegs.SCIRXBUF.all & 0x00FF;			
		if(ReceivedChar != SendChar)
			Error_TxAToRxB++;
		
		// Send on B recv on A
		NotSendChar  = ~SendChar;
		NotSendChar &=  0x00FF;
	    
	    scib_xmit(NotSendChar);

		Timeout = MAX_WAIT;
		do{
		
			Xrdy = (SciaRegs.SCIFFRX.bit.RXFFST !=1 ) ?0:1;	// wait for XRDY =1 for empty state
			DELAY_US(BIT_TIME);
		}while( ( Timeout-- > 0) && (!Xrdy) );
		
		if( Timeout <= 0 ) {
		    Error_TxAToRxB = Error_TxBToRxA = (unsigned)-3;
			return( -3 );
		}
			
		// Check received character
		ReceivedChar = SciaRegs.SCIRXBUF.all & 0x00FF;			
		if(ReceivedChar != NotSendChar) 			
			Error_TxBToRxA++;
		
		// Move to the next character and repeat the test
		SendChar++;
		SendChar &= 0x00FF;

    }
    if( Error_TxAToRxB != 0 )
    	return( -2 );
    	
    if( Error_TxBToRxA != 0 )
    	return( -4 );
    	
	return( 0 );
} 	

void scia_reset()
{
	SciaRegs.SCICTL1.all = 0x0000;      // SW Reset
    SciaRegs.SCIFFTX.all = 0x0040;      // TX fifo reset
    SciaRegs.SCIFFRX.all = 0x404F;      // RX fifo reset
    SciaRegs.SCIFFCT.all = 0x4000;      // ABD clear
    SciaRegs.SCIHBAUD    = 0x0000;
    SciaRegs.SCILBAUD    = 0x0000;    
}

// Test 1,SCIA  DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity 
void scia_loopback_init()
{    
    // Note: Clocks were turned on to the SCIA peripheral
    // in the InitSysCtrl() function
    

    
 	SciaRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback 
                                   // No parity,8 char bits,
                                   // async mode, idle-line protocol
	SciaRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK, 
                                   // Disable RX ERR, SLEEP, TXWAKE
	SciaRegs.SCICTL2.all =0x0003; 
	SciaRegs.SCICTL2.bit.TXINTENA =1;
	SciaRegs.SCICTL2.bit.RXBKINTENA =1;
    SciaRegs.SCIHBAUD    =0x0000;
    SciaRegs.SCILBAUD    =BRR;
    SciaRegs.SCIPRI.bit.FREE         = 1;
	//SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back  
	SciaRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset 
}

// Transmit a character from the SCI'
void scia_xmit(int a)
{
    SciaRegs.SCITXBUF=a;
}    

// Initalize the SCI FIFO
void scia_fifo_init()										
{
    SciaRegs.SCIFFTX.all=0xE040;
    SciaRegs.SCIFFRX.all=0x204f;
    SciaRegs.SCIFFCT.all=0x0;
    
}  
  
void scib_reset()
{
	ScibRegs.SCICTL1.all = 0x0000;      // SW Reset
    ScibRegs.SCIFFTX.all = 0x0040;      // TX fifo reset
    ScibRegs.SCIFFRX.all = 0x404F;      // RX fifo reset
    ScibRegs.SCIFFCT.all = 0x4000;      // ABD clear
    ScibRegs.SCIHBAUD    = 0x0000;
    ScibRegs.SCILBAUD    = 0x0000;    
}
              							
// Test 1,SCIb  DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity 
void scib_loopback_init()
{    
    // Note: Clocks were turned on to the SCIA peripheral
    // in the InitSysCtrl() function
    
 	ScibRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback 
                                   // No parity,8 char bits,
                                   // async mode, idle-line protocol
	ScibRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK, 
                                   // Disable RX ERR, SLEEP, TXWAKE
	ScibRegs.SCICTL2.all =0x0003; 
	ScibRegs.SCICTL2.bit.TXINTENA =1;
	ScibRegs.SCICTL2.bit.RXBKINTENA =1;
    ScibRegs.SCIHBAUD    =0x0000;
    ScibRegs.SCILBAUD    =BRR;
    ScibRegs.SCIPRI.bit.FREE         = 1;
	//SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back  
	ScibRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset 
}

// Transmit a character from the SCI'
void scib_xmit(int a)
{
    ScibRegs.SCITXBUF=a;
}    

// Initalize the SCI FIFO
void scib_fifo_init()										
{
    ScibRegs.SCIFFTX.all=0xE040;
    ScibRegs.SCIFFRX.all=0x204f;
    ScibRegs.SCIFFCT.all=0x0;
    
}  

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

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