XScuGic_Connect分析

本文深入探讨了ZYNQ中断处理中Xilinx的XScuGic_Connect函数。该函数用于将中断源的中断ID与指定的中断处理函数连接,并设置回调参考。在分析中,强调了函数参数的作用,包括中断ID的范围检查、处理函数的指针验证以及中断表的更新。通过这个函数,开发者可以有效地管理中断处理流程。

说明

最近在研究ZYNQ中断的事情,感觉搞清楚Xilinx的一些官方函数或许有帮助吧。
一下是笔者对XScuGic_Connect的分析。


源代码

XScuGic_Connect函数代码如下,

/*****************************************************************************/
/**
*
* Makes the connection between the Int_Id of the interrupt source and the
* associated handler that is to run when the interrupt is recognized. The
* argument provided in this call as the Callbackref is used as the argument
* for the handler when it is called.
*
* @param	InstancePtr is a pointer to the XScuGic instance.
* @param	Int_Id contains the ID of the interrupt source and should be
*		in the range of 0 to XSCUGIC_MAX_NUM_INTR_INPUTS - 1
* @param	Handler to the handler for that interrupt.
* @param	CallBackRef is the callback reference, usually the instance
*		pointer of the connecting driver.
*
* @return
*
*		- XST_SUCCESS if the handler was connected correctly.
*
* @note
*
* WARNING: The handler provided as an argument will overwrite any handler
* that was previously connected.
*
****************************************************************************/
s32  XScuGic_Connect(XScuGic *InstancePtr, u32 Int_Id,
				Xil_InterruptHandler Handler, void *CallBackRef)
{
	/*
	 * Assert the arguments
	 */
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(Int_Id < XSCUGIC_MAX_NUM_INTR_INPUTS);
	Xil_AssertNonvoid(Handler != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);

	/*
	 * The Int_Id is used as an index into the table to select the proper
	 * handler
	 */
	InstancePtr->Config->HandlerTable[Int_Id].Handler = (Xil_InterruptHandler)Handler;
	InstancePtr->Config->HandlerTable[Int_Id].CallBackRef = CallBackRef;

	return XST_SUCCESS;
}


代码分析

结合XScuGic_Connect函数代码,分析如下,

/*****************************************************************************/
/**
*
* 该函数用于将识别中断的函数(handler)与中断源的中断ID(Int_Id)。
* 该函数中的Callbackref参数作为调用中断函数(handler)时的参数。
*
* @参数	InstancePtr 为XScuGic实例的指针。
* @参数	Int_Id包含中断源的ID,其取值应该在 0 到 XSCUGIC_MAX_NUM_INTR_INPUTS - 1
* @参数	中断的处理函数
* @参数	CallBackRef为回调参考,通常为所连接驱动的实例指针。
*
* @返回
*
*		- XST_SUCCESS 如果处理函数(handler)正确连接
*
* @说明
*
* 警告: 作为参数提供的处理函数handler,它将覆盖之前连接的所有处理函数handler。
*
****************************************************************************/
s32  XScuGic_Connect(XScuGic *InstancePtr, u32 Int_Id,
				Xil_InterruptHandler Handler, void *CallBackRef)
{
	/*
	 * 检查输入是否合法
	 */
	Xil_AssertNonvoid(InstancePtr != NULL);  //指针非空
	Xil_AssertNonvoid(Int_Id < XSCUGIC_MAX_NUM_INTR_INPUTS);  //中断ID取值合法
	Xil_AssertNonvoid(Handler != NULL);  //处理函数非空
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);  //指针就绪

	/*
	 * 参数Int_Id作为中断表的索引,用于选择相应的中断处理函数handler
	 */
	InstancePtr->Config->HandlerTable[Int_Id].Handler = (Xil_InterruptHandler)Handler;  //处理函数
	InstancePtr->Config->HandlerTable[Int_Id].CallBackRef = CallBackRef;  //回调参数

	return XST_SUCCESS;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值