+++ /dev/null
-/*----------------------------------------------------------------------------\r
- * Name: vcomdemo.c\r
- * Purpose: USB virtual COM port Demo\r
- * Version: V1.20\r
- *----------------------------------------------------------------------------\r
- * This software is supplied "AS IS" without any warranties, express,\r
- * implied or statutory, including but not limited to the implied\r
- * warranties of fitness for purpose, satisfactory quality and\r
- * noninfringement. Keil extends you a royalty-free right to reproduce\r
- * and distribute executable files created using this software for use\r
- * on NXP Semiconductors LPC microcontroller devices only. Nothing else\r
- * gives you the right to use this software.\r
- *\r
- * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
- *---------------------------------------------------------------------------*/\r
-\r
-#include "../LPC17xx.h"\r
-#include "lpc_types.h"\r
-\r
-#include "usb.h"\r
-#include "usbcfg.h"\r
-#include "usbhw.h"\r
-#include "usbcore.h"\r
-#include "cdc.h"\r
-#include "cdcuser.h"\r
-#include "serial.h"\r
-#include "vcomdemo.h"\r
-\r
-/* Example group ----------------------------------------------------------- */\r
-/** @defgroup USBDEV_USBCDC USBCDC\r
- * @ingroup USBDEV_Examples\r
- * @{\r
- */\r
-\r
-/*----------------------------------------------------------------------------\r
- Initialises the VCOM port.\r
- Call this function before using VCOM_putchar or VCOM_getchar\r
- *---------------------------------------------------------------------------*/\r
-void VCOM_Init(void) {\r
-#if PORT_NUM\r
- CDC_Init (1);\r
-#else\r
- CDC_Init (0);\r
-#endif\r
-}\r
-\r
-\r
-/*----------------------------------------------------------------------------\r
- Reads character from serial port buffer and writes to USB buffer\r
- *---------------------------------------------------------------------------*/\r
-void VCOM_Serial2Usb(void) {\r
- static char serBuf [USB_CDC_BUFSIZE];\r
- int numBytesRead, numAvailByte;\r
-\r
- ser_AvailChar (&numAvailByte);\r
- if (numAvailByte > 0) {\r
- if (CDC_DepInEmpty) {\r
- numBytesRead = ser_Read (&serBuf[0], &numAvailByte);\r
-\r
- CDC_DepInEmpty = 0;\r
- USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], numBytesRead);\r
- }\r
- }\r
-\r
-}\r
-\r
-/*----------------------------------------------------------------------------\r
- Reads character from USB buffer and writes to serial port buffer\r
- *---------------------------------------------------------------------------*/\r
-void VCOM_Usb2Serial(void) {\r
- static char serBuf [32];\r
- int numBytesToRead, numBytesRead, numAvailByte;\r
-\r
- CDC_OutBufAvailChar (&numAvailByte);\r
- if (numAvailByte > 0) {\r
- numBytesToRead = numAvailByte > 32 ? 32 : numAvailByte;\r
- numBytesRead = CDC_RdOutBuf (&serBuf[0], &numBytesToRead);\r
-#if PORT_NUM\r
- ser_Write (1, &serBuf[0], &numBytesRead);\r
-#else\r
- ser_Write (0, &serBuf[0], &numBytesRead);\r
-#endif\r
- }\r
-\r
-}\r
-\r
-\r
-/*----------------------------------------------------------------------------\r
- checks the serial state and initiates notification\r
- *---------------------------------------------------------------------------*/\r
-void VCOM_CheckSerialState (void) {\r
- unsigned short temp;\r
- static unsigned short serialState;\r
-\r
- temp = CDC_GetSerialState();\r
- if (serialState != temp) {\r
- serialState = temp;\r
- CDC_NotificationIn(); // send SERIAL_STATE notification\r
- }\r
-}\r
-\r
-/*----------------------------------------------------------------------------\r
- Main Program\r
- *---------------------------------------------------------------------------*/\r
-int main (void) {\r
- SystemInit();\r
-\r
- VCOM_Init(); // VCOM Initialization\r
-\r
- USB_Init(); // USB Initialization\r
- USB_Connect(TRUE); // USB Connect\r
-\r
- while (!USB_Configuration) ; // wait until USB is configured\r
-\r
- while (1) { // Loop forever\r
- VCOM_Serial2Usb(); // read serial port and initiate USB event\r
- VCOM_CheckSerialState();\r
- VCOM_Usb2Serial();\r
- } // end while\r
-} // end main ()\r
-\r
-/*\r
- * @}\r
- */\r