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

被折叠的 条评论
为什么被折叠?



