Merge pull request #11678 from haslinghuis/update-msp-api-level
[betaflight.git] / src / main / vcp / usb_istr.c
bloba935a585fceac45d10b510603e71000b104ca1f9
1 /**
2 ******************************************************************************
3 * @file usb_istr.c
4 * @author MCD Application Team
5 * @version V4.0.0
6 * @date 21-January-2013
7 * @brief ISTR events interrupt service routines
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT 2013 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 ------------------------------------------------------------------*/
30 #include "platform.h"
32 #include "usb_lib.h"
33 #include "usb_prop.h"
34 #include "usb_pwr.h"
35 #include "usb_istr.h"
37 /* Private typedef -----------------------------------------------------------*/
38 /* Private define ------------------------------------------------------------*/
39 /* Private macro -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 __IO uint16_t wIstr; /* ISTR register last read value */
42 __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */
43 __IO uint32_t esof_counter = 0; /* expected SOF counter */
44 __IO uint32_t wCNTR = 0;
46 /* Extern variables ----------------------------------------------------------*/
47 /* Private function prototypes -----------------------------------------------*/
48 /* Private functions ---------------------------------------------------------*/
49 /* function pointers to non-control endpoints service routines */
50 void (*pEpInt_IN[7])(void) =
52 EP1_IN_Callback,
53 EP2_IN_Callback,
54 EP3_IN_Callback,
55 EP4_IN_Callback,
56 EP5_IN_Callback,
57 EP6_IN_Callback,
58 EP7_IN_Callback,
61 void (*pEpInt_OUT[7])(void) =
63 EP1_OUT_Callback,
64 EP2_OUT_Callback,
65 EP3_OUT_Callback,
66 EP4_OUT_Callback,
67 EP5_OUT_Callback,
68 EP6_OUT_Callback,
69 EP7_OUT_Callback,
72 /*******************************************************************************
73 * Function Name : USB_Istr
74 * Description : ISTR events interrupt service routine
75 * Input :
76 * Output :
77 * Return :
78 *******************************************************************************/
79 void USB_Istr(void)
81 wIstr = _GetISTR();
83 #if (IMR_MSK & ISTR_SOF)
84 if (wIstr & ISTR_SOF & wInterrupt_Mask) {
85 _SetISTR((uint16_t)CLR_SOF);
86 bIntPackSOF++;
88 #ifdef SOF_CALLBACK
89 SOF_Callback();
90 #endif
92 #endif
93 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
95 #if (IMR_MSK & ISTR_CTR)
96 if (wIstr & ISTR_CTR & wInterrupt_Mask) {
97 /* servicing of the endpoint correct transfer interrupt */
98 /* clear of the CTR flag into the sub */
99 CTR_LP();
100 #ifdef CTR_CALLBACK
101 CTR_Callback();
102 #endif
104 #endif
105 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
106 #if (IMR_MSK & ISTR_RESET)
107 if (wIstr & ISTR_RESET & wInterrupt_Mask) {
108 _SetISTR((uint16_t)CLR_RESET);
109 Device_Property.Reset();
110 #ifdef RESET_CALLBACK
111 RESET_Callback();
112 #endif
114 #endif
115 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
116 #if (IMR_MSK & ISTR_DOVR)
117 if (wIstr & ISTR_DOVR & wInterrupt_Mask)
119 _SetISTR((uint16_t)CLR_DOVR);
120 #ifdef DOVR_CALLBACK
121 DOVR_Callback();
122 #endif
124 #endif
125 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
126 #if (IMR_MSK & ISTR_ERR)
127 if (wIstr & ISTR_ERR & wInterrupt_Mask) {
128 _SetISTR((uint16_t)CLR_ERR);
129 #ifdef ERR_CALLBACK
130 ERR_Callback();
131 #endif
133 #endif
134 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
135 #if (IMR_MSK & ISTR_WKUP)
136 if (wIstr & ISTR_WKUP & wInterrupt_Mask) {
137 _SetISTR((uint16_t)CLR_WKUP);
138 Resume(RESUME_EXTERNAL);
139 #ifdef WKUP_CALLBACK
140 WKUP_Callback();
141 #endif
143 #endif
144 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
145 #if (IMR_MSK & ISTR_SUSP)
146 if (wIstr & ISTR_SUSP & wInterrupt_Mask)
149 /* check if SUSPEND is possible */
150 if (fSuspendEnabled)
152 Suspend();
154 else
156 /* if not possible then resume after xx ms */
157 Resume(RESUME_LATER);
159 /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
160 _SetISTR((uint16_t)CLR_SUSP);
161 #ifdef SUSP_CALLBACK
162 SUSP_Callback();
163 #endif
165 #endif
166 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
168 #if (IMR_MSK & ISTR_ESOF)
169 if (wIstr & ISTR_ESOF & wInterrupt_Mask)
171 /* clear ESOF flag in ISTR */
172 _SetISTR((uint16_t)CLR_ESOF);
174 if ((_GetFNR()&FNR_RXDP)!=0)
176 /* increment ESOF counter */
177 esof_counter ++;
179 /* test if we enter in ESOF more than 3 times with FSUSP =0 and RXDP =1=>> possible missing SUSP flag*/
180 if ((esof_counter >3)&&((_GetCNTR()&CNTR_FSUSP)==0))
182 /* this a sequence to apply a force RESET*/
184 /*Store CNTR value */
185 wCNTR = _GetCNTR();
187 /*Store endpoints registers status */
188 for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i);
190 /*apply FRES */
191 wCNTR|=CNTR_FRES;
192 _SetCNTR(wCNTR);
194 /*clear FRES*/
195 wCNTR&=~CNTR_FRES;
196 _SetCNTR(wCNTR);
198 /*poll for RESET flag in ISTR*/
199 while ((_GetISTR()&ISTR_RESET) == 0);
200 /* clear RESET flag in ISTR */
201 _SetISTR((uint16_t)CLR_RESET);
203 /*restore Enpoints*/
204 for (i=0;i<8;i++)
205 _SetENDPOINT(i, EP[i]);
207 esof_counter = 0;
210 else
212 esof_counter = 0;
215 /* resume handling timing is made with ESOFs */
216 Resume(RESUME_ESOF); /* request without change of the machine state */
218 #ifdef ESOF_CALLBACK
219 ESOF_Callback();
220 #endif
222 #endif
223 } /* USB_Istr */
225 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/