pbled_test.c

来自「ADI 公司的DSP ADSP21262 EZ-KIT LITE开发板的全部源代」· C语言 代码 · 共 453 行

C
453
字号
////////////////////////////////////////////////////////////////////////////
//
//  Program to check the functionality of core accesses to 32-bit SRAM
//    device
//
//    - PRD
//

#include <Cdef21262.h>
#include <def21262.h>
#include <sru21262.h>
#include <signal.h>
#include <stdio.h>
#include <sysreg.h>

#include "post_common.h"
#include "PBLED_test.h"


//////////////////////////////////////////////////////////////////////////////
//
// globals
//
//////////////////////////////////////////////////////////////////////////////
int g_iEnterTestMode = 0;



//////////////////////////////////////////////////////////////////////////////
//
// Function Prototypes
//
//////////////////////////////////////////////////////////////////////////////
int TEST_PBLED(void);
void ClearSet_LED(const enLED led, const int bState);
void IRQ2_routine(int sig_int);
void IRQ1_routine(int sig_int);
void DAIroutine(int sig_int);

void Cleanup_SRU_INTS(void);


//////////////////////////////////////////////////////////////////////////////
//
// Stand alone test jig
//
//////////////////////////////////////////////////////////////////////////////
#ifdef _STANDALONE_ // use this to run standalone tests
int main(void)
{
	int bPassed = 0;
	int n;
	
	Setup_leds();

	while(1)
	{
		bPassed = TEST_PBLED();
	}
	
	return 0;
}
#endif //#ifdef _STANDALONE_


//////////////////////////////////////////////////////////////////////////////
// int TEST_LED_and_PB(void)
// 
// PURPOSE:		Test the push buttons and LED's
// 
//////////////////////////////////////////////////////////////////////////////
int TEST_PBLED(void)
{
	int iReturn = 0;
	
    Setup_Ints();
  
	// for each push button, illuminate two LED's
	// when all PB's have been pressed, test will return
	// with a pass or fail, or it will get stuck here.
	do{
	    asm("nop;");
	}while( 0x0F != g_iEnterTestMode );
	
    sysreg_bit_set(sysreg_MODE1, IRPTEN); // disable interrupt
	iReturn = 1;
	
	Cleanup_SRU_INTS();
	
	return iReturn;
}


//////////////////////////////////////////////////////////////////////////////
// void LED_BAR(const int iSpeed)
// 
// PURPOSE:		Display a blinking LED bar
// 
// INPUT:		iSpeed - the speed of the blink
//////////////////////////////////////////////////////////////////////////////
void LED_BAR(const int iSpeed)
{
	enLED n;
	int j;
	
    // Note that MS2 & MS3 pin multiplexed with flag2 & flag3.
    // MSEN bit must be enabled to access SDRAM, but LED8 cannot be driven with sdram
    // Note that MS2 & MS3 pin multiplexed with flag2 & flag3
    // Programming the mutliplexed pin as MS2
	for( n = LED1; n < LAST_LED; (n <<= 1) )
	{
		ClearSet_LED(n, 3);
		Delay(iSpeed);
	}
	
	
}


//////////////////////////////////////////////////////////////////////////////
// void Blink_LED(const int enleds, const int iSpeed)
// 
// PURPOSE:		Blink various LED's
// 
// INPUT:		iSpeed - the speed of the blink
//				enleds - the LED to actually blink
//////////////////////////////////////////////////////////////////////////////
void Blink_LED(const int enleds, const int iSpeed)
{
	int j;
	enLED n;
	
	while( 1 )
	{
		for( n = LED1; n < LAST_LED; (n <<= 1) )
		{
			if( n & enleds )
			{
				ClearSet_LED(n, 3);
			}
		}
		
		Delay(iSpeed);
	}
}


//////////////////////////////////////////////////////////////////////////////
// void ClearSet_LED_Bank(const int enleds, const int iState)
// 
// PURPOSE:		Clear or set a particular LED or group of LED's
// 
// INPUT:		iState - the state ON, OFF, TGL
//				enleds - the LED(s) to actually blink
//////////////////////////////////////////////////////////////////////////////
void ClearSet_LED_Bank(const int enleds, const int iState)
{
	enLED n;
	int nTempState = iState;
	
	
	for( n = LED1; n < LAST_LED; (n <<= 1) )
	{
		if( n & enleds )
		{
			ClearSet_LED(n, (nTempState & 0x3) );
		}
		
		nTempState >>= 2;
	}
}


