Merge pull request #10546 from iNavFlight/delta-formatting
[inav.git] / src / main / vcp / usb_istr.c
blob74a1a56c57cfa894bb15c0ece939a7536558386a
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 ------------------------------------------------------------------*/
29 #include "usb_lib.h"
30 #include "usb_prop.h"
31 #include "usb_pwr.h"
32 #include "usb_istr.h"
34 /* Private typedef -----------------------------------------------------------*/
35 /* Private define ------------------------------------------------------------*/
36 /* Private macro -------------------------------------------------------------*/
37 /* Private variables ---------------------------------------------------------*/
38 __IO uint16_t wIstr; /* ISTR register last read value */
39 __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */
40 __IO uint32_t esof_counter = 0; /* expected SOF counter */
41 __IO uint32_t wCNTR = 0;
43 /* Extern variables ----------------------------------------------------------*/
44 /* Private function prototypes -----------------------------------------------*/
45 /* Private functions ---------------------------------------------------------*/
46 /* function pointers to non-control endpoints service routines */
47 void (*pEpInt_IN[7])(void) =
49 EP1_IN_Callback,
50 EP2_IN_Callback,
51 EP3_IN_Callback,
52 EP4_IN_Callback,
53 EP5_IN_Callback,
54 EP6_IN_Callback,
55 EP7_IN_Callback,
58 void (*pEpInt_OUT[7])(void) =
60 EP1_OUT_Callback,
61 EP2_OUT_Callback,
62 EP3_OUT_Callback,
63 EP4_OUT_Callback,
64 EP5_OUT_Callback,
65 EP6_OUT_Callback,
66 EP7_OUT_Callback,
69 /*******************************************************************************
70 * Function Name : USB_Istr
71 * Description : ISTR events interrupt service routine
72 * Input :
73 * Output :
74 * Return :
75 *******************************************************************************/
76 void USB_Istr(void)
78 wIstr = _GetISTR();
80 #if (IMR_MSK & ISTR_SOF)
81 if (wIstr & ISTR_SOF & wInterrupt_Mask) {
82 _SetISTR((uint16_t)CLR_SOF);
83 bIntPackSOF++;
85 #ifdef SOF_CALLBACK
86 SOF_Callback();
87 #endif
89 #endif
90 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
92 #if (IMR_MSK & ISTR_CTR)
93 if (wIstr & ISTR_CTR & wInterrupt_Mask) {
94 /* servicing of the endpoint correct transfer interrupt */
95 /* clear of the CTR flag into the sub */
96 CTR_LP();
97 #ifdef CTR_CALLBACK
98 CTR_Callback();
99 #endif
101 #endif
102 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
103 #if (IMR_MSK & ISTR_RESET)
104 if (wIstr & ISTR_RESET & wInterrupt_Mask) {
105 _SetISTR((uint16_t)CLR_RESET);
106 Device_Property.Reset();
107 #ifdef RESET_CALLBACK
108 RESET_Callback();
109 #endif
111 #endif
112 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
113 #if (IMR_MSK & ISTR_DOVR)
114 if (wIstr & ISTR_DOVR & wInterrupt_Mask)
116 _SetISTR((uint16_t)CLR_DOVR);
117 #ifdef DOVR_CALLBACK
118 DOVR_Callback();
119 #endif
121 #endif
122 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
123 #if (IMR_MSK & ISTR_ERR)
124 if (wIstr & ISTR_ERR & wInterrupt_Mask) {
125 _SetISTR((uint16_t)CLR_ERR);
126 #ifdef ERR_CALLBACK
127 ERR_Callback();
128 #endif
130 #endif
131 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
132 #if (IMR_MSK & ISTR_WKUP)
133 if (wIstr & ISTR_WKUP & wInterrupt_Mask) {
134 _SetISTR((uint16_t)CLR_WKUP);
135 Resume(RESUME_EXTERNAL);
136 #ifdef WKUP_CALLBACK
137 WKUP_Callback();
138 #endif
140 #endif
141 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
142 #if (IMR_MSK & ISTR_SUSP)
143 if (wIstr & ISTR_SUSP & wInterrupt_Mask)
146 /* check if SUSPEND is possible */
147 if (fSuspendEnabled)
149 Suspend();
151 else
153 /* if not possible then resume after xx ms */
154 Resume(RESUME_LATER);
156 /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
157 _SetISTR((uint16_t)CLR_SUSP);
158 #ifdef SUSP_CALLBACK
159 SUSP_Callback();
160 #endif
162 #endif
163 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
165 #if (IMR_MSK & ISTR_ESOF)
166 if (wIstr & ISTR_ESOF & wInterrupt_Mask)
168 /* clear ESOF flag in ISTR */
169 _SetISTR((uint16_t)CLR_ESOF);
171 if ((_GetFNR()&FNR_RXDP)!=0)
173 /* increment ESOF counter */
174 esof_counter ++;
176 /* test if we enter in ESOF more than 3 times with FSUSP =0 and RXDP =1=>> possible missing SUSP flag*/
177 if ((esof_counter >3)&&((_GetCNTR()&CNTR_FSUSP)==0))
179 /* this a sequence to apply a force RESET*/
181 /*Store CNTR value */
182 wCNTR = _GetCNTR();
184 /*Store endpoints registers status */
185 for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i);
187 /*apply FRES */
188 wCNTR|=CNTR_FRES;
189 _SetCNTR(wCNTR);
191 /*clear FRES*/
192 wCNTR&=~CNTR_FRES;
193 _SetCNTR(wCNTR);
195 /*poll for RESET flag in ISTR*/
196 while ((_GetISTR()&ISTR_RESET) == 0);
197 /* clear RESET flag in ISTR */
198 _SetISTR((uint16_t)CLR_RESET);
200 /*restore Enpoints*/
201 for (i=0;i<8;i++)
202 _SetENDPOINT(i, EP[i]);
204 esof_counter = 0;
207 else
209 esof_counter = 0;
212 /* resume handling timing is made with ESOFs */
213 Resume(RESUME_ESOF); /* request without change of the machine state */
215 #ifdef ESOF_CALLBACK
216 ESOF_Callback();
217 #endif
219 #endif
220 } /* USB_Istr */
222 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/