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

📄 r2808post.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 <stdio.h>
#include "DSP280x_Device.h"
#include "r2808cfg.h"
#include "r2808init.h"
#include "memtest.h"
#include "led.h"

// Set to fail values to force test to overwrite
volatile unsigned EnableInterrupts    = 1;		// Enable int1 for realtime
volatile unsigned TogglePeriod        = 100;	// LedtToggle rate
volatile unsigned ToggleUpdate        = 0;		// Led toggle update
volatile unsigned LoopForever         = 0;		// If set the memory forever
volatile unsigned RanTheTest          = 0;		// Signal to indicate test ran
volatile unsigned SciLoopBack         = 0;
volatile unsigned CanLoopBack         = 0;
volatile unsigned I2CLoopBack         = 0;

long     TotalErrors                  = 0;
long     TestCount                    = 0;
	
#define STATUS_LED_TOGGLE  LED_Toggle()
#define STATUS_LED_OFF     LED_Off()
#define STATUS_LED_ON      LED_On()

extern int SCI_LoopBack(void);
extern int CAN_LoopBack(void);
extern int I2C_LoopBack(void);

//---------------------------------------------------------------------------
// Define test build switches
//---------------------------------------------------------------------------
//#define DEBUG_LOOP          // Will loop forever or error
#define DO_MEMORY_TEST      // Enable memory test code
#define DO_SCI_TEST         // Enable sci loopback test
#define DO_CAN_TEST			// Enable can loopback test
#define DO_I2C_TEST         // Enable i2c loopback test
/*-----------------------------------------------------------------------------
* interrupt void Int1Isr(void)
*  
* Entry point for INT1's ISR - note that this does NOT enable interrupts or
* debug accesses - INT1's ISR can not be debugged in real-time.
*----------------------------------------------------------------------------*/
interrupt void Int1Isr(void)
{
	static int ToggleRate = 0;
	
	if( ++ToggleRate == TogglePeriod ) {
		STATUS_LED_TOGGLE;
		ToggleRate = 0;
		
		// Check to see if host has posted a new TogglePerid.  If so then
		// do parameter update and clear update value as a signal back to
		// the host.
		if( ToggleUpdate != 0 ) {
			TogglePeriod = ToggleUpdate;
			ToggleUpdate = 0;
		}
	}
	
	PieCtrlRegs.PIEACK.bit.ACK1 = 1;
}


void TestFail( void )
{
    int Loop = 10;
	while(Loop--)
	{
		STATUS_LED_TOGGLE;
		DELAY_US(100000);
	}
	STATUS_LED_OFF;
}

void TestPass( void )
{
    int Loop = 6;
	while(Loop--)
	{
		STATUS_LED_TOGGLE;
		DELAY_US(1000000);
	}
	STATUS_LED_ON;
}

void TestDone( int StopOnDone )
{

#if !defined( INCL_POST )
  // Do not stop on post build
  asm ("      ESTOP0");
  asm ("      NOP"   );
  asm ("      NOP"   );
  asm ("      NOP"   );
#endif
    
  if( StopOnDone == 1 ){
  	while(1){}
  } else {
  	return;
  	}
}

/*-----------------------------------------------------------------------------
* void SetupInterrupts(void)
*  
* Setup interrupts to be used in the real-time tutorial. This consists of
* configuring the function generator to generate interrupts, and then
* setting the IER/DBGIER registers. Then the INTM and DBGM bits of ST1 are
* cleared, thus enabling interrupts and real-time debug.
*----------------------------------------------------------------------------*/
void SetupInterrupts(void)
{
    extern cregister volatile Uint16 IER;
    EALLOW;    
    
    /*-------------------------------------------------------------------------
    * Cause INT1 to occur every 1066 cycles
    *------------------------------------------------------------------------*/
    CpuTimer0Regs.TIM.all  = 0x1066;
    CpuTimer0Regs.PRD.all  = 0X1066;
    CpuTimer0Regs.TPR.all  = 0;
    CpuTimer0Regs.TPRH.all = 0;
    CpuTimer0Regs.TCR.all  = 0x4820;
    
    // Map the vector
    PieVectTable.TINT0 = Int1Isr;
    
    PieCtrlRegs.PIEIER1.all = 0x40;
    EDIS;
           
    /*-------------------------------------------------------------------------
    * Now the interrupts. Setting the IER register is easy, since the
    * compiler supports this as a control register. The DBGIER register is
    * not ort, so we need to use assembly.
    *------------------------------------------------------------------------*/
    IER = 1; 
    asm(" mov  *SP++, #0x0001 ; Want to enable INT1 and INT13 in the DBGIER.");
    asm(" pop  DBGIER         ; ...register");    
    asm(" clrc INTM, DBGM     ; Enable global interrupts and debug accesses");
    return;
}

void main(void)
{
	int Error = 0;

   	InitSysCtrl();
   	DINT;
	InitPieCtrl();  
    IER = 0x0000;
    IFR = 0x0000;	
    InitPieVectTable();
	XINTF_Init();
    CSM_unlock();
    InitGpio();
	
#if defined( DEBUG_LOOP )
	SciLoopBack = 1;
	CanLoopBack = 1;
	LoopForever = 1;
	I2CLoopBack = 1;
	EnableInterrupts = 0;
#endif

	do {
	
#if defined( DO_MEMORY_TEST )
		// Test memory
 		Error = MEM_DoTest(5);
		if( Error != 0 ) {
			TotalErrors++;
		}
#endif

#if defined( DO_SCI_TEST ) 		
 		// Test SCI loopback.  Requires
 		// SCIATX -> SCIBRX
 		// SCIARX -> SCIBTX
 		if( SciLoopBack ) {
 			Error = SCI_LoopBack();
 			if( Error != 0 ) {
 				TotalErrors++;
 			}
 		}
#endif
 
#if defined( DO_CAN_TEST )
        // Test CAN loopback.  Requires
        // CAN-A tied to CAN-B
        //
 		if( CanLoopBack ) {
 			Error = CAN_LoopBack();
 			if( Error != 0 ) {
 				TotalErrors++;
 			}
 		}
#endif
  			
#if defined( DO_I2C_TEST )
		if( I2CLoopBack ) {
			Error = I2C_LoopBack();
 			if( Error != 0 ) {
 				TotalErrors++;
 			}
 			DINT; // Turn interrupts that I2C turned on
		}
#endif
 		STATUS_LED_TOGGLE;
 		TestCount++;
  	}while( LoopForever == 1 );
  	
  	RanTheTest = 1;
  	
  	if( Error != 0 )
  		TestFail();
  	else
  		TestPass();	
  	
  	// Run to embedded breakpoint.  This allows host a chance to
  	// get the memory results and then continue if it wants with
  	// some realtime stuff.
  	TestDone( 0 );

  	if( EnableInterrupts != 0 ) 
  	{
  		DINT;
  		IER = 0;
    	LED_On();  		
		SetupInterrupts();
	}
	
	TestDone( 1 );
} 					



⌨️ 快捷键说明

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