root/Examples_CP-JR_ARM7_LPC2368/ETT_LPC2368_Examples/USB_DEMO/USBCDC/vcomdemo.c

Revision 8, 3.1 kB (checked in by phil, 16 years ago)

Added Examples etc. from CD

Line 
1 /*----------------------------------------------------------------------------
2  *      Name:    vcomdemo.c
3  *      Purpose: USB virtual COM port Demo
4  *      Version: V1.01
5  *----------------------------------------------------------------------------
6  *      This file is part of the uVision/ARM development tools.
7  *      This software may only be used under the terms of a valid, current,
8  *      end user licence from KEIL for a compatible version of KEIL software
9  *      development tools. Nothing else gives you the right to use it.
10  *
11  *      Copyright (c) 2005-2007 Keil Software.
12  *---------------------------------------------------------------------------*/
13
14 #include <LPC23xx.H>                                  /* LPC23xx definitions */
15
16 #include "type.h"
17
18 #include "usb.h"
19 #include "usbcfg.h"
20 #include "usbhw.h"
21 #include "usbcore.h"
22 #include "cdc.h"
23 #include "cdcuser.h"
24 #include "serial.h"
25 #include "vcomdemo.h"
26
27
28
29 /*----------------------------------------------------------------------------
30  Initialises the VCOM port.
31  Call this function before using VCOM_putchar or VCOM_getchar
32  *---------------------------------------------------------------------------*/
33 void VCOM_Init(void) {
34
35   CDC_Init ();
36 }
37
38
39 /*----------------------------------------------------------------------------
40   Reads character from serial port
41  *---------------------------------------------------------------------------*/
42 void VCOM_Serial2Usb(void) {
43   static BYTE serBuf [USB_CDC_BUFSIZE];
44          int numReadBytes, numAvailChar;
45        
46   ser_AvailChar (CDC_SerDevNo, &numAvailChar);
47   if (numAvailChar > 0) {
48     if (CDC_DepInEmpty) {
49       numReadBytes = ser_Read (CDC_SerDevNo, (char *)&serBuf[0], &numAvailChar);
50       CDC_DepInEmpty = 0;
51           USB_WriteEP (CDC_DEP_IN, &serBuf[0], numReadBytes);
52     }
53   }
54
55 }
56
57
58 /*----------------------------------------------------------------------------
59   checks the serial state and initiates notification
60  *---------------------------------------------------------------------------*/
61 void VCOM_CheckSerialState (void) {
62          WORD temp;
63   static WORD serialState;
64
65   temp = CDC_GetSerialState();
66   if (serialState != temp) {
67      serialState = temp;
68      CDC_NotificationIn();                  // send SERIAL_STATE notification
69   }
70 }
71
72
73 /*----------------------------------------------------------------------------
74   Main Program
75  *---------------------------------------------------------------------------*/
76 int main (void) {
77
78   PINSEL10 = 0;                             // Disable ETM interface
79   FIO2DIR  = LEDMSK;                        // LED's defined as Outputs
80
81   VCOM_Init();                              // VCOM Initialization
82
83   USB_Init();                               // USB Initialization
84   USB_Connect(TRUE);                        // USB Connect
85
86   while (!USB_Configuration) ;              // wait until USB is configured
87
88   while (1) {                               // Loop forever
89     VCOM_Serial2Usb();                      // read serial port and initiate USB event
90     VCOM_CheckSerialState();
91   }                                                                                       
92 }
93
Note: See TracBrowser for help on using the browser.