1 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
2 * File Name : usb_int.c
3 * Author : MCD Application Team
6 * Description : Endpoint CTR (Low and High) interrupt's service routines
7 ********************************************************************************
8 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
9 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
10 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
11 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
12 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
13 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
14 *******************************************************************************/
17 /* Includes ------------------------------------------------------------------*/
20 /* Private typedef -----------------------------------------------------------*/
21 /* Private define ------------------------------------------------------------*/
22 /* Private macro -------------------------------------------------------------*/
23 /* Private variables ---------------------------------------------------------*/
24 __IO
uint16_t SaveRState
;
25 __IO
uint16_t SaveTState
;
27 /* Extern variables ----------------------------------------------------------*/
28 extern void (*pEpInt_IN
[7])(void); /* Handles IN interrupts */
29 extern void (*pEpInt_OUT
[7])(void); /* Handles OUT interrupts */
31 /* Private function prototypes -----------------------------------------------*/
32 /* Private functions ---------------------------------------------------------*/
34 /*******************************************************************************
35 * Function Name : CTR_LP.
36 * Description : Low priority Endpoint Correct Transfer interrupt's service
41 *******************************************************************************/
44 __IO
uint16_t wEPVal
= 0;
45 /* stay in loop while pending ints */
46 while (((wIstr
= _GetISTR()) & ISTR_CTR
) != 0)
48 /* extract highest priority endpoint number */
49 EPindex
= (uint8_t)(wIstr
& ISTR_EP_ID
);
52 /* Decode and service control endpoint interrupt */
53 /* calling related service routine */
54 /* (Setup0_Process, In0_Process, Out0_Process) */
56 /* save RX & TX status */
57 /* and set both to NAK */
60 SaveRState
= _GetENDPOINT(ENDP0
);
61 SaveTState
= SaveRState
& EPTX_STAT
;
62 SaveRState
&= EPRX_STAT
;
64 _SetEPRxTxStatus(ENDP0
,EP_RX_NAK
,EP_TX_NAK
);
66 /* DIR bit = origin of the interrupt */
68 if ((wIstr
& ISTR_DIR
) == 0)
72 /* DIR = 0 => IN int */
73 /* DIR = 0 implies that (EP_CTR_TX = 1) always */
76 _ClearEP_CTR_TX(ENDP0
);
79 /* before terminate set Tx & Rx status */
81 _SetEPRxTxStatus(ENDP0
,SaveRState
,SaveTState
);
88 /* DIR = 1 & CTR_RX => SETUP or OUT int */
89 /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
91 wEPVal
= _GetENDPOINT(ENDP0
);
93 if ((wEPVal
&EP_SETUP
) != 0)
95 _ClearEP_CTR_RX(ENDP0
); /* SETUP bit kept frozen while CTR_RX = 1 */
97 /* before terminate set Tx & Rx status */
99 _SetEPRxTxStatus(ENDP0
,SaveRState
,SaveTState
);
103 else if ((wEPVal
& EP_CTR_RX
) != 0)
105 _ClearEP_CTR_RX(ENDP0
);
107 /* before terminate set Tx & Rx status */
109 _SetEPRxTxStatus(ENDP0
,SaveRState
,SaveTState
);
113 }/* if(EPindex == 0) */
116 /* Decode and service non control endpoints interrupt */
118 /* process related endpoint register */
119 wEPVal
= _GetENDPOINT(EPindex
);
120 if ((wEPVal
& EP_CTR_RX
) != 0)
123 _ClearEP_CTR_RX(EPindex
);
125 /* call OUT service function */
126 (*pEpInt_OUT
[EPindex
-1])();
128 } /* if((wEPVal & EP_CTR_RX) */
130 if ((wEPVal
& EP_CTR_TX
) != 0)
133 _ClearEP_CTR_TX(EPindex
);
135 /* call IN service function */
136 (*pEpInt_IN
[EPindex
-1])();
137 } /* if((wEPVal & EP_CTR_TX) != 0) */
139 }/* if(EPindex == 0) else */
144 /*******************************************************************************
145 * Function Name : CTR_HP.
146 * Description : High Priority Endpoint Correct Transfer interrupt's service
151 *******************************************************************************/
156 while (((wIstr
= _GetISTR()) & ISTR_CTR
) != 0)
158 _SetISTR((uint16_t)CLR_CTR
); /* clear CTR flag */
159 /* extract highest priority endpoint number */
160 EPindex
= (uint8_t)(wIstr
& ISTR_EP_ID
);
161 /* process related endpoint register */
162 wEPVal
= _GetENDPOINT(EPindex
);
163 if ((wEPVal
& EP_CTR_RX
) != 0)
166 _ClearEP_CTR_RX(EPindex
);
168 /* call OUT service function */
169 (*pEpInt_OUT
[EPindex
-1])();
171 } /* if((wEPVal & EP_CTR_RX) */
172 else if ((wEPVal
& EP_CTR_TX
) != 0)
175 _ClearEP_CTR_TX(EPindex
);
177 /* call IN service function */
178 (*pEpInt_IN
[EPindex
-1])();
181 } /* if((wEPVal & EP_CTR_TX) != 0) */
186 #endif /* STM32F10X_CL */
188 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/