Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / pios / stm32f10x / libraries / STM32_USB-FS-Device_Driver / src / usb_int.c
blobc60553b19e5b588ab812a95dfd2ed8e0fabdc5f0
1 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
2 * File Name : usb_int.c
3 * Author : MCD Application Team
4 * Version : V3.2.1
5 * Date : 07/05/2010
6 * Description : Endpoint CTR (Low and High) interrupt's service routines
7 ********************************************************************************
8 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
9 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
10 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
11 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
12 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
13 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
14 *******************************************************************************/
15 #ifndef STM32F10X_CL
17 /* Includes ------------------------------------------------------------------*/
18 #include "usb_lib.h"
20 /* Private typedef -----------------------------------------------------------*/
21 /* Private define ------------------------------------------------------------*/
22 /* Private macro -------------------------------------------------------------*/
23 /* Private variables ---------------------------------------------------------*/
24 __IO uint16_t SaveRState;
25 __IO uint16_t SaveTState;
27 /* Extern variables ----------------------------------------------------------*/
28 extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */
29 extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */
31 /* Private function prototypes -----------------------------------------------*/
32 /* Private functions ---------------------------------------------------------*/
34 /*******************************************************************************
35 * Function Name : CTR_LP.
36 * Description : Low priority Endpoint Correct Transfer interrupt's service
37 * routine.
38 * Input : None.
39 * Output : None.
40 * Return : None.
41 *******************************************************************************/
42 void CTR_LP(void)
44 __IO uint16_t wEPVal = 0;
45 /* stay in loop while pending ints */
46 while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
48 /* extract highest priority endpoint number */
49 EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
50 if (EPindex == 0)
52 /* Decode and service control endpoint interrupt */
53 /* calling related service routine */
54 /* (Setup0_Process, In0_Process, Out0_Process) */
56 /* save RX & TX status */
57 /* and set both to NAK */
60 SaveRState = _GetENDPOINT(ENDP0);
61 SaveTState = SaveRState & EPTX_STAT;
62 SaveRState &= EPRX_STAT;
64 _SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK);
66 /* DIR bit = origin of the interrupt */
68 if ((wIstr & ISTR_DIR) == 0)
70 /* DIR = 0 */
72 /* DIR = 0 => IN int */
73 /* DIR = 0 implies that (EP_CTR_TX = 1) always */
76 _ClearEP_CTR_TX(ENDP0);
77 In0_Process();
79 /* before terminate set Tx & Rx status */
81 _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
82 return;
84 else
86 /* DIR = 1 */
88 /* DIR = 1 & CTR_RX => SETUP or OUT int */
89 /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
91 wEPVal = _GetENDPOINT(ENDP0);
93 if ((wEPVal &EP_SETUP) != 0)
95 _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
96 Setup0_Process();
97 /* before terminate set Tx & Rx status */
99 _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
100 return;
103 else if ((wEPVal & EP_CTR_RX) != 0)
105 _ClearEP_CTR_RX(ENDP0);
106 Out0_Process();
107 /* before terminate set Tx & Rx status */
109 _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
110 return;
113 }/* if(EPindex == 0) */
114 else
116 /* Decode and service non control endpoints interrupt */
118 /* process related endpoint register */
119 wEPVal = _GetENDPOINT(EPindex);
120 if ((wEPVal & EP_CTR_RX) != 0)
122 /* clear int flag */
123 _ClearEP_CTR_RX(EPindex);
125 /* call OUT service function */
126 (*pEpInt_OUT[EPindex-1])();
128 } /* if((wEPVal & EP_CTR_RX) */
130 if ((wEPVal & EP_CTR_TX) != 0)
132 /* clear int flag */
133 _ClearEP_CTR_TX(EPindex);
135 /* call IN service function */
136 (*pEpInt_IN[EPindex-1])();
137 } /* if((wEPVal & EP_CTR_TX) != 0) */
139 }/* if(EPindex == 0) else */
141 }/* while(...) */
144 /*******************************************************************************
145 * Function Name : CTR_HP.
146 * Description : High Priority Endpoint Correct Transfer interrupt's service
147 * routine.
148 * Input : None.
149 * Output : None.
150 * Return : None.
151 *******************************************************************************/
152 void CTR_HP(void)
154 uint32_t wEPVal = 0;
156 while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
158 _SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */
159 /* extract highest priority endpoint number */
160 EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
161 /* process related endpoint register */
162 wEPVal = _GetENDPOINT(EPindex);
163 if ((wEPVal & EP_CTR_RX) != 0)
165 /* clear int flag */
166 _ClearEP_CTR_RX(EPindex);
168 /* call OUT service function */
169 (*pEpInt_OUT[EPindex-1])();
171 } /* if((wEPVal & EP_CTR_RX) */
172 else if ((wEPVal & EP_CTR_TX) != 0)
174 /* clear int flag */
175 _ClearEP_CTR_TX(EPindex);
177 /* call IN service function */
178 (*pEpInt_IN[EPindex-1])();
181 } /* if((wEPVal & EP_CTR_TX) != 0) */
183 }/* while(...) */
186 #endif /* STM32F10X_CL */
188 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/