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

📄 timer_isr.c

📁 ADSP 地层驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
**																			**
**	 Name: 	Timer_ISR.c													**	
**																			**
******************************************************************************

(C) Copyright 2006 - Analog Devices, Inc.  All rights reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.  

Purpose:	Perform a POST timer interrupt test on the BF533 EZ-Kit Lite	

                                                                               

******************************************************************************/   
#include <ccblkfn.h>
#include "Timer_ISR.h"

#include "video_test.h"

#define MAX_NUM_COUNTDOWN_TIMERS 5

/*************** SCCB Variables  ************************************/
extern int		SCCB_Variable_High_Address;
extern int		SCCB_Control;
extern int		SCCB_Bit_Count;
extern int		SCCB_Word_Count;
extern int		SCCB_Write_Read_Register;
extern int		*pSCCB_Data_Pointer;
extern int		SCCB_DataIn[60];				
extern int		SCCB_DataOut[60];				
extern int		SCCB_Point_of_State;
extern int		SCCB_Read_Count;


EX_INTERRUPT_HANDLER(Timer0_ISR);
extern VIDEO_TEST video_test;

//--------------------------------------------------------------------------//
// Variables																//
//--------------------------------------------------------------------------//
static volatile unsigned long g_ulTickCount;


typedef struct CountDownTimer_TAG
{
	bool m_IsActive;
	unsigned long m_ulTimeoutCounter;
}countdowntimer;

static countdowntimer sCountDownTimer[MAX_NUM_COUNTDOWN_TIMERS] = { {0,0},{0,0},{0,0},{0,0},{0,0} };

extern bool bVideoTest;



SCCB_STATE sccb_state;


#define scl_bit 0               // scl = PF0
#define sda_bit 1               // sda = PF1


//--------------------------------------------------------------------------//
// Function:	Init_Timers													//
//																			//
// Parameters:	None														//
//																			//
// Return:		None														//
//																			//
// Description:	This function initialises Timer0 for PWM mode.				//
//
//              When clocked internally, the clock source is the
//				processor抯 peripheral clock (SCLK). Assuming the
//              peripheral clock is running at 133 MHz, the maximum period
//              for the timer count is ((2^32-1) / 133 MHz) = 32.2 seconds.
//
//--------------------------------------------------------------------------//
void Init_Timers(void)
{
	*pTIMER0_CONFIG		= 0x0019;
	*pTIMER0_PERIOD		= TIMEOUT_PERIOD;
	*pTIMER0_WIDTH		= TIMEOUT_PERIOD/2;	// width = period/2 = 50% duty cycle
	*pTIMER_ENABLE		= 0x0001;
}

//--------------------------------------------------------------------------//
// Function:	Init_Timer_Interrupts												//
//																			//
// Parameters:	None														//
//																			//
// Return:		None														//
//																			//
// Description:	This function initialises the interrupts for Timer0
//--------------------------------------------------------------------------//
void Init_Timer_Interrupts(void)
{
	// assign core IDs to interrupts
	*pSIC_IAR0 = 0xffffffff;
	*pSIC_IAR1 = 0xffffffff;
	*pSIC_IAR2 = 0xfffffff4;					// Timer0 -> ID4;

	// assign ISRs to interrupt vectors
	register_handler(ik_ivg11, Timer0_ISR);		// Timer0 ISR -> IVG 11

	// enable Timer0 interrupt
	*pSIC_IMASK |= IRQ_TIMER0;
}



//--------------------------------------------------------------------------//
// Function:	SetTimeout												//
//																			//
// Parameters:	ulTicks - number of ticks to count down														//
//																			//
// Return:		The index of the timer structure being used or
//				-1 if none are available.
//
// Description:	Set a value for a global timeout, return the timer
//
//--------------------------------------------------------------------------//
unsigned int SetTimeout(const unsigned long ulTicks)
{
	unsigned int uiTIMASK = cli();
	unsigned int n;

	// we don't care which countdown timer is used, so search for a free
	// timer structure
	for( n = 0;  n < MAX_NUM_COUNTDOWN_TIMERS; n++ )
	{
		if( false == sCountDownTimer[n].m_IsActive )
		{
			sCountDownTimer[n].m_IsActive = true;
			sCountDownTimer[n].m_ulTimeoutCounter = ulTicks;


			sti(uiTIMASK);
			return n;
		}
	}

	sti(uiTIMASK);
	return ((unsigned int)-1);
}

//--------------------------------------------------------------------------//
// Function:	ClearTimeout												//
//																			//
// Parameters:	the index of the countdown structure														//
//																			//
// Return:		the number of ticks left to count down
//
// Description:	Set a value for a global timeout, return the timer
//
//--------------------------------------------------------------------------//
unsigned long ClearTimeout(const unsigned int nIndex)
{
	unsigned int uiTIMASK = cli();
	unsigned long ulTemp = (unsigned int)(-1);

	if( nIndex < MAX_NUM_COUNTDOWN_TIMERS )
	{
		// turn off the timer
		ulTemp = sCountDownTimer[nIndex].m_ulTimeoutCounter;
		sCountDownTimer[nIndex].m_ulTimeoutCounter = 0;
		sCountDownTimer[nIndex].m_IsActive = false;
	}

	sti(uiTIMASK);
	return (ulTemp);
}

//--------------------------------------------------------------------------//
// Function:	IsTimedout												//
//																			//
// Parameters:	the index of the timer to check														//
//																			//
// Return:		1 if timeout value expired, 0 if timeout NOT expired		//
//																			//
// Description:	Checks to see if the timeout value has expired
//				                                                            //
//--------------------------------------------------------------------------//
bool IsTimedout(const unsigned int nIndex)
{
	unsigned int uiTIMASK = cli();
	if( nIndex < MAX_NUM_COUNTDOWN_TIMERS )
	{
		sti(uiTIMASK);
		return ( 0 == sCountDownTimer[nIndex].m_ulTimeoutCounter );
	}

	sti(uiTIMASK);
	return 0;// an invalid index should cause a hang wherever a timer is being used
}


//--------------------------------------------------------------------------//
// Function:	Timer0_ISR													//
//																			//
// Parameters:	None														//
//																			//
// Return:		None														//
//																			//
// Description:	This ISR is executed every time Timer0 expires.				//
//										//
//--------------------------------------------------------------------------//
EX_INTERRUPT_HANDLER(Timer0_ISR)
{
    if(!bVideoTest)
    {
		unsigned int n;
		// confirm interrupt handling
		*pTIMER_STATUS = 0x0001;
		ssync();

		g_ulTickCount++;


		// decrement each counter if it is non-zero
		for( n = 0;  n < MAX_NUM_COUNTDOWN_TIMERS; n++ )
		{
			if( 0 != sCountDownTimer[n].m_ulTimeoutCounter )
			{
				sCountDownTimer[n].m_ulTimeoutCounter--;
			}
		}
    }
    else
    {  
	    switch(sccb_state)
	    {
		    case SCCB_Start_Cond0:
		    	//configure SDA as output
	 			*pFIO_DIR |= SDA;
	 			// drive both SCL and SDA high
		    	*pFIO_FLAG_S |= SCL;
		    	// next state
		    	sccb_state = SCCB_Start_Cond1;
	    	
		    	*pTIMER_STATUS = 0x0011;
	    
		    	break;
		    case SCCB_Start_Cond1:
		    	// drive SDA low first (Start Condition!)
				*pFIO_FLAG_C = SDA;
		    	// next state
		    	sccb_state = SCCB_Start_Cond2;
	    	
		    	*pTIMER_STATUS = 0x0011;
	    
		    	break;
	    	
	 	    case SCCB_Start_Cond2:
 	    
	 	    	// drive SCL low (Start Condition!)
	 	    	*pFIO_FLAG_C = SCL;
		    	// next state
		    	sccb_state = SCCB_Xmt_Data;
	    	
		    	*pTIMER_STATUS = 0x0011;
 	
		    	break;

		    case SCCB_Xmt_Data:
				// "SCCB_Send_Data" will send all the addresses and 
				// data required for communication to the device. 
				// The data must be shifted through the GPIO Pin 15
			
				// set the SCL low
				*pFIO_FLAG_C = SCL;
				if(SCCB_Bit_Count != 0)
				{
				    if(!(SCCB_Write_Read_Register & 0x80))
				    {
				        // bit is low, drive SDA low
				        *pFIO_FLAG_C = SDA;
			        
				    }
				    else
				    {
				        // bit is hi, drive SDA hi
				        *pFIO_FLAG_S = SDA;
				    }
			    
				}else
				{
				    //SCCB_Xmt_Byte_Done
				    // byte has been sent
					// change SDA to input 
					*pFIO_DIR &= (~SDA);
					// change SDA to input 
					*pFIO_INEN |= SDA;
			    	// next state
			    	sccb_state = SCCB_ACK_TST;
	    	
			    	*pTIMER_STATUS = 0x0011;
			    	break;
		    
				}

				//shift the byte to get the next bit
				//save the shifted byte for the run
				SCCB_Write_Read_Register = SCCB_Write_Read_Register << 1;
				//decrement the bit counter. 
				SCCB_Bit_Count--;
			

⌨️ 快捷键说明

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