在USB鼠标实验中有2个中断函数:
[mw_shl_code=c,true]void USB_LP_CAN_RX0_IRQHandler(void)
{
USB_Istr();
}
void USBWakeUp_IRQHandler(void)
{
EXTI->  R|=1<<18;//清除USB唤醒中断挂起位
#ifdef DEBUG
printf("USB待机唤醒中断请求\n");
#endif
}[/mw_shl_code]
USBWakeUp_IRQHandler连接到EXTI线18,由USB唤醒事件触发。
但是USB_Istr中也有判断ISTR_WKUP标志的代码,ISTR_WKUP标志也是由USB唤醒事件触发的么?这样USB唤醒岂不是会同时触发2个中断(USB_LP_CAN_RX0_IRQHandler和USBWakeUp_IRQHandler)?
另外USB唤醒事件是什么事件呢?是接收到主机发来的唤醒请求么?
USB_Istr也包含了对唤醒中断的处理:
[mw_shl_code=c,true]#if (IMR_MSK & ISTR_WKUP)
if (wIstr & ISTR_WKUP & wInterrupt_Mask)
{
_SetISTR((u16)CLR_WKUP);
#ifdef DEBUG
printf("ISTR唤醒中断\n");
#endif
Resume(RESUME_EXTERNAL);
#ifdef WKUP_CALLBACK
WKUP_Callback();
#endif
}
#endif
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#if (IMR_MSK & ISTR_SUSP)
if (wIstr & ISTR_SUSP & wInterrupt_Mask)
{
/* check if SUSPEND is possible */
if (fSuspendEnabled)
{
Suspend();
}
else
{
/* if not possible then resume after xx ms */
Resume(RESUME_LATER);
}
/* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
_SetISTR((u16)CLR_SUSP);
#ifdef DEBUG
printf("USB挂起中断\n");
#endif
#ifdef SUSP_CALLBACK
SUSP_Callback();
#endif[/mw_shl_code]
观察打印信息,确实看到触发USBWakeUp_IRQHandler之后同时也打印了Usb_Istr中的ISTR唤醒中断:
USB待机唤醒中断请求
USB待机唤醒中断请求
ISTR_唤醒
USB总线复位
USB总线挂起
USB待机唤醒中断请求
ISTR_唤醒
USB总线复位
端点 0 输出中断
端点 0 输出中断
端点 0 输出中断
|