Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
2 | * File Name : usb_int.c |
||
3 | * Author : MCD Application Team |
||
4 | * Date First Issued : 10/27/2003 : V1.0 |
||
5 | * Description : Endpoint CTR (Low and High) interrupt's service routines |
||
6 | ******************************************************************************** |
||
7 | * History: |
||
8 | * 09/18/2006 : V3.0 |
||
9 | * 09/01/2006 : V2.0 |
||
10 | * 10/27/2003 : V1.0 |
||
11 | ******************************************************************************** |
||
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
||
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
||
14 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
||
15 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
||
16 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
||
17 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
18 | *******************************************************************************/ |
||
19 | |||
20 | /* Includes ------------------------------------------------------------------*/ |
||
21 | #include "usb_lib.h" |
||
22 | /* Private typedef -----------------------------------------------------------*/ |
||
23 | /* Private define ------------------------------------------------------------*/ |
||
24 | /* Private macro -------------------------------------------------------------*/ |
||
25 | /* Private variables ---------------------------------------------------------*/ |
||
26 | u16 SaveRState; |
||
27 | u16 SaveTState; |
||
28 | /* Extern variables ----------------------------------------------------------*/ |
||
29 | extern void (*pEpInt_IN[15])(void); /* Handles IN interrupts */ |
||
30 | extern void (*pEpInt_OUT[15])(void); /* Handles OUT interrupts */ |
||
31 | /* Private function prototypes -----------------------------------------------*/ |
||
32 | /* Private functions ---------------------------------------------------------*/ |
||
33 | /******************************************************************************* |
||
34 | * Function Name : CTR_LP |
||
35 | * Description : Low Endpoint Correct Transfer interrupt's service routine |
||
36 | * Input : None |
||
37 | * Output : None |
||
38 | * Return : None |
||
39 | *******************************************************************************/ |
||
40 | void CTR_LP(void) |
||
41 | { |
||
42 | u32 wEPVal; |
||
43 | /* stay in loop while pending ints */ |
||
44 | while(((wIstr = _GetISTR()) & ISTR_CTR)!= 0) |
||
45 | { |
||
46 | _SetISTR((u16)CLR_CTR); /* clear CTR flag */ |
||
47 | /* extract highest priority endpoint number */ |
||
48 | EPindex = (u8)(wIstr & ISTR_EP_ID); |
||
49 | if(EPindex == 0) |
||
50 | { |
||
51 | /* Decode and service control endpoint interrupt */ |
||
52 | /* calling related service routine */ |
||
53 | /* (Setup0_Process, In0_Process, Out0_Process) */ |
||
54 | |||
55 | /* save RX & TX status */ |
||
56 | /* and set both to NAK */ |
||
57 | SaveRState = _GetEPRxStatus(ENDP0); |
||
58 | SaveTState = _GetEPTxStatus(ENDP0); |
||
59 | _SetEPRxStatus(ENDP0, EP_RX_NAK); |
||
60 | _SetEPTxStatus(ENDP0, EP_TX_NAK); |
||
61 | |||
62 | |||
63 | /* DIR bit = origin of the interrupt */ |
||
64 | |||
65 | if((wIstr & ISTR_DIR) == 0) |
||
66 | {/* DIR = 0 */ |
||
67 | |||
68 | /* DIR = 0 => IN int */ |
||
69 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ |
||
70 | |||
71 | |||
72 | _ClearEP_CTR_TX(ENDP0); |
||
73 | In0_Process(); |
||
74 | |||
75 | /* check if SETUP arrived during IN processing */ |
||
76 | wEPVal = _GetENDPOINT(ENDP0); |
||
77 | if((wEPVal & (EP_CTR_RX|EP_SETUP)) != 0) |
||
78 | { |
||
79 | _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */ |
||
80 | Setup0_Process(); |
||
81 | } |
||
82 | |||
83 | }/* DIR = 0 */ |
||
84 | else |
||
85 | {/* DIR = 1 */ |
||
86 | |||
87 | |||
88 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ |
||
89 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ |
||
90 | |||
91 | wEPVal = _GetENDPOINT(ENDP0); |
||
92 | if((wEPVal & EP_CTR_TX) != 0) |
||
93 | { |
||
94 | _ClearEP_CTR_TX(ENDP0); |
||
95 | In0_Process(); |
||
96 | } |
||
97 | if((wEPVal &EP_SETUP) != 0) |
||
98 | { |
||
99 | _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */ |
||
100 | Setup0_Process(); |
||
101 | } |
||
102 | |||
103 | else if((wEPVal & EP_CTR_RX) != 0) |
||
104 | { |
||
105 | _ClearEP_CTR_RX(ENDP0); |
||
106 | Out0_Process(); |
||
107 | } |
||
108 | |||
109 | }/* DIR = 1 */ |
||
110 | |||
111 | /* before terminate set Tx & Rx status */ |
||
112 | _SetEPRxStatus(ENDP0, SaveRState); |
||
113 | _SetEPTxStatus(ENDP0, SaveTState); |
||
114 | }/* if(EPindex == 0) */ |
||
115 | else |
||
116 | { /* Decode and service non control endpoints interrupt */ |
||
117 | |||
118 | /* process related endpoint register */ |
||
119 | wEPVal = _GetENDPOINT(EPindex); |
||
120 | if((wEPVal & EP_CTR_RX) != 0) |
||
121 | { |
||
122 | /* clear int flag */ |
||
123 | _ClearEP_CTR_RX(EPindex); |
||
124 | |||
125 | /* call OUT service function */ |
||
126 | (*pEpInt_OUT[EPindex-1])(); |
||
127 | |||
128 | } /* if((wEPVal & EP_CTR_RX) */ |
||
129 | if((wEPVal & EP_CTR_TX) != 0) |
||
130 | { |
||
131 | /* clear int flag */ |
||
132 | _ClearEP_CTR_TX(EPindex); |
||
133 | |||
134 | /* call IN service function */ |
||
135 | (*pEpInt_IN[EPindex-1])(); |
||
136 | |||
137 | |||
138 | } /* if((wEPVal & EP_CTR_TX) != 0) */ |
||
139 | |||
140 | |||
141 | }/* if(EPindex == 0) else */ |
||
142 | |||
143 | }/* while(...) */ |
||
144 | } /* CTR_LP */ |
||
145 | |||
146 | |||
147 | /******************************************************************************* |
||
148 | * Function Name : CTR_HP |
||
149 | * Description : High Endpoint Correct Transfer interrupt's service routine |
||
150 | * Input : None |
||
151 | * Output : None |
||
152 | * Return : None |
||
153 | *******************************************************************************/ |
||
154 | void CTR_HP(void) |
||
155 | { |
||
156 | u32 wEPVal; |
||
157 | |||
158 | while(((wIstr = _GetISTR()) & ISTR_CTR)!= 0) |
||
159 | { |
||
160 | _SetISTR((u16)CLR_CTR); /* clear CTR flag */ |
||
161 | /* extract highest priority endpoint number */ |
||
162 | EPindex = (u8)(wIstr & ISTR_EP_ID); |
||
163 | /* process related endpoint register */ |
||
164 | wEPVal = _GetENDPOINT(EPindex); |
||
165 | if((wEPVal & EP_CTR_RX) != 0) |
||
166 | { |
||
167 | /* clear int flag */ |
||
168 | _ClearEP_CTR_RX(EPindex); |
||
169 | |||
170 | /* call OUT service function */ |
||
171 | (*pEpInt_OUT[EPindex-1])(); |
||
172 | |||
173 | } /* if((wEPVal & EP_CTR_RX) */ |
||
174 | if((wEPVal & EP_CTR_TX) != 0) |
||
175 | { |
||
176 | /* clear int flag */ |
||
177 | _ClearEP_CTR_TX(EPindex); |
||
178 | |||
179 | /* call IN service function */ |
||
180 | (*pEpInt_IN[EPindex-1])(); |
||
181 | |||
182 | |||
183 | } /* if((wEPVal & EP_CTR_TX) != 0) */ |
||
184 | |||
185 | }/* while(...) */ |
||
186 | } /* CTR_HP */ |
||
187 | |||
188 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
||
189 |