📄 periph.lst
字号:
C51 COMPILER V6.10 PERIPH 06/30/2004 23:04:04 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE PERIPH
OBJECT MODULE PLACED IN .\PERIPH.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\PERIPH.C ROM(COMPACT) OPTIMIZE(6,SPEED) DEBUG OBJECTEXTEND
stmt level source
1 #pragma NOIV // Do not generate interrupt vectors
2 //-----------------------------------------------------------------------------
3 // File: periph.c
4 // Contents: Hooks required to implement USB peripheral function.
5 //
6 // Copyright (c) 1997 AnchorChips, Inc. All rights reserved
7 //-----------------------------------------------------------------------------
8 #include <ezusb.h>
9 #include <ezregs.h>
10
11 extern BOOL GotSUD; // Received setup data flag
12 extern BOOL Sleep;
13 extern BOOL Rwuen;
14 extern BOOL Selfpwr;
15
16 BYTE Configuration; // Current configuration
17 BYTE AlternateSetting; // Alternate settings
18 BYTE suspCount;
19 //-----------------------------------------------------------------------------
20 // Task Dispatcher hooks
21 // The following hooks are called by the task dispatcher.
22 //-----------------------------------------------------------------------------
23
24 void TD_Init(void) // Called once at startup
25 {
26 1 // Enable endpoints 0-7 IN and OUT
27 1 IN07VAL |= bmEP1 + bmEP2 + bmEP3 + bmEP4 + bmEP5 + bmEP6 + bmEP7;
28 1 OUT07VAL |= bmEP1 + bmEP2 + bmEP3 + bmEP4 + bmEP5 + bmEP6 + bmEP7;
29 1
30 1 // Enable interrupts for the OUT endpoints
31 1 OUT07IEN |= bmEP1 + bmEP2 + bmEP3 + bmEP4 + bmEP5 + bmEP6 + bmEP7;
32 1
33 1 suspCount = 1;
34 1
35 1 OEA = 0xFF;
36 1
37 1 Rwuen = TRUE; // Enable remote-wakeup
38 1 }
39
40 void TD_Poll(void) // Called repeatedly while the device is idle
41 {
42 1 }
43
44 BOOL TD_Suspend(void) // Called before the device goes into suspend mode
45 {
46 1 return(TRUE);
47 1 }
48
49 BOOL TD_Resume(void) // Called after the device resumes
50 {
51 1 return(TRUE);
52 1 }
53
54 //-----------------------------------------------------------------------------
55 // Device Request hooks
C51 COMPILER V6.10 PERIPH 06/30/2004 23:04:04 PAGE 2
56 // The following hooks are called by the end point 0 device request parser.
57 //-----------------------------------------------------------------------------
58
59 BOOL DR_GetDescriptor(void)
60 {
61 1 return(TRUE);
62 1 }
63
64 BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
65 {
66 1 Configuration = SETUPDAT[2];
67 1 return(TRUE); // Handled by user code
68 1 }
69
70 BOOL DR_GetConfiguration(void) // Called when a Get Configuration command is received
71 {
72 1 IN0BUF[0] = Configuration;
73 1 EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
74 1 return(TRUE); // Handled by user code
75 1 }
76
77 BOOL DR_SetInterface(void) // Called when a Set Interface command is received
78 {
79 1 AlternateSetting = SETUPDAT[2];
80 1 return(TRUE); // Handled by user code
81 1 }
82
83 BOOL DR_GetInterface(void) // Called when a Set Interface command is received
84 {
85 1 IN0BUF[0] = AlternateSetting;
86 1 EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
87 1 return(TRUE); // Handled by user code
88 1 }
89
90 BOOL DR_GetStatus(void)
91 {
92 1 return(TRUE);
93 1 }
94
95 BOOL DR_ClearFeature(void)
96 {
97 1 return(TRUE);
98 1 }
99
100 BOOL DR_SetFeature(void)
101 {
102 1 return(TRUE);
103 1 }
104
105 #define EZUSB_UNARM_EP(ep_id) EPIO[ep_id].cntrl = bmEPBUSY
106
107 BOOL DR_VendorCmnd(void)
108 {
109 1 return(TRUE);
110 1 }
111
112 //-----------------------------------------------------------------------------
113 // USB Interrupt Handlers
114 // The following functions are called by the USB interrupt jump table.
115 //-----------------------------------------------------------------------------
116
117
C51 COMPILER V6.10 PERIPH 06/30/2004 23:04:04 PAGE 3
118 // Setup Data Available Interrupt Handler
119 void ISR_Sudav(void) interrupt 0
120 {
121 1 GotSUD = TRUE; // Set flag
122 1
123 1
124 1 EZUSB_IRQ_CLEAR();
125 1 USBIRQ = bmSUDAV; // Clear SUDAV IRQ
126 1 }
127
128 // Setup Token Interrupt Handler
129 void ISR_Sutok(void) interrupt 0
130 {
131 1 EZUSB_IRQ_CLEAR();
132 1 USBIRQ = bmSUTOK; // Clear SUTOK IRQ
133 1 }
134
135 void ISR_Sof(void) interrupt 0
136 {
137 1 EZUSB_IRQ_CLEAR();
138 1 USBIRQ = bmSOF; // Clear SOF IRQ
139 1 }
140
141 void ISR_Ures(void) interrupt 0
142 {
143 1 //
144 1 // Arm all of the OUT endpoints so they can accept data
145 1 //
146 1 EPIO[OUT1BUF_ID].bytes = 0;
147 1 EPIO[OUT2BUF_ID].bytes = 0;
148 1 EPIO[OUT3BUF_ID].bytes = 0;
149 1 EPIO[OUT4BUF_ID].bytes = 0;
150 1 EPIO[OUT5BUF_ID].bytes = 0;
151 1 EPIO[OUT6BUF_ID].bytes = 0;
152 1 EPIO[OUT7BUF_ID].bytes = 0;
153 1
154 1 EZUSB_IRQ_CLEAR();
155 1 USBIRQ = bmURES; // Clear URES IRQ
156 1 }
157
158 void ISR_IBN(void) interrupt 0
159 {
160 1 // ISR for the IN Bulk NAK (IBN) interrupt.
161 1 }
162
163 void ISR_Susp(void) interrupt 0
164 {
165 1 Sleep = TRUE;
166 1
167 1 EZUSB_IRQ_CLEAR();
168 1 USBIRQ = bmSUSP;
169 1 }
170
171 void ISR_Ep0in(void) interrupt 0
172 {
173 1 }
174
175 void ISR_Ep0out(void) interrupt 0
176 {
177 1 }
178
179 void ISR_Ep1in(void) interrupt 0
C51 COMPILER V6.10 PERIPH 06/30/2004 23:04:04 PAGE 4
180 {
181 1 }
182
183 void ISR_Ep1out(void) interrupt 0
184 {
185 1 int i;
186 1
187 1 //
188 1 // workaround to cover the case where the host thinks the
189 1 // previous IN completed but EZ-USB didn't receive a valid
190 1 // handshake (i.e. the ACK was scrambled). If we have
191 1 // received new OUT data (which we have, because we're in this
192 1 // ISR) but the corresponding IN endpoint is still busy, then
193 1 // we know we missed the handshake. The solution is to flip
194 1 // the data toggle and proceed with the new data.
195 1 //
196 1 // NOTE: This workaround is specific to this particular loopback
197 1 // application and should not be included in normal endpoint handling
198 1 // firmware.
199 1 //
200 1 if (EPIO[IN1BUF_ID].cntrl & bmEPBUSY)
201 1 {
202 2 TOGCTL = 0x08 | IN1BUF_ID;
203 2 WRITEDELAY();
204 2 if (TOGCTL & 0x80)
205 2 TOGCTL |= 0x20;
206 2 else
207 2 TOGCTL |= 0x40;
208 2 }
209 1
210 1 // Loop the data to the IN endpoint
211 1 for (i=0; i < OUT1BC; i++)
212 1 {
213 2 IN1BUF[i] = ~OUT1BUF[i];
214 2 }
215 1
216 1 // Arm the IN endpoint
217 1 IN1BC = i;
218 1
219 1 // Arm the OUT so it can receive the next packet
220 1 OUT1BC = 0;
221 1
222 1
223 1 // clear the IRQ
224 1 EZUSB_IRQ_CLEAR();
225 1 OUT07IRQ = bmEP1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -