STM32中斷入口有兩個,分別是USB_HP_CAN1_TX_IRQHandler和USB_LP_CAN1_RX0_IRQHandler。
其中USB_Istr函數(shù)調(diào)用了CTR_LP函數(shù),代碼如下。
/*******************************************************************************
* Function Name : USB_HP_CAN1_TX_IRQHandler
* Description : This function handles USB High Priority or CAN TX interrupts
* requests.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void USB_HP_CAN1_TX_IRQHandler(void)
{
CTR_HP();
}
/*******************************************************************************
* Function Name : USB_LP_CAN1_RX0_IRQHandler
* Description : This function handles USB Low Priority or CAN RX0 interrupts
* requests.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void USB_LP_CAN1_RX0_IRQHandler(void)
{
USB_Istr();
}
2 CTR_LP
CTR_LP為低優(yōu)先級端點傳輸正常時的中斷服務函數(shù),控制傳輸只能在CTR_LP里面處理,代碼如下。
/*******************************************************************************
* Function Name : CTR_LP.
* Description : Low priority Endpoint Correct Transfer interrupt's service
* routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void CTR_LP(void)
{
uint32_t wEPVal = 0;
/* stay in loop while pending ints */
while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
{
_SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */
/* extract highest priority endpoint number */
EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
if (EPindex == 0)
{
/* Decode and service control endpoint interrupt */
/* calling related service routine */
/* (Setup0_Process, In0_Process, Out0_Process) */
/* save RX & TX status */
/* and set both to NAK */
SaveRState = _GetEPRxStatus(ENDP0);
SaveTState = _GetEPTxStatus(ENDP0);
_SetEPRxStatus(ENDP0, EP_RX_NAK);
_SetEPTxStatus(ENDP0, EP_TX_NAK);
/* DIR bit = origin of the interrupt */
if ((wIstr & ISTR_DIR) == 0)
{
/* DIR = 0 */
/* DIR = 0 = > IN int */
/* DIR = 0 implies that (EP_CTR_TX = 1) always */
_ClearEP_CTR_TX(ENDP0);
In0_Process();
/* before terminate set Tx & Rx status */
_SetEPRxStatus(ENDP0, SaveRState);
_SetEPTxStatus(ENDP0, SaveTState);
return;
}
else
{
/* DIR = 1 */
/* DIR = 1 & CTR_RX = > SETUP or OUT int */
/* DIR = 1 & (CTR_TX | CTR_RX) = > 2 int pending */
wEPVal = _GetENDPOINT(ENDP0);
if ((wEPVal & EP_CTR_TX) != 0)
{
_ClearEP_CTR_TX(ENDP0);
In0_Process();
/* before terminate set Tx & Rx status */
_SetEPRxStatus(ENDP0, SaveRState);
_SetEPTxStatus(ENDP0, SaveTState);
return;
}
else if ((wEPVal &EP_SETUP) != 0)
{
_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
Setup0_Process();
/* before terminate set Tx & Rx status */
_SetEPRxStatus(ENDP0, SaveRState);
_SetEPTxStatus(ENDP0, SaveTState);
return;
}
else if ((wEPVal & EP_CTR_RX) != 0)
{
_ClearEP_CTR_RX(ENDP0);
Out0_Process();
/* before terminate set Tx & Rx status */
_SetEPRxStatus(ENDP0, SaveRState);
_SetEPTxStatus(ENDP0, SaveTState);
return;
}
}
}/* if(EPindex == 0) */
else
{
/* Decode and service non control endpoints interrupt */
/* process related endpoint register */
wEPVal = _GetENDPOINT(EPindex);
if ((wEPVal & EP_CTR_RX) != 0)
{
/* clear int flag */
_ClearEP_CTR_RX(EPindex);
/* call OUT service function */
(*pEpInt_OUT[EPindex-1])();
} /* if((wEPVal & EP_CTR_RX) */
if ((wEPVal & EP_CTR_TX) != 0)
{
/* clear int flag */
_ClearEP_CTR_TX(EPindex);
/* call IN service function */
(*pEpInt_IN[EPindex-1])();
} /* if((wEPVal & EP_CTR_TX) != 0) */
}/* if(EPindex == 0) else */
}/* while(...) */
}
3 CTR_HP
CTR_HP為高優(yōu)先級端點傳輸正常時的中斷服務函數(shù),代碼如下。
/*******************************************************************************
* Function Name : CTR_HP.
* Description : High Priority Endpoint Correct Transfer interrupt's service
* routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void CTR_HP(void)
{
uint32_t wEPVal = 0;
while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
{
_SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */
/* extract highest priority endpoint number */
EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
/* process related endpoint register */
wEPVal = _GetENDPOINT(EPindex);
if ((wEPVal & EP_CTR_RX) != 0)
{
/* clear int flag */
_ClearEP_CTR_RX(EPindex);
/* call OUT service function */
(*pEpInt_OUT[EPindex-1])();
} /* if((wEPVal & EP_CTR_RX) */
else if ((wEPVal & EP_CTR_TX) != 0)
{
/* clear int flag */
_ClearEP_CTR_TX(EPindex);
/* call IN service function */
(*pEpInt_IN[EPindex-1])();
} /* if((wEPVal & EP_CTR_TX) != 0) */
}/* while(...) */
}
4 CTR_LP和CTR_HP各自處理的事務類型
這兩個函數(shù)定義在usb_int.c中,用法如下。
CTR_LP(低優(yōu)先級中斷Low-priority interrupt),用于控制傳輸、中斷傳輸、批量傳輸( 單緩沖模式)。
CTR_HP(高優(yōu)先級中斷 High-priority interrupt),用于快速大數(shù)據(jù)量傳輸處理,比如同步傳輸、批量傳輸,但是都是處理雙緩沖模式。
5 核心注意要點
如果把只初始化了USB_LP_CAN1_RX0_IRQn中斷向量,則所有的正確傳輸中斷只會進入USB_LP_CAN1_RX0_IRQHandler->CTR_LP,所以要想進入CTR_HP必須對其中斷向量進行初始化,否則會使用默認的CTR_LP路徑進行處理。
-
usb
+關注
關注
60文章
7872瀏覽量
263657 -
STM32
+關注
關注
2264文章
10854瀏覽量
354228 -
中斷
+關注
關注
5文章
895瀏覽量
41343 -
stm32f1
+關注
關注
1文章
56瀏覽量
12159
發(fā)布評論請先 登錄
相關推薦
評論