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

📄 exceptions.h

📁 GM5621原代码
💻 H
字号:
/*
	$Workfile:   EXCEPTIONS.H  $
	$Revision:   1.6  $
	$Date:   Feb 25 2004 13:40:04  $
*/

//******************************************************************
//
//		Copyright (C) 2001.  GENESIS MICROCHIP INC.
// All rights reserved.  No part of this program may be reproduced
//
//	Genesis Microchip Inc., 165 Commerce Valley Dr. West
//		Thornhill, Ontario, Canada, L3T 7V8
//
//================================================================
//
// MODULE:  exceptions.h
//
// USAGE :  provide 80c186 exception handlers for divide by 0 interrupt
//			bus watchdog timer, software watchdog timer
//
//
//******************************************************************

//
// define options of exception handlers
//
enum 
{
	DisableExceptions,
	EnableExceptions,
	ReportExceptions
};
#define ProcessExceptions EnableExceptions
#define UseWatchdogTimer 0  //note, this has no effect if ProcessExceptions is set to DisableExceptions
#define WDT_TIMEOUT_SECONDS 20
#define Exception_STACKSIZE 20 // size of WORD array to store stack at time of exception, can dump with appstest

// define index into savestack at time of exception, 
// CAUTION - if exception.c code is changed these indices may be incorrect
enum exception_StackFrame 
{
	exception_type,
	exception_es,
	exception_ds,
	exception_du,
	exception_si,
	exception_bp,
	exception_sp,
	exception_bx,
	exception_dx,
	exception_cx,
	exception_ax,
	exception_ip,
	exception_cs,
	exception_flags
};

//
// if ProcessExceptions is set to DisableExceptions InitExceptionHandler
//  will surpress all exception handling (except those interrupt handlers that are
//  explicitly setup by other means than the exception.c code.)
#if ProcessExceptions != DisableExceptions
	#if ProcessExceptions == EnableExceptions
	//*********************************************************************************
	// enabling exceptions prevents an exception from causing the system to lock up.  In
	// general the exception handler will return after clearing the source of the problem
	// in some cases that may mean simply returning (eg div/0).  The exception handler
	// will set a bit in exceptionFound corresponding the the exception type encountered.
	//  This can be used by the debug-handler to report an exception.
	// NOTE: customer may prefer to have OCM watchdog timer reset board.  To do so
	//    set RESET_ON_WDT to 1.
	//  This option is meant to be appropriate for PRODUCTION
	//*********************************************************************************
		#define TRAP_BOUND 0    // set to 1 to invoke exception context switch for BOUND ERROR
		#define TRAP_GENERIC 0  // set to 1 for misc exceptions all processed by generic handler
		#define TRAP_WDT 0 // set to 1 to invoke exception context switch for Watch Dog Timer ERROR
		#define RESET_ON_WDT 0  // set to 1 to cause OCM reset if WDT timeout occurs
		#define TRAP_DIV0 0	    //	set to 1 to invoke exception context switch for BOUND ERROR
		#define ENABLE_BUS_WDT_IRQ 0 // set to 1 to allow exception trapping of bus watch dog timer
		#define USE_OCM_WDT 1		// enable OCM watch dog timer if set to 1
	#elif ProcessExceptions == ReportExceptions
	//*********************************************************************************
	// This option should be used during development.  When an exception is encountered
	//   the context will be switched immediately to the debug handler allowing examination
	//   of stack contents, etc.  Also, the jtag debugger can be used to apply a breakpoint
	//   to the common exception handler allowing a single breakpoint to be  used to
	//   stop on any exception.
	//*********************************************************************************

		#define TRAP_BOUND 01    // set to 1 to invoke exception context switch for BOUND ERROR
		#define TRAP_GENERIC 01  // set to 1 for misc exceptions all processed by generic handler
		#define TRAP_WDT 01 // set to 1 to invoke exception context switch for Watch Dog Timer ERROR
		#define RESET_ON_WDT 0  // set to 1 to cause OCM reset if WDT timeout occurs
		#define TRAP_DIV0 01	    //	set to 1 to invoke exception context switch for BOUND ERROR
		#define ENABLE_BUS_WDT_IRQ 1 // set to 1 to allow exception trapping of bus watch dog timer
		#define USE_OCM_WDT 1		// enable OCM watch dog timer if set to 1							
		#define USE_ExceptionHandler
	#endif
	#if ProcessExceptions == ReportExceptions
		extern WORD savestack[Exception_STACKSIZE]; // save 20 WORD of stack if ReportExceptions if enabled
	#endif

	void InitExceptionHandler(void); 
	void PetWatchdog(void);  // must invoke periodically if USE_OCM_WDT is set to 1
	extern WORD exceptionFound;  // global indicating exception trapped by IRQ - useful for checking with gprobe
#else // ProcessExceptions != DisableExceptions
// since the exception handler is disabled define macros for exception API with null bodies.
//  This allows us to disable exceptions without #ifdefs surrounded calls to the following function in the main code.
	#define InitExceptionHandler()
	#define InitWatchdog()
	#define PetWatchdog()
	#define exceptionFound 0  //so that if debug_handler checks this variable it will be 0
#endif

	
//
//  INTERRUPT VECTOR ADDRESSES
//

#define BUS_WDT_VECTOR		INT1_VECTOR		// USES OCM INT_1
#define IRQIN				INT2_VECTOR      // gpio IRQIN can be enabled to receve interrupt on int 2
#define IFM_VECTOR			INT3_VECTOR		// 5221 IFM Genreates interrupt on int 3 ( see IFM_OCMMASK)
#define INPUT_VECTOR		INT4_VECTOR      // 5221 INPUT generates interrupt on int 4 (see INPUT_OCMMASK )
#define MISC_VECTOR			INT5_VECTOR		// 5221 Misc interrupts on int 5 (see MISC_OCMMASK)
#define WDT_VECTOR			NMI_VECTOR	// watchdog timer interrupts on NMI

//
// Set interrupt vector address
// NOTE:  The high word of the W_CodeAddr is CS, the compiler will copy
//        the CS value to the high word of W_VectAddr.
//
#define SET_VECTOR(W_VectAddr, W_CodeAddr)	\
	*((WORD volatile* volatile)(W_VectAddr))		= (WORD)(W_CodeAddr); \
	*((WORD volatile* volatile)(W_VectAddr) + 1)	= (WORD) ( ((DWORD)(W_CodeAddr))>>16 )

#define GET_VECTOR(W_VectAddr)	\
	((DWORD)(*((WORD volatile* volatile)(W_VectAddr))) | \
	((DWORD)(*((WORD volatile* volatile)(W_VectAddr) + 1)) << 16))

⌨️ 快捷键说明

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