欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

XScuGic_Connect分析

发布时间:2024/10/14 编程问答 24 豆豆
生活随笔 收集整理的这篇文章主要介绍了 XScuGic_Connect分析 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

说明

最近在研究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; }

总结

以上是生活随笔为你收集整理的XScuGic_Connect分析的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。