Updated and Validated
[betaflight.git] / lib / main / STM32_USB-FS-Device_Driver / src / usb_int.c
blobdbaa33102d662d3d3d4b03fe2f2522f08b43b0bd
1 /**
2 ******************************************************************************
3 * @file usb_int.c
4 * @author MCD Application Team
5 * @version V4.0.0
6 * @date 28-August-2012
7 * @brief Endpoint CTR (Low and High) interrupt's service routines
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
17 * http://www.st.com/software_license_agreement_liberty_v2
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 ******************************************************************************
28 /* Includes ------------------------------------------------------------------*/
29 #include "usb_lib.h"
31 /* Private typedef -----------------------------------------------------------*/
32 /* Private define ------------------------------------------------------------*/
33 /* Private macro -------------------------------------------------------------*/
34 /* Private variables ---------------------------------------------------------*/
35 __IO uint16_t SaveRState;
36 __IO uint16_t SaveTState;
38 /* Extern variables ----------------------------------------------------------*/
39 extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */
40 extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */
42 /* Private function prototypes -----------------------------------------------*/
43 /* Private functions ---------------------------------------------------------*/
45 /*******************************************************************************
46 * Function Name : CTR_LP.
47 * Description : Low priority Endpoint Correct Transfer interrupt's service
48 * routine.
49 * Input : None.
50 * Output : None.
51 * Return : None.
52 *******************************************************************************/
53 void CTR_LP(void)
55 __IO uint16_t wEPVal = 0;
56 /* stay in loop while pending interrupts */
57 while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
59 /* extract highest priority endpoint number */
60 EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
61 if (EPindex == 0)
63 /* Decode and service control endpoint interrupt */
64 /* calling related service routine */
65 /* (Setup0_Process, In0_Process, Out0_Process) */
67 /* save RX & TX status */
68 /* and set both to NAK */
70 SaveRState = _GetENDPOINT(ENDP0);
71 SaveTState = SaveRState & EPTX_STAT;
72 SaveRState &= EPRX_STAT;
74 _SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK);
76 /* DIR bit = origin of the interrupt */
78 if ((wIstr & ISTR_DIR) == 0)
80 /* DIR = 0 */
82 /* DIR = 0 => IN int */
83 /* DIR = 0 implies that (EP_CTR_TX = 1) always */
85 _ClearEP_CTR_TX(ENDP0);
86 In0_Process();
88 /* before terminate set Tx & Rx status */
90 _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
91 return;
93 else
95 /* DIR = 1 */
97 /* DIR = 1 & CTR_RX => SETUP or OUT int */
98 /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
100 wEPVal = _GetENDPOINT(ENDP0);
102 if ((wEPVal &EP_SETUP) != 0)
104 _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
105 Setup0_Process();
106 /* before terminate set Tx & Rx status */
108 _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
109 return;
112 else if ((wEPVal & EP_CTR_RX) != 0)
114 _ClearEP_CTR_RX(ENDP0);
115 Out0_Process();
116 /* before terminate set Tx & Rx status */
118 _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
119 return;
122 }/* if(EPindex == 0) */
123 else
125 /* Decode and service non control endpoints interrupt */
127 /* process related endpoint register */
128 wEPVal = _GetENDPOINT(EPindex);
129 if ((wEPVal & EP_CTR_RX) != 0)
131 /* clear int flag */
132 _ClearEP_CTR_RX(EPindex);
134 /* call OUT service function */
135 (*pEpInt_OUT[EPindex-1])();
137 } /* if((wEPVal & EP_CTR_RX) */
139 if ((wEPVal & EP_CTR_TX) != 0)
141 /* clear int flag */
142 _ClearEP_CTR_TX(EPindex);
144 /* call IN service function */
145 (*pEpInt_IN[EPindex-1])();
146 } /* if((wEPVal & EP_CTR_TX) != 0) */
148 }/* if(EPindex == 0) else */
150 }/* while(...) */
153 /*******************************************************************************
154 * Function Name : CTR_HP.
155 * Description : High Priority Endpoint Correct Transfer interrupt's service
156 * routine.
157 * Input : None.
158 * Output : None.
159 * Return : None.
160 *******************************************************************************/
161 void CTR_HP(void)
163 uint32_t wEPVal = 0;
165 while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
167 _SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */
168 /* extract highest priority endpoint number */
169 EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
170 /* process related endpoint register */
171 wEPVal = _GetENDPOINT(EPindex);
172 if ((wEPVal & EP_CTR_RX) != 0)
174 /* clear int flag */
175 _ClearEP_CTR_RX(EPindex);
177 /* call OUT service function */
178 (*pEpInt_OUT[EPindex-1])();
180 } /* if((wEPVal & EP_CTR_RX) */
181 else if ((wEPVal & EP_CTR_TX) != 0)
183 /* clear int flag */
184 _ClearEP_CTR_TX(EPindex);
186 /* call IN service function */
187 (*pEpInt_IN[EPindex-1])();
190 } /* if((wEPVal & EP_CTR_TX) != 0) */
192 }/* while(...) */
195 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/