外部触发一个GPIO中断,在这个IO中断函数中调用了一个I2C写函数,但是这个I2C写函数是使用中断方式进行的,结果实现不了。
不用操作系统,请问 C6748可以进行可屏蔽中断之间的嵌套吗? 如果可以的话,怎么实现?如果不可以,请问有没有I2C查询方式的写函数?
Tong xie:
这个问题没找到解决办法?求解答
Denny%20Yang99373:
可以进行中断嵌套的
需要在中断处理函数里把系统的总中断再打开。
Tong xie:
被这个问题困扰了一段时间了?
谁知道有什么解决办法
Tong xie:
回复 Denny%20Yang99373:
我在IO中断函数里调用stareware 库里的 IntGlobalEnable();// 使能 DSP 全局中断
来打开总中断,IIC每写一个字节都需要进一次中断的。
这样只用一次IntGlobalEnable() 可以吗? 另外需要考虑优先级的问题吗?
Tong xie:
回复 Tong xie:
我试了下,嵌套的中断进不去,不知道是哪里的配置会出问题??
Denny%20Yang99373:
回复 Tong xie:
一般来说中断处理函数进入之前会把全局中断关掉,需要你在中断处理函数里显示的打开,才能重入。
需要测试一下,单独的能否分别进入中断?
在这基础上,观察一下中断相关的寄存器,全局的中断寄存器和I2C相关的中断寄存器,和单独的情况对比一下
Tong xie:
回复 Denny%20Yang99373:
我单步调试了下,确实会在中断处理函数进入之前会把全局中断关掉。单独的都可以正确执行中断处理函数。我已经在IO中断处理中我已经将全局中断又打开了,全局中断标志使能位已经置1了,我观察了一下I2C相关的寄存器和单独的情况一样,就是进不去I2C的中断处理函数。
可能是我没搞明白,怎样算显示的打开?有没有可屏蔽中断嵌套的例程可以参考一下?
实在搞不清楚自己哪里错了
Denny%20Yang99373:
回复 Tong xie:
如果全局中断打开了,应该是可以进去的。
你可以简化一下,看看两个GPIO中断能不能重入?
Tony Tang:
参考文档sprufe8b。(嵌套中断实现还是有点麻烦的,最好权衡一下是改一下程序结构,还是要实现中断嵌套)
5.6.2 Nested InterruptsGenerally, when the CPU enters an interrupt service routine, interrupts are disabled. However, when theinterrupt service routine is for one of the maskable interrupts (INT4-INT15), an NMI can interruptprocessing of the maskable interrupt. In other words, an NMI can interrupt a maskable interrupt, butneither an NMI nor a maskable interrupt can interrupt an NMI.Also, there may be times when you want to allow an interrupt service routine to be interrupted by another(particularly higher priority) interrupt. Even though the processor by default does not allow interrupt serviceroutines to be interrupted unless the source is an NMI, it is possible to nest interrupts under softwarecontrol. To allow nested interrupts, the interrupt service routine must perform the following initial steps inaddition to its normal work of saving any registers (including control registers) that it modifies:1. The contents of IRP (or NRP) must be saved2. The contents of the PGIE bit must be saved3. The contents of ITSR must be saved4. The GIE bit must be set to 1
Prior to returning from the interrupt service routine, the code must restore the registers saved above asfollows:1. The GIE bit must be first cleared to 02. The PGIE bit saved value must be restored3. The contents of ITSR must be restored4. The IRP (or NRP) saved value must be restoredAlthough steps 2, 3, and 4 above may be performed in any order, it is important that the GIE bit is clearedfirst. This means that the GIE and PGIE bits must be restored with separate writes to CSR. If these bitsare not restored separately, then it is possible that the PGIE bit is overwritten by nested interruptprocessing just as interrupts are being disabled.NOTE: When coding nested interrupts for the CPU, the ITSR should be saved and restored toprevent corruption by the nested interrupt.
Victorsunhao:
回复 Tony Tang:
您好,如果我不是明确知道会在什么地方打断,我该怎么样进行Prior to 这4个步骤的操作呢?