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

📄 isr.c

📁 motorola自己开发的针对coldfire 5272的Dbug bootloader程序
💻 C
字号:
/*
 * File:		isr.c
 * Purpose:		Generic Interrupt Service Routine dispatcher.
 *
 * Notes:
 *
 * Author:		Eric DeVolder
 * Date:		
 *
 * Modifications:
 *
 */

#include "src/include/dbug.h"
#include "src/uif/uif.h"

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

#ifndef UIF_MAX_ISR_ENTRY
#define UIF_MAX_ISR_ENTRY	(20)
#endif

typedef struct
{
	int		vector;
	int		type;
	int		(*handler)(void *, void *);
	void	*hdev;
	void	*harg;
} ISRENTRY;

ISRENTRY
isrtab[UIF_MAX_ISR_ENTRY];

/********************************************************************/
void
isr_init (void)
{
	int index;
	for (index = 0; index < UIF_MAX_ISR_ENTRY; index++)
	{
		isrtab[index].vector = 0;
		isrtab[index].type = 0;
		isrtab[index].handler = 0;
		isrtab[index].hdev = 0;
		isrtab[index].harg = 0;
	}
}

/********************************************************************/
int
isr_register_handler (
	int type, int vector, 
	int (*handler)(void *, void *), void *hdev, void *harg)
{
	/*
	 * This function places an interrupt handler in the ISR table,
	 * thereby registering it so that the low-level handler may call it.
	 *
	 * The two parameters to are intended for
	 * the first arg to be a pointer to the device itself, and the
	 * second a pointer to a data structure used by the device driver
	 * for that particular device.
	 */
	int index;

	if ((vector == 0) || 
		((type != ISR_DBUG_ISR) && (type != ISR_USER_ISR)) ||
		(handler == NULL))
	{
		return FALSE;
	}

	for (index = 0; index < UIF_MAX_ISR_ENTRY; index++)
	{
		if ((isrtab[index].vector == vector) &&
			(isrtab[index].type == type))
		{
			/* only one entry of each type per vector */
			return 0;
		}

		if (isrtab[index].vector == 0)
		{
			isrtab[index].vector = vector;
			isrtab[index].type = type;
			isrtab[index].handler = handler;
			isrtab[index].hdev = hdev;
			isrtab[index].harg = harg;
			return 1;
		}
	}
	return FALSE;	/* no available slots */
}

/********************************************************************/
void
isr_remove_handler (int type ,int (*handler)(void *, void *))
{
	/*
	 * This routine removes from the ISR table all
	 * entries that matches 'type' and 'handler'.
	 */
	int index;

	for (index = 0; index < UIF_MAX_ISR_ENTRY; index++)
	{
		if ((isrtab[index].handler == handler) && 
			(isrtab[index].type == type))
		{
			isrtab[index].vector = 0;
			isrtab[index].type = 0;
			isrtab[index].handler = 0;
			isrtab[index].hdev = 0;
			isrtab[index].harg = 0;
		}
	}
}

/********************************************************************/
int
isr_execute_handler (int vector)
{
	/*
	 * This routine searches the ISR table for an entry that matches
	 * 'vector'.  If one is found, then 'handler' is executed.
	 */
	int index, retval = FALSE;

	/*
	 * First locate a dBUG Interrupt Service Routine handler.
	 */
	for (index = 0; index < UIF_MAX_ISR_ENTRY; index++)
	{
		if ((isrtab[index].vector == vector) &&
			(isrtab[index].type == ISR_DBUG_ISR))
		{
			if (isrtab[index].handler(isrtab[index].hdev,isrtab[index].harg))
			{
				retval = TRUE;
				break;
			}
		}
	}

	/*
	 * Try to locate a user-registered Interrupt Service Routine handler.
	 */
	for (index = 0; index < UIF_MAX_ISR_ENTRY; index++)
	{
		if ((isrtab[index].vector == vector) &&
			(isrtab[index].type == ISR_USER_ISR))
		{
			if (isrtab[index].handler(isrtab[index].hdev,isrtab[index].harg))
			{
				retval = TRUE;
				break;
			}
		}
	}

	return retval;
}

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

⌨️ 快捷键说明

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