//////////////////////////////////////////////////////////////////////////////
// void ClearSet_LED(const enLED led, const int bState)
// 
// PURPOSE:		Clear or set a particular LED (NOT A GROUP)
// 
// INPUT:		iState - the state ON, OFF, TGL
//				enleds - the LED(s) to actually blink
//////////////////////////////////////////////////////////////////////////////
void ClearSet_LED(const enLED led, const int bState)
{
	switch( led )
	{
		
		case LED1:
		{
			if( 0 == bState )
			{
				sysreg_bit_clr(sysreg_FLAGS, FLG8); 
			}
			else if( 1 == bState )
			{
				sysreg_bit_set(sysreg_FLAGS, FLG8); 
			}
			else // toggle the bits
			{
				sysreg_bit_tgl(sysreg_FLAGS, FLG8); 
			}
		}
		break;
		
		case LED2:
		{
			if( 0 == bState )
			{
				sysreg_bit_clr(sysreg_FLAGS, FLG9); 
			}
			else if( 1 == bState )
			{
				sysreg_bit_set(sysreg_FLAGS, FLG9); 
			}
			else // toggle the bits
			{
				sysreg_bit_tgl(sysreg_FLAGS, FLG9); 
			}
		}
		break;
		
		case LED3:
		{
			if( 0 == bState )
			{
				sysreg_bit_clr(sysreg_FLAGS, FLG10); 
			}
			else if( 1 == bState )
			{
				sysreg_bit_set(sysreg_FLAGS, FLG10); 
			}
			else // toggle the bits
			{
				sysreg_bit_tgl(sysreg_FLAGS, FLG10); 
			}
		}
		break;
		
		case LED4:
		{
			if( 0 == bState )
			{
				sysreg_bit_clr(sysreg_FLAGS, FLG11); 
			}
			else if( 1 == bState )
			{
				sysreg_bit_set(sysreg_FLAGS, FLG11); 
			}
			else // toggle the bits
			{
				sysreg_bit_tgl(sysreg_FLAGS, FLG11); 
			}
		}
		break;
		
		case LED5:
		{
			if( 0 == bState )
			{
				sysreg_bit_clr(sysreg_FLAGS, FLG12); 
			}
			else if( 1 == bState )
			{
				sysreg_bit_set(sysreg_FLAGS, FLG12); 
			}
			else // toggle the bits
			{
				sysreg_bit_tgl(sysreg_FLAGS, FLG12); 
			}
		}
		break;

		case LED6:
		{
			if( 0 == bState )
			{
				sysreg_bit_clr(sysreg_FLAGS, FLG13); 
			}
			else if( 1 == bState )
			{
				sysreg_bit_set(sysreg_FLAGS, FLG13); 
			}
			else // toggle the bits
			{
				sysreg_bit_tgl(sysreg_FLAGS, FLG13); 
			}
		}
		break;
		
		case LED7:
		{
			if( 0 == bState )
			{
				sysreg_bit_clr(sysreg_FLAGS, FLG14); 
			}
			else if( 1 == bState )
			{
				sysreg_bit_set(sysreg_FLAGS, FLG14); 
			}
			else // toggle the bits
			{
				sysreg_bit_tgl(sysreg_FLAGS, FLG14); 
			}
		}
		break;
				
		case LED8:
		{
			if( 0 == bState )
			{
				sysreg_bit_clr(sysreg_FLAGS, FLG15); 
			}
			else if( 1 == bState )
			{
				sysreg_bit_set(sysreg_FLAGS, FLG15); 
			}
			else // toggle the bits
			{
				sysreg_bit_tgl(sysreg_FLAGS, FLG15); 
			}
		}
		break;
	}// end switch
	
}


//////////////////////////////////////////////////////////////////////////////
// void Setup_Ints(void)
// 
// PURPOSE:		Configure the system to accept the push buttons as inputs
// 
//////////////////////////////////////////////////////////////////////////////
void Setup_Ints(void)
{
	Config_SRU_INTS();
	
	//The 8 user LEDs on the ADSP-21262 EZ-Kit are mapped to flag
	//pins as well as the parallel port AD0-7 pins, so we can use the parallel port 
	//to write the latch to light the LEDs
	
	*pPPCTL = PPTRAN|   // transmit in 8-bit mode
              PPBHC|    // bus hold cycle
              PPDUR20|  // cycle duration
              PPEN;     // Enable for core driven transfer.

	
    (*pDAI_IRPTL_PRI) = (SRU_EXTMISCA1_INT  | SRU_EXTMISCA2_INT);    //unmask individual interrupts
    (*pDAI_IRPTL_RE) = (SRU_EXTMISCA1_INT  | SRU_EXTMISCA2_INT);    //make sure interrupts latch on the rising edge
 
	//Set up interrupt priorities
    sysreg_bit_set(sysreg_IMASK, DAIHI); //make DAI interrupts high priority

    (*pSYSCTL) |= (IRQ1EN|IRQ2EN);
    
    sysreg_bit_set(sysreg_MODE2, (IRQ1E|IRQ2E) ); 
    sysreg_bit_clr(sysreg_IRPTL, (IRQ1I|IRQ2I) ); 
    sysreg_bit_set(sysreg_IMASK, (IRQ1I|IRQ2I) ); //enable IRQ interrupts
 //   sysreg_bit_set(sysreg_MODE1, IRPTEN ); 		  //enable global interrupts
    sysreg_bit_clr(sysreg_MODE1, IRPTEN ); 		  //enable global interrupts
	
    interrupt(SIG_DAIH,DAIroutine);
    interrupt(SIG_IRQ2,IRQ2_routine);
    interrupt(SIG_IRQ1,IRQ1_routine);
}

//////////////////////////////////////////////////////////////////////////////
// void Cleanup_SRU_INTS(void)
//
// PURPOSE: 	Re Configure the interrupts after LED test
//
// INPUT:	none
// RETURNS: none
//	
//////////////////////////////////////////////////////////////////////////////
void Cleanup_SRU_INTS(void)
{
    interrupt(SIG_DAIH,SIG_IGN);
    interrupt(SIG_IRQ0,SIG_IGN);
    interrupt(SIG_IRQ1,SIG_IGN);
}


//////////////////////////////////////////////////////////////////////////////
// void Setup_leds(void)
// 
// PURPOSE:		Setup LED's to be outputs 
// 
//////////////////////////////////////////////////////////////////////////////
void Setup_leds(void)
{
	*pSYSCTL |= PPFLGS;
	
    sysreg_bit_set(sysreg_FLAGS, (FLG8O|FLG9O|FLG10O|FLG11O|FLG12O|FLG13O|FLG14O|FLG15O) ); 	//Setting flag pins as outputs
	sysreg_bit_clr(sysreg_FLAGS, (FLG8|FLG9|FLG10|FLG11|FLG12|FLG13|FLG14|FLG15) );			//Clearing flag pins 
}


//////////////////////////////////////////////////////////////////////////////
// void IRQ0_routine(int sig_int)
// 
// PURPOSE:		ISR for pushbutton 2
// 
//////////////////////////////////////////////////////////////////////////////
void IRQ2_routine(int sig_int)
{
	g_iEnterTestMode |= 0x02;

	ClearSet_LED(LED3, 3);
   	ClearSet_LED(LED4, 3);
}

//////////////////////////////////////////////////////////////////////////////
// void IRQ1_routine(int sig_int)
// 
// PURPOSE:		ISR for pushbutton 1
// 
//////////////////////////////////////////////////////////////////////////////
void IRQ1_routine(int sig_int)
{
	g_iEnterTestMode |= 0x01;

	ClearSet_LED(LED1, 3);
   	ClearSet_LED(LED2, 3);
}


//////////////////////////////////////////////////////////////////////////////
// void IRQ1_routine(int sig_int)
// 
// PURPOSE:		ISR for pushbutton 3 and 4
// 
//////////////////////////////////////////////////////////////////////////////
void DAIroutine(int sig_int)
{
	int iTest;
    iTest = (*pDAI_IRPTL_H); // reading pDAI_IRPTL_H clears the latched interrupt.
    if( SRU_EXTMISCA1_INT == iTest )
    {
		g_iEnterTestMode |= 0x04;
    	ClearSet_LED(LED5, 3);
    	ClearSet_LED(LED6, 3);
    }
    else if( SRU_EXTMISCA2_INT == iTest )
    {
		g_iEnterTestMode |= 0x08;
    	ClearSet_LED(LED7, 3);
    	ClearSet_LED(LED8, 3);
    }
}



⌨️ 快捷键说明

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