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

📄 watchdog.c

📁 ADI公司blackfin DSP开发板BF533 EZ-KIT LITE附带的全部原代码
💻 C
字号:
/*********************************************************************************

Copyright(c) 2004 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.  

$RCSfile: watchdog.c,v $
$Revision: 1.1 $
$Date: 2007/03/28 18:50:35 $ 

***********************************************************************************

Please refer to the 'readme.txt' file for a description of the watchdog timer example


*********************************************************************

Include files

*********************************************************************/

#include <services/services.h>
#include "ezkitutilities.h"

/*********************************************************************

Enumerations and defines

*********************************************************************/


#define WATCHDOG_COUNT		0x07ffffff


/*********************************************************************

Data Structures 

*********************************************************************/

/*********************************************************************

Static data

*********************************************************************/


// Table to set up the watchdog timer.
ADI_TMR_WDOG_CMD_VALUE_PAIR wdog_table[] = {
	{ ADI_TMR_WDOG_CMD_SET_COUNT,        (void *) WATCHDOG_COUNT },	
	{ ADI_TMR_WDOG_CMD_RESET_EXPIRED,    (void *) 0 },
	{ ADI_TMR_WDOG_CMD_EVENT_SELECT,     (void *) 2 },	// set up for normal interrupt
	{ ADI_TMR_WDOG_CMD_ENABLE_TIMER,     (void *) 1 },
	ADI_TMR_WDOG_CMD_END
};


ADI_TMR_WDOG_CMD_VALUE_PAIR wdog_reset_table[] = {
	{ ADI_TMR_WDOG_CMD_ENABLE_TIMER,     (void *) 0 },
	{ ADI_TMR_WDOG_CMD_SET_COUNT,        (void *) WATCHDOG_COUNT },
	{ ADI_TMR_WDOG_CMD_RESET_EXPIRED,    (void *) 0 },
	{ ADI_TMR_WDOG_CMD_ENABLE_TIMER,     (void *) 1 },
	ADI_TMR_WDOG_CMD_END
};


/*********************************************************************

Static functions

*********************************************************************/


//  This is the handler for the watchdog timeout
static ADI_INT_HANDLER(wdog_handler) {
	// "volatile" is used to avoid the compiler optimizing out the while loop	
	volatile u32 i;							

	// when the watchdog timer expires, loop while cycling LEDs, until button 1 is pressed
	while(1) {
		for(i=0; i<0x003FFFFF; i++);		// delay for a little while
		ezCycleLEDs();
		
		// When the user presses the first button, reset the watchdog timer
		if( ezIsButtonPushed(EZ_FIRST_BUTTON)) {
			ezErrorCheck( adi_tmr_WatchdogControl(ADI_TMR_WDOG_CMD_TABLE, wdog_reset_table));
			ezClearButton(EZ_FIRST_BUTTON);			// clear the button press
			ezTurnOffAllLEDs();						// shut off any LEDs
			return (ADI_INT_RESULT_PROCESSED);		// go back to main()
		}
		
	}
}


/*********************************************************************

 Callback functions

*********************************************************************/



/****************************************************************************
  Function:	Init
				
  Do all initialization
******************************************************************************/

void Init(void)
{
	u32 Response_Count;
	u32 i; //loop variable
	
	// initialize the EZ-Kit
	ezInit(1);	

	// initialize the interrupt manager. No storage data needed since there are no 2ndary interrupts
	ezErrorCheck( adi_int_Init(NULL, 0, &Response_Count, NULL)!= ADI_INT_RESULT_SUCCESS);
	
	// watchdog is IVG 13 on all processors
	ezErrorCheck( adi_int_CECHook(13, wdog_handler, &wdog_handler, FALSE) != ADI_INT_RESULT_SUCCESS);
	
	// Enable interrupts
	ezErrorCheck( adi_int_SICEnable(ADI_INT_WATCHDOG) != 0 );
	
	// Initialize the timer manager
	ezErrorCheck( adi_tmr_Init( &Response_Count ) != ADI_TMR_RESULT_SUCCESS);
	
	//Initialize the flag service, memory is not passed because callbacks are not being used
	ezErrorCheck(adi_flag_Init(NULL, 0, &Response_Count, NULL));
	
	
	//Initialize one button and all LEDS
	ezInitButton(EZ_FIRST_BUTTON);
	
	for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
        ezInitLED(i);
	}
	
	// Open the watchdog timer
	ezErrorCheck( adi_tmr_Open( ADI_TMR_WDOG_TIMER ) != ADI_TMR_RESULT_SUCCESS);
	
	// Configure the watchdog timer
	ezErrorCheck( adi_tmr_WatchdogControl(ADI_TMR_WDOG_CMD_TABLE, wdog_table));
}
 
	
/*********************************************************************
*
*	Function:	main
*
*********************************************************************/

void main(void) {
	volatile u32 i;			
	// "volatile" is used to avoid having the spin loop optimized out by 
	u32 Response;
	
	Init();
	while (1) {
		
		// When the user presses the first button, reset the watchdog timer
		if( ezIsButtonPushed(EZ_FIRST_BUTTON)) {
			ezErrorCheck( adi_tmr_WatchdogControl(ADI_TMR_WDOG_CMD_TABLE, wdog_reset_table));
			ezClearButton(EZ_FIRST_BUTTON);
		}
	}
}

⌨️ 快捷键说明

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