2 ******************************************************************************
4 * @author MCD Application Team
6 * @date 21-January-2013
7 * @brief ISTR events interrupt service routines
8 ******************************************************************************
11 * <h2><center>© 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 ------------------------------------------------------------------*/
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) =
61 void (*pEpInt_OUT
[7])(void) =
72 /*******************************************************************************
73 * Function Name : USB_Istr
74 * Description : ISTR events interrupt service routine
78 *******************************************************************************/
83 #if (IMR_MSK & ISTR_SOF)
84 if (wIstr
& ISTR_SOF
& wInterrupt_Mask
) {
85 _SetISTR((uint16_t)CLR_SOF
);
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 */
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
115 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
116 #if (IMR_MSK & ISTR_DOVR)
117 if (wIstr
& ISTR_DOVR
& wInterrupt_Mask
)
119 _SetISTR((uint16_t)CLR_DOVR
);
125 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
126 #if (IMR_MSK & ISTR_ERR)
127 if (wIstr
& ISTR_ERR
& wInterrupt_Mask
) {
128 _SetISTR((uint16_t)CLR_ERR
);
134 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
135 #if (IMR_MSK & ISTR_WKUP)
136 if (wIstr
& ISTR_WKUP
& wInterrupt_Mask
) {
137 _SetISTR((uint16_t)CLR_WKUP
);
138 Resume(RESUME_EXTERNAL
);
144 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
145 #if (IMR_MSK & ISTR_SUSP)
146 if (wIstr
& ISTR_SUSP
& wInterrupt_Mask
)
149 /* check if SUSPEND is possible */
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
);
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 */
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 */
187 /*Store endpoints registers status */
188 for (i
=0;i
<8;i
++) EP
[i
] = _GetENDPOINT(i
);
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
);
205 _SetENDPOINT(i
, EP
[i
]);
215 /* resume handling timing is made with ESOFs */
216 Resume(RESUME_ESOF
); /* request without change of the machine state */
225 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/