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 ------------------------------------------------------------------*/
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) =
58 void (*pEpInt_OUT
[7])(void) =
69 /*******************************************************************************
70 * Function Name : USB_Istr
71 * Description : ISTR events interrupt service routine
75 *******************************************************************************/
80 #if (IMR_MSK & ISTR_SOF)
81 if (wIstr
& ISTR_SOF
& wInterrupt_Mask
) {
82 _SetISTR((uint16_t)CLR_SOF
);
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 */
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
112 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
113 #if (IMR_MSK & ISTR_DOVR)
114 if (wIstr
& ISTR_DOVR
& wInterrupt_Mask
)
116 _SetISTR((uint16_t)CLR_DOVR
);
122 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
123 #if (IMR_MSK & ISTR_ERR)
124 if (wIstr
& ISTR_ERR
& wInterrupt_Mask
) {
125 _SetISTR((uint16_t)CLR_ERR
);
131 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
132 #if (IMR_MSK & ISTR_WKUP)
133 if (wIstr
& ISTR_WKUP
& wInterrupt_Mask
) {
134 _SetISTR((uint16_t)CLR_WKUP
);
135 Resume(RESUME_EXTERNAL
);
141 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
142 #if (IMR_MSK & ISTR_SUSP)
143 if (wIstr
& ISTR_SUSP
& wInterrupt_Mask
)
146 /* check if SUSPEND is possible */
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
);
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 */
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 */
184 /*Store endpoints registers status */
185 for (i
=0;i
<8;i
++) EP
[i
] = _GetENDPOINT(i
);
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
);
202 _SetENDPOINT(i
, EP
[i
]);
212 /* resume handling timing is made with ESOFs */
213 Resume(RESUME_ESOF
); /* request without change of the machine state */
222 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/