📄 vcomuser.lst
字号:
ARM COMPILER V2.31, VCOMuser 23/11/05 10:53:11 PAGE 1
ARM COMPILER V2.31, COMPILATION OF MODULE VCOMuser
OBJECT MODULE PLACED IN .\Obj\VCOMuser.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe VCOMuser.c THUMB DEFINE(MCB2140) DEBUG PRINT(.\LST\VCOMUSER.LST) TABS(4) OBJ
-ECT(.\Obj\VCOMuser.obj)
stmt level source
1 /*----------------------------------------------------------------------------
2 * U S B - K e r n e l
3 *----------------------------------------------------------------------------
4 * Name: vcomuser.c
5 * Purpose: Virtual COM custom user module file for Philips LPC214x Family
6 * Microprocessors
7 * Version: V1.04
8 *----------------------------------------------------------------------------
9 * This software is supplied "AS IS" without any warranties, express,
10 * implied or statutory, including but not limited to the implied
11 * warranties of fitness for purpose, satisfactory quality and
12 * noninfringement. Keil extends you a royalty-free right to reproduce and
13 * distribute executable files created using this software for use on
14 * Philips LPC2xxx microcontroller devices only. Nothing else gives you the
15 * right to use this software.
16 *
17 * Copyright (c) 2005 Keil Software.
18 * Modified by Philips Semiconductor
19 *---------------------------------------------------------------------------*/
20 #include <string.h>
21 #include <LPC214x.h> /* LPC214x definitions */
22
23 #include "type.h"
24 #include "usb.h"
25 #include "usbhw.h"
26 #include "usbcfg.h"
27 #include "usbcore.h"
28 #include "vcomuser.h"
29 #include "demo.h"
30
31 #define CR 0x0D
32
33 static BYTE KeyPressed = 0;
34
35 BYTE ReportStatus0 = 0, ReportStatus1 = 0;
36 BYTE Data2Host0 = 0, Data2Host1 = 0;
37
38 #if USB_VCOM
39 BYTE RxLength0, RxLength1;
40
41 BYTE USB2UARTBuf0[USB_MAX_PACKET0];
42 BYTE USB2UARTBuf1[USB_MAX_PACKET0];
43
44 BYTE UART2USBBuf0[USB_MAX_PACKET0];
45 BYTE UART2USBBuf1[USB_MAX_PACKET0];
46
47 /* if the portNum is 0, EP1 is the endpoints for
48 STATUS IN, EP2 EP is BULK IN, BULK OUT and UART0 Virtual COM port.
49 if the portNum is 1, EP4 is the endpoints for
50 STATUS IN, EP5 is BULK IN, BULK OUT and UART1 Virtual COM port */
51
52 void DeviceData2UART( BYTE portNum )
53 {
54 1 #if NO_UART_CABLE
DWORD cnt;
#else
57 1 DWORD cnt, i;
58 1 #endif
ARM COMPILER V2.31, VCOMuser 23/11/05 10:53:11 PAGE 2
59 1 BYTE *pData;
60 1
61 1 if ( portNum == 0 ) {
62 2 pData = &USB2UARTBuf0[0];
63 2 cnt = USB_ReadEP(0x02, pData);
64 2 #if NO_UART_CABLE
if (*pData & 0x01) IOSET1 = LED1; else IOCLR1 = LED1;
if (*pData & 0x02) IOSET1 = LED2; else IOCLR1 = LED2;
if (*pData & 0x04) IOSET1 = LED3; else IOCLR1 = LED3;
if (*pData & 0x08) IOSET1 = LED4; else IOCLR1 = LED4;
if (*pData & 0x10) IOSET1 = LED5; else IOCLR1 = LED5;
if (*pData & 0x20) IOSET1 = LED6; else IOCLR1 = LED6;
if (*pData & 0x40) IOSET1 = LED7; else IOCLR1 = LED7;
if (*pData & 0x80) IOSET1 = LED8; else IOCLR1 = LED8;
#else
74 2 for ( i = 0; i < cnt; i++ ) {
75 3 putchar( portNum, (BYTE)*pData );
76 3 pData++;
77 3 }
78 2 #endif
79 2 }
80 1 else if ( portNum == 1 ) {
81 2 pData = &USB2UARTBuf1[0];
82 2 cnt = USB_ReadEP(0x05, pData);
83 2 #if NO_UART_CABLE
if (*pData & 0x01) IOSET1 = LED1; else IOCLR1 = LED1;
if (*pData & 0x02) IOSET1 = LED2; else IOCLR1 = LED2;
if (*pData & 0x04) IOSET1 = LED3; else IOCLR1 = LED3;
if (*pData & 0x08) IOSET1 = LED4; else IOCLR1 = LED4;
if (*pData & 0x10) IOSET1 = LED5; else IOCLR1 = LED5;
if (*pData & 0x20) IOSET1 = LED6; else IOCLR1 = LED6;
if (*pData & 0x40) IOSET1 = LED7; else IOCLR1 = LED7;
if (*pData & 0x80) IOSET1 = LED8; else IOCLR1 = LED8;
#else
93 2 for ( i = 0; i < cnt; i++ ) {
94 3 putchar( portNum, (BYTE)*pData );
95 3 pData++;
96 3 }
97 2 #endif
98 2 }
99 1 return;
100 1 }
101
102 void DeviceData2Host( BYTE portNum )
103 {
104 1 #if NO_UART_CABLE
const BYTE msg[] = "INT1 pressed\r\n";
BYTE length;
#endif
108 1
109 1 if ( portNum == 0 ) {
110 2 #if NO_UART_CABLE
if ((IOPIN0 & S2) == 0 && !KeyPressed ) /* Check if S2 is pressed */
{
KeyPressed = 1;
length = strlen(msg);
memcpy( UART2USBBuf0, msg, length );
USB_WriteEP(0x80 | 0x02, &UART2USBBuf0[0], length );
KeyPressed = 0;
// Data2Host0 = 0;
}
#else
121 2 /* if the RX buffer is not empty, suck in data from UART0 */
122 2 if ( ((U0LSR & 0x01) == 1) && (RxLength0 < USB_VCOM_BUFSIZE) ) {
123 3 UART2USBBuf0[RxLength0] = getchar( portNum );
124 3 RxLength0++;
ARM COMPILER V2.31, VCOMuser 23/11/05 10:53:11 PAGE 3
125 3 }
126 2 else if ( (RxLength0 == USB_VCOM_BUFSIZE) ) {
127 3 USB_WriteEP(0x80 | 0x02, &UART2USBBuf0[0], USB_VCOM_BUFSIZE );
128 3 RxLength0 = 0;
129 3 }
130 2 #endif
131 2 }
132 1 else if ( portNum == 1 )
133 1 {
134 2 #if NO_UART_CABLE
if ((IOPIN0 & S2) == 0 && !KeyPressed ) /* Check if S2 is pressed */
{
KeyPressed = 1;
length = strlen(msg);
memcpy( UART2USBBuf1, msg, length );
USB_WriteEP(0x80 | 0x05, &UART2USBBuf1[0], length );
KeyPressed = 0;
Data2Host1 = 0;
}
#else
145 2 /* if the RX buffer is not empty, suck in data from UART1 */
146 2 if ( ((U1LSR & 0x01) == 1) && (RxLength1 < USB_VCOM_BUFSIZE) ) {
147 3 UART2USBBuf1[RxLength1] = getchar( portNum );
148 3 RxLength1++;
149 3 }
150 2 else if ( (RxLength1 == USB_VCOM_BUFSIZE) ) {
151 3 USB_WriteEP(0x80 | 0x05, &UART2USBBuf1[0], USB_VCOM_BUFSIZE );
152 3 RxLength1 = 0;
153 3 }
154 2 #endif
155 2 }
156 1 return;
157 1 }
158 #endif
159
160 /*
161 * USB Power Event Callback
162 * Parameter: power: On(TRUE)/Off(FALSE)
163 */
164
165 #if USB_POWER_EVENT
void USB_Power_Event (BOOL power) {
power;
}
#endif
170
171
172 /*
173 * USB Reset Event Callback
174 */
175
176 #if USB_RESET_EVENT
177 void USB_Reset_Event (void) {
178 1 USB_ResetCore();
179 1 }
180 #endif
181
182
183 /*
184 * USB Suspend Event Callback
185 */
186
187 #if USB_SUSPEND_EVENT
void USB_Suspend_Event (void) {
}
#endif
ARM COMPILER V2.31, VCOMuser 23/11/05 10:53:11 PAGE 4
191
192
193 /*
194 * USB Resume Event Callback
195 */
196
197 #if USB_RESUME_EVENT
void USB_Resume_Event (void) {
}
#endif
201
202
203 /*
204 * USB Remote Wakeup Event Callback
205 */
206
207 #if USB_WAKEUP_EVENT
void USB_WakeUp_Event (void) {
}
#endif
211
212
213 /*
214 * USB Start of frame Event Callback
215 * Parameter: frame: 11-bit Frame Number
216 */
217
218 #if USB_SOF_EVENT
void USB_SOF_Event (DWORD frame) {
frame;
}
#endif
223
224
225 /*
226 * USB Error Event Callback
227 * Parameter: error: Error Code
228 */
229
230 #if USB_ERROR_EVENT
void USB_Error_Event (DWORD error) {
error;
}
#endif
235
236 /*
237 * USB Set Configuration Event Callback
238 */
239 #if USB_CONFIGURE_EVENT
240 void USB_Configure_Event (void) {
241 1 if (USB_Configuration) { /* Check if USB is configured */
242 2 ReportStatus0 = ReportStatus1 = 1;
243 2 Data2Host0 = Data2Host1 = 1;
244 2 }
245 1 }
246 #endif
247
248 /*
249 * USB Set Interface Event Callback
250 */
251
252 #if USB_INTERFACE_EVENT
void USB_Interface_Event (void) {
}
#endif
256
ARM COMPILER V2.31, VCOMuser 23/11/05 10:53:11 PAGE 5
257 /*
258 * USB Set/Clear Feature Event Callback
259 */
260
261 #if USB_FEATURE_EVENT
void USB_Feature_Event (void) {
}
#endif
265
266
267 #define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)
268
269 /* USB Endpoint Events Callback Pointers */
270 const void (* USB_P_EP[16]) (DWORD event) = {
271 P_EP(0),
272 P_EP(1),
273 P_EP(2),
274 P_EP(3),
275 P_EP(4),
276 P_EP(5),
277 P_EP(6),
278 P_EP(7),
279 P_EP(8),
280 P_EP(9),
281 P_EP(10),
282 P_EP(11),
283 P_EP(12),
284 P_EP(13),
285 P_EP(14),
286 P_EP(15),
287 };
288
289 /*
290 * USB Endpoint 1 Event Callback
291 * Parameter: event
292 */
293
294 void USB_EndPoint1 (DWORD event) {
295 1 event;
296 1 }
297
298 /*
299 * USB Endpoint 2 Event Callback
300 * Parameter: event
301 */
302
303 void USB_EndPoint2 (DWORD event) {
304 1 switch (event) {
305 2 case USB_EVT_IN:
306 2 Data2Host0 = 1;
307 2 break;
308 2 case USB_EVT_OUT:
309 2 DeviceData2UART( 0 );
310 2 break;
311 2 }
312 1 event;
313 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -