--- /dev/null
+ ******************** (C) COPYRIGHT 2010 NXPSemiconductors *******************\r
+ * @file USBDEV\USBCDC\abstract.txt \r
+ * @author NXP MCU SW Application Team\r
+ * @version 2.0\r
+ * @date \r
+ * @brief Description of the USBDEV CDC example.\r
+ ******************************************************************************\r
+ * Software that is described herein is for illustrative purposes only\r
+ * which provides customers with programming information regarding the\r
+ * products. This software is supplied "AS IS" without any warranties.\r
+ * NXP Semiconductors assumes no responsibility or liability for the\r
+ * use of the software, conveys no license or title under any patent,\r
+ * copyright, or mask work right to the product. NXP Semiconductors\r
+ * reserves the right to make changes in the software without\r
+ * notification. NXP Semiconductors also make no representation or\r
+ * warranty that such application will be suitable for the specified\r
+ * use without further testing or modification.\r
+ ******************************************************************************\r
+ \r
+@Example description:\r
+ Purpose:\r
+ This example describes how to use USBDEV on LPC1768 to demo the virtual COM port.\r
+ Process: \r
+ Clock Settings:\r
+ - XTAL = 12 MHz\r
+ - PLL = 400 MHz\r
+ - processor clock = CCLK = 100 MHz\r
+ - USB clock = 48 MHz\r
+ - CCLK / 4 clock = 25 MHz\r
+ \r
+ The PC will install a virtual COM port on the PC (see Driver Installation).\r
+ After installation an additional port "LPC17xx USB VCom Port(COMx)"\r
+ can be found under System/Hardware/Device Manager/Ports(COM&LPT).\r
+ Number "x" is not fixed as different PC configuration may have different \r
+ "x" displayed on the device manager. The USB host driver assigns "x" \r
+ dynamically based on the existing COM port configuration of the system.\r
+ \r
+ Testing the USB Virtual COM port with serial cable:\r
+\r
+ Open two Hyperterminal windows. \r
+ One with "LPC17xx USB VCom Port(COMx)" \r
+ One with "Communications Port (COM1)".\r
+ Connect PC port COM1 to the comport on the board and open "COM1" \r
+ and "COMx". Data from COM1 will be echoed on "COMx" and visa versa. \r
+ So, this is bi-directional communication between the physical COM\r
+ port 0 or 1 on the board and the virtual COM port COMx on host PC.\r
+ By default, COM PORT1 on the board is used for VirtualCOM port test.\r
+ In order to use COM PORT0 on the board, modify the definition PORT_NUM\r
+ from 1 to 0 in serial.h, recompile and reprogram the flash. RST jumper\r
+ needs to removed to start the Virtual COM port test. \r
+ \r
+@Driver Installation:\r
+ "Welcome to the Found New Hardware Wizard" appears\r
+ - select 'No, not this time'\r
+ - press 'Next'\r
+\r
+ - select 'Install from a list or specific location (Advanced)'\r
+ - press 'Next'\r
+\r
+ - select 'Search for the best driver in these locations'\r
+ - check 'include this location in the serach'\r
+ - set to <project folder>\r
+ - press 'Next'\r
+\r
+ "Hardware Installation" appears\r
+ "has not passed Windows Logo testing..."\r
+ - press 'Continue Anyway'\r
+\r
+ "Completing the Found New Hardware Wizard" appears\r
+ - press 'Finish'\r
+ \r
+@Directory contents:\r
+ \EWARM: includes EWARM (IAR) project and configuration files\r
+ \Keil: includes RVMDK (Keil)project and configuration files \r
+ \r
+ cdc.h: USB CDC (Communication Device) Definitions\r
+ cdcuser.h/.c: USB Communication Device Class User module\r
+ lpc17xx_libcfg.h: Library configuration file - include needed driver library for this example \r
+ serial.h/.c: serial port handling for LPC17xx\r
+ usb.h: USB Definitions\r
+ usbcfg.h: USB Custom Configuration\r
+ usbcore.h/.c: USB Core Module\r
+ usbdesc.h/.c: USB Descriptors\r
+ usbhw.h/.c: SB Hardware Layer Module\r
+ usbreg.h: USB Hardware Layer Definitions for NXP Semiconductors LPC \r
+ usbuser.h/.c: USB Custom User Module\r
+ vcomdemo.h/.c: main program \r
+ makefile: Example's makefile (to build with GNU toolchain)\r
+ lpc17xx-vom.inf: driver info for VCOM LPC17xx (used when Windows requires install driver)\r
+\r
+@How to run:\r
+ Hardware configuration: \r
+ This example was tested only on:\r
+ Keil MCB1700 with LPC1768 vers.1\r
+ These jumpers must be configured as following:\r
+ - VDDIO: ON\r
+ - VDDREGS: ON \r
+ - VBUS: ON\r
+ - D+: DEVICE\r
+ - D-: DEVICE\r
+ - UMODE: 1-2 (USB)\r
+ - E/U: 1-2 (USB)\r
+ - Remain jumpers: OFF\r
+ \r
+ Running mode:\r
+ This example can run on RAM/ROM mode.\r
+ \r
+ Note: If want to burn hex file to board by using Flash Magic, these jumpers need\r
+ to be connected:\r
+ - MCB1700 with LPC1768 ver.1:\r
+ + RST: ON\r
+ + ISP: ON\r
+ - IAR LPC1768 KickStart vers.A:\r
+ + RST_E: ON\r
+ + ISP_E: ON\r
+ \r
+ (Please reference "LPC1000 Software Development Toolchain" - chapter 4 "Creating and working with\r
+ LPC1000CMSIS project" for more information)\r
+ \r
+ Step to run:\r
+ - Step 1: Build example.\r
+ - Step 2: Burn hex file into board (if run on ROM mode)\r
+ - Step 3: Configure hardware as above instruction \r
+ - Step 4: Hit reset button to run example. (install driver if required)\r
+ - Step 5: After see UGL(USB Good Link) led on board turn on, open Device Manager > Ports (COM & LPT)\r
+ see if "LPC17xx USB Vcom Port (COMx)" appears or not. \r
+ - Step 6: Open one HyperTerminal for COM1 and other for COMx with below configuration:\r
+ - 9600 bps\r
+ - 8 data bits\r
+ - none parity\r
+ - 1 stop bit\r
+ - None flow control\r
+ - Step 7: Sure that you already connected COM1 port on board with PC. Type any character on \r
+ one HyperTerminal screen and see this character will be echoed in other screen and vice versa \r
+ \r
+ (Pls see "LPC17xx Example Description" document - chapter "Examples > USBDEV > USBCDC"\r
+ for more details)\r
+ \r
+@Tip:\r
+ - Open \EWARM\*.eww project file to run example on IAR\r
+ - Open \RVMDK\*.uvproj project file to run example on Keil
\ No newline at end of file
--- /dev/null
+/*
+ * This is the NXP LPC1768 linker file for code running from flash.
+ *
+ * TODO:
+ * - handle the exotic input sections (e.g. glue and veneer, C++ sections)
+ * - add additional Ethernet and USB RAM memory regions (2x16k)
+ * - add boot ROM memory regions
+ *
+ * See also: http://bitbucket.org/jpc/lpc1768/
+ *
+ * Copyright (c) 2010 LoEE - Jakub Piotr Cłapa
+ * This program is released under the new BSD license.
+ */
+OUTPUT_FORMAT("elf32-littlearm")
+OUTPUT_ARCH(arm)
+
+ENTRY(Reset_Handler)
+
+MEMORY {
+ flash (rx) : ORIGIN = 0x00000000, LENGTH = 512K
+ ram (rwx) : ORIGIN = 0x10000000, LENGTH = 32K
+}
+
+SECTIONS {
+ . = 0;
+
+ .text : {
+ _stext = .;
+ KEEP(*(.isr_vector))
+ *(.text*)
+ *(.rodata*)
+ . = ALIGN(4);
+ _etext = .;
+ } > flash
+
+ .data : {
+ _sdata = .;
+ *(.data*)
+ _edata = .;
+ } > ram AT > flash
+
+ .bss : {
+ _sbss = .;
+ *(.bss*)
+ . = ALIGN(4);
+ _ebss = .;
+ } > ram
+
+ _sstack = ORIGIN(ram) + LENGTH(ram);
+}
--- /dev/null
+PROJECT=usbdemo\r
+PLATFORM ?= arm-none-eabi\r
+LDFLAGS=--gc-sections -g -T LPC1768-flash.ld\r
+CFLAGS=-W -Wall --std=gnu99 -fgnu89-inline -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -I. -g\r
+#CFLAGS+=-Os\r
+\r
+# objects are separated by space\r
+OBJECTS=serial.o usbcore.o usbdesc.o usbhw.o usbuser.o vcomdemo.o startup.o cdcuser.o ../system_LPC17xx.o\r
+\r
+\r
+all: $(PROJECT).elf\r
+\r
+$(PROJECT).elf: $(OBJECTS)\r
+ $(PLATFORM)-ld -Map $(PROJECT).map $(LDFLAGS) $(OBJECTS) -o $@\r
+\r
+%.o: %.c\r
+ $(PLATFORM)-gcc -MM $< -MF $(patsubst %.o,%.d,$@) -MP\r
+ $(PLATFORM)-gcc $(CFLAGS) -c $< -o $@\r
+\r
+.PHONY: clean gdb\r
+\r
+clean:\r
+ rm -f $(PROJECT).elf $(OBJECTS) $(OBJECTS:.o=.d) $(PROJECT).map\r
+\r
+gdb:\r
+ $(PLATFORM)-gdb $(PROJECT).elf\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: CDC.h\r
+ * Purpose: USB Communication Device Class Definitions\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 family microcontroller devices only. Nothing\r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *---------------------------------------------------------------------------*/\r
+\r
+#ifndef __CDC_H\r
+#define __CDC_H\r
+#include "lpc_types.h"\r
+\r
+#if defined ( __GNUC__ )\r
+#define __packed __attribute__((__packed__))\r
+#endif\r
+/*----------------------------------------------------------------------------\r
+ * Definitions based on usbcdc11.pdf (www.usb.org)\r
+ *---------------------------------------------------------------------------*/\r
+// Communication device class specification version 1.10\r
+#define CDC_V1_10 0x0110\r
+\r
+// Communication interface class code\r
+// (usbcdc11.pdf, 4.2, Table 15)\r
+#define CDC_COMMUNICATION_INTERFACE_CLASS 0x02\r
+\r
+// Communication interface class subclass codes\r
+// (usbcdc11.pdf, 4.3, Table 16)\r
+#define CDC_DIRECT_LINE_CONTROL_MODEL 0x01\r
+#define CDC_ABSTRACT_CONTROL_MODEL 0x02\r
+#define CDC_TELEPHONE_CONTROL_MODEL 0x03\r
+#define CDC_MULTI_CHANNEL_CONTROL_MODEL 0x04\r
+#define CDC_CAPI_CONTROL_MODEL 0x05\r
+#define CDC_ETHERNET_NETWORKING_CONTROL_MODEL 0x06\r
+#define CDC_ATM_NETWORKING_CONTROL_MODEL 0x07\r
+\r
+// Communication interface class control protocol codes\r
+// (usbcdc11.pdf, 4.4, Table 17)\r
+#define CDC_PROTOCOL_COMMON_AT_COMMANDS 0x01\r
+\r
+// Data interface class code\r
+// (usbcdc11.pdf, 4.5, Table 18)\r
+#define CDC_DATA_INTERFACE_CLASS 0x0A\r
+\r
+// Data interface class protocol codes\r
+// (usbcdc11.pdf, 4.7, Table 19)\r
+#define CDC_PROTOCOL_ISDN_BRI 0x30\r
+#define CDC_PROTOCOL_HDLC 0x31\r
+#define CDC_PROTOCOL_TRANSPARENT 0x32\r
+#define CDC_PROTOCOL_Q921_MANAGEMENT 0x50\r
+#define CDC_PROTOCOL_Q921_DATA_LINK 0x51\r
+#define CDC_PROTOCOL_Q921_MULTIPLEXOR 0x52\r
+#define CDC_PROTOCOL_V42 0x90\r
+#define CDC_PROTOCOL_EURO_ISDN 0x91\r
+#define CDC_PROTOCOL_V24_RATE_ADAPTATION 0x92\r
+#define CDC_PROTOCOL_CAPI 0x93\r
+#define CDC_PROTOCOL_HOST_BASED_DRIVER 0xFD\r
+#define CDC_PROTOCOL_DESCRIBED_IN_PUFD 0xFE\r
+\r
+// Type values for bDescriptorType field of functional descriptors\r
+// (usbcdc11.pdf, 5.2.3, Table 24)\r
+#define CDC_CS_INTERFACE 0x24\r
+#define CDC_CS_ENDPOINT 0x25\r
+\r
+// Type values for bDescriptorSubtype field of functional descriptors\r
+// (usbcdc11.pdf, 5.2.3, Table 25)\r
+#define CDC_HEADER 0x00\r
+#define CDC_CALL_MANAGEMENT 0x01\r
+#define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02\r
+#define CDC_DIRECT_LINE_MANAGEMENT 0x03\r
+#define CDC_TELEPHONE_RINGER 0x04\r
+#define CDC_REPORTING_CAPABILITIES 0x05\r
+#define CDC_UNION 0x06\r
+#define CDC_COUNTRY_SELECTION 0x07\r
+#define CDC_TELEPHONE_OPERATIONAL_MODES 0x08\r
+#define CDC_USB_TERMINAL 0x09\r
+#define CDC_NETWORK_CHANNEL 0x0A\r
+#define CDC_PROTOCOL_UNIT 0x0B\r
+#define CDC_EXTENSION_UNIT 0x0C\r
+#define CDC_MULTI_CHANNEL_MANAGEMENT 0x0D\r
+#define CDC_CAPI_CONTROL_MANAGEMENT 0x0E\r
+#define CDC_ETHERNET_NETWORKING 0x0F\r
+#define CDC_ATM_NETWORKING 0x10\r
+\r
+// CDC class-specific request codes\r
+// (usbcdc11.pdf, 6.2, Table 46)\r
+// see Table 45 for info about the specific requests.\r
+#define CDC_SEND_ENCAPSULATED_COMMAND 0x00\r
+#define CDC_GET_ENCAPSULATED_RESPONSE 0x01\r
+#define CDC_SET_COMM_FEATURE 0x02\r
+#define CDC_GET_COMM_FEATURE 0x03\r
+#define CDC_CLEAR_COMM_FEATURE 0x04\r
+#define CDC_SET_AUX_LINE_STATE 0x10\r
+#define CDC_SET_HOOK_STATE 0x11\r
+#define CDC_PULSE_SETUP 0x12\r
+#define CDC_SEND_PULSE 0x13\r
+#define CDC_SET_PULSE_TIME 0x14\r
+#define CDC_RING_AUX_JACK 0x15\r
+#define CDC_SET_LINE_CODING 0x20\r
+#define CDC_GET_LINE_CODING 0x21\r
+#define CDC_SET_CONTROL_LINE_STATE 0x22\r
+#define CDC_SEND_BREAK 0x23\r
+#define CDC_SET_RINGER_PARMS 0x30\r
+#define CDC_GET_RINGER_PARMS 0x31\r
+#define CDC_SET_OPERATION_PARMS 0x32\r
+#define CDC_GET_OPERATION_PARMS 0x33\r
+#define CDC_SET_LINE_PARMS 0x34\r
+#define CDC_GET_LINE_PARMS 0x35\r
+#define CDC_DIAL_DIGITS 0x36\r
+#define CDC_SET_UNIT_PARAMETER 0x37\r
+#define CDC_GET_UNIT_PARAMETER 0x38\r
+#define CDC_CLEAR_UNIT_PARAMETER 0x39\r
+#define CDC_GET_PROFILE 0x3A\r
+#define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40\r
+#define CDC_SET_ETHERNET_PMP_FILTER 0x41\r
+#define CDC_GET_ETHERNET_PMP_FILTER 0x42\r
+#define CDC_SET_ETHERNET_PACKET_FILTER 0x43\r
+#define CDC_GET_ETHERNET_STATISTIC 0x44\r
+#define CDC_SET_ATM_DATA_FORMAT 0x50\r
+#define CDC_GET_ATM_DEVICE_STATISTICS 0x51\r
+#define CDC_SET_ATM_DEFAULT_VC 0x52\r
+#define CDC_GET_ATM_VC_STATISTICS 0x53\r
+\r
+// Communication feature selector codes\r
+// (usbcdc11.pdf, 6.2.2..6.2.4, Table 47)\r
+#define CDC_ABSTRACT_STATE 0x01\r
+#define CDC_COUNTRY_SETTING 0x02\r
+\r
+// Feature Status returned for ABSTRACT_STATE Selector\r
+// (usbcdc11.pdf, 6.2.3, Table 48)\r
+#define CDC_IDLE_SETTING (1 << 0)\r
+#define CDC_DATA_MULTPLEXED_STATE (1 << 1)\r
+\r
+\r
+// Control signal bitmap values for the SetControlLineState request\r
+// (usbcdc11.pdf, 6.2.14, Table 51)\r
+#define CDC_DTE_PRESENT (1 << 0)\r
+#define CDC_ACTIVATE_CARRIER (1 << 1)\r
+\r
+// CDC class-specific notification codes\r
+// (usbcdc11.pdf, 6.3, Table 68)\r
+// see Table 67 for Info about class-specific notifications\r
+#define CDC_NOTIFICATION_NETWORK_CONNECTION 0x00\r
+#define CDC_RESPONSE_AVAILABLE 0x01\r
+#define CDC_AUX_JACK_HOOK_STATE 0x08\r
+#define CDC_RING_DETECT 0x09\r
+#define CDC_NOTIFICATION_SERIAL_STATE 0x20\r
+#define CDC_CALL_STATE_CHANGE 0x28\r
+#define CDC_LINE_STATE_CHANGE 0x29\r
+#define CDC_CONNECTION_SPEED_CHANGE 0x2A\r
+\r
+// UART state bitmap values (Serial state notification).\r
+// (usbcdc11.pdf, 6.3.5, Table 69)\r
+#define CDC_SERIAL_STATE_OVERRUN (1 << 6) // receive data overrun error has occurred\r
+#define CDC_SERIAL_STATE_PARITY (1 << 5) // parity error has occurred\r
+#define CDC_SERIAL_STATE_FRAMING (1 << 4) // framing error has occurred\r
+#define CDC_SERIAL_STATE_RING (1 << 3) // state of ring signal detection\r
+#define CDC_SERIAL_STATE_BREAK (1 << 2) // state of break detection\r
+#define CDC_SERIAL_STATE_TX_CARRIER (1 << 1) // state of transmission carrier\r
+#define CDC_SERIAL_STATE_RX_CARRIER (1 << 0) // state of receiver carrier\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ * Structures based on usbcdc11.pdf (www.usb.org)\r
+ *---------------------------------------------------------------------------*/\r
+\r
+// Header functional descriptor\r
+// (usbcdc11.pdf, 5.2.3.1)\r
+// This header must precede any list of class-specific descriptors.\r
+\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _CDC_HEADER_DESCRIPTOR{\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _CDC_HEADER_DESCRIPTOR{\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _CDC_HEADER_DESCRIPTOR {\r
+#endif\r
+ uint8_t bFunctionLength; // size of this descriptor in bytes\r
+ uint8_t bDescriptorType; // CS_INTERFACE descriptor type\r
+ uint8_t bDescriptorSubtype; // Header functional descriptor subtype\r
+ uint16_t bcdCDC; // USB CDC specification release version\r
+} CDC_HEADER_DESCRIPTOR;\r
+\r
+//Call management functional descriptor\r
+// (usbcdc11.pdf, 5.2.3.2)\r
+// Describes the processing of calls for the communication class interface.\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _CDC_CALL_MANAGEMENT_DESCRIPTOR{\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _CDC_CALL_MANAGEMENT_DESCRIPTOR{\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _CDC_CALL_MANAGEMENT_DESCRIPTOR {\r
+#endif\r
+ uint8_t bFunctionLength; // size of this descriptor in bytes\r
+ uint8_t bDescriptorType; // CS_INTERFACE descriptor type\r
+ uint8_t bDescriptorSubtype; // call management functional descriptor subtype\r
+ uint8_t bmCapabilities; // capabilities that this configuration supports\r
+ uint8_t bDataInterface; // interface number of the data class interface used for call management (optional)\r
+} CDC_CALL_MANAGEMENT_DESCRIPTOR;\r
+\r
+// Abstract control management functional descriptor\r
+// (usbcdc11.pdf, 5.2.3.3)\r
+// Describes the command supported by the communication interface class with the Abstract Control Model subclass code.\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR{\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR{\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR {\r
+#endif\r
+ uint8_t bFunctionLength; // size of this descriptor in bytes\r
+ uint8_t bDescriptorType; // CS_INTERFACE descriptor type\r
+ uint8_t bDescriptorSubtype; // abstract control management functional descriptor subtype\r
+ uint8_t bmCapabilities; // capabilities supported by this configuration\r
+} CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR;\r
+\r
+// Union functional descriptors\r
+// (usbcdc11.pdf, 5.2.3.8)\r
+// Describes the relationship between a group of interfaces that can be considered to form a functional unit.\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _CDC_UNION_DESCRIPTOR{\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _CDC_UNION_DESCRIPTOR{\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _CDC_UNION_DESCRIPTOR {\r
+#endif\r
+ uint8_t bFunctionLength; // size of this descriptor in bytes\r
+ uint8_t bDescriptorType; // CS_INTERFACE descriptor type\r
+ uint8_t bDescriptorSubtype; // union functional descriptor subtype\r
+ uint8_t bMasterInterface; // interface number designated as master\r
+} CDC_UNION_DESCRIPTOR;\r
+\r
+// Union functional descriptors with one slave interface\r
+// (usbcdc11.pdf, 5.2.3.8)\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _CDC_UNION_1SLAVE_DESCRIPTOR{\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _CDC_UNION_1SLAVE_DESCRIPTOR{\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _CDC_UNION_1SLAVE_DESCRIPTOR {\r
+#endif\r
+ CDC_UNION_DESCRIPTOR sUnion; // Union functional descriptor\r
+ uint8_t bSlaveInterfaces[1]; // Slave interface 0\r
+} CDC_UNION_1SLAVE_DESCRIPTOR;\r
+\r
+// Line coding structure\r
+// Format of the data returned when a GetLineCoding request is received\r
+// (usbcdc11.pdf, 6.2.13)\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _CDC_LINE_CODING{\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _CDC_LINE_CODING{\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _CDC_LINE_CODING {\r
+#endif\r
+ uint32_t dwDTERate; // Data terminal rate in bits per second\r
+ uint8_t bCharFormat; // Number of stop bits\r
+ uint8_t bParityType; // Parity bit type\r
+ uint8_t bDataBits; // Number of data bits\r
+} CDC_LINE_CODING;\r
+\r
+// Notification header\r
+// Data sent on the notification endpoint must follow this header.\r
+// see USB_SETUP_PACKET in file usb.h\r
+typedef USB_SETUP_PACKET CDC_NOTIFICATION_HEADER;\r
+\r
+#endif /* __CDC_H */\r
+\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: cdcuser.c\r
+ * Purpose: USB Communication Device Class User module\r
+ * Version: V1.10\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 "lpc_types.h"\r
+\r
+#include "usb.h"\r
+#include "usbhw.h"\r
+#include "usbcfg.h"\r
+#include "usbcore.h"\r
+#include "cdc.h"\r
+#include "cdcuser.h"\r
+#include "serial.h"\r
+\r
+\r
+unsigned char BulkBufIn [USB_CDC_BUFSIZE]; // Buffer to store USB IN packet\r
+unsigned char BulkBufOut [USB_CDC_BUFSIZE]; // Buffer to store USB OUT packet\r
+unsigned char NotificationBuf [10];\r
+\r
+CDC_LINE_CODING CDC_LineCoding = {9600, 0, 0, 8};\r
+unsigned short CDC_SerialState = 0x0000;\r
+unsigned short CDC_DepInEmpty = 1; // Data IN EP is empty\r
+\r
+/*----------------------------------------------------------------------------\r
+ We need a buffer for incomming data on USB port because USB receives\r
+ much faster than UART transmits\r
+ *---------------------------------------------------------------------------*/\r
+/* Buffer masks */\r
+#define CDC_BUF_SIZE (64) // Output buffer in bytes (power 2)\r
+ // large enough for file transfer\r
+#define CDC_BUF_MASK (CDC_BUF_SIZE-1ul)\r
+\r
+/* Buffer read / write macros */\r
+#define CDC_BUF_RESET(cdcBuf) (cdcBuf.rdIdx = cdcBuf.wrIdx = 0)\r
+#define CDC_BUF_WR(cdcBuf, dataIn) (cdcBuf.data[CDC_BUF_MASK & cdcBuf.wrIdx++] = (dataIn))\r
+#define CDC_BUF_RD(cdcBuf) (cdcBuf.data[CDC_BUF_MASK & cdcBuf.rdIdx++])\r
+#define CDC_BUF_EMPTY(cdcBuf) (cdcBuf.rdIdx == cdcBuf.wrIdx)\r
+#define CDC_BUF_FULL(cdcBuf) (cdcBuf.rdIdx == cdcBuf.wrIdx+1)\r
+#define CDC_BUF_COUNT(cdcBuf) (CDC_BUF_MASK & (cdcBuf.wrIdx - cdcBuf.rdIdx))\r
+\r
+\r
+// CDC output buffer\r
+typedef struct __CDC_BUF_T {\r
+ unsigned char data[CDC_BUF_SIZE];\r
+ unsigned int wrIdx;\r
+ unsigned int rdIdx;\r
+} CDC_BUF_T;\r
+\r
+CDC_BUF_T CDC_OutBuf; // buffer for all CDC Out data\r
+\r
+/*----------------------------------------------------------------------------\r
+ read data from CDC_OutBuf\r
+ *---------------------------------------------------------------------------*/\r
+int CDC_RdOutBuf (char *buffer, const int *length) {\r
+ int bytesToRead, bytesRead;\r
+\r
+ /* Read *length bytes, block if *bytes are not avaialable */\r
+ bytesToRead = *length;\r
+ bytesToRead = (bytesToRead < (*length)) ? bytesToRead : (*length);\r
+ bytesRead = bytesToRead;\r
+\r
+\r
+ // ... add code to check for underrun\r
+\r
+ while (bytesToRead--) {\r
+ *buffer++ = CDC_BUF_RD(CDC_OutBuf);\r
+ }\r
+ return (bytesRead);\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ write data to CDC_OutBuf\r
+ *---------------------------------------------------------------------------*/\r
+int CDC_WrOutBuf (const char *buffer, int *length) {\r
+ int bytesToWrite, bytesWritten;\r
+\r
+ // Write *length bytes\r
+ bytesToWrite = *length;\r
+ bytesWritten = bytesToWrite;\r
+\r
+\r
+ // ... add code to check for overwrite\r
+\r
+ while (bytesToWrite) {\r
+ CDC_BUF_WR(CDC_OutBuf, *buffer++); // Copy Data to buffer\r
+ bytesToWrite--;\r
+ }\r
+\r
+ return (bytesWritten);\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ check if character(s) are available at CDC_OutBuf\r
+ *---------------------------------------------------------------------------*/\r
+int CDC_OutBufAvailChar (int *availChar) {\r
+\r
+ *availChar = CDC_BUF_COUNT(CDC_OutBuf);\r
+\r
+ return (0);\r
+}\r
+/* end Buffer handling */\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC Initialisation\r
+ Initializes the data structures and serial port\r
+ Parameters: None\r
+ Return Value: None\r
+ *---------------------------------------------------------------------------*/\r
+void CDC_Init (char portNum ) {\r
+\r
+ if ( portNum == 0 )\r
+ {\r
+ ser_OpenPort (0);\r
+ ser_InitPort0 (CDC_LineCoding.dwDTERate,\r
+ CDC_LineCoding.bDataBits,\r
+ CDC_LineCoding.bParityType,\r
+ CDC_LineCoding.bCharFormat);\r
+ }\r
+ else\r
+ {\r
+ ser_OpenPort (1);\r
+ ser_InitPort1 (CDC_LineCoding.dwDTERate,\r
+ CDC_LineCoding.bDataBits,\r
+ CDC_LineCoding.bParityType,\r
+ CDC_LineCoding.bCharFormat);\r
+ }\r
+ CDC_DepInEmpty = 1;\r
+ CDC_SerialState = CDC_GetSerialState();\r
+\r
+ CDC_BUF_RESET(CDC_OutBuf);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC SendEncapsulatedCommand Request Callback\r
+ Called automatically on CDC SEND_ENCAPSULATED_COMMAND Request\r
+ Parameters: None (global SetupPacket and EP0Buf)\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_SendEncapsulatedCommand (void) {\r
+\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC GetEncapsulatedResponse Request Callback\r
+ Called automatically on CDC Get_ENCAPSULATED_RESPONSE Request\r
+ Parameters: None (global SetupPacket and EP0Buf)\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_GetEncapsulatedResponse (void) {\r
+\r
+ /* ... add code to handle request */\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC SetCommFeature Request Callback\r
+ Called automatically on CDC Set_COMM_FATURE Request\r
+ Parameters: FeatureSelector\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_SetCommFeature (unsigned short wFeatureSelector) {\r
+\r
+ /* ... add code to handle request */\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC GetCommFeature Request Callback\r
+ Called automatically on CDC Get_COMM_FATURE Request\r
+ Parameters: FeatureSelector\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_GetCommFeature (unsigned short wFeatureSelector) {\r
+\r
+ /* ... add code to handle request */\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC ClearCommFeature Request Callback\r
+ Called automatically on CDC CLEAR_COMM_FATURE Request\r
+ Parameters: FeatureSelector\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_ClearCommFeature (unsigned short wFeatureSelector) {\r
+\r
+ /* ... add code to handle request */\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC SetLineCoding Request Callback\r
+ Called automatically on CDC SET_LINE_CODING Request\r
+ Parameters: none (global SetupPacket and EP0Buf)\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_SetLineCoding (void) {\r
+\r
+ CDC_LineCoding.dwDTERate = (EP0Buf[0] << 0)\r
+ | (EP0Buf[1] << 8)\r
+ | (EP0Buf[2] << 16)\r
+ | (EP0Buf[3] << 24);\r
+ CDC_LineCoding.bCharFormat = EP0Buf[4];\r
+ CDC_LineCoding.bParityType = EP0Buf[5];\r
+ CDC_LineCoding.bDataBits = EP0Buf[6];\r
+\r
+#if PORT_NUM\r
+ ser_ClosePort(1);\r
+ ser_OpenPort (1);\r
+ ser_InitPort1 (CDC_LineCoding.dwDTERate,\r
+ CDC_LineCoding.bDataBits,\r
+ CDC_LineCoding.bParityType,\r
+ CDC_LineCoding.bCharFormat);\r
+#else\r
+ ser_ClosePort(0);\r
+ ser_OpenPort (0);\r
+ ser_InitPort0 (CDC_LineCoding.dwDTERate,\r
+ CDC_LineCoding.bDataBits,\r
+ CDC_LineCoding.bParityType,\r
+ CDC_LineCoding.bCharFormat);\r
+#endif\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC GetLineCoding Request Callback\r
+ Called automatically on CDC GET_LINE_CODING Request\r
+ Parameters: None (global SetupPacket and EP0Buf)\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_GetLineCoding (void) {\r
+\r
+ EP0Buf[0] = (CDC_LineCoding.dwDTERate >> 0) & 0xFF;\r
+ EP0Buf[1] = (CDC_LineCoding.dwDTERate >> 8) & 0xFF;\r
+ EP0Buf[2] = (CDC_LineCoding.dwDTERate >> 16) & 0xFF;\r
+ EP0Buf[3] = (CDC_LineCoding.dwDTERate >> 24) & 0xFF;\r
+ EP0Buf[4] = CDC_LineCoding.bCharFormat;\r
+ EP0Buf[5] = CDC_LineCoding.bParityType;\r
+ EP0Buf[6] = CDC_LineCoding.bDataBits;\r
+\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC SetControlLineState Request Callback\r
+ Called automatically on CDC SET_CONTROL_LINE_STATE Request\r
+ Parameters: ControlSignalBitmap\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_SetControlLineState (unsigned short wControlSignalBitmap) {\r
+\r
+ /* ... add code to handle request */\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC SendBreak Request Callback\r
+ Called automatically on CDC Set_COMM_FATURE Request\r
+ Parameters: 0xFFFF start of Break\r
+ 0x0000 stop of Break\r
+ 0x#### Duration of Break\r
+ Return Value: TRUE - Success, FALSE - Error\r
+ *---------------------------------------------------------------------------*/\r
+uint32_t CDC_SendBreak (unsigned short wDurationOfBreak) {\r
+\r
+ /* ... add code to handle request */\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC_BulkIn call on DataIn Request\r
+ Parameters: none\r
+ Return Value: none\r
+ *---------------------------------------------------------------------------*/\r
+void CDC_BulkIn(void) {\r
+ int numBytesRead, numBytesAvail;\r
+\r
+ ser_AvailChar (&numBytesAvail);\r
+\r
+ // ... add code to check for overwrite\r
+\r
+ numBytesRead = ser_Read ((char *)&BulkBufIn[0], &numBytesAvail);\r
+\r
+ // send over USB\r
+ if (numBytesRead > 0) {\r
+ USB_WriteEP (CDC_DEP_IN, &BulkBufIn[0], numBytesRead);\r
+ }\r
+ else {\r
+ CDC_DepInEmpty = 1;\r
+ }\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ CDC_BulkOut call on DataOut Request\r
+ Parameters: none\r
+ Return Value: none\r
+ *---------------------------------------------------------------------------*/\r
+void CDC_BulkOut(void) {\r
+ int numBytesRead;\r
+\r
+ // get data from USB into intermediate buffer\r
+ numBytesRead = USB_ReadEP(CDC_DEP_OUT, &BulkBufOut[0]);\r
+\r
+ // ... add code to check for overwrite\r
+\r
+ // store data in a buffer to transmit it over serial interface\r
+ CDC_WrOutBuf ((char *)&BulkBufOut[0], &numBytesRead);\r
+\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ Get the SERIAL_STATE as defined in usbcdc11.pdf, 6.3.5, Table 69.\r
+ Parameters: none\r
+ Return Value: SerialState as defined in usbcdc11.pdf\r
+ *---------------------------------------------------------------------------*/\r
+unsigned short CDC_GetSerialState (void) {\r
+ unsigned short temp;\r
+\r
+ CDC_SerialState = 0;\r
+ ser_LineState (&temp);\r
+\r
+ if (temp & 0x8000) CDC_SerialState |= CDC_SERIAL_STATE_RX_CARRIER;\r
+ if (temp & 0x2000) CDC_SerialState |= CDC_SERIAL_STATE_TX_CARRIER;\r
+ if (temp & 0x0010) CDC_SerialState |= CDC_SERIAL_STATE_BREAK;\r
+ if (temp & 0x4000) CDC_SerialState |= CDC_SERIAL_STATE_RING;\r
+ if (temp & 0x0008) CDC_SerialState |= CDC_SERIAL_STATE_FRAMING;\r
+ if (temp & 0x0004) CDC_SerialState |= CDC_SERIAL_STATE_PARITY;\r
+ if (temp & 0x0002) CDC_SerialState |= CDC_SERIAL_STATE_OVERRUN;\r
+\r
+ return (CDC_SerialState);\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ Send the SERIAL_STATE notification as defined in usbcdc11.pdf, 6.3.5.\r
+ *---------------------------------------------------------------------------*/\r
+void CDC_NotificationIn (void) {\r
+\r
+ NotificationBuf[0] = 0xA1; // bmRequestType\r
+ NotificationBuf[1] = CDC_NOTIFICATION_SERIAL_STATE; // bNotification (SERIAL_STATE)\r
+ NotificationBuf[2] = 0x00; // wValue\r
+ NotificationBuf[3] = 0x00;\r
+ NotificationBuf[4] = 0x00; // wIndex (Interface #, LSB first)\r
+ NotificationBuf[5] = 0x00;\r
+ NotificationBuf[6] = 0x02; // wLength (Data length = 2 bytes, LSB first)\r
+ NotificationBuf[7] = 0x00;\r
+ NotificationBuf[8] = (CDC_SerialState >> 0) & 0xFF; // UART State Bitmap (16bits, LSB first)\r
+ NotificationBuf[9] = (CDC_SerialState >> 8) & 0xFF;\r
+\r
+ USB_WriteEP (CDC_CEP_IN, &NotificationBuf[0], 10); // send notification\r
+}\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: cdcuser.h\r
+ * Purpose: USB Communication Device Class User module Definitions\r
+ * Version: V1.10\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
+#ifndef __CDCUSER_H__\r
+#define __CDCUSER_H__\r
+\r
+/* CDC buffer handling */\r
+extern int CDC_RdOutBuf (char *buffer, const int *length);\r
+extern CDC_WrOutBuf (const char *buffer, int *length);\r
+extern CDC_OutBufAvailChar (int *availChar);\r
+\r
+\r
+/* CDC Data In/Out Endpoint Address */\r
+#define CDC_DEP_IN 0x82\r
+#define CDC_DEP_OUT 0x02\r
+\r
+/* CDC Communication In Endpoint Address */\r
+#define CDC_CEP_IN 0x81\r
+\r
+/* CDC Requests Callback Functions */\r
+extern uint32_t CDC_SendEncapsulatedCommand (void);\r
+extern uint32_t CDC_GetEncapsulatedResponse (void);\r
+extern uint32_t CDC_SetCommFeature (unsigned short wFeatureSelector);\r
+extern uint32_t CDC_GetCommFeature (unsigned short wFeatureSelector);\r
+extern uint32_t CDC_ClearCommFeature (unsigned short wFeatureSelector);\r
+extern uint32_t CDC_GetLineCoding (void);\r
+extern uint32_t CDC_SetLineCoding (void);\r
+extern uint32_t CDC_SetControlLineState (unsigned short wControlSignalBitmap);\r
+extern uint32_t CDC_SendBreak (unsigned short wDurationOfBreak);\r
+\r
+/* CDC Bulk Callback Functions */\r
+extern void CDC_BulkIn (void);\r
+extern void CDC_BulkOut (void);\r
+\r
+/* CDC Notification Callback Function */\r
+extern void CDC_NotificationIn (void);\r
+\r
+/* CDC Initializtion Function */\r
+extern void CDC_Init (char portNum);\r
+\r
+/* CDC prepare the SERAIAL_STATE */\r
+extern unsigned short CDC_GetSerialState (void);\r
+\r
+/* flow control */\r
+extern unsigned short CDC_DepInEmpty; // DataEndPoint IN empty\r
+\r
+#endif /* __CDCUSER_H__ */\r
+\r
--- /dev/null
+; \r
+; Keil - An ARM Company Comunication Device Class driver installation file\r
+; (C)2007 Copyright \r
+;\r
+\r
+[Version] \r
+Signature="$Windows NT$" \r
+Class=Ports\r
+ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} \r
+Provider=%Keil% \r
+;LayoutFile=layout.inf\r
+DriverVer=01/06/07\r
+\r
+[Manufacturer] \r
+%Keil%=DeviceList\r
+\r
+[DestinationDirs] \r
+DefaultDestDir=12 \r
+\r
+[SourceDisksFiles]\r
+\r
+[SourceDisksNames]\r
+\r
+[DeviceList] \r
+%DESCRIPTION%=LPC17xxUSB, USB\VID_1FC9&PID_2002 \r
+\r
+;------------------------------------------------------------------------------\r
+; Windows 2000/XP Sections\r
+;------------------------------------------------------------------------------\r
+\r
+[LPC17xxUSB.nt] \r
+include=mdmcpq.inf\r
+CopyFiles=DriverCopyFiles\r
+AddReg=LPC17xxUSB.nt.AddReg \r
+\r
+[DriverCopyFiles]\r
+usbser.sys,,,0x20\r
+\r
+[LPC17xxUSB.nt.AddReg] \r
+HKR,,DevLoader,,*ntkern \r
+HKR,,NTMPDriver,,usbser.sys \r
+HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" \r
+\r
+[LPC17xxUSB.nt.Services] \r
+include=mdmcpq.inf\r
+AddService=usbser, 0x00000002, DriverService\r
+\r
+\r
+[LPC17xxUSB.nt.HW]\r
+include=mdmcpq.inf\r
+\r
+[DriverService] \r
+DisplayName=%DESCRIPTION% \r
+ServiceType=1\r
+StartType=3\r
+ErrorControl=1\r
+ServiceBinary=%12%\usbser.sys \r
+\r
+;------------------------------------------------------------------------------\r
+; String Definitions\r
+;------------------------------------------------------------------------------\r
+\r
+[Strings] \r
+NXP="NXP - Founded by Philips"\r
+DESCRIPTION="LPC17xx USB VCom Port" \r
--- /dev/null
+/***********************************************************************//**\r
+ * @file lpc17xx_libcfg.h\r
+ * @purpose Library configuration file\r
+ * @version 2.0\r
+ * @date 21. May. 2010\r
+ * @author NXP MCU SW Application Team\r
+ **************************************************************************\r
+ * Software that is described herein is for illustrative purposes only\r
+ * which provides customers with programming information regarding the\r
+ * products. This software is supplied "AS IS" without any warranties.\r
+ * NXP Semiconductors assumes no responsibility or liability for the\r
+ * use of the software, conveys no license or title under any patent,\r
+ * copyright, or mask work right to the product. NXP Semiconductors\r
+ * reserves the right to make changes in the software without\r
+ * notification. NXP Semiconductors also make no representation or\r
+ * warranty that such application will be suitable for the specified\r
+ * use without further testing or modification.\r
+ **************************************************************************/\r
+\r
+#ifndef LPC17XX_LIBCFG_H_\r
+#define LPC17XX_LIBCFG_H_\r
+\r
+#include "lpc_types.h"\r
+\r
+\r
+/************************** DEBUG MODE DEFINITIONS *********************************/\r
+/* Un-comment the line below to compile the library in DEBUG mode, this will expanse\r
+ the "CHECK_PARAM" macro in the FW library code */\r
+\r
+#define DEBUG\r
+\r
+\r
+/******************* PERIPHERAL FW LIBRARY CONFIGURATION DEFINITIONS ***********************/\r
+\r
+/* Comment the line below to disable the specific peripheral inclusion */\r
+\r
+/* DEBUG_FRAMWORK -------------------- */\r
+///#define _DBGFWK\r
+\r
+/* GPIO ------------------------------- */\r
+//#define _GPIO\r
+\r
+/* EXTI ------------------------------- */\r
+//#define _EXTI\r
+\r
+/* UART ------------------------------- */\r
+//#define _UART\r
+//#define _UART0\r
+//#define _UART1\r
+//#define _UART2\r
+//#define _UART3\r
+\r
+/* SPI ------------------------------- */\r
+//#define _SPI\r
+\r
+/* SYSTICK --------------------------- */\r
+//#define _SYSTICK\r
+\r
+/* SSP ------------------------------- */\r
+//#define _SSP\r
+//#define _SSP0\r
+//#define _SSP1\r
+\r
+\r
+/* I2C ------------------------------- */\r
+//#define _I2C\r
+//#define _I2C0\r
+//#define _I2C1\r
+//#define _I2C2\r
+\r
+/* TIMER ------------------------------- */\r
+//#define _TIM\r
+\r
+/* WDT ------------------------------- */\r
+//#define _WDT\r
+\r
+\r
+/* GPDMA ------------------------------- */\r
+//#define _GPDMA\r
+\r
+\r
+/* DAC ------------------------------- */\r
+//#define _DAC\r
+\r
+/* DAC ------------------------------- */\r
+//#define _ADC\r
+\r
+\r
+/* PWM ------------------------------- */\r
+//#define _PWM\r
+//#define _PWM1\r
+\r
+/* RTC ------------------------------- */\r
+//#define _RTC\r
+\r
+/* I2S ------------------------------- */\r
+//#define _I2S\r
+\r
+/* USB device ------------------------------- */\r
+//#define _USBDEV\r
+//#define _USB_DMA\r
+\r
+/* QEI ------------------------------- */\r
+//#define _QEI\r
+\r
+/* MCPWM ------------------------------- */\r
+//#define _MCPWM\r
+\r
+/* CAN--------------------------------*/\r
+//#define _CAN\r
+\r
+/* RIT ------------------------------- */\r
+//#define _RIT\r
+\r
+/* EMAC ------------------------------ */\r
+//#define _EMAC\r
+\r
+/************************** GLOBAL/PUBLIC MACRO DEFINITIONS *********************************/\r
+\r
+#ifdef DEBUG\r
+/*******************************************************************************\r
+* @brief The CHECK_PARAM macro is used for function's parameters check.\r
+* It is used only if the library is compiled in DEBUG mode.\r
+* @param[in] expr - If expr is false, it calls check_failed() function\r
+* which reports the name of the source file and the source\r
+* line number of the call that failed.\r
+* - If expr is true, it returns no value.\r
+* @return None\r
+*******************************************************************************/\r
+#define CHECK_PARAM(expr) ((expr) ? (void)0 : check_failed((uint8_t *)__FILE__, __LINE__))\r
+#else\r
+#define CHECK_PARAM(expr)\r
+#endif /* DEBUG */\r
+\r
+\r
+\r
+/************************** GLOBAL/PUBLIC FUNCTION DECLARATION *********************************/\r
+\r
+#ifdef DEBUG\r
+void check_failed(uint8_t *file, uint32_t line);\r
+#endif\r
+\r
+\r
+#endif /* LPC17XX_LIBCFG_H_ */\r
--- /dev/null
+/***********************************************************************//**\r
+ * @file lpc_types.h\r
+ * @brief Contains the NXP ABL typedefs for C standard types.\r
+ * It is intended to be used in ISO C conforming development\r
+ * environments and checks for this insofar as it is possible\r
+ * to do so.\r
+ * @version 1.0\r
+ * @date 27 Jul. 2008\r
+ * @author wellsk\r
+ **************************************************************************\r
+ * Software that is described herein is for illustrative purposes only\r
+ * which provides customers with programming information regarding the\r
+ * products. This software is supplied "AS IS" without any warranties.\r
+ * NXP Semiconductors assumes no responsibility or liability for the\r
+ * use of the software, conveys no license or title under any patent,\r
+ * copyright, or mask work right to the product. NXP Semiconductors\r
+ * reserves the right to make changes in the software without\r
+ * notification. NXP Semiconductors also make no representation or\r
+ * warranty that such application will be suitable for the specified\r
+ * use without further testing or modification.\r
+ **************************************************************************/\r
+\r
+/* Type group ----------------------------------------------------------- */\r
+/** @defgroup LPC_Types LPC_Types\r
+ * @ingroup LPC1700CMSIS_FwLib_Drivers\r
+ * @{\r
+ */\r
+\r
+#ifndef LPC_TYPES_H\r
+#define LPC_TYPES_H\r
+\r
+/* Includes ------------------------------------------------------------------- */\r
+#include <stdint.h>\r
+\r
+\r
+/* Public Types --------------------------------------------------------------- */\r
+/** @defgroup LPC_Types_Public_Types LPC_Types Public Types\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @brief Boolean Type definition\r
+ */\r
+typedef enum {FALSE = 0, TRUE = !FALSE} Bool;\r
+\r
+/**\r
+ * @brief Flag Status and Interrupt Flag Status type definition\r
+ */\r
+typedef enum {RESET = 0, SET = !RESET} FlagStatus, IntStatus, SetState;\r
+#define PARAM_SETSTATE(State) ((State==RESET) || (State==SET))\r
+\r
+/**\r
+ * @brief Functional State Definition\r
+ */\r
+typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;\r
+#define PARAM_FUNCTIONALSTATE(State) ((State==DISABLE) || (State==ENABLE))\r
+\r
+/**\r
+ * @ Status type definition\r
+ */\r
+typedef enum {ERROR = 0, SUCCESS = !ERROR} Status;\r
+\r
+\r
+/**\r
+ * Read/Write transfer type mode (Block or non-block)\r
+ */\r
+typedef enum\r
+{\r
+ NONE_BLOCKING = 0, /**< None Blocking type */\r
+ BLOCKING, /**< Blocking type */\r
+} TRANSFER_BLOCK_Type;\r
+\r
+\r
+/** Pointer to Function returning Void (any number of parameters) */\r
+typedef void (*PFV)();\r
+\r
+/** Pointer to Function returning int32_t (any number of parameters) */\r
+typedef int32_t(*PFI)();\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+\r
+/* Public Macros -------------------------------------------------------------- */\r
+/** @defgroup LPC_Types_Public_Macros LPC_Types Public Macros\r
+ * @{\r
+ */\r
+\r
+/* _BIT(n) sets the bit at position "n"\r
+ * _BIT(n) is intended to be used in "OR" and "AND" expressions:\r
+ * e.g., "(_BIT(3) | _BIT(7))".\r
+ */\r
+#undef _BIT\r
+/* Set bit macro */\r
+#define _BIT(n) (1<<n)\r
+\r
+/* _SBF(f,v) sets the bit field starting at position "f" to value "v".\r
+ * _SBF(f,v) is intended to be used in "OR" and "AND" expressions:\r
+ * e.g., "((_SBF(5,7) | _SBF(12,0xF)) & 0xFFFF)"\r
+ */\r
+#undef _SBF\r
+/* Set bit field macro */\r
+#define _SBF(f,v) (v<<f)\r
+\r
+/* _BITMASK constructs a symbol with 'field_width' least significant\r
+ * bits set.\r
+ * e.g., _BITMASK(5) constructs '0x1F', _BITMASK(16) == 0xFFFF\r
+ * The symbol is intended to be used to limit the bit field width\r
+ * thusly:\r
+ * <a_register> = (any_expression) & _BITMASK(x), where 0 < x <= 32.\r
+ * If "any_expression" results in a value that is larger than can be\r
+ * contained in 'x' bits, the bits above 'x - 1' are masked off. When\r
+ * used with the _SBF example above, the example would be written:\r
+ * a_reg = ((_SBF(5,7) | _SBF(12,0xF)) & _BITMASK(16))\r
+ * This ensures that the value written to a_reg is no wider than\r
+ * 16 bits, and makes the code easier to read and understand.\r
+ */\r
+#undef _BITMASK\r
+/* Bitmask creation macro */\r
+#define _BITMASK(field_width) ( _BIT(field_width) - 1)\r
+\r
+/* NULL pointer */\r
+#ifndef NULL\r
+#define NULL ((void*) 0)\r
+#endif\r
+\r
+/* Number of elements in an array */\r
+#define NELEMENTS(array) (sizeof (array) / sizeof (array[0]))\r
+\r
+/* Static data/function define */\r
+#define STATIC static\r
+/* External data/function define */\r
+#define EXTERN extern\r
+\r
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))\r
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+\r
+/* Old Type Definition compatibility ------------------------------------------ */\r
+/** @addtogroup LPC_Types_Public_Types LPC_Types Public Types\r
+ * @{\r
+ */\r
+\r
+/** SMA type for character type */\r
+typedef char CHAR;\r
+\r
+/** SMA type for 8 bit unsigned value */\r
+typedef uint8_t UNS_8;\r
+\r
+/** SMA type for 8 bit signed value */\r
+typedef int8_t INT_8;\r
+\r
+/** SMA type for 16 bit unsigned value */\r
+typedef uint16_t UNS_16;\r
+\r
+/** SMA type for 16 bit signed value */\r
+typedef int16_t INT_16;\r
+\r
+/** SMA type for 32 bit unsigned value */\r
+typedef uint32_t UNS_32;\r
+\r
+/** SMA type for 32 bit signed value */\r
+typedef int32_t INT_32;\r
+\r
+/** SMA type for 64 bit signed value */\r
+typedef int64_t INT_64;\r
+\r
+/** SMA type for 64 bit unsigned value */\r
+typedef uint64_t UNS_64;\r
+\r
+/** 32 bit boolean type */\r
+typedef Bool BOOL_32;\r
+\r
+/** 16 bit boolean type */\r
+typedef Bool BOOL_16;\r
+\r
+/** 8 bit boolean type */\r
+typedef Bool BOOL_8;\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+\r
+#endif /* LPC_TYPES_H */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/* --------------------------------- End Of File ------------------------------ */\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * Name: serial.c\r
+ * Purpose: serial port handling for LPC17xx\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
+#include "../LPC17xx.h" // LPC17xx definitions\r
+#include "lpc_types.h"\r
+#include "serial.h"\r
+\r
+\r
+/*----------------------------------------------------------------------------\r
+ Defines for ring buffers\r
+ *---------------------------------------------------------------------------*/\r
+#define SER_BUF_SIZE (128) // serial buffer in bytes (power 2)\r
+#define SER_BUF_MASK (SER_BUF_SIZE-1ul) // buffer size mask\r
+\r
+/* Buffer read / write macros */\r
+#define SER_BUF_RESET(serBuf) (serBuf.rdIdx = serBuf.wrIdx = 0)\r
+#define SER_BUF_WR(serBuf, dataIn) (serBuf.data[SER_BUF_MASK & serBuf.wrIdx++] = (dataIn))\r
+#define SER_BUF_RD(serBuf) (serBuf.data[SER_BUF_MASK & serBuf.rdIdx++])\r
+#define SER_BUF_EMPTY(serBuf) (serBuf.rdIdx == serBuf.wrIdx)\r
+#define SER_BUF_FULL(serBuf) (serBuf.rdIdx == serBuf.wrIdx+1)\r
+#define SER_BUF_COUNT(serBuf) (SER_BUF_MASK & (serBuf.wrIdx - serBuf.rdIdx))\r
+\r
+// buffer type\r
+typedef struct __SER_BUF_T {\r
+ unsigned char data[SER_BUF_SIZE];\r
+ unsigned int wrIdx;\r
+ unsigned int rdIdx;\r
+} SER_BUF_T;\r
+\r
+unsigned long ser_txRestart; // NZ if TX restart is required\r
+unsigned short ser_lineState; // ((msr << 8) | (lsr))\r
+SER_BUF_T ser_out; // Serial data buffers\r
+SER_BUF_T ser_in;\r
+\r
+/*----------------------------------------------------------------------------\r
+ open the serial port\r
+ *---------------------------------------------------------------------------*/\r
+void ser_OpenPort (char portNum) {\r
+\r
+ if ( portNum == 0 )\r
+ {\r
+ /* Port 0 */\r
+ NVIC_DisableIRQ(UART0_IRQn);\r
+ PINCON->PINSEL0 &= ~0x000000F0;\r
+ PINCON->PINSEL0 |= 0x00000050; /* RxD0 is P0.3 and TxD0 is P0.2 */\r
+ }\r
+ else\r
+ {\r
+ /* Port 1 */\r
+ NVIC_DisableIRQ(UART1_IRQn);\r
+ PINCON->PINSEL4 &= ~0x0000000F;\r
+ PINCON->PINSEL4 |= 0x0000000A; /* Enable RxD1 P2.1, TxD1 P2.0 */\r
+ }\r
+ return;\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ close the serial port\r
+ *---------------------------------------------------------------------------*/\r
+void ser_ClosePort (char portNum ) {\r
+ if ( portNum == 0 )\r
+ {\r
+ /* POrt 0 */\r
+ PINCON->PINSEL0 &= ~0x000000F0;\r
+ /* Disable the interrupt in the VIC and UART controllers */\r
+ UART0->IER = 0;\r
+ NVIC_DisableIRQ(UART0_IRQn);\r
+ }\r
+ else\r
+ {\r
+ /* Port 1 */\r
+ PINCON->PINSEL4 &= ~0x0000000F;\r
+ /* Disable the interrupt in the VIC and UART controllers */\r
+ UART1->IER = 0;\r
+ NVIC_DisableIRQ(UART1_IRQn);\r
+ }\r
+ return;\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ initialize the serial port\r
+ *---------------------------------------------------------------------------*/\r
+void ser_InitPort0 (unsigned long baudrate, unsigned int databits,\r
+ unsigned int parity, unsigned int stopbits) {\r
+\r
+ unsigned char lcr_p, lcr_s, lcr_d;\r
+ unsigned int dll;\r
+ unsigned int pclkdiv, pclk;\r
+\r
+ switch (databits) {\r
+ case 5: // 5 Data bits\r
+ lcr_d = 0x00;\r
+ break;\r
+ case 6: // 6 Data bits\r
+ lcr_d = 0x01;\r
+ break;\r
+ case 7: // 7 Data bits\r
+ lcr_d = 0x02;\r
+ break;\r
+ case 8: // 8 Data bits\r
+ default:\r
+ lcr_d = 0x03;\r
+ break;\r
+ }\r
+\r
+ switch (stopbits) {\r
+ case 1: // 1,5 Stop bits\r
+ case 2: // 2 Stop bits\r
+ lcr_s = 0x04;\r
+ break;\r
+ case 0: // 1 Stop bit\r
+ default:\r
+ lcr_s = 0x00;\r
+ break;\r
+ }\r
+\r
+ switch (parity) {\r
+ case 1: // Parity Odd\r
+ lcr_p = 0x08;\r
+ break;\r
+ case 2: // Parity Even\r
+ lcr_p = 0x18;\r
+ break;\r
+ case 3: // Parity Mark\r
+ lcr_p = 0x28;\r
+ break;\r
+ case 4: // Parity Space\r
+ lcr_p = 0x38;\r
+ break;\r
+ case 0: // Parity None\r
+ default:\r
+ lcr_p = 0x00;\r
+ break;\r
+ }\r
+\r
+ SER_BUF_RESET(ser_out); // reset out buffer\r
+ SER_BUF_RESET(ser_in); // reset in buffer\r
+\r
+ /* Bit 6~7 is for UART0 */\r
+ pclkdiv = (SC->PCLKSEL0 >> 6) & 0x03;\r
+\r
+ switch ( pclkdiv )\r
+ {\r
+ case 0x00:\r
+ default:\r
+ pclk = SystemFrequency/4;\r
+ break;\r
+ case 0x01:\r
+ pclk = SystemFrequency;\r
+ break;\r
+ case 0x02:\r
+ pclk = SystemFrequency/2;\r
+ break;\r
+ case 0x03:\r
+ pclk = SystemFrequency/8;\r
+ break;\r
+ }\r
+\r
+ dll = (pclk/16)/baudrate ; /*baud rate */\r
+ UART0->FDR = 0; // Fractional divider not used\r
+ UART0->LCR = 0x80 | lcr_d | lcr_p | lcr_s; // Data bits, Parity, Stop bit\r
+ UART0->DLL = dll; // Baud Rate depending on PCLK\r
+ UART0->DLM = (dll >> 8); // High divisor latch\r
+ UART0->LCR = 0x00 | lcr_d | lcr_p | lcr_s; // DLAB = 0\r
+ UART0->IER = 0x03; // Enable TX/RX interrupts\r
+\r
+ UART0->FCR = 0x07; /* Enable and reset TX and RX FIFO. */\r
+ ser_txRestart = 1; // TX fifo is empty\r
+\r
+ /* Enable the UART Interrupt */\r
+ NVIC_EnableIRQ(UART0_IRQn);\r
+ return;\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ initialize the serial port\r
+ *---------------------------------------------------------------------------*/\r
+void ser_InitPort1 (unsigned long baudrate, unsigned int databits,\r
+ unsigned int parity, unsigned int stopbits) {\r
+\r
+ unsigned char lcr_p, lcr_s, lcr_d;\r
+ unsigned int dll;\r
+ unsigned int pclkdiv, pclk;\r
+\r
+ switch (databits) {\r
+ case 5: // 5 Data bits\r
+ lcr_d = 0x00;\r
+ break;\r
+ case 6: // 6 Data bits\r
+ lcr_d = 0x01;\r
+ break;\r
+ case 7: // 7 Data bits\r
+ lcr_d = 0x02;\r
+ break;\r
+ case 8: // 8 Data bits\r
+ default:\r
+ lcr_d = 0x03;\r
+ break;\r
+ }\r
+\r
+ switch (stopbits) {\r
+ case 1: // 1,5 Stop bits\r
+ case 2: // 2 Stop bits\r
+ lcr_s = 0x04;\r
+ break;\r
+ case 0: // 1 Stop bit\r
+ default:\r
+ lcr_s = 0x00;\r
+ break;\r
+ }\r
+\r
+ switch (parity) {\r
+ case 1: // Parity Odd\r
+ lcr_p = 0x08;\r
+ break;\r
+ case 2: // Parity Even\r
+ lcr_p = 0x18;\r
+ break;\r
+ case 3: // Parity Mark\r
+ lcr_p = 0x28;\r
+ break;\r
+ case 4: // Parity Space\r
+ lcr_p = 0x38;\r
+ break;\r
+ case 0: // Parity None\r
+ default:\r
+ lcr_p = 0x00;\r
+ break;\r
+ }\r
+\r
+ SER_BUF_RESET(ser_out); // reset out buffer\r
+ SER_BUF_RESET(ser_in); // reset in buffer\r
+\r
+ /* Bit 8,9 are for UART1 */\r
+ pclkdiv = (SC->PCLKSEL0 >> 8) & 0x03;\r
+\r
+ switch ( pclkdiv )\r
+ {\r
+ case 0x00:\r
+ default:\r
+ pclk = SystemFrequency/4;\r
+ break;\r
+ case 0x01:\r
+ pclk = SystemFrequency;\r
+ break;\r
+ case 0x02:\r
+ pclk = SystemFrequency/2;\r
+ break;\r
+ case 0x03:\r
+ pclk = SystemFrequency/8;\r
+ break;\r
+ }\r
+\r
+ dll = (pclk/16)/baudrate ; /*baud rate */\r
+ UART1->FDR = 0; // Fractional divider not used\r
+ UART1->LCR = 0x80 | lcr_d | lcr_p | lcr_s; // Data bits, Parity, Stop bit\r
+ UART1->DLL = dll; // Baud Rate depending on PCLK\r
+ UART1->DLM = (dll >> 8); // High divisor latch\r
+ UART1->LCR = 0x00 | lcr_d | lcr_p | lcr_s; // DLAB = 0\r
+ UART1->IER = 0x03; // Enable TX/RX interrupts\r
+\r
+ UART1->FCR = 0x07; /* Enable and reset TX and RX FIFO. */\r
+ ser_txRestart = 1; // TX fifo is empty\r
+\r
+ /* Enable the UART Interrupt */\r
+ NVIC_EnableIRQ(UART1_IRQn);\r
+ return;\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ read data from serial port\r
+ *---------------------------------------------------------------------------*/\r
+int ser_Read (char *buffer, const int *length) {\r
+ int bytesToRead, bytesRead;\r
+\r
+ /* Read *length bytes, block if *bytes are not avaialable */\r
+ bytesToRead = *length;\r
+ bytesToRead = (bytesToRead < (*length)) ? bytesToRead : (*length);\r
+ bytesRead = bytesToRead;\r
+\r
+ while (bytesToRead--) {\r
+ while (SER_BUF_EMPTY(ser_in)); // Block until data is available if none\r
+ *buffer++ = SER_BUF_RD(ser_in);\r
+ }\r
+ return (bytesRead);\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ write data to the serial port\r
+ *---------------------------------------------------------------------------*/\r
+int ser_Write (char portNum, const char *buffer, int *length) {\r
+ int bytesToWrite, bytesWritten;\r
+\r
+ // Write *length bytes\r
+ bytesToWrite = *length;\r
+ bytesWritten = bytesToWrite;\r
+\r
+ while (!SER_BUF_EMPTY(ser_out)); // Block until space is available if none\r
+ while (bytesToWrite) {\r
+ SER_BUF_WR(ser_out, *buffer++); // Read Rx FIFO to buffer\r
+ bytesToWrite--;\r
+ }\r
+\r
+ if (ser_txRestart) {\r
+ ser_txRestart = 0;\r
+ if ( portNum == 0 )\r
+ {\r
+ UART0->THR = SER_BUF_RD(ser_out); // Write to the Tx Register\r
+ }\r
+ else\r
+ {\r
+ UART1->THR = SER_BUF_RD(ser_out); // Write to the Tx Register\r
+ }\r
+ }\r
+\r
+ return (bytesWritten);\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ check if character(s) are available at the serial interface\r
+ *---------------------------------------------------------------------------*/\r
+void ser_AvailChar (int *availChar) {\r
+\r
+ *availChar = SER_BUF_COUNT(ser_in);\r
+\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ read the line state of the serial port\r
+ *---------------------------------------------------------------------------*/\r
+void ser_LineState (unsigned short *lineState) {\r
+\r
+ *lineState = ser_lineState;\r
+ ser_lineState = 0;\r
+\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ serial port 0 interrupt\r
+ *---------------------------------------------------------------------------*/\r
+void UART0_IRQHandler(void)\r
+{\r
+ volatile unsigned long iir;\r
+\r
+ iir = UART0->IIR;\r
+\r
+ if ((iir & 0x4) || (iir & 0xC)) { // RDA or CTI pending\r
+ while (UART0->LSR & 0x01) { // Rx FIFO is not empty\r
+ SER_BUF_WR(ser_in, UART0->RBR); // Read Rx FIFO to buffer\r
+ }\r
+ }\r
+ if ((iir & 0x2)) { // TXMIS pending\r
+ if (SER_BUF_COUNT(ser_out) != 0) {\r
+ UART0->THR = SER_BUF_RD(ser_out); // Write to the Tx FIFO\r
+ ser_txRestart = 0;\r
+ }\r
+ else {\r
+ ser_txRestart = 1;\r
+ }\r
+ }\r
+ ser_lineState = UART0->LSR & 0x1E; // update linestate\r
+ return;\r
+}\r
+\r
+/*----------------------------------------------------------------------------\r
+ serial port 1 interrupt\r
+ *---------------------------------------------------------------------------*/\r
+void UART1_IRQHandler(void)\r
+{\r
+ volatile unsigned long iir;\r
+\r
+ iir = UART1->IIR;\r
+\r
+ if ((iir & 0x4) || (iir & 0xC)) { // RDA or CTI pending\r
+ while (UART1->LSR & 0x01) { // Rx FIFO is not empty\r
+ SER_BUF_WR(ser_in, UART1->RBR); // Read Rx FIFO to buffer\r
+ }\r
+ }\r
+ if ((iir & 0x2)) { // TXMIS pending\r
+ if (SER_BUF_COUNT(ser_out) != 0) {\r
+ UART1->THR = SER_BUF_RD(ser_out); // Write to the Tx FIFO\r
+ ser_txRestart = 0;\r
+ }\r
+ else {\r
+ ser_txRestart = 1;\r
+ }\r
+ }\r
+ ser_lineState = ((UART1->MSR<<8)|UART1->LSR) & 0xE01E; // update linestate\r
+ return;\r
+}\r
+\r
+\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * Name: serial.h\r
+ * Purpose: serial port handling\r
+ * Version: V1.10\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
+#define PORT_NUM 1\r
+\r
+/*----------------------------------------------------------------------------\r
+ Serial interface related prototypes\r
+ *---------------------------------------------------------------------------*/\r
+extern void ser_OpenPort (char portNum);\r
+extern void ser_ClosePort (char portNum);\r
+extern void ser_InitPort0 (unsigned long baudrate, unsigned int databits, unsigned int parity, unsigned int stopbits);\r
+extern void ser_InitPort1 (unsigned long baudrate, unsigned int databits, unsigned int parity, unsigned int stopbits);\r
+extern void ser_AvailChar (int *availChar);\r
+extern int ser_Write (char portNum, const char *buffer, int *length);\r
+extern int ser_Read (char *buffer, const int *length);\r
+extern void ser_LineState (unsigned short *lineState);\r
+\r
--- /dev/null
+//*****************************************************************************\r
+//\r
+// startup_gcc.c - Startup code for use with GNU tools.\r
+//\r
+// Copyright (c) 2009 Luminary Micro, Inc. All rights reserved.\r
+// Software License Agreement\r
+// \r
+// Luminary Micro, Inc. (LMI) is supplying this software for use solely and\r
+// exclusively on LMI's microcontroller products.\r
+// \r
+// The software is owned by LMI and/or its suppliers, and is protected under\r
+// applicable copyright laws. All rights are reserved. You may not combine\r
+// this software with "viral" open-source software in order to form a larger\r
+// program. Any use in violation of the foregoing restrictions may subject\r
+// the user to criminal sanctions under applicable laws, as well as to civil\r
+// liability for the breach of the terms and conditions of this license.\r
+// \r
+// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
+// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
+// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
+// \r
+// This is part of revision 32 of the Stellaris CMSIS Package.\r
+//\r
+//*****************************************************************************\r
+\r
+#define WEAK __attribute__ ((weak))\r
+\r
+//*****************************************************************************\r
+//\r
+// Forward declaration of the default fault handlers.\r
+//\r
+//*****************************************************************************\r
+void WEAK Reset_Handler(void);\r
+static void Default_Handler(void);\r
+void WEAK NMI_Handler(void);\r
+void WEAK HardFault_Handler(void);\r
+void WEAK MemManage_Handler(void);\r
+void WEAK BusFault_Handler(void);\r
+void WEAK UsageFault_Handler(void);\r
+void WEAK MemManage_Handler(void);\r
+void WEAK SVC_Handler(void);\r
+void WEAK DebugMon_Handler(void);\r
+void WEAK PendSV_Handler(void);\r
+void WEAK SysTick_Handler(void);\r
+void WEAK GPIOPortA_IRQHandler(void);\r
+void WEAK GPIOPortB_IRQHandler(void);\r
+void WEAK GPIOPortC_IRQHandler(void);\r
+void WEAK GPIOPortD_IRQHandler(void);\r
+void WEAK GPIOPortE_IRQHandler(void);\r
+void WEAK UART0_IRQHandler(void);\r
+void WEAK UART1_IRQHandler(void);\r
+void WEAK SSI0_IRQHandler(void);\r
+void WEAK I2C0_IRQHandler(void);\r
+void WEAK PWMFault_IRQHandler(void);\r
+void WEAK PWMGen0_IRQHandler(void);\r
+void WEAK PWMGen1_IRQHandler(void);\r
+void WEAK PWMGen2_IRQHandler(void);\r
+void WEAK QEI0_IRQHandler(void);\r
+void WEAK ADCSeq0_IRQHandler(void);\r
+void WEAK ADCSeq1_IRQHandler(void);\r
+void WEAK ADCSeq2_IRQHandler(void);\r
+void WEAK ADCSeq3_IRQHandler(void);\r
+void WEAK Watchdog_IRQHandler(void);\r
+void WEAK Timer0A_IRQHandler(void);\r
+void WEAK Timer0B_IRQHandler(void);\r
+void WEAK Timer1A_IRQHandler(void);\r
+void WEAK Timer1B_IRQHandler(void);\r
+void WEAK Timer2A_IRQHandler(void);\r
+void WEAK Timer2B_IRQHandler(void);\r
+void WEAK Comp0_IRQHandler(void);\r
+void WEAK Comp1_IRQHandler(void);\r
+void WEAK Comp2_IRQHandler(void);\r
+void WEAK SysCtrl_IRQHandler(void);\r
+void WEAK FlashCtrl_IRQHandler(void);\r
+void WEAK GPIOPortF_IRQHandler(void);\r
+void WEAK GPIOPortG_IRQHandler(void);\r
+void WEAK GPIOPortH_IRQHandler(void);\r
+void WEAK UART2_IRQHandler(void);\r
+void WEAK SSI1_IRQHandler(void);\r
+void WEAK Timer3A_IRQHandler(void);\r
+void WEAK Timer3B_IRQHandler(void);\r
+void WEAK I2C1_IRQHandler(void);\r
+void WEAK QEI1_IRQHandler(void);\r
+void WEAK CAN0_IRQHandler(void);\r
+void WEAK CAN1_IRQHandler(void);\r
+void WEAK CAN2_IRQHandler(void);\r
+void WEAK Ethernet_IRQHandler(void);\r
+void WEAK Hibernate_IRQHandler(void);\r
+\r
+//*****************************************************************************\r
+//\r
+// The entry point for the application.\r
+//\r
+//*****************************************************************************\r
+extern int main(void);\r
+\r
+//*****************************************************************************\r
+//\r
+// Reserve space for the system stack.\r
+//\r
+//*****************************************************************************\r
+static unsigned long pulStack[64];\r
+\r
+//*****************************************************************************\r
+//\r
+// The vector table. Note that the proper constructs must be placed on this to\r
+// ensure that it ends up at physical address 0x0000.0000.\r
+//\r
+//*****************************************************************************\r
+__attribute__ ((section(".isr_vector")))\r
+void (* const g_pfnVectors[])(void) =\r
+{\r
+ (void (*)(void))((unsigned long)pulStack + sizeof(pulStack)),\r
+ // The initial stack pointer\r
+ Reset_Handler, // The reset handler\r
+ NMI_Handler, // The NMI handler\r
+ HardFault_Handler, // The hard fault handler\r
+ MemManage_Handler, // The MPU fault handler\r
+ BusFault_Handler, // The bus fault handler\r
+ UsageFault_Handler, // The usage fault handler\r
+ 0xefff9d6e, // Reserved\r
+ 0, // Reserved\r
+ 0, // Reserved\r
+ 0, // Reserved\r
+ SVC_Handler, // SVCall handler\r
+ DebugMon_Handler, // Debug monitor handler\r
+ 0, // Reserved\r
+ PendSV_Handler, // The PendSV handler\r
+ SysTick_Handler, // The SysTick handler\r
+\r
+ //\r
+ // External Interrupts\r
+ //\r
+ GPIOPortA_IRQHandler, // GPIO Port A\r
+ GPIOPortB_IRQHandler, // GPIO Port B\r
+ GPIOPortC_IRQHandler, // GPIO Port C\r
+ GPIOPortD_IRQHandler, // GPIO Port D\r
+ GPIOPortE_IRQHandler, // GPIO Port E\r
+ UART0_IRQHandler, // UART0 Rx and Tx\r
+ UART1_IRQHandler, // UART1 Rx and Tx\r
+ SSI0_IRQHandler, // SSI0 Rx and Tx\r
+ I2C0_IRQHandler, // I2C0 Master and Slave\r
+ PWMFault_IRQHandler, // PWM Fault\r
+ PWMGen0_IRQHandler, // PWM Generator 0\r
+ PWMGen1_IRQHandler, // PWM Generator 1\r
+ PWMGen2_IRQHandler, // PWM Generator 2\r
+ QEI0_IRQHandler, // Quadrature Encoder 0\r
+ ADCSeq0_IRQHandler, // ADC Sequence 0\r
+ ADCSeq1_IRQHandler, // ADC Sequence 1\r
+ ADCSeq2_IRQHandler, // ADC Sequence 2\r
+ ADCSeq3_IRQHandler, // ADC Sequence 3\r
+ Watchdog_IRQHandler, // Watchdog timer\r
+ Timer0A_IRQHandler, // Timer 0 subtimer A\r
+ Timer0B_IRQHandler, // Timer 0 subtimer B\r
+ Timer1A_IRQHandler, // Timer 1 subtimer A\r
+ Timer1B_IRQHandler, // Timer 1 subtimer B\r
+ Timer2A_IRQHandler, // Timer 2 subtimer A\r
+ Timer2B_IRQHandler, // Timer 2 subtimer B\r
+ Comp0_IRQHandler, // Analog Comparator 0\r
+ Comp1_IRQHandler, // Analog Comparator 1\r
+ Comp2_IRQHandler, // Analog Comparator 2\r
+ SysCtrl_IRQHandler, // System Control (PLL, OSC, BO)\r
+ FlashCtrl_IRQHandler, // FLASH Control\r
+ GPIOPortF_IRQHandler, // GPIO Port F\r
+ GPIOPortG_IRQHandler, // GPIO Port G\r
+ GPIOPortH_IRQHandler, // GPIO Port H\r
+ UART2_IRQHandler, // UART2 Rx and Tx\r
+ SSI1_IRQHandler, // SSI1 Rx and Tx\r
+ Timer3A_IRQHandler, // Timer 3 subtimer A\r
+ Timer3B_IRQHandler, // Timer 3 subtimer B\r
+ I2C1_IRQHandler, // I2C1 Master and Slave\r
+ QEI1_IRQHandler, // Quadrature Encoder 1\r
+ CAN0_IRQHandler, // CAN0\r
+ CAN1_IRQHandler, // CAN1\r
+ CAN2_IRQHandler, // CAN2\r
+ Ethernet_IRQHandler, // Ethernet\r
+ Hibernate_IRQHandler // Hibernate\r
+};\r
+\r
+//*****************************************************************************\r
+//\r
+// The following are constructs created by the linker, indicating where the\r
+// the "data" and "bss" segments reside in memory. The initializers for the\r
+// for the "data" segment resides immediately following the "text" segment.\r
+//\r
+//*****************************************************************************\r
+extern unsigned long _etext;\r
+extern unsigned long _sdata;\r
+extern unsigned long _edata;\r
+extern unsigned long _sbss;\r
+extern unsigned long _ebss;\r
+\r
+//*****************************************************************************\r
+//\r
+// This is the code that gets called when the processor first starts execution\r
+// following a reset event. Only the absolutely necessary set is performed,\r
+// after which the application supplied entry() routine is called. Any fancy\r
+// actions (such as making decisions based on the reset cause register, and\r
+// resetting the bits in that register) are left solely in the hands of the\r
+// application.\r
+//\r
+//*****************************************************************************\r
+void\r
+Reset_Handler(void)\r
+{\r
+ unsigned long *pulSrc, *pulDest;\r
+\r
+ //\r
+ // Copy the data segment initializers from flash to SRAM.\r
+ //\r
+ pulSrc = &_etext;\r
+ for(pulDest = &_sdata; pulDest < &_edata; )\r
+ {\r
+ *pulDest++ = *pulSrc++;\r
+ }\r
+\r
+ //\r
+ // Zero fill the bss segment. This is done with inline assembly since this\r
+ // will clear the value of pulDest if it is not kept in a register.\r
+ //\r
+ __asm(" ldr r0, =_sbss\n"\r
+ " ldr r1, =_ebss\n"\r
+ " mov r2, #0\n"\r
+ " .thumb_func\n"\r
+ "zero_loop:\n"\r
+ " cmp r0, r1\n"\r
+ " it lt\n"\r
+ " strlt r2, [r0], #4\n"\r
+ " blt zero_loop");\r
+\r
+ //\r
+ // Call the application's entry point.\r
+ //\r
+ main();\r
+}\r
+\r
+//*****************************************************************************\r
+//\r
+// Provide weak aliases for each Exception handler to the Default_Handler.\r
+// As they are weak aliases, any function with the same name will override\r
+// this definition.\r
+//\r
+//*****************************************************************************\r
+#pragma weak NMI_Handler = Default_Handler\r
+#pragma weak HardFault_Handler = Default_Handler\r
+#pragma weak MemManage_Handler = Default_Handler\r
+#pragma weak BusFault_Handler = Default_Handler\r
+#pragma weak UsageFault_Handler = Default_Handler\r
+#pragma weak SVC_Handler = Default_Handler\r
+#pragma weak DebugMon_Handler = Default_Handler\r
+#pragma weak PendSV_Handler = Default_Handler\r
+#pragma weak SysTick_Handler = Default_Handler\r
+#pragma weak GPIOPortA_IRQHandler = Default_Handler\r
+#pragma weak GPIOPortB_IRQHandler = Default_Handler\r
+#pragma weak GPIOPortC_IRQHandler = Default_Handler\r
+#pragma weak GPIOPortD_IRQHandler = Default_Handler\r
+#pragma weak GPIOPortE_IRQHandler = Default_Handler\r
+#pragma weak UART0_IRQHandler = Default_Handler\r
+#pragma weak UART1_IRQHandler = Default_Handler\r
+#pragma weak SSI0_IRQHandler = Default_Handler\r
+#pragma weak I2C0_IRQHandler = Default_Handler\r
+#pragma weak PWMFault_IRQHandler = Default_Handler\r
+#pragma weak PWMGen0_IRQHandler = Default_Handler\r
+#pragma weak PWMGen1_IRQHandler = Default_Handler\r
+#pragma weak PWMGen2_IRQHandler = Default_Handler\r
+#pragma weak QEI0_IRQHandler = Default_Handler\r
+#pragma weak ADCSeq0_IRQHandler = Default_Handler\r
+#pragma weak ADCSeq1_IRQHandler = Default_Handler\r
+#pragma weak ADCSeq2_IRQHandler = Default_Handler\r
+#pragma weak ADCSeq3_IRQHandler = Default_Handler\r
+#pragma weak Watchdog_IRQHandler = Default_Handler\r
+#pragma weak Timer0A_IRQHandler = Default_Handler\r
+#pragma weak Timer0B_IRQHandler = Default_Handler\r
+#pragma weak Timer1A_IRQHandler = Default_Handler\r
+#pragma weak Timer1B_IRQHandler = Default_Handler\r
+#pragma weak Timer2A_IRQHandler = Default_Handler\r
+#pragma weak Timer2B_IRQHandler = Default_Handler\r
+#pragma weak Comp0_IRQHandler = Default_Handler\r
+#pragma weak Comp1_IRQHandler = Default_Handler\r
+#pragma weak Comp2_IRQHandler = Default_Handler\r
+#pragma weak SysCtrl_IRQHandler = Default_Handler\r
+#pragma weak FlashCtrl_IRQHandler = Default_Handler\r
+#pragma weak GPIOPortF_IRQHandler = Default_Handler\r
+#pragma weak GPIOPortG_IRQHandler = Default_Handler\r
+#pragma weak GPIOPortH_IRQHandler = Default_Handler\r
+#pragma weak UART2_IRQHandler = Default_Handler\r
+#pragma weak SSI1_IRQHandler = Default_Handler\r
+#pragma weak Timer3A_IRQHandler = Default_Handler\r
+#pragma weak Timer3B_IRQHandler = Default_Handler\r
+#pragma weak I2C1_IRQHandler = Default_Handler\r
+#pragma weak QEI1_IRQHandler = Default_Handler\r
+#pragma weak CAN0_IRQHandler = Default_Handler\r
+#pragma weak CAN1_IRQHandler = Default_Handler\r
+#pragma weak CAN2_IRQHandler = Default_Handler\r
+#pragma weak Ethernet_IRQHandler = Default_Handler\r
+#pragma weak Hibernate_IRQHandler = Default_Handler\r
+\r
+//*****************************************************************************\r
+//\r
+// This is the code that gets called when the processor receives an unexpected\r
+// interrupt. This simply enters an infinite loop, preserving the system state\r
+// for examination by a debugger.\r
+//\r
+//*****************************************************************************\r
+static void\r
+Default_Handler(void)\r
+{\r
+ //\r
+ // Go into an infinite loop.\r
+ //\r
+ while(1)\r
+ {\r
+ }\r
+}\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usb.h\r
+ * Purpose: USB Definitions\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 family microcontroller devices only. Nothing\r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *---------------------------------------------------------------------------*/\r
+\r
+#ifndef __USB_H__\r
+#define __USB_H__\r
+#include "lpc_types.h"\r
+\r
+#if defined ( __GNUC__ )\r
+#define __packed __attribute__((__packed__))\r
+#endif\r
+\r
+#if defined ( __CC_ARM )\r
+typedef __packed union {\r
+#elif defined ( __GNUC__ )\r
+typedef union __packed {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef union {\r
+#endif\r
+ uint16_t W;\r
+#if defined ( __CC_ARM )\r
+ __packed struct {\r
+#elif defined ( __GNUC__ )\r
+ struct __packed {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+ struct {\r
+#endif\r
+ uint8_t L;\r
+ uint8_t H;\r
+ } WB;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+} WORD_BYTE;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+\r
+/* bmRequestType.Dir */\r
+#define REQUEST_HOST_TO_DEVICE 0\r
+#define REQUEST_DEVICE_TO_HOST 1\r
+\r
+/* bmRequestType.Type */\r
+#define REQUEST_STANDARD 0\r
+#define REQUEST_CLASS 1\r
+#define REQUEST_VENDOR 2\r
+#define REQUEST_RESERVED 3\r
+\r
+/* bmRequestType.Recipient */\r
+#define REQUEST_TO_DEVICE 0\r
+#define REQUEST_TO_INTERFACE 1\r
+#define REQUEST_TO_ENDPOINT 2\r
+#define REQUEST_TO_OTHER 3\r
+\r
+/* bmRequestType Definition */\r
+#if defined ( __CC_ARM )\r
+typedef __packed union _REQUEST_TYPE {\r
+#elif defined ( __GNUC__ )\r
+typedef union __packed _REQUEST_TYPE {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef union _REQUEST_TYPE {\r
+#endif\r
+#if defined ( __CC_ARM )\r
+ __packed struct _BM {\r
+#elif defined ( __GNUC__ )\r
+ struct __packed _BM {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+ struct _BM {\r
+#endif\r
+ uint8_t Recipient : 5;\r
+ uint8_t Type : 2;\r
+ uint8_t Dir : 1;\r
+ } BM;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+ uint8_t B;\r
+} REQUEST_TYPE;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+/* USB Standard Request Codes */\r
+#define USB_REQUEST_GET_STATUS 0\r
+#define USB_REQUEST_CLEAR_FEATURE 1\r
+#define USB_REQUEST_SET_FEATURE 3\r
+#define USB_REQUEST_SET_ADDRESS 5\r
+#define USB_REQUEST_GET_DESCRIPTOR 6\r
+#define USB_REQUEST_SET_DESCRIPTOR 7\r
+#define USB_REQUEST_GET_CONFIGURATION 8\r
+#define USB_REQUEST_SET_CONFIGURATION 9\r
+#define USB_REQUEST_GET_INTERFACE 10\r
+#define USB_REQUEST_SET_INTERFACE 11\r
+#define USB_REQUEST_SYNC_FRAME 12\r
+\r
+/* USB GET_STATUS Bit Values */\r
+#define USB_GETSTATUS_SELF_POWERED 0x01\r
+#define USB_GETSTATUS_REMOTE_WAKEUP 0x02\r
+#define USB_GETSTATUS_ENDPOINT_STALL 0x01\r
+\r
+/* USB Standard Feature selectors */\r
+#define USB_FEATURE_ENDPOINT_STALL 0\r
+#define USB_FEATURE_REMOTE_WAKEUP 1\r
+\r
+/* USB Default Control Pipe Setup Packet */\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _USB_SETUP_PACKET {\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _USB_SETUP_PACKET {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _USB_SETUP_PACKET {\r
+#endif\r
+ REQUEST_TYPE bmRequestType;\r
+ uint8_t bRequest;\r
+ WORD_BYTE wValue;\r
+ WORD_BYTE wIndex;\r
+ uint16_t wLength;\r
+} USB_SETUP_PACKET;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+\r
+/* USB Descriptor Types */\r
+#define USB_DEVICE_DESCRIPTOR_TYPE 1\r
+#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2\r
+#define USB_STRING_DESCRIPTOR_TYPE 3\r
+#define USB_INTERFACE_DESCRIPTOR_TYPE 4\r
+#define USB_ENDPOINT_DESCRIPTOR_TYPE 5\r
+#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6\r
+#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7\r
+#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8\r
+#define USB_OTG_DESCRIPTOR_TYPE 9\r
+#define USB_DEBUG_DESCRIPTOR_TYPE 10\r
+#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11\r
+\r
+/* USB Device Classes */\r
+#define USB_DEVICE_CLASS_RESERVED 0x00\r
+#define USB_DEVICE_CLASS_AUDIO 0x01\r
+#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02\r
+#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03\r
+#define USB_DEVICE_CLASS_MONITOR 0x04\r
+#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05\r
+#define USB_DEVICE_CLASS_POWER 0x06\r
+#define USB_DEVICE_CLASS_PRINTER 0x07\r
+#define USB_DEVICE_CLASS_STORAGE 0x08\r
+#define USB_DEVICE_CLASS_HUB 0x09\r
+#define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF\r
+#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF\r
+\r
+/* bmAttributes in Configuration Descriptor */\r
+#define USB_CONFIG_POWERED_MASK 0x40\r
+#define USB_CONFIG_BUS_POWERED 0x80\r
+#define USB_CONFIG_SELF_POWERED 0xC0\r
+#define USB_CONFIG_REMOTE_WAKEUP 0x20\r
+\r
+/* bMaxPower in Configuration Descriptor */\r
+#define USB_CONFIG_POWER_MA(mA) ((mA)/2)\r
+\r
+/* bEndpointAddress in Endpoint Descriptor */\r
+#define USB_ENDPOINT_DIRECTION_MASK 0x80\r
+#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)\r
+#define USB_ENDPOINT_IN(addr) ((addr) | 0x80)\r
+\r
+/* bmAttributes in Endpoint Descriptor */\r
+#define USB_ENDPOINT_TYPE_MASK 0x03\r
+#define USB_ENDPOINT_TYPE_CONTROL 0x00\r
+#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01\r
+#define USB_ENDPOINT_TYPE_BULK 0x02\r
+#define USB_ENDPOINT_TYPE_INTERRUPT 0x03\r
+#define USB_ENDPOINT_SYNC_MASK 0x0C\r
+#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00\r
+#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04\r
+#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08\r
+#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C\r
+#define USB_ENDPOINT_USAGE_MASK 0x30\r
+#define USB_ENDPOINT_USAGE_DATA 0x00\r
+#define USB_ENDPOINT_USAGE_FEEDBACK 0x10\r
+#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20\r
+#define USB_ENDPOINT_USAGE_RESERVED 0x30\r
+\r
+/* USB Standard Device Descriptor */\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _USB_DEVICE_DESCRIPTOR {\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _USB_DEVICE_DESCRIPTOR {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _USB_DEVICE_DESCRIPTOR {\r
+#endif\r
+ uint8_t bLength;\r
+ uint8_t bDescriptorType;\r
+ uint16_t bcdUSB;\r
+ uint8_t bDeviceClass;\r
+ uint8_t bDeviceSubClass;\r
+ uint8_t bDeviceProtocol;\r
+ uint8_t bMaxPacketSize0;\r
+ uint16_t idVendor;\r
+ uint16_t idProduct;\r
+ uint16_t bcdDevice;\r
+ uint8_t iManufacturer;\r
+ uint8_t iProduct;\r
+ uint8_t iSerialNumber;\r
+ uint8_t bNumConfigurations;\r
+} USB_DEVICE_DESCRIPTOR;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+/* USB 2.0 Device Qualifier Descriptor */\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _USB_DEVICE_QUALIFIER_DESCRIPTOR {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {\r
+#endif\r
+ uint8_t bLength;\r
+ uint8_t bDescriptorType;\r
+ uint16_t bcdUSB;\r
+ uint8_t bDeviceClass;\r
+ uint8_t bDeviceSubClass;\r
+ uint8_t bDeviceProtocol;\r
+ uint8_t bMaxPacketSize0;\r
+ uint8_t bNumConfigurations;\r
+ uint8_t bReserved;\r
+} USB_DEVICE_QUALIFIER_DESCRIPTOR;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _USB_CONFIGURATION_DESCRIPTOR {\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _USB_CONFIGURATION_DESCRIPTOR {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _USB_CONFIGURATION_DESCRIPTOR {\r
+#endif\r
+ uint8_t bLength;\r
+ uint8_t bDescriptorType;\r
+ uint16_t wTotalLength;\r
+ uint8_t bNumInterfaces;\r
+ uint8_t bConfigurationValue;\r
+ uint8_t iConfiguration;\r
+ uint8_t bmAttributes;\r
+ uint8_t bMaxPower;\r
+} USB_CONFIGURATION_DESCRIPTOR;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+/* USB Standard Interface Descriptor */\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _USB_INTERFACE_DESCRIPTOR {\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _USB_INTERFACE_DESCRIPTOR {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _USB_INTERFACE_DESCRIPTOR {\r
+#endif\r
+ uint8_t bLength;\r
+ uint8_t bDescriptorType;\r
+ uint8_t bInterfaceNumber;\r
+ uint8_t bAlternateSetting;\r
+ uint8_t bNumEndpoints;\r
+ uint8_t bInterfaceClass;\r
+ uint8_t bInterfaceSubClass;\r
+ uint8_t bInterfaceProtocol;\r
+ uint8_t iInterface;\r
+} USB_INTERFACE_DESCRIPTOR;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+/* USB Standard Endpoint Descriptor */\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _USB_ENDPOINT_DESCRIPTOR {\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _USB_ENDPOINT_DESCRIPTOR {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _USB_ENDPOINT_DESCRIPTOR {\r
+#endif\r
+ uint8_t bLength;\r
+ uint8_t bDescriptorType;\r
+ uint8_t bEndpointAddress;\r
+ uint8_t bmAttributes;\r
+ uint16_t wMaxPacketSize;\r
+ uint8_t bInterval;\r
+} USB_ENDPOINT_DESCRIPTOR;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+/* USB String Descriptor */\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _USB_STRING_DESCRIPTOR {\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _USB_STRING_DESCRIPTOR {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _USB_STRING_DESCRIPTOR {\r
+#endif\r
+ uint8_t bLength;\r
+ uint8_t bDescriptorType;\r
+ uint16_t bString/*[]*/;\r
+} USB_STRING_DESCRIPTOR;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+/* USB Common Descriptor */\r
+#if defined ( __CC_ARM )\r
+typedef __packed struct _USB_COMMON_DESCRIPTOR {\r
+#elif defined ( __GNUC__ )\r
+typedef struct __packed _USB_COMMON_DESCRIPTOR {\r
+#elif defined ( __IAR_SYSTEMS_ICC__ )\r
+#pragma pack(1)\r
+typedef struct _USB_COMMON_DESCRIPTOR {\r
+#endif\r
+ uint8_t bLength;\r
+ uint8_t bDescriptorType;\r
+} USB_COMMON_DESCRIPTOR;\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+#pragma pack()\r
+#endif\r
+\r
+\r
+\r
+#endif /* __USB_H__ */\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbcfg.h\r
+ * Purpose: USB Custom Configuration\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 family microcontroller devices only. Nothing \r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *----------------------------------------------------------------------------\r
+ * History:\r
+ * V1.20 Added vendor specific support\r
+ * V1.00 Initial Version\r
+ *---------------------------------------------------------------------------*/\r
+\r
+#ifndef __USBCFG_H__\r
+#define __USBCFG_H__\r
+\r
+\r
+//*** <<< Use Configuration Wizard in Context Menu >>> ***\r
+\r
+\r
+/*\r
+// <h> USB Configuration\r
+// <o0> USB Power\r
+// <i> Default Power Setting\r
+// <0=> Bus-powered\r
+// <1=> Self-powered\r
+// <o1> Max Number of Interfaces <1-256>\r
+// <o2> Max Number of Endpoints <1-32>\r
+// <o3> Max Endpoint 0 Packet Size\r
+// <8=> 8 Bytes <16=> 16 Bytes <32=> 32 Bytes <64=> 64 Bytes\r
+// <e4> DMA Transfer\r
+// <i> Use DMA for selected Endpoints\r
+// <o5.0> Endpoint 0 Out\r
+// <o5.1> Endpoint 0 In\r
+// <o5.2> Endpoint 1 Out\r
+// <o5.3> Endpoint 1 In\r
+// <o5.4> Endpoint 2 Out\r
+// <o5.5> Endpoint 2 In\r
+// <o5.6> Endpoint 3 Out\r
+// <o5.7> Endpoint 3 In\r
+// <o5.8> Endpoint 4 Out\r
+// <o5.9> Endpoint 4 In\r
+// <o5.10> Endpoint 5 Out\r
+// <o5.11> Endpoint 5 In\r
+// <o5.12> Endpoint 6 Out\r
+// <o5.13> Endpoint 6 In\r
+// <o5.14> Endpoint 7 Out\r
+// <o5.15> Endpoint 7 In\r
+// <o5.16> Endpoint 8 Out\r
+// <o5.17> Endpoint 8 In\r
+// <o5.18> Endpoint 9 Out\r
+// <o5.19> Endpoint 9 In\r
+// <o5.20> Endpoint 10 Out\r
+// <o5.21> Endpoint 10 In\r
+// <o5.22> Endpoint 11 Out\r
+// <o5.23> Endpoint 11 In\r
+// <o5.24> Endpoint 12 Out\r
+// <o5.25> Endpoint 12 In\r
+// <o5.26> Endpoint 13 Out\r
+// <o5.27> Endpoint 13 In\r
+// <o5.28> Endpoint 14 Out\r
+// <o5.29> Endpoint 14 In\r
+// <o5.30> Endpoint 15 Out\r
+// <o5.31> Endpoint 15 In\r
+// </e>\r
+// </h>\r
+*/\r
+\r
+#define USB_POWER 0\r
+#define USB_IF_NUM 4\r
+#define USB_EP_NUM 32\r
+#define USB_MAX_PACKET0 8\r
+#define USB_DMA 0\r
+#define USB_DMA_EP 0x00000000\r
+\r
+\r
+/*\r
+// <h> USB Event Handlers\r
+// <h> Device Events\r
+// <o0.0> Power Event\r
+// <o1.0> Reset Event\r
+// <o2.0> Suspend Event\r
+// <o3.0> Resume Event\r
+// <o4.0> Remote Wakeup Event\r
+// <o5.0> Start of Frame Event\r
+// <o6.0> Error Event\r
+// </h>\r
+// <h> Endpoint Events\r
+// <o7.0> Endpoint 0 Event\r
+// <o7.1> Endpoint 1 Event\r
+// <o7.2> Endpoint 2 Event\r
+// <o7.3> Endpoint 3 Event\r
+// <o7.4> Endpoint 4 Event\r
+// <o7.5> Endpoint 5 Event\r
+// <o7.6> Endpoint 6 Event\r
+// <o7.7> Endpoint 7 Event\r
+// <o7.8> Endpoint 8 Event\r
+// <o7.9> Endpoint 9 Event\r
+// <o7.10> Endpoint 10 Event\r
+// <o7.11> Endpoint 11 Event\r
+// <o7.12> Endpoint 12 Event\r
+// <o7.13> Endpoint 13 Event\r
+// <o7.14> Endpoint 14 Event\r
+// <o7.15> Endpoint 15 Event\r
+// </h>\r
+// <h> USB Core Events\r
+// <o8.0> Set Configuration Event\r
+// <o9.0> Set Interface Event\r
+// <o10.0> Set/Clear Feature Event\r
+// </h>\r
+// </h>\r
+*/\r
+\r
+#define USB_POWER_EVENT 0\r
+#define USB_RESET_EVENT 1\r
+#define USB_SUSPEND_EVENT 0\r
+#define USB_RESUME_EVENT 0\r
+#define USB_WAKEUP_EVENT 0\r
+#define USB_SOF_EVENT 0\r
+#define USB_ERROR_EVENT 0\r
+#define USB_EP_EVENT 0x0007\r
+#define USB_CONFIGURE_EVENT 1\r
+#define USB_INTERFACE_EVENT 0\r
+#define USB_FEATURE_EVENT 0\r
+\r
+\r
+/*\r
+// <e0> USB Class Support\r
+// <i> enables USB Class specific Requests\r
+// <e1> Human Interface Device (HID)\r
+// <o2> Interface Number <0-255>\r
+// </e>\r
+// <e3> Mass Storage\r
+// <o4> Interface Number <0-255>\r
+// </e>\r
+// <e5> Audio Device\r
+// <o6> Control Interface Number <0-255>\r
+// <o7> Streaming Interface 1 Number <0-255>\r
+// <o8> Streaming Interface 2 Number <0-255>\r
+// </e>\r
+// <e9> Communication Device\r
+// <o10> Control Interface Number <0-255>\r
+// <o11> Bulk Interface Number <0-255>\r
+// <o12> Max Communication Device Buffer Size\r
+// <8=> 8 Bytes <16=> 16 Bytes <32=> 32 Bytes <64=> 64 Bytes \r
+// </e>\r
+// </e>\r
+*/\r
+\r
+#define USB_CLASS 1\r
+#define USB_HID 0\r
+#define USB_HID_IF_NUM 0\r
+#define USB_MSC 0\r
+#define USB_MSC_IF_NUM 0\r
+#define USB_AUDIO 0\r
+#define USB_ADC_CIF_NUM 0\r
+#define USB_ADC_SIF1_NUM 1\r
+#define USB_ADC_SIF2_NUM 2\r
+#define USB_CDC 1\r
+#define USB_CDC_CIF_NUM 0\r
+#define USB_CDC_DIF_NUM 1\r
+#define USB_CDC_BUFSIZE 64\r
+\r
+/*\r
+// <e0> USB Vendor Support\r
+// <i> enables USB Vendor specific Requests\r
+// </e>\r
+*/\r
+#define USB_VENDOR 0\r
+\r
+\r
+#endif /* __USBCFG_H__ */\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbcore.c\r
+ * Purpose: USB Core Module\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 family microcontroller devices only. Nothing\r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *----------------------------------------------------------------------------\r
+ * History:\r
+ * V1.20 Added vendor specific requests\r
+ * Changed string descriptor handling\r
+ * Reworked Endpoint0\r
+ * V1.00 Initial Version\r
+ *----------------------------------------------------------------------------*/\r
+#include "lpc_types.h"\r
+\r
+#include "usb.h"\r
+#include "usbcfg.h"\r
+#include "usbhw.h"\r
+#include "usbcore.h"\r
+#include "usbdesc.h"\r
+#include "usbuser.h"\r
+\r
+#if (USB_CLASS)\r
+\r
+#if (USB_AUDIO)\r
+#include "audio.h"\r
+#include "adcuser.h"\r
+#endif\r
+\r
+#if (USB_HID)\r
+#include "hid.h"\r
+#include "hiduser.h"\r
+#endif\r
+\r
+#if (USB_MSC)\r
+#include "msc.h"\r
+#include "mscuser.h"\r
+extern MSC_CSW CSW;\r
+#endif\r
+\r
+#if (USB_CDC)\r
+#include "cdc.h"\r
+#include "cdcuser.h"\r
+#endif\r
+\r
+#endif\r
+\r
+#if (USB_VENDOR)\r
+#include "vendor.h"\r
+#endif\r
+\r
+#if defined ( __CC_ARM )\r
+#pragma diag_suppress 111,1441\r
+#endif\r
+\r
+#if defined ( __GNUC__ )\r
+#define __packed __attribute__((__packed__))\r
+#endif\r
+\r
+uint16_t USB_DeviceStatus;\r
+uint8_t USB_DeviceAddress;\r
+uint8_t USB_Configuration;\r
+uint32_t USB_EndPointMask;\r
+uint32_t USB_EndPointHalt;\r
+uint32_t USB_EndPointStall; /* EP must stay stalled */\r
+uint8_t USB_NumInterfaces;\r
+uint8_t USB_AltSetting[USB_IF_NUM];\r
+\r
+uint8_t EP0Buf[USB_MAX_PACKET0];\r
+\r
+\r
+USB_EP_DATA EP0Data;\r
+\r
+USB_SETUP_PACKET SetupPacket;\r
+\r
+\r
+/*\r
+ * Reset USB Core\r
+ * Parameters: None\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_ResetCore (void) {\r
+\r
+ USB_DeviceStatus = USB_POWER;\r
+ USB_DeviceAddress = 0;\r
+ USB_Configuration = 0;\r
+ USB_EndPointMask = 0x00010001;\r
+ USB_EndPointHalt = 0x00000000;\r
+ USB_EndPointStall = 0x00000000;\r
+}\r
+\r
+\r
+/*\r
+ * USB Request - Setup Stage\r
+ * Parameters: None (global SetupPacket)\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_SetupStage (void) {\r
+ USB_ReadEP(0x00, (uint8_t *)&SetupPacket);\r
+}\r
+\r
+\r
+/*\r
+ * USB Request - Data In Stage\r
+ * Parameters: None (global EP0Data)\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_DataInStage (void) {\r
+ uint32_t cnt;\r
+\r
+ if (EP0Data.Count > USB_MAX_PACKET0) {\r
+ cnt = USB_MAX_PACKET0;\r
+ } else {\r
+ cnt = EP0Data.Count;\r
+ }\r
+ cnt = USB_WriteEP(0x80, EP0Data.pData, cnt);\r
+ EP0Data.pData += cnt;\r
+ EP0Data.Count -= cnt;\r
+}\r
+\r
+\r
+/*\r
+ * USB Request - Data Out Stage\r
+ * Parameters: None (global EP0Data)\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_DataOutStage (void) {\r
+ uint32_t cnt;\r
+\r
+ cnt = USB_ReadEP(0x00, EP0Data.pData);\r
+ EP0Data.pData += cnt;\r
+ EP0Data.Count -= cnt;\r
+}\r
+\r
+\r
+/*\r
+ * USB Request - Status In Stage\r
+ * Parameters: None\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_StatusInStage (void) {\r
+ USB_WriteEP(0x80, NULL, 0);\r
+}\r
+\r
+\r
+/*\r
+ * USB Request - Status Out Stage\r
+ * Parameters: None\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_StatusOutStage (void) {\r
+ USB_ReadEP(0x00, EP0Buf);\r
+}\r
+\r
+\r
+/*\r
+ * Get Status USB Request\r
+ * Parameters: None (global SetupPacket)\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+\r
+#if defined ( __IAR_SYSTEMS_ICC__ )\r
+inline uint32_t USB_ReqGetStatus (void) {\r
+#else \r
+__inline uint32_t USB_ReqGetStatus (void) {\r
+#endif\r
+ uint32_t n, m;\r
+\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_DEVICE:\r
+ EP0Data.pData = (uint8_t *)&USB_DeviceStatus;\r
+ break;\r
+ case REQUEST_TO_INTERFACE:\r
+ if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) {\r
+ *((__packed uint16_t *)EP0Buf) = 0;\r
+ *((uint16_t *)EP0Buf) = 0;\r
+ EP0Data.pData = EP0Buf;\r
+ } else {\r
+ return (FALSE);\r
+ }\r
+ break;\r
+ case REQUEST_TO_ENDPOINT:\r
+ n = SetupPacket.wIndex.WB.L & 0x8F;\r
+ m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);\r
+ if (((USB_Configuration != 0) || ((n & 0x0F) == 0)) && (USB_EndPointMask & m)) {\r
+ *((__packed uint16_t *)EP0Buf) = (USB_EndPointHalt & m) ? 1 : 0;\r
+ *((uint16_t *)EP0Buf) = (USB_EndPointHalt & m) ? 1 : 0;\r
+ EP0Data.pData = EP0Buf;\r
+ } else {\r
+ return (FALSE);\r
+ }\r
+ break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*\r
+ * Set/Clear Feature USB Request\r
+ * Parameters: sc: 0 - Clear, 1 - Set\r
+ * (global SetupPacket)\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+\r
+#if defined ( __IAR_SYSTEMS_ICC__ )\r
+inline uint32_t USB_ReqSetClrFeature (uint32_t sc) {\r
+#else\r
+__inline uint32_t USB_ReqSetClrFeature (uint32_t sc) {\r
+#endif\r
+ uint32_t n, m;\r
+\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_DEVICE:\r
+ if (SetupPacket.wValue.W == USB_FEATURE_REMOTE_WAKEUP) {\r
+ if (sc) {\r
+ USB_WakeUpCfg(TRUE);\r
+ USB_DeviceStatus |= USB_GETSTATUS_REMOTE_WAKEUP;\r
+ } else {\r
+ USB_WakeUpCfg(FALSE);\r
+ USB_DeviceStatus &= ~USB_GETSTATUS_REMOTE_WAKEUP;\r
+ }\r
+ } else {\r
+ return (FALSE);\r
+ }\r
+ break;\r
+ case REQUEST_TO_INTERFACE:\r
+ return (FALSE);\r
+ case REQUEST_TO_ENDPOINT:\r
+ n = SetupPacket.wIndex.WB.L & 0x8F;\r
+ m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);\r
+ if ((USB_Configuration != 0) && ((n & 0x0F) != 0) && (USB_EndPointMask & m)) {\r
+ if (SetupPacket.wValue.W == USB_FEATURE_ENDPOINT_STALL) {\r
+ if (sc) {\r
+ USB_SetStallEP(n);\r
+ USB_EndPointHalt |= m;\r
+ } else {\r
+ if ((USB_EndPointStall & m) != 0) {\r
+ return (TRUE);\r
+ }\r
+ USB_ClrStallEP(n);\r
+#if (USB_MSC)\r
+ if ((n == MSC_EP_IN) && ((USB_EndPointHalt & m) != 0)) {\r
+ /* Compliance Test: rewrite CSW after unstall */\r
+ if (CSW.dSignature == MSC_CSW_Signature) {\r
+ USB_WriteEP(MSC_EP_IN, (uint8_t *)&CSW, sizeof(CSW));\r
+ }\r
+ }\r
+#endif\r
+ USB_EndPointHalt &= ~m;\r
+ }\r
+ } else {\r
+ return (FALSE);\r
+ }\r
+ } else {\r
+ return (FALSE);\r
+ }\r
+ break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*\r
+ * Set Address USB Request\r
+ * Parameters: None (global SetupPacket)\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+\r
+#if defined ( __IAR_SYSTEMS_ICC__ )\r
+inline uint32_t USB_ReqSetAddress (void) {\r
+#else\r
+__inline uint32_t USB_ReqSetAddress (void) {\r
+#endif\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_DEVICE:\r
+ USB_DeviceAddress = 0x80 | SetupPacket.wValue.WB.L;\r
+ break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*\r
+ * Get Descriptor USB Request\r
+ * Parameters: None (global SetupPacket)\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+\r
+#if defined ( __IAR_SYSTEMS_ICC__ )\r
+inline uint32_t USB_ReqGetDescriptor (void) {\r
+#else\r
+__inline uint32_t USB_ReqGetDescriptor (void) {\r
+#endif\r
+ uint8_t *pD;\r
+ uint32_t len, n;\r
+\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_DEVICE:\r
+ switch (SetupPacket.wValue.WB.H) {\r
+ case USB_DEVICE_DESCRIPTOR_TYPE:\r
+ EP0Data.pData = (uint8_t *)USB_DeviceDescriptor;\r
+ len = USB_DEVICE_DESC_SIZE;\r
+ break;\r
+ case USB_CONFIGURATION_DESCRIPTOR_TYPE:\r
+ pD = (uint8_t *)USB_ConfigDescriptor;\r
+ for (n = 0; n != SetupPacket.wValue.WB.L; n++) {\r
+ if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength != 0) {\r
+ pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;\r
+ }\r
+ }\r
+ if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength == 0) {\r
+ return (FALSE);\r
+ }\r
+ EP0Data.pData = pD;\r
+ len = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;\r
+ break;\r
+ case USB_STRING_DESCRIPTOR_TYPE:\r
+ pD = (uint8_t *)USB_StringDescriptor;\r
+ for (n = 0; n != SetupPacket.wValue.WB.L; n++) {\r
+ if (((USB_STRING_DESCRIPTOR *)pD)->bLength != 0) {\r
+ pD += ((USB_STRING_DESCRIPTOR *)pD)->bLength;\r
+ }\r
+ }\r
+ if (((USB_STRING_DESCRIPTOR *)pD)->bLength == 0) {\r
+ return (FALSE);\r
+ }\r
+ EP0Data.pData = pD;\r
+ len = ((USB_STRING_DESCRIPTOR *)EP0Data.pData)->bLength;\r
+ break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+ break;\r
+ case REQUEST_TO_INTERFACE:\r
+ switch (SetupPacket.wValue.WB.H) {\r
+#if USB_HID\r
+ case HID_HID_DESCRIPTOR_TYPE:\r
+ if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) {\r
+ return (FALSE); /* Only Single HID Interface is supported */\r
+ }\r
+ EP0Data.pData = (uint8_t *)USB_ConfigDescriptor + HID_DESC_OFFSET;\r
+ len = HID_DESC_SIZE;\r
+ break;\r
+ case HID_REPORT_DESCRIPTOR_TYPE:\r
+ if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) {\r
+ return (FALSE); /* Only Single HID Interface is supported */\r
+ }\r
+ EP0Data.pData = (uint8_t *)HID_ReportDescriptor;\r
+ len = HID_ReportDescSize;\r
+ break;\r
+ case HID_PHYSICAL_DESCRIPTOR_TYPE:\r
+ return (FALSE); /* HID Physical Descriptor is not supported */\r
+#endif\r
+ default:\r
+ return (FALSE);\r
+ }\r
+// break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+\r
+ if (EP0Data.Count > len) {\r
+ EP0Data.Count = len;\r
+ }\r
+\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*\r
+ * Get Configuration USB Request\r
+ * Parameters: None (global SetupPacket)\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+\r
+#if defined ( __IAR_SYSTEMS_ICC__ )\r
+inline uint32_t USB_ReqGetConfiguration (void) {\r
+#else\r
+__inline uint32_t USB_ReqGetConfiguration (void) {\r
+#endif\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_DEVICE:\r
+ EP0Data.pData = &USB_Configuration;\r
+ break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*\r
+ * Set Configuration USB Request\r
+ * Parameters: None (global SetupPacket)\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+\r
+#if defined ( __IAR_SYSTEMS_ICC__ )\r
+inline uint32_t USB_ReqSetConfiguration (void) {\r
+#else\r
+__inline uint32_t USB_ReqSetConfiguration (void) {\r
+#endif\r
+ USB_COMMON_DESCRIPTOR *pD;\r
+ uint32_t alt = 0;\r
+ uint32_t n, m;\r
+ uint32_t tmp;\r
+\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_DEVICE:\r
+\r
+ if (SetupPacket.wValue.WB.L) {\r
+ pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor;\r
+ while (pD->bLength) {\r
+ switch (pD->bDescriptorType) {\r
+ case USB_CONFIGURATION_DESCRIPTOR_TYPE:\r
+ if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue == SetupPacket.wValue.WB.L) {\r
+ USB_Configuration = SetupPacket.wValue.WB.L;\r
+ USB_NumInterfaces = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->bNumInterfaces;\r
+ for (n = 0; n < USB_IF_NUM; n++) {\r
+ USB_AltSetting[n] = 0;\r
+ }\r
+ for (n = 1; n < 16; n++) {\r
+ if (USB_EndPointMask & (1 << n)) {\r
+ USB_DisableEP(n);\r
+ }\r
+ if (USB_EndPointMask & ((1 << 16) << n)) {\r
+ USB_DisableEP(n | 0x80);\r
+ }\r
+ }\r
+ USB_EndPointMask = 0x00010001;\r
+ USB_EndPointHalt = 0x00000000;\r
+ USB_EndPointStall= 0x00000000;\r
+ USB_Configure(TRUE);\r
+ if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bmAttributes & USB_CONFIG_POWERED_MASK) {\r
+ USB_DeviceStatus |= USB_GETSTATUS_SELF_POWERED;\r
+ } else {\r
+ USB_DeviceStatus &= ~USB_GETSTATUS_SELF_POWERED;\r
+ }\r
+ } else {\r
+// (uint8_t *)pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;\r
+ tmp = (uint32_t)pD;\r
+ tmp += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;\r
+ pD = (USB_COMMON_DESCRIPTOR *)tmp;\r
+ continue;\r
+ }\r
+ break;\r
+ case USB_INTERFACE_DESCRIPTOR_TYPE:\r
+ alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting;\r
+ break;\r
+ case USB_ENDPOINT_DESCRIPTOR_TYPE:\r
+ if (alt == 0) {\r
+ n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F;\r
+ m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);\r
+ USB_EndPointMask |= m;\r
+ USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD);\r
+ USB_EnableEP(n);\r
+ USB_ResetEP(n);\r
+ }\r
+ break;\r
+ }\r
+// (uint8_t *)pD += pD->bLength;\r
+ tmp = (uint32_t)pD;\r
+ tmp += pD->bLength;\r
+ pD = (USB_COMMON_DESCRIPTOR *)tmp;\r
+ }\r
+ }\r
+ else {\r
+ USB_Configuration = 0;\r
+ for (n = 1; n < 16; n++) {\r
+ if (USB_EndPointMask & (1 << n)) {\r
+ USB_DisableEP(n);\r
+ }\r
+ if (USB_EndPointMask & ((1 << 16) << n)) {\r
+ USB_DisableEP(n | 0x80);\r
+ }\r
+ }\r
+ USB_EndPointMask = 0x00010001;\r
+ USB_EndPointHalt = 0x00000000;\r
+ USB_EndPointStall = 0x00000000;\r
+ USB_Configure(FALSE);\r
+ }\r
+\r
+ if (USB_Configuration != SetupPacket.wValue.WB.L) {\r
+ return (FALSE);\r
+ }\r
+ break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*\r
+ * Get Interface USB Request\r
+ * Parameters: None (global SetupPacket)\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+\r
+#if defined ( __IAR_SYSTEMS_ICC__ )\r
+inline uint32_t USB_ReqGetInterface (void) {\r
+#else\r
+__inline uint32_t USB_ReqGetInterface (void) {\r
+#endif\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_INTERFACE:\r
+ if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) {\r
+ EP0Data.pData = USB_AltSetting + SetupPacket.wIndex.WB.L;\r
+ } else {\r
+ return (FALSE);\r
+ }\r
+ break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+ return (TRUE);\r
+}\r
+\r
+\r
+/*\r
+ * Set Interface USB Request\r
+ * Parameters: None (global SetupPacket)\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+#if defined ( __IAR_SYSTEMS_ICC__ )\r
+inline uint32_t USB_ReqSetInterface (void) {\r
+#else\r
+__inline uint32_t USB_ReqSetInterface (void) {\r
+#endif\r
+ USB_COMMON_DESCRIPTOR *pD;\r
+ uint32_t ifn = 0, alt = 0, old = 0, msk = 0;\r
+ uint32_t n, m;\r
+ uint32_t set;\r
+ uint32_t tmp;\r
+\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_INTERFACE:\r
+ if (USB_Configuration == 0) return (FALSE);\r
+ set = FALSE;\r
+ pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor;\r
+ while (pD->bLength) {\r
+ switch (pD->bDescriptorType) {\r
+ case USB_CONFIGURATION_DESCRIPTOR_TYPE:\r
+ if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue != USB_Configuration) {\r
+// (uint8_t *)pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;\r
+ tmp = (uint32_t)pD;\r
+ tmp += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;\r
+ pD = (USB_COMMON_DESCRIPTOR *)tmp;\r
+\r
+ continue;\r
+ }\r
+ break;\r
+ case USB_INTERFACE_DESCRIPTOR_TYPE:\r
+ ifn = ((USB_INTERFACE_DESCRIPTOR *)pD)->bInterfaceNumber;\r
+ alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting;\r
+ msk = 0;\r
+ if ((ifn == SetupPacket.wIndex.WB.L) && (alt == SetupPacket.wValue.WB.L)) {\r
+ set = TRUE;\r
+ old = USB_AltSetting[ifn];\r
+ USB_AltSetting[ifn] = (uint8_t)alt;\r
+ }\r
+ break;\r
+ case USB_ENDPOINT_DESCRIPTOR_TYPE:\r
+ if (ifn == SetupPacket.wIndex.WB.L) {\r
+ n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F;\r
+ m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);\r
+ if (alt == SetupPacket.wValue.WB.L) {\r
+ USB_EndPointMask |= m;\r
+ USB_EndPointHalt &= ~m;\r
+ USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD);\r
+ USB_EnableEP(n);\r
+ USB_ResetEP(n);\r
+ msk |= m;\r
+ }\r
+ else if ((alt == old) && ((msk & m) == 0)) {\r
+ USB_EndPointMask &= ~m;\r
+ USB_EndPointHalt &= ~m;\r
+ USB_DisableEP(n);\r
+ }\r
+ }\r
+ break;\r
+ }\r
+// (uint8_t *)pD += pD->bLength;\r
+ tmp = (uint32_t)pD;\r
+ tmp += pD->bLength;\r
+ pD = (USB_COMMON_DESCRIPTOR *)tmp;\r
+ }\r
+ break;\r
+ default:\r
+ return (FALSE);\r
+ }\r
+\r
+ return (set);\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 0 Event Callback\r
+ * Parameters: event\r
+ * Return Value: none\r
+ */\r
+\r
+void USB_EndPoint0 (uint32_t event) {\r
+\r
+ switch (event) {\r
+ case USB_EVT_SETUP:\r
+ USB_SetupStage();\r
+ USB_DirCtrlEP(SetupPacket.bmRequestType.BM.Dir);\r
+ EP0Data.Count = SetupPacket.wLength; /* Number of bytes to transfer */\r
+ switch (SetupPacket.bmRequestType.BM.Type) {\r
+\r
+ case REQUEST_STANDARD:\r
+ switch (SetupPacket.bRequest) {\r
+ case USB_REQUEST_GET_STATUS:\r
+ if (!USB_ReqGetStatus()) {\r
+ goto stall_i;\r
+ }\r
+ USB_DataInStage();\r
+ break;\r
+\r
+ case USB_REQUEST_CLEAR_FEATURE:\r
+ if (!USB_ReqSetClrFeature(0)) {\r
+ goto stall_i;\r
+ }\r
+ USB_StatusInStage();\r
+#if USB_FEATURE_EVENT\r
+ USB_Feature_Event();\r
+#endif\r
+ break;\r
+\r
+ case USB_REQUEST_SET_FEATURE:\r
+ if (!USB_ReqSetClrFeature(1)) {\r
+ goto stall_i;\r
+ }\r
+ USB_StatusInStage();\r
+#if USB_FEATURE_EVENT\r
+ USB_Feature_Event();\r
+#endif\r
+ break;\r
+\r
+ case USB_REQUEST_SET_ADDRESS:\r
+ if (!USB_ReqSetAddress()) {\r
+ goto stall_i;\r
+ }\r
+ USB_StatusInStage();\r
+ break;\r
+\r
+ case USB_REQUEST_GET_DESCRIPTOR:\r
+ if (!USB_ReqGetDescriptor()) {\r
+ goto stall_i;\r
+ }\r
+ USB_DataInStage();\r
+ break;\r
+\r
+ case USB_REQUEST_SET_DESCRIPTOR:\r
+/*stall_o:*/ USB_SetStallEP(0x00); /* not supported */\r
+ EP0Data.Count = 0;\r
+ break;\r
+\r
+ case USB_REQUEST_GET_CONFIGURATION:\r
+ if (!USB_ReqGetConfiguration()) {\r
+ goto stall_i;\r
+ }\r
+ USB_DataInStage();\r
+ break;\r
+\r
+ case USB_REQUEST_SET_CONFIGURATION:\r
+ if (!USB_ReqSetConfiguration()) {\r
+ goto stall_i;\r
+ }\r
+ USB_StatusInStage();\r
+#if USB_CONFIGURE_EVENT\r
+ USB_Configure_Event();\r
+#endif\r
+ break;\r
+\r
+ case USB_REQUEST_GET_INTERFACE:\r
+ if (!USB_ReqGetInterface()) {\r
+ goto stall_i;\r
+ }\r
+ USB_DataInStage();\r
+ break;\r
+\r
+ case USB_REQUEST_SET_INTERFACE:\r
+ if (!USB_ReqSetInterface()) {\r
+ goto stall_i;\r
+ }\r
+ USB_StatusInStage();\r
+#if USB_INTERFACE_EVENT\r
+ USB_Interface_Event();\r
+#endif\r
+ break;\r
+\r
+ default:\r
+ goto stall_i;\r
+ }\r
+ break; /* end case REQUEST_STANDARD */\r
+\r
+#if USB_CLASS\r
+ case REQUEST_CLASS:\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+\r
+ case REQUEST_TO_DEVICE:\r
+ goto stall_i; /* not supported */\r
+\r
+ case REQUEST_TO_INTERFACE:\r
+#if USB_HID\r
+ if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { /* IF number correct? */\r
+ switch (SetupPacket.bRequest) {\r
+ case HID_REQUEST_GET_REPORT:\r
+ if (HID_GetReport()) {\r
+ EP0Data.pData = EP0Buf; /* point to data to be sent */\r
+ USB_DataInStage(); /* send requested data */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case HID_REQUEST_SET_REPORT:\r
+ EP0Data.pData = EP0Buf; /* data to be received */\r
+ goto setup_class_ok;\r
+ case HID_REQUEST_GET_IDLE:\r
+ if (HID_GetIdle()) {\r
+ EP0Data.pData = EP0Buf; /* point to data to be sent */\r
+ USB_DataInStage(); /* send requested data */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case HID_REQUEST_SET_IDLE:\r
+ if (HID_SetIdle()) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case HID_REQUEST_GET_PROTOCOL:\r
+ if (HID_GetProtocol()) {\r
+ EP0Data.pData = EP0Buf; /* point to data to be sent */\r
+ USB_DataInStage(); /* send requested data */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case HID_REQUEST_SET_PROTOCOL:\r
+ if (HID_SetProtocol()) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+#endif /* USB_HID */\r
+#if USB_MSC\r
+ if (SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) { /* IF number correct? */\r
+ switch (SetupPacket.bRequest) {\r
+ case MSC_REQUEST_RESET:\r
+ if ((SetupPacket.wValue.W == 0) && /* RESET with invalid parameters -> STALL */\r
+ (SetupPacket.wLength == 0)) {\r
+ if (MSC_Reset()) {\r
+ USB_StatusInStage();\r
+ goto setup_class_ok;\r
+ }\r
+ }\r
+ break;\r
+ case MSC_REQUEST_GET_MAX_LUN:\r
+ if ((SetupPacket.wValue.W == 0) && /* GET_MAX_LUN with invalid parameters -> STALL */\r
+ (SetupPacket.wLength == 1)) {\r
+ if (MSC_GetMaxLUN()) {\r
+ EP0Data.pData = EP0Buf;\r
+ USB_DataInStage();\r
+ goto setup_class_ok;\r
+ }\r
+ }\r
+ break;\r
+ }\r
+ }\r
+#endif /* USB_MSC */\r
+#if USB_AUDIO\r
+ if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */\r
+ (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) ||\r
+ (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) {\r
+ switch (SetupPacket.bRequest) {\r
+ case AUDIO_REQUEST_GET_CUR:\r
+ case AUDIO_REQUEST_GET_MIN:\r
+ case AUDIO_REQUEST_GET_MAX:\r
+ case AUDIO_REQUEST_GET_RES:\r
+ if (ADC_IF_GetRequest()) {\r
+ EP0Data.pData = EP0Buf; /* point to data to be sent */\r
+ USB_DataInStage(); /* send requested data */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case AUDIO_REQUEST_SET_CUR:\r
+// case AUDIO_REQUEST_SET_MIN:\r
+// case AUDIO_REQUEST_SET_MAX:\r
+// case AUDIO_REQUEST_SET_RES:\r
+ EP0Data.pData = EP0Buf; /* data to be received */\r
+ goto setup_class_ok;\r
+ }\r
+ }\r
+#endif /* USB_AUDIO */\r
+#if USB_CDC\r
+ if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */\r
+ (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) {\r
+ switch (SetupPacket.bRequest) {\r
+ case CDC_SEND_ENCAPSULATED_COMMAND:\r
+ EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */\r
+ goto setup_class_ok;\r
+ case CDC_GET_ENCAPSULATED_RESPONSE:\r
+ if (CDC_GetEncapsulatedResponse()) {\r
+ EP0Data.pData = EP0Buf; /* point to data to be sent */\r
+ USB_DataInStage(); /* send requested data */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case CDC_SET_COMM_FEATURE:\r
+ EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */\r
+ goto setup_class_ok;\r
+ case CDC_GET_COMM_FEATURE:\r
+ if (CDC_GetCommFeature(SetupPacket.wValue.W)) {\r
+ EP0Data.pData = EP0Buf; /* point to data to be sent */\r
+ USB_DataInStage(); /* send requested data */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case CDC_CLEAR_COMM_FEATURE:\r
+ if (CDC_ClearCommFeature(SetupPacket.wValue.W)) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case CDC_SET_LINE_CODING:\r
+ EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */\r
+ goto setup_class_ok;\r
+ case CDC_GET_LINE_CODING:\r
+ if (CDC_GetLineCoding()) {\r
+ EP0Data.pData = EP0Buf; /* point to data to be sent */\r
+ USB_DataInStage(); /* send requested data */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case CDC_SET_CONTROL_LINE_STATE:\r
+ if (CDC_SetControlLineState(SetupPacket.wValue.W)) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case CDC_SEND_BREAK:\r
+ if (CDC_SendBreak(SetupPacket.wValue.W)) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+#endif /* USB_CDC */\r
+ goto stall_i; /* not supported */\r
+ /* end case REQUEST_TO_INTERFACE */\r
+\r
+ case REQUEST_TO_ENDPOINT:\r
+#if USB_AUDIO\r
+ switch (SetupPacket.bRequest) {\r
+ case AUDIO_REQUEST_GET_CUR:\r
+ case AUDIO_REQUEST_GET_MIN:\r
+ case AUDIO_REQUEST_GET_MAX:\r
+ case AUDIO_REQUEST_GET_RES:\r
+ if (ADC_EP_GetRequest()) {\r
+ EP0Data.pData = EP0Buf; /* point to data to be sent */\r
+ USB_DataInStage(); /* send requested data */\r
+ goto setup_class_ok;\r
+ }\r
+ break;\r
+ case AUDIO_REQUEST_SET_CUR:\r
+// case AUDIO_REQUEST_SET_MIN:\r
+// case AUDIO_REQUEST_SET_MAX:\r
+// case AUDIO_REQUEST_SET_RES:\r
+ EP0Data.pData = EP0Buf; /* data to be received */\r
+ goto setup_class_ok;\r
+ }\r
+#endif /* USB_AUDIO */\r
+ goto stall_i;\r
+ /* end case REQUEST_TO_ENDPOINT */\r
+\r
+ default:\r
+ goto stall_i;\r
+ }\r
+setup_class_ok: /* request finished successfully */\r
+ break; /* end case REQUEST_CLASS */\r
+#endif /* USB_CLASS */\r
+\r
+#if USB_VENDOR\r
+ case REQUEST_VENDOR:\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+\r
+ case REQUEST_TO_DEVICE:\r
+ if (!USB_ReqVendorDev(TRUE)) {\r
+ goto stall_i; /* not supported */\r
+ }\r
+ break;\r
+\r
+ case REQUEST_TO_INTERFACE:\r
+ if (!USB_ReqVendorIF(TRUE)) {\r
+ goto stall_i; /* not supported */\r
+ }\r
+ break;\r
+\r
+ case REQUEST_TO_ENDPOINT:\r
+ if (!USB_ReqVendorEP(TRUE)) {\r
+ goto stall_i; /* not supported */\r
+ }\r
+ break;\r
+\r
+ default:\r
+ goto stall_i;\r
+ }\r
+\r
+ if (SetupPacket.wLength) {\r
+ if (SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) {\r
+ USB_DataInStage();\r
+ }\r
+ } else {\r
+ USB_StatusInStage();\r
+ }\r
+\r
+ break; /* end case REQUEST_VENDOR */\r
+#endif /* USB_VENDOR */\r
+\r
+ default:\r
+stall_i: USB_SetStallEP(0x80);\r
+ EP0Data.Count = 0;\r
+ break;\r
+ }\r
+ break; /* end case USB_EVT_SETUP */\r
+\r
+ case USB_EVT_OUT:\r
+ if (SetupPacket.bmRequestType.BM.Dir == REQUEST_HOST_TO_DEVICE) {\r
+ if (EP0Data.Count) { /* still data to receive ? */\r
+ USB_DataOutStage(); /* receive data */\r
+ if (EP0Data.Count == 0) { /* data complete ? */\r
+ switch (SetupPacket.bmRequestType.BM.Type) {\r
+\r
+ case REQUEST_STANDARD:\r
+ goto stall_i; /* not supported */\r
+\r
+#if (USB_CLASS)\r
+ case REQUEST_CLASS:\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+ case REQUEST_TO_DEVICE:\r
+ goto stall_i; /* not supported */\r
+\r
+ case REQUEST_TO_INTERFACE:\r
+#if USB_HID\r
+ if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { /* IF number correct? */\r
+ switch (SetupPacket.bRequest) {\r
+ case HID_REQUEST_SET_REPORT:\r
+ if (HID_SetReport()) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto out_class_ok;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+#endif /* USB_HID */\r
+#if USB_AUDIO\r
+ if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */\r
+ (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) ||\r
+ (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) {\r
+ switch (SetupPacket.bRequest) {\r
+ case AUDIO_REQUEST_SET_CUR:\r
+// case AUDIO_REQUEST_SET_MIN:\r
+// case AUDIO_REQUEST_SET_MAX:\r
+// case AUDIO_REQUEST_SET_RES:\r
+ if (ADC_IF_SetRequest()) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto out_class_ok;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+#endif /* USB_AUDIO */\r
+#if USB_CDC\r
+ if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */\r
+ (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) {\r
+ switch (SetupPacket.bRequest) {\r
+ case CDC_SEND_ENCAPSULATED_COMMAND:\r
+ if (CDC_SendEncapsulatedCommand()) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto out_class_ok;\r
+ }\r
+ break;\r
+ case CDC_SET_COMM_FEATURE:\r
+ if (CDC_SetCommFeature(SetupPacket.wValue.W)) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto out_class_ok;\r
+ }\r
+ break;\r
+ case CDC_SET_LINE_CODING:\r
+ if (CDC_SetLineCoding()) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto out_class_ok;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+#endif /* USB_CDC */\r
+ goto stall_i;\r
+ /* end case REQUEST_TO_INTERFACE */\r
+\r
+ case REQUEST_TO_ENDPOINT:\r
+#if USB_AUDIO\r
+ switch (SetupPacket.bRequest) {\r
+ case AUDIO_REQUEST_SET_CUR:\r
+// case AUDIO_REQUEST_SET_MIN:\r
+// case AUDIO_REQUEST_SET_MAX:\r
+// case AUDIO_REQUEST_SET_RES:\r
+ if (ADC_EP_SetRequest()) {\r
+ USB_StatusInStage(); /* send Acknowledge */\r
+ goto out_class_ok;\r
+ }\r
+ break;\r
+ }\r
+#endif /* USB_AUDIO */\r
+ goto stall_i;\r
+ /* end case REQUEST_TO_ENDPOINT */\r
+\r
+ default:\r
+ goto stall_i;\r
+ }\r
+out_class_ok: /* request finished successfully */\r
+ break; /* end case REQUEST_CLASS */\r
+#endif /* USB_CLASS */\r
+\r
+#if USB_VENDOR\r
+ case REQUEST_VENDOR:\r
+ switch (SetupPacket.bmRequestType.BM.Recipient) {\r
+\r
+ case REQUEST_TO_DEVICE:\r
+ if (!USB_ReqVendorDev(FALSE)) {\r
+ goto stall_i; /* not supported */\r
+ }\r
+ break;\r
+\r
+ case REQUEST_TO_INTERFACE:\r
+ if (!USB_ReqVendorIF(FALSE)) {\r
+ goto stall_i; /* not supported */\r
+ }\r
+ break;\r
+\r
+ case REQUEST_TO_ENDPOINT:\r
+ if (!USB_ReqVendorEP(FALSE)) {\r
+ goto stall_i; /* not supported */\r
+ }\r
+ break;\r
+\r
+ default:\r
+ goto stall_i;\r
+ }\r
+\r
+ USB_StatusInStage();\r
+\r
+ break; /* end case REQUEST_VENDOR */\r
+#endif /* USB_VENDOR */\r
+\r
+ default:\r
+ goto stall_i;\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ USB_StatusOutStage(); /* receive Acknowledge */\r
+ }\r
+ break; /* end case USB_EVT_OUT */\r
+\r
+ case USB_EVT_IN :\r
+ if (SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) {\r
+ USB_DataInStage(); /* send data */\r
+ } else {\r
+ if (USB_DeviceAddress & 0x80) {\r
+ USB_DeviceAddress &= 0x7F;\r
+ USB_SetAddress(USB_DeviceAddress);\r
+ }\r
+ }\r
+ break; /* end case USB_EVT_IN */\r
+\r
+ case USB_EVT_OUT_STALL:\r
+ USB_ClrStallEP(0x00);\r
+ break;\r
+\r
+ case USB_EVT_IN_STALL:\r
+ USB_ClrStallEP(0x80);\r
+ break;\r
+\r
+ }\r
+}\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbcore.h\r
+ * Purpose: USB Core Definitions\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
+#ifndef __USBCORE_H__\r
+#define __USBCORE_H__\r
+\r
+\r
+/* USB Endpoint Data Structure */\r
+typedef struct _USB_EP_DATA {\r
+ uint8_t *pData;\r
+ uint16_t Count;\r
+} USB_EP_DATA;\r
+\r
+/* USB Core Global Variables */\r
+extern uint16_t USB_DeviceStatus;\r
+extern uint8_t USB_DeviceAddress;\r
+extern uint8_t USB_Configuration;\r
+extern uint32_t USB_EndPointMask;\r
+extern uint32_t USB_EndPointHalt;\r
+extern uint32_t USB_EndPointStall;\r
+extern uint8_t USB_AltSetting[USB_IF_NUM];\r
+\r
+/* USB Endpoint 0 Buffer */\r
+extern uint8_t EP0Buf[USB_MAX_PACKET0];\r
+\r
+/* USB Endpoint 0 Data Info */\r
+extern USB_EP_DATA EP0Data;\r
+\r
+/* USB Setup Packet */\r
+extern USB_SETUP_PACKET SetupPacket;\r
+\r
+/* USB Core Functions */\r
+extern void USB_ResetCore (void);\r
+\r
+\r
+\r
+#endif /* __USBCORE_H__ */\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbdesc.c\r
+ * Purpose: USB Descriptors\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
+ * History:\r
+ * V1.20 Changed string descriptor handling\r
+ * V1.00 Initial Version\r
+ *---------------------------------------------------------------------------*/\r
+#include "lpc_types.h"\r
+#include "usb.h"\r
+#include "cdc.h"\r
+#include "usbcfg.h"\r
+#include "usbdesc.h"\r
+\r
+\r
+/* USB Standard Device Descriptor */\r
+const uint8_t USB_DeviceDescriptor[] = {\r
+ USB_DEVICE_DESC_SIZE, /* bLength */\r
+ USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ WBVAL(0x0200), /* 2.0 */ /* bcdUSB */\r
+ USB_DEVICE_CLASS_COMMUNICATIONS, /* bDeviceClass CDC*/\r
+ 0x00, /* bDeviceSubClass */\r
+ 0x00, /* bDeviceProtocol */\r
+ USB_MAX_PACKET0, /* bMaxPacketSize0 */\r
+ WBVAL(0x1FC9), /* idVendor */\r
+ WBVAL(0x2002), /* idProduct */\r
+ WBVAL(0x0100), /* 1.00 */ /* bcdDevice */\r
+ 0x01, /* iManufacturer */\r
+ 0x02, /* iProduct */\r
+ 0x03, /* iSerialNumber */\r
+ 0x01 /* bNumConfigurations: one possible configuration*/\r
+};\r
+\r
+/* USB Configuration Descriptor */\r
+/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */\r
+const uint8_t USB_ConfigDescriptor[] = {\r
+/* Configuration 1 */\r
+ USB_CONFIGUARTION_DESC_SIZE, /* bLength */\r
+ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ WBVAL( /* wTotalLength */\r
+ 1*USB_CONFIGUARTION_DESC_SIZE +\r
+ 1*USB_INTERFACE_DESC_SIZE + /* communication interface */\r
+ 0x0013 + /* CDC functions */\r
+ 1*USB_ENDPOINT_DESC_SIZE + /* interrupt endpoint */\r
+ 1*USB_INTERFACE_DESC_SIZE + /* data interface */\r
+ 2*USB_ENDPOINT_DESC_SIZE /* bulk endpoints */\r
+ ),\r
+ 0x02, /* bNumInterfaces */\r
+ 0x01, /* bConfigurationValue: 0x01 is used to select this configuration */\r
+ 0x00, /* iConfiguration: no string to describe this configuration */\r
+ USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */\r
+/*USB_CONFIG_REMOTE_WAKEUP*/,\r
+ USB_CONFIG_POWER_MA(100), /* bMaxPower, device power consumption is 100 mA */\r
+/* Interface 0, Alternate Setting 0, Communication class interface descriptor */\r
+ USB_INTERFACE_DESC_SIZE, /* bLength */\r
+ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ USB_CDC_CIF_NUM, /* bInterfaceNumber: Number of Interface */\r
+ 0x00, /* bAlternateSetting: Alternate setting */\r
+ 0x01, /* bNumEndpoints: One endpoint used */\r
+ CDC_COMMUNICATION_INTERFACE_CLASS, /* bInterfaceClass: Communication Interface Class */\r
+ CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass: Abstract Control Model */\r
+ 0x00, /* bInterfaceProtocol: no protocol used */\r
+ 0x5E, /* iInterface: */\r
+/*Header Functional Descriptor*/\r
+ 0x05, /* bLength: Endpoint Descriptor size */\r
+ CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\r
+ CDC_HEADER, /* bDescriptorSubtype: Header Func Desc */\r
+ WBVAL(CDC_V1_10), /* 1.10 */ /* bcdCDC */\r
+/*Call Management Functional Descriptor*/\r
+ 0x05, /* bFunctionLength */\r
+ CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\r
+ CDC_CALL_MANAGEMENT, /* bDescriptorSubtype: Call Management Func Desc */\r
+ 0x01, /* bmCapabilities: device handles call management */\r
+ 0x01, /* bDataInterface: CDC data IF ID */\r
+/*Abstract Control Management Functional Descriptor*/\r
+ 0x04, /* bFunctionLength */\r
+ CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\r
+ CDC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype: Abstract Control Management desc */\r
+ 0x02, /* bmCapabilities: SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported */\r
+/*Union Functional Descriptor*/\r
+ 0x05, /* bFunctionLength */\r
+ CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\r
+ CDC_UNION, /* bDescriptorSubtype: Union func desc */\r
+ USB_CDC_CIF_NUM, /* bMasterInterface: Communication class interface is master */\r
+ USB_CDC_DIF_NUM, /* bSlaveInterface0: Data class interface is slave 0 */\r
+/*Endpoint 1 Descriptor*/ /* event notification (optional) */\r
+ USB_ENDPOINT_DESC_SIZE, /* bLength */\r
+ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ USB_ENDPOINT_IN(1), /* bEndpointAddress */\r
+ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */\r
+ WBVAL(0x0010), /* wMaxPacketSize */\r
+ 0x02, /* 2ms */ /* bInterval */\r
+/* Interface 1, Alternate Setting 0, Data class interface descriptor*/\r
+ USB_INTERFACE_DESC_SIZE, /* bLength */\r
+ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ USB_CDC_DIF_NUM, /* bInterfaceNumber: Number of Interface */\r
+ 0x00, /* bAlternateSetting: no alternate setting */\r
+ 0x02, /* bNumEndpoints: two endpoints used */\r
+ CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass: Data Interface Class */\r
+ 0x00, /* bInterfaceSubClass: no subclass available */\r
+ 0x00, /* bInterfaceProtocol: no protocol used */\r
+ 0x5E, /* iInterface: */\r
+/* Endpoint, EP2 Bulk Out */\r
+ USB_ENDPOINT_DESC_SIZE, /* bLength */\r
+ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ USB_ENDPOINT_OUT(2), /* bEndpointAddress */\r
+ USB_ENDPOINT_TYPE_BULK, /* bmAttributes */\r
+ WBVAL(USB_CDC_BUFSIZE), /* wMaxPacketSize */\r
+ 0x00, /* bInterval: ignore for Bulk transfer */\r
+/* Endpoint, EP2 Bulk In */\r
+ USB_ENDPOINT_DESC_SIZE, /* bLength */\r
+ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ USB_ENDPOINT_IN(2), /* bEndpointAddress */\r
+ USB_ENDPOINT_TYPE_BULK, /* bmAttributes */\r
+ WBVAL(USB_CDC_BUFSIZE), /* wMaxPacketSize */\r
+ 0x00, /* bInterval: ignore for Bulk transfer */\r
+/* Terminator */\r
+ 0 /* bLength */\r
+};\r
+\r
+\r
+\r
+\r
+/* USB String Descriptor (optional) */\r
+const uint8_t USB_StringDescriptor[] = {\r
+/* Index 0x00: LANGID Codes */\r
+ 0x04, /* bLength */\r
+ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ WBVAL(0x0409), /* US English */ /* wLANGID */\r
+/* Index 0x01: Manufacturer */\r
+ (13*2 + 2), /* bLength (13 Char + Type + lenght) */\r
+ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ 'N',0,\r
+ 'X',0,\r
+ 'P',0,\r
+ ' ',0,\r
+ 'S',0,\r
+ 'E',0,\r
+ 'M',0,\r
+ 'I',0,\r
+ 'C',0,\r
+ 'O',0,\r
+ 'N',0,\r
+ 'D',0,\r
+ ' ',0,\r
+/* Index 0x02: Product */\r
+ (17*2 + 2), /* bLength ( 17 Char + Type + lenght) */\r
+ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ 'N',0,\r
+ 'X',0,\r
+ 'P',0,\r
+ ' ',0,\r
+ 'L',0,\r
+ 'P',0,\r
+ 'C',0,\r
+ '1',0,\r
+ '7',0,\r
+ 'x',0,\r
+ 'x',0,\r
+ ' ',0,\r
+ 'V',0,\r
+ 'C',0,\r
+ 'O',0,\r
+ 'M',0,\r
+ ' ',0,\r
+/* Index 0x03: Serial Number */\r
+ (12*2 + 2), /* bLength (12 Char + Type + lenght) */\r
+ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ 'D',0,\r
+ 'E',0,\r
+ 'M',0,\r
+ 'O',0,\r
+ '0',0,\r
+ '0',0,\r
+ '0',0,\r
+ '0',0,\r
+ '0',0,\r
+ '0',0,\r
+ '0',0,\r
+ '0',0,\r
+/* Index 0x04: Interface 0, Alternate Setting 0 */\r
+ ( 4*2 + 2), /* bLength (4 Char + Type + lenght) */\r
+ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */\r
+ 'V',0,\r
+ 'C',0,\r
+ 'O',0,\r
+ 'M',0,\r
+};\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbdesc.h\r
+ * Purpose: USB Descriptors Definitions\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
+#ifndef __USBDESC_H__\r
+#define __USBDESC_H__\r
+\r
+\r
+#define WBVAL(x) (x & 0xFF),((x >> 8) & 0xFF)\r
+\r
+#define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR))\r
+#define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR))\r
+#define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR))\r
+#define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR))\r
+\r
+extern const uint8_t USB_DeviceDescriptor[];\r
+extern const uint8_t USB_ConfigDescriptor[];\r
+extern const uint8_t USB_StringDescriptor[];\r
+\r
+\r
+#endif /* __USBDESC_H__ */\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbhw.c\r
+ * Purpose: USB Hardware Layer Module for NXP's LPC17xx MCU\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 family microcontroller devices only. Nothing \r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *----------------------------------------------------------------------------\r
+ * History:\r
+ * V1.20 Added USB_ClearEPBuf\r
+ * V1.00 Initial Version\r
+ *----------------------------------------------------------------------------*/\r
+#include "../LPC17xx.h" /* LPC17xx definitions */\r
+#include "usb.h"\r
+#include "usbcfg.h"\r
+#include "usbreg.h"\r
+#include "usbhw.h"\r
+#include "usbcore.h"\r
+#include "usbuser.h"\r
+\r
+#if defined ( __CC_ARM__ )\r
+#pragma diag_suppress 1441\r
+#endif\r
+\r
+\r
+#define EP_MSK_CTRL 0x0001 /* Control Endpoint Logical Address Mask */\r
+#define EP_MSK_BULK 0xC924 /* Bulk Endpoint Logical Address Mask */\r
+#define EP_MSK_INT 0x4492 /* Interrupt Endpoint Logical Address Mask */\r
+#define EP_MSK_ISO 0x1248 /* Isochronous Endpoint Logical Address Mask */\r
+\r
+\r
+#if USB_DMA\r
+\r
+#pragma arm section zidata = "USB_RAM"\r
+uint32_t UDCA[USB_EP_NUM]; /* UDCA in USB RAM */\r
+uint32_t DD_NISO_Mem[4*DD_NISO_CNT]; /* Non-Iso DMA Descriptor Memory */\r
+uint32_t DD_ISO_Mem [5*DD_ISO_CNT]; /* Iso DMA Descriptor Memory */\r
+#pragma arm section zidata\r
+uint32_t udca[USB_EP_NUM]; /* UDCA saved values */\r
+\r
+uint32_t DDMemMap[2]; /* DMA Descriptor Memory Usage */\r
+\r
+#endif\r
+\r
+\r
+/*\r
+ * Get Endpoint Physical Address\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: Endpoint Physical Address\r
+ */\r
+\r
+uint32_t EPAdr (uint32_t EPNum) {\r
+ uint32_t val;\r
+\r
+ val = (EPNum & 0x0F) << 1;\r
+ if (EPNum & 0x80) {\r
+ val += 1;\r
+ }\r
+ return (val);\r
+}\r
+\r
+\r
+/*\r
+ * Write Command\r
+ * Parameters: cmd: Command\r
+ * Return Value: None\r
+ */\r
+\r
+void WrCmd (uint32_t cmd) {\r
+\r
+ USB->USBDevIntClr = CCEMTY_INT;\r
+ USB->USBCmdCode = cmd;\r
+ while ((USB->USBDevIntSt & CCEMTY_INT) == 0);\r
+}\r
+\r
+\r
+/*\r
+ * Write Command Data\r
+ * Parameters: cmd: Command\r
+ * val: Data\r
+ * Return Value: None\r
+ */\r
+\r
+void WrCmdDat (uint32_t cmd, uint32_t val) {\r
+\r
+ USB->USBDevIntClr = CCEMTY_INT;\r
+ USB->USBCmdCode = cmd;\r
+ while ((USB->USBDevIntSt & CCEMTY_INT) == 0);\r
+ USB->USBDevIntClr = CCEMTY_INT;\r
+ USB->USBCmdCode = val;\r
+ while ((USB->USBDevIntSt & CCEMTY_INT) == 0);\r
+}\r
+\r
+\r
+/*\r
+ * Write Command to Endpoint\r
+ * Parameters: cmd: Command\r
+ * val: Data\r
+ * Return Value: None\r
+ */\r
+\r
+void WrCmdEP (uint32_t EPNum, uint32_t cmd){\r
+\r
+ USB->USBDevIntClr = CCEMTY_INT;\r
+ USB->USBCmdCode = CMD_SEL_EP(EPAdr(EPNum));\r
+ while ((USB->USBDevIntSt & CCEMTY_INT) == 0);\r
+ USB->USBDevIntClr = CCEMTY_INT;\r
+ USB->USBCmdCode = cmd;\r
+ while ((USB->USBDevIntSt & CCEMTY_INT) == 0);\r
+}\r
+\r
+\r
+/*\r
+ * Read Command Data\r
+ * Parameters: cmd: Command\r
+ * Return Value: Data Value\r
+ */\r
+\r
+uint32_t RdCmdDat (uint32_t cmd) {\r
+\r
+ USB->USBDevIntClr = CCEMTY_INT | CDFULL_INT;\r
+ USB->USBCmdCode = cmd;\r
+ while ((USB->USBDevIntSt & CDFULL_INT) == 0);\r
+ return (USB->USBCmdData);\r
+}\r
+\r
+\r
+/*\r
+ * USB Initialize Function\r
+ * Called by the User to initialize USB\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_Init (void) {\r
+\r
+ PINCON->PINSEL1 &= ~((3<<26)|(3<<28)); /* P0.29 D+, P0.30 D- */\r
+ PINCON->PINSEL1 |= ((1<<26)|(1<<28)); /* PINSEL1 26.27, 28.29 = 01 */\r
+\r
+ PINCON->PINSEL3 &= ~((3<< 4)|(3<<28)); /* P1.18 GoodLink, P1.30 VBUS */\r
+ PINCON->PINSEL3 |= ((1<< 4)|(2<<28)); /* PINSEL3 4.5 = 01, 28.29 = 10 */\r
+\r
+ PINCON->PINSEL4 &= ~((3<<18) ); /* P2.9 SoftConnect */\r
+ PINCON->PINSEL4 |= ((1<<18) ); /* PINSEL4 18.19 = 01 */\r
+\r
+ SC->PCONP |= (1UL<<31); /* USB PCLK -> enable USB Per. */\r
+\r
+ USB->USBClkCtrl = 0x1A; /* Dev, PortSel, AHB clock enable */\r
+ while ((USB->USBClkSt & 0x1A) != 0x1A); \r
+\r
+ NVIC_EnableIRQ(USB_IRQn); /* enable USB interrupt */\r
+\r
+ USB_Reset();\r
+ USB_SetAddress(0);\r
+}\r
+\r
+\r
+/*\r
+ * USB Connect Function\r
+ * Called by the User to Connect/Disconnect USB\r
+ * Parameters: con: Connect/Disconnect\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_Connect (uint32_t con) {\r
+ WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(con ? DEV_CON : 0));\r
+}\r
+\r
+\r
+/*\r
+ * USB Reset Function\r
+ * Called automatically on USB Reset\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_Reset (void) {\r
+#if USB_DMA\r
+ uint32_t n;\r
+#endif\r
+\r
+ USB->USBEpInd = 0;\r
+ USB->USBMaxPSize = USB_MAX_PACKET0;\r
+ USB->USBEpInd = 1;\r
+ USB->USBMaxPSize = USB_MAX_PACKET0;\r
+ while ((USB->USBDevIntSt & EP_RLZED_INT) == 0);\r
+\r
+ USB->USBEpIntClr = 0xFFFFFFFF;\r
+ USB->USBEpIntEn = 0xFFFFFFFF ^ USB_DMA_EP;\r
+ USB->USBDevIntClr = 0xFFFFFFFF;\r
+ USB->USBDevIntEn = DEV_STAT_INT | EP_SLOW_INT |\r
+ (USB_SOF_EVENT ? FRAME_INT : 0) |\r
+ (USB_ERROR_EVENT ? ERR_INT : 0);\r
+\r
+#if USB_DMA\r
+ USB->USBUDCAH = USB_RAM_ADR;\r
+ USB->USBDMARClr = 0xFFFFFFFF;\r
+ USB->USBEpDMADis = 0xFFFFFFFF;\r
+ USB->USBEpDMAEn = USB_DMA_EP;\r
+ USB->USBEoTIntClr = 0xFFFFFFFF;\r
+ USB->USBNDDRIntClr = 0xFFFFFFFF;\r
+ USB->USBSysErrIntClr = 0xFFFFFFFF;\r
+ USB->USBDMAIntEn = 0x00000007;\r
+ DDMemMap[0] = 0x00000000;\r
+ DDMemMap[1] = 0x00000000;\r
+ for (n = 0; n < USB_EP_NUM; n++) {\r
+ udca[n] = 0;\r
+ UDCA[n] = 0;\r
+ }\r
+#endif\r
+}\r
+\r
+\r
+/*\r
+ * USB Suspend Function\r
+ * Called automatically on USB Suspend\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_Suspend (void) {\r
+ /* Performed by Hardware */\r
+}\r
+\r
+\r
+/*\r
+ * USB Resume Function\r
+ * Called automatically on USB Resume\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_Resume (void) {\r
+ /* Performed by Hardware */\r
+}\r
+\r
+\r
+/*\r
+ * USB Remote Wakeup Function\r
+ * Called automatically on USB Remote Wakeup\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_WakeUp (void) {\r
+\r
+ if (USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP) {\r
+ WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON));\r
+ }\r
+}\r
+\r
+\r
+/*\r
+ * USB Remote Wakeup Configuration Function\r
+ * Parameters: cfg: Enable/Disable\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_WakeUpCfg (uint32_t cfg) {\r
+ /* Not needed */\r
+}\r
+\r
+\r
+/*\r
+ * USB Set Address Function\r
+ * Parameters: adr: USB Address\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_SetAddress (uint32_t adr) {\r
+ WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Don't wait for next */\r
+ WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Setup Status Phase */\r
+}\r
+\r
+\r
+/*\r
+ * USB Configure Function\r
+ * Parameters: cfg: Configure/Deconfigure\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_Configure (uint32_t cfg) {\r
+\r
+ WrCmdDat(CMD_CFG_DEV, DAT_WR_BYTE(cfg ? CONF_DVICE : 0));\r
+\r
+ USB->USBReEp = 0x00000003;\r
+ while ((USB->USBDevIntSt & EP_RLZED_INT) == 0);\r
+ USB->USBDevIntClr = EP_RLZED_INT;\r
+}\r
+\r
+\r
+/*\r
+ * Configure USB Endpoint according to Descriptor\r
+ * Parameters: pEPD: Pointer to Endpoint Descriptor\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) {\r
+ uint32_t num;\r
+\r
+ num = EPAdr(pEPD->bEndpointAddress);\r
+ USB->USBReEp |= (1 << num);\r
+ USB->USBEpInd = num;\r
+ USB->USBMaxPSize = pEPD->wMaxPacketSize;\r
+ while ((USB->USBDevIntSt & EP_RLZED_INT) == 0);\r
+ USB->USBDevIntClr = EP_RLZED_INT;\r
+}\r
+\r
+\r
+/*\r
+ * Set Direction for USB Control Endpoint\r
+ * Parameters: dir: Out (dir == 0), In (dir <> 0)\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_DirCtrlEP (uint32_t dir) {\r
+ /* Not needed */\r
+}\r
+\r
+\r
+/*\r
+ * Enable USB Endpoint\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_EnableEP (uint32_t EPNum) {\r
+ WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0));\r
+}\r
+\r
+\r
+/*\r
+ * Disable USB Endpoint\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_DisableEP (uint32_t EPNum) {\r
+ WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(EP_STAT_DA));\r
+}\r
+\r
+\r
+/*\r
+ * Reset USB Endpoint\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_ResetEP (uint32_t EPNum) {\r
+ WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0));\r
+}\r
+\r
+\r
+/*\r
+ * Set Stall for USB Endpoint\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_SetStallEP (uint32_t EPNum) {\r
+ WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(EP_STAT_ST));\r
+}\r
+\r
+\r
+/*\r
+ * Clear Stall for USB Endpoint\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_ClrStallEP (uint32_t EPNum) {\r
+ WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0));\r
+}\r
+\r
+\r
+/*\r
+ * Clear USB Endpoint Buffer\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_ClearEPBuf (uint32_t EPNum) {\r
+ WrCmdEP(EPNum, CMD_CLR_BUF);\r
+}\r
+\r
+\r
+/*\r
+ * Read USB Endpoint Data\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * pData: Pointer to Data Buffer\r
+ * Return Value: Number of bytes read\r
+ */\r
+\r
+uint32_t USB_ReadEP (uint32_t EPNum, uint8_t *pData) {\r
+ uint32_t cnt, n;\r
+\r
+ USB->USBCtrl = ((EPNum & 0x0F) << 2) | CTRL_RD_EN;\r
+\r
+ do {\r
+ cnt = USB->USBRxPLen;\r
+ } while ((cnt & PKT_RDY) == 0);\r
+ cnt &= PKT_LNGTH_MASK;\r
+\r
+ for (n = 0; n < (cnt + 3) / 4; n++) {\r
+ *((__packed uint32_t *)pData) = USB->USBRxData;\r
+ pData += 4;\r
+ }\r
+ USB->USBCtrl = 0;\r
+\r
+ if (((EP_MSK_ISO >> EPNum) & 1) == 0) { /* Non-Isochronous Endpoint */\r
+ WrCmdEP(EPNum, CMD_CLR_BUF);\r
+ }\r
+\r
+ return (cnt);\r
+}\r
+\r
+\r
+/*\r
+ * Write USB Endpoint Data\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * pData: Pointer to Data Buffer\r
+ * cnt: Number of bytes to write\r
+ * Return Value: Number of bytes written\r
+ */\r
+\r
+uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt) {\r
+ uint32_t n;\r
+\r
+ USB->USBCtrl = ((EPNum & 0x0F) << 2) | CTRL_WR_EN;\r
+\r
+ USB->USBTxPLen = cnt;\r
+\r
+ for (n = 0; n < (cnt + 3) / 4; n++) {\r
+ USB->USBTxData = *((__packed uint32_t *)pData);\r
+ pData += 4;\r
+ }\r
+ USB->USBCtrl = 0;\r
+ WrCmdEP(EPNum, CMD_VALID_BUF);\r
+ return (cnt);\r
+}\r
+\r
+#if USB_DMA\r
+\r
+/* DMA Descriptor Memory Layout */\r
+const uint32_t DDAdr[2] = { DD_NISO_ADR, DD_ISO_ADR };\r
+const uint32_t DDSz [2] = { 16, 20 };\r
+\r
+\r
+/*\r
+ * Setup USB DMA Transfer for selected Endpoint\r
+ * Parameters: EPNum: Endpoint Number\r
+ * pDD: Pointer to DMA Descriptor\r
+ * Return Value: TRUE - Success, FALSE - Error\r
+ */\r
+\r
+uint32_t USB_DMA_Setup(uint32_t EPNum, USB_DMA_DESCRIPTOR *pDD) {\r
+ uint32_t num, ptr, nxt, iso, n;\r
+\r
+ iso = pDD->Cfg.Type.IsoEP; /* Iso or Non-Iso Descriptor */\r
+ num = EPAdr(EPNum); /* Endpoint's Physical Address */\r
+\r
+ ptr = 0; /* Current Descriptor */\r
+ nxt = udca[num]; /* Initial Descriptor */\r
+ while (nxt) { /* Go through Descriptor List */\r
+ ptr = nxt; /* Current Descriptor */\r
+ if (!pDD->Cfg.Type.Link) { /* Check for Linked Descriptors */\r
+ n = (ptr - DDAdr[iso]) / DDSz[iso]; /* Descriptor Index */\r
+ DDMemMap[iso] &= ~(1 << n); /* Unmark Memory Usage */\r
+ }\r
+ nxt = *((uint32_t *)ptr); /* Next Descriptor */\r
+ }\r
+\r
+ for (n = 0; n < 32; n++) { /* Search for available Memory */\r
+ if ((DDMemMap[iso] & (1 << n)) == 0) {\r
+ break; /* Memory found */\r
+ }\r
+ }\r
+ if (n == 32) return (FALSE); /* Memory not available */\r
+\r
+ DDMemMap[iso] |= 1 << n; /* Mark Memory Usage */\r
+ nxt = DDAdr[iso] + n * DDSz[iso]; /* Next Descriptor */\r
+\r
+ if (ptr && pDD->Cfg.Type.Link) {\r
+ *((uint32_t *)(ptr + 0)) = nxt; /* Link in new Descriptor */\r
+ *((uint32_t *)(ptr + 4)) |= 0x00000004; /* Next DD is Valid */\r
+ } else {\r
+ udca[num] = nxt; /* Save new Descriptor */\r
+ UDCA[num] = nxt; /* Update UDCA in USB */\r
+ }\r
+\r
+ /* Fill in DMA Descriptor */\r
+ *(((uint32_t *)nxt)++) = 0; /* Next DD Pointer */\r
+ *(((uint32_t *)nxt)++) = pDD->Cfg.Type.ATLE |\r
+ (pDD->Cfg.Type.IsoEP << 4) |\r
+ (pDD->MaxSize << 5) |\r
+ (pDD->BufLen << 16);\r
+ *(((uint32_t *)nxt)++) = pDD->BufAdr;\r
+ *(((uint32_t *)nxt)++) = pDD->Cfg.Type.LenPos << 8;\r
+ if (iso) {\r
+ *((uint32_t *)nxt) = pDD->InfoAdr;\r
+ }\r
+\r
+ return (TRUE); /* Success */\r
+}\r
+\r
+\r
+/*\r
+ * Enable USB DMA Endpoint\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_DMA_Enable (uint32_t EPNum) {\r
+ USB->USBEpDMAEn = 1 << EPAdr(EPNum);\r
+}\r
+\r
+\r
+/*\r
+ * Disable USB DMA Endpoint\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: None\r
+ */\r
+\r
+void USB_DMA_Disable (uint32_t EPNum) {\r
+ USB->USBEpDMADis = 1 << EPAdr(EPNum);\r
+}\r
+\r
+\r
+/*\r
+ * Get USB DMA Endpoint Status\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: DMA Status\r
+ */\r
+\r
+uint32_t USB_DMA_Status (uint32_t EPNum) {\r
+ uint32_t ptr, val;\r
+ \r
+ ptr = UDCA[EPAdr(EPNum)]; /* Current Descriptor */\r
+ if (ptr == 0) \r
+ return (USB_DMA_INVALID);\r
+\r
+ val = *((uint32_t *)(ptr + 3*4)); /* Status Information */\r
+ switch ((val >> 1) & 0x0F) {\r
+ case 0x00: /* Not serviced */\r
+ return (USB_DMA_IDLE);\r
+ case 0x01: /* Being serviced */\r
+ return (USB_DMA_BUSY);\r
+ case 0x02: /* Normal Completition */\r
+ return (USB_DMA_DONE);\r
+ case 0x03: /* Data Under Run */\r
+ return (USB_DMA_UNDER_RUN);\r
+ case 0x08: /* Data Over Run */\r
+ return (USB_DMA_OVER_RUN);\r
+ case 0x09: /* System Error */\r
+ return (USB_DMA_ERROR);\r
+ }\r
+\r
+ return (USB_DMA_UNKNOWN);\r
+}\r
+\r
+\r
+/*\r
+ * Get USB DMA Endpoint Current Buffer Address\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: DMA Address (or -1 when DMA is Invalid)\r
+ */\r
+\r
+uint32_t USB_DMA_BufAdr (uint32_t EPNum) {\r
+ uint32_t ptr, val;\r
+\r
+ ptr = UDCA[EPAdr(EPNum)]; /* Current Descriptor */\r
+ if (ptr == 0)\r
+ {\r
+ return ((uint32_t)(-1)); /* DMA Invalid */\r
+ }\r
+\r
+ val = *((uint32_t *)(ptr + 2*4)); /* Buffer Address */\r
+ return (val); /* Current Address */\r
+}\r
+\r
+\r
+/*\r
+ * Get USB DMA Endpoint Current Buffer Count\r
+ * Number of transfered Bytes or Iso Packets\r
+ * Parameters: EPNum: Endpoint Number\r
+ * EPNum.0..3: Address\r
+ * EPNum.7: Dir\r
+ * Return Value: DMA Count (or -1 when DMA is Invalid)\r
+ */\r
+\r
+uint32_t USB_DMA_BufCnt (uint32_t EPNum) {\r
+ uint32_t ptr, val;\r
+\r
+ ptr = UDCA[EPAdr(EPNum)]; /* Current Descriptor */\r
+ if (ptr == 0)\r
+ { \r
+ return ((uint32_t)(-1)); /* DMA Invalid */\r
+ }\r
+ val = *((uint32_t *)(ptr + 3*4)); /* Status Information */\r
+ return (val >> 16); /* Current Count */\r
+}\r
+\r
+\r
+#endif /* USB_DMA */\r
+\r
+\r
+/*\r
+ * Get USB Last Frame Number\r
+ * Parameters: None\r
+ * Return Value: Frame Number\r
+ */\r
+\r
+uint32_t USB_GetFrame (void) {\r
+ uint32_t val;\r
+\r
+ WrCmd(CMD_RD_FRAME);\r
+ val = RdCmdDat(DAT_RD_FRAME);\r
+ val = val | (RdCmdDat(DAT_RD_FRAME) << 8);\r
+\r
+ return (val);\r
+}\r
+\r
+\r
+/*\r
+ * USB Interrupt Service Routine\r
+ */\r
+\r
+void USB_IRQHandler (void) {\r
+ uint32_t disr, val, n, m;\r
+ uint32_t episr, episrCur;\r
+\r
+ disr = USB->USBDevIntSt; /* Device Interrupt Status */\r
+\r
+ /* Device Status Interrupt (Reset, Connect change, Suspend/Resume) */\r
+ if (disr & DEV_STAT_INT) {\r
+ USB->USBDevIntClr = DEV_STAT_INT;\r
+ WrCmd(CMD_GET_DEV_STAT);\r
+ val = RdCmdDat(DAT_GET_DEV_STAT); /* Device Status */\r
+ if (val & DEV_RST) { /* Reset */\r
+ USB_Reset();\r
+#if USB_RESET_EVENT\r
+ USB_Reset_Event();\r
+#endif\r
+ }\r
+ if (val & DEV_CON_CH) { /* Connect change */\r
+#if USB_POWER_EVENT\r
+ USB_Power_Event(val & DEV_CON);\r
+#endif\r
+ }\r
+ if (val & DEV_SUS_CH) { /* Suspend/Resume */\r
+ if (val & DEV_SUS) { /* Suspend */\r
+ USB_Suspend();\r
+#if USB_SUSPEND_EVENT\r
+ USB_Suspend_Event();\r
+#endif\r
+ } else { /* Resume */\r
+ USB_Resume();\r
+#if USB_RESUME_EVENT\r
+ USB_Resume_Event();\r
+#endif\r
+ }\r
+ }\r
+ goto isr_end;\r
+ }\r
+\r
+#if USB_SOF_EVENT\r
+ /* Start of Frame Interrupt */\r
+ if (disr & FRAME_INT) {\r
+ USB_SOF_Event();\r
+ }\r
+#endif\r
+\r
+#if USB_ERROR_EVENT\r
+ /* Error Interrupt */\r
+ if (disr & ERR_INT) {\r
+ WrCmd(CMD_RD_ERR_STAT);\r
+ val = RdCmdDat(DAT_RD_ERR_STAT);\r
+ USB_Error_Event(val);\r
+ }\r
+#endif\r
+\r
+ /* Endpoint's Slow Interrupt */\r
+ if (disr & EP_SLOW_INT) {\r
+ episrCur = 0;\r
+ episr = USB->USBEpIntSt;\r
+ for (n = 0; n < USB_EP_NUM; n++) { /* Check All Endpoints */\r
+ if (episr == episrCur) break; /* break if all EP interrupts handled */\r
+ if (episr & (1 << n)) {\r
+ episrCur |= (1 << n);\r
+ m = n >> 1;\r
+ \r
+ USB->USBEpIntClr = (1 << n);\r
+ while ((USB->USBDevIntSt & CDFULL_INT) == 0);\r
+ val = USB->USBCmdData;\r
+ \r
+ if ((n & 1) == 0) { /* OUT Endpoint */\r
+ if (n == 0) { /* Control OUT Endpoint */\r
+ if (val & EP_SEL_STP) { /* Setup Packet */\r
+ if (USB_P_EP[0]) {\r
+ USB_P_EP[0](USB_EVT_SETUP);\r
+ continue;\r
+ }\r
+ }\r
+ }\r
+ if (USB_P_EP[m]) {\r
+ USB_P_EP[m](USB_EVT_OUT);\r
+ }\r
+ } else { /* IN Endpoint */\r
+ if (USB_P_EP[m]) {\r
+ USB_P_EP[m](USB_EVT_IN);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ USB->USBDevIntClr = EP_SLOW_INT;\r
+ }\r
+\r
+#if USB_DMA\r
+\r
+ if (USB->USBDMAIntSt & 0x00000001) { /* End of Transfer Interrupt */\r
+ val = USB->USBEoTIntSt;\r
+ for (n = 2; n < USB_EP_NUM; n++) { /* Check All Endpoints */\r
+ if (val & (1 << n)) {\r
+ m = n >> 1;\r
+ if ((n & 1) == 0) { /* OUT Endpoint */\r
+ if (USB_P_EP[m]) {\r
+ USB_P_EP[m](USB_EVT_OUT_DMA_EOT);\r
+ }\r
+ } else { /* IN Endpoint */\r
+ if (USB_P_EP[m]) {\r
+ USB_P_EP[m](USB_EVT_IN_DMA_EOT);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ USB->USBEoTIntClr = val;\r
+ }\r
+\r
+ if (USB->USBDMAIntSt & 0x00000002) { /* New DD Request Interrupt */\r
+ val = USB->USBNDDRIntSt;\r
+ for (n = 2; n < USB_EP_NUM; n++) { /* Check All Endpoints */\r
+ if (val & (1 << n)) {\r
+ m = n >> 1;\r
+ if ((n & 1) == 0) { /* OUT Endpoint */\r
+ if (USB_P_EP[m]) {\r
+ USB_P_EP[m](USB_EVT_OUT_DMA_NDR);\r
+ }\r
+ } else { /* IN Endpoint */\r
+ if (USB_P_EP[m]) {\r
+ USB_P_EP[m](USB_EVT_IN_DMA_NDR);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ USB->USBNDDRIntClr = val;\r
+ }\r
+\r
+ if (USB->USBDMAIntSt & 0x00000004) { /* System Error Interrupt */\r
+ val = USB->USBSysErrIntSt;\r
+ for (n = 2; n < USB_EP_NUM; n++) { /* Check All Endpoints */\r
+ if (val & (1 << n)) {\r
+ m = n >> 1;\r
+ if ((n & 1) == 0) { /* OUT Endpoint */\r
+ if (USB_P_EP[m]) {\r
+ USB_P_EP[m](USB_EVT_OUT_DMA_ERR);\r
+ }\r
+ } else { /* IN Endpoint */\r
+ if (USB_P_EP[m]) {\r
+ USB_P_EP[m](USB_EVT_IN_DMA_ERR);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ USB->USBSysErrIntClr = val;\r
+ }\r
+\r
+#endif /* USB_DMA */\r
+\r
+isr_end:\r
+ return;\r
+}\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbhw.h\r
+ * Purpose: USB Hardware Layer Definitions\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 family microcontroller devices only. Nothing\r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *----------------------------------------------------------------------------\r
+ * History:\r
+ * V1.20 Added USB_ClearEPBuf\r
+ * V1.00 Initial Version\r
+ *----------------------------------------------------------------------------*/\r
+\r
+#ifndef __USBHW_H__\r
+#define __USBHW_H__\r
+#include "lpc_types.h"\r
+\r
+/* USB RAM Definitions */\r
+#define USB_RAM_ADR 0x20080000 /* USB RAM Start Address */\r
+#define USB_RAM_SZ 0x00004000 /* USB RAM Size (4kB) */\r
+\r
+/* DMA Endpoint Descriptors */\r
+#define DD_NISO_CNT 16 /* Non-Iso EP DMA Descr. Count (max. 32) */\r
+#define DD_ISO_CNT 8 /* Iso EP DMA Descriptor Count (max. 32) */\r
+#define DD_NISO_SZ (DD_NISO_CNT * 16) /* Non-Iso DMA Descr. Size */\r
+#define DD_ISO_SZ (DD_ISO_CNT * 20) /* Iso DMA Descriptor Size */\r
+#define DD_NISO_ADR (USB_RAM_ADR + 128) /* Non-Iso DMA Descr. Address */\r
+#define DD_ISO_ADR (DD_NISO_ADR + DD_NISO_SZ) /* Iso DMA Descr. Address */\r
+#define DD_SZ (128 + DD_NISO_SZ + DD_ISO_SZ) /* Descr. Size */\r
+\r
+/* DMA Buffer Memory Definitions */\r
+#define DMA_BUF_ADR (USB_RAM_ADR + DD_SZ) /* DMA Buffer Start Address */\r
+#define DMA_BUF_SZ (USB_RAM_SZ - DD_SZ) /* DMA Buffer Size */\r
+\r
+/* USB Error Codes */\r
+#define USB_ERR_PID 0x0001 /* PID Error */\r
+#define USB_ERR_UEPKT 0x0002 /* Unexpected Packet */\r
+#define USB_ERR_DCRC 0x0004 /* Data CRC Error */\r
+#define USB_ERR_TIMOUT 0x0008 /* Bus Time-out Error */\r
+#define USB_ERR_EOP 0x0010 /* End of Packet Error */\r
+#define USB_ERR_B_OVRN 0x0020 /* Buffer Overrun */\r
+#define USB_ERR_BTSTF 0x0040 /* Bit Stuff Error */\r
+#define USB_ERR_TGL 0x0080 /* Toggle Bit Error */\r
+\r
+/* USB DMA Status Codes */\r
+#define USB_DMA_INVALID 0x0000 /* DMA Invalid - Not Configured */\r
+#define USB_DMA_IDLE 0x0001 /* DMA Idle - Waiting for Trigger */\r
+#define USB_DMA_BUSY 0x0002 /* DMA Busy - Transfer in progress */\r
+#define USB_DMA_DONE 0x0003 /* DMA Transfer Done (no Errors)*/\r
+#define USB_DMA_OVER_RUN 0x0004 /* Data Over Run */\r
+#define USB_DMA_UNDER_RUN 0x0005 /* Data Under Run (Short Packet) */\r
+#define USB_DMA_ERROR 0x0006 /* Error */\r
+#define USB_DMA_UNKNOWN 0xFFFF /* Unknown State */\r
+\r
+/* USB DMA Descriptor */\r
+typedef struct _USB_DMA_DESCRIPTOR {\r
+ uint32_t BufAdr; /* DMA Buffer Address */\r
+ uint16_t BufLen; /* DMA Buffer Length */\r
+ uint16_t MaxSize; /* Maximum Packet Size */\r
+ uint32_t InfoAdr; /* Packet Info Memory Address */\r
+ union { /* DMA Configuration */\r
+ struct {\r
+ uint32_t Link : 1; /* Link to existing Descriptors */\r
+ uint32_t IsoEP : 1; /* Isonchronous Endpoint */\r
+ uint32_t ATLE : 1; /* ATLE (Auto Transfer Length Extract) */\r
+ uint32_t Rsrvd : 5; /* Reserved */\r
+ uint32_t LenPos : 8; /* Length Position (ATLE) */\r
+ } Type;\r
+ uint32_t Val;\r
+ } Cfg;\r
+} USB_DMA_DESCRIPTOR;\r
+\r
+/* USB Hardware Functions */\r
+extern void USB_Init (void);\r
+extern void USB_Connect (uint32_t con);\r
+extern void USB_Reset (void);\r
+extern void USB_Suspend (void);\r
+extern void USB_Resume (void);\r
+extern void USB_WakeUp (void);\r
+extern void USB_WakeUpCfg (uint32_t cfg);\r
+extern void USB_SetAddress (uint32_t adr);\r
+extern void USB_Configure (uint32_t cfg);\r
+extern void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD);\r
+extern void USB_DirCtrlEP (uint32_t dir);\r
+extern void USB_EnableEP (uint32_t EPNum);\r
+extern void USB_DisableEP (uint32_t EPNum);\r
+extern void USB_ResetEP (uint32_t EPNum);\r
+extern void USB_SetStallEP (uint32_t EPNum);\r
+extern void USB_ClrStallEP (uint32_t EPNum);\r
+extern void USB_ClearEPBuf (uint32_t EPNum);\r
+extern uint32_t USB_ReadEP (uint32_t EPNum, uint8_t *pData);\r
+extern uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt);\r
+extern uint32_t USB_DMA_Setup (uint32_t EPNum, USB_DMA_DESCRIPTOR *pDD);\r
+extern void USB_DMA_Enable (uint32_t EPNum);\r
+extern void USB_DMA_Disable(uint32_t EPNum);\r
+extern uint32_t USB_DMA_Status (uint32_t EPNum);\r
+extern uint32_t USB_DMA_BufAdr (uint32_t EPNum);\r
+extern uint32_t USB_DMA_BufCnt (uint32_t EPNum);\r
+extern uint32_t USB_GetFrame (void);\r
+extern void USB_IRQHandler (void);\r
+\r
+\r
+#endif /* __USBHW_H__ */\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbreg.h\r
+ * Purpose: USB Hardware Layer Definitions for NXP LPC Family MCUs\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 family microcontroller devices only. Nothing \r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *---------------------------------------------------------------------------*/\r
+\r
+#ifndef __USBREG_H\r
+#define __USBREG_H\r
+\r
+/* Device Interrupt Bit Definitions */\r
+#define FRAME_INT 0x00000001\r
+#define EP_FAST_INT 0x00000002\r
+#define EP_SLOW_INT 0x00000004\r
+#define DEV_STAT_INT 0x00000008\r
+#define CCEMTY_INT 0x00000010\r
+#define CDFULL_INT 0x00000020\r
+#define RxENDPKT_INT 0x00000040\r
+#define TxENDPKT_INT 0x00000080\r
+#define EP_RLZED_INT 0x00000100\r
+#define ERR_INT 0x00000200\r
+\r
+/* Rx & Tx Packet Length Definitions */\r
+#define PKT_LNGTH_MASK 0x000003FF\r
+#define PKT_DV 0x00000400\r
+#define PKT_RDY 0x00000800\r
+\r
+/* USB Control Definitions */\r
+#define CTRL_RD_EN 0x00000001\r
+#define CTRL_WR_EN 0x00000002\r
+\r
+/* Command Codes */\r
+#define CMD_SET_ADDR 0x00D00500\r
+#define CMD_CFG_DEV 0x00D80500\r
+#define CMD_SET_MODE 0x00F30500\r
+#define CMD_RD_FRAME 0x00F50500\r
+#define DAT_RD_FRAME 0x00F50200\r
+#define CMD_RD_TEST 0x00FD0500\r
+#define DAT_RD_TEST 0x00FD0200\r
+#define CMD_SET_DEV_STAT 0x00FE0500\r
+#define CMD_GET_DEV_STAT 0x00FE0500\r
+#define DAT_GET_DEV_STAT 0x00FE0200\r
+#define CMD_GET_ERR_CODE 0x00FF0500\r
+#define DAT_GET_ERR_CODE 0x00FF0200\r
+#define CMD_RD_ERR_STAT 0x00FB0500\r
+#define DAT_RD_ERR_STAT 0x00FB0200\r
+#define DAT_WR_BYTE(x) (0x00000100 | ((x) << 16))\r
+#define CMD_SEL_EP(x) (0x00000500 | ((x) << 16))\r
+#define DAT_SEL_EP(x) (0x00000200 | ((x) << 16))\r
+#define CMD_SEL_EP_CLRI(x) (0x00400500 | ((x) << 16))\r
+#define DAT_SEL_EP_CLRI(x) (0x00400200 | ((x) << 16))\r
+#define CMD_SET_EP_STAT(x) (0x00400500 | ((x) << 16))\r
+#define CMD_CLR_BUF 0x00F20500\r
+#define DAT_CLR_BUF 0x00F20200\r
+#define CMD_VALID_BUF 0x00FA0500\r
+\r
+/* Device Address Register Definitions */\r
+#define DEV_ADDR_MASK 0x7F\r
+#define DEV_EN 0x80\r
+\r
+/* Device Configure Register Definitions */\r
+#define CONF_DVICE 0x01\r
+\r
+/* Device Mode Register Definitions */\r
+#define AP_CLK 0x01\r
+#define INAK_CI 0x02\r
+#define INAK_CO 0x04\r
+#define INAK_II 0x08\r
+#define INAK_IO 0x10\r
+#define INAK_BI 0x20\r
+#define INAK_BO 0x40\r
+\r
+/* Device Status Register Definitions */\r
+#define DEV_CON 0x01\r
+#define DEV_CON_CH 0x02\r
+#define DEV_SUS 0x04\r
+#define DEV_SUS_CH 0x08\r
+#define DEV_RST 0x10\r
+\r
+/* Error Code Register Definitions */\r
+#define ERR_EC_MASK 0x0F\r
+#define ERR_EA 0x10\r
+\r
+/* Error Status Register Definitions */\r
+#define ERR_PID 0x01\r
+#define ERR_UEPKT 0x02\r
+#define ERR_DCRC 0x04\r
+#define ERR_TIMOUT 0x08\r
+#define ERR_EOP 0x10\r
+#define ERR_B_OVRN 0x20\r
+#define ERR_BTSTF 0x40\r
+#define ERR_TGL 0x80\r
+\r
+/* Endpoint Select Register Definitions */\r
+#define EP_SEL_F 0x01\r
+#define EP_SEL_ST 0x02\r
+#define EP_SEL_STP 0x04\r
+#define EP_SEL_PO 0x08\r
+#define EP_SEL_EPN 0x10\r
+#define EP_SEL_B_1_FULL 0x20\r
+#define EP_SEL_B_2_FULL 0x40\r
+\r
+/* Endpoint Status Register Definitions */\r
+#define EP_STAT_ST 0x01\r
+#define EP_STAT_DA 0x20\r
+#define EP_STAT_RF_MO 0x40\r
+#define EP_STAT_CND_ST 0x80\r
+\r
+/* Clear Buffer Register Definitions */\r
+#define CLR_BUF_PO 0x01\r
+\r
+\r
+/* DMA Interrupt Bit Definitions */\r
+#define EOT_INT 0x01\r
+#define NDD_REQ_INT 0x02\r
+#define SYS_ERR_INT 0x04\r
+\r
+\r
+#endif /* __USBREG_H */\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbuser.c\r
+ * Purpose: USB Custom User Module\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 family microcontroller devices only. Nothing\r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *---------------------------------------------------------------------------*/\r
+#include "lpc_types.h"\r
+\r
+#include "usb.h"\r
+#include "usbcfg.h"\r
+#include "usbhw.h"\r
+#include "usbcore.h"\r
+#include "usbuser.h"\r
+#include "cdcuser.h"\r
+\r
+\r
+/*\r
+ * USB Power Event Callback\r
+ * Called automatically on USB Power Event\r
+ * Parameter: power: On(TRUE)/Off(FALSE)\r
+ */\r
+\r
+#if USB_POWER_EVENT\r
+void USB_Power_Event (uint32_t power) {\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Reset Event Callback\r
+ * Called automatically on USB Reset Event\r
+ */\r
+\r
+#if USB_RESET_EVENT\r
+void USB_Reset_Event (void) {\r
+ USB_ResetCore();\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Suspend Event Callback\r
+ * Called automatically on USB Suspend Event\r
+ */\r
+\r
+#if USB_SUSPEND_EVENT\r
+void USB_Suspend_Event (void) {\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Resume Event Callback\r
+ * Called automatically on USB Resume Event\r
+ */\r
+\r
+#if USB_RESUME_EVENT\r
+void USB_Resume_Event (void) {\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Remote Wakeup Event Callback\r
+ * Called automatically on USB Remote Wakeup Event\r
+ */\r
+\r
+#if USB_WAKEUP_EVENT\r
+void USB_WakeUp_Event (void) {\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Start of Frame Event Callback\r
+ * Called automatically on USB Start of Frame Event\r
+ */\r
+\r
+#if USB_SOF_EVENT\r
+void USB_SOF_Event (void) {\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Error Event Callback\r
+ * Called automatically on USB Error Event\r
+ * Parameter: error: Error Code\r
+ */\r
+\r
+#if USB_ERROR_EVENT\r
+void USB_Error_Event (uint32_t error) {\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Set Configuration Event Callback\r
+ * Called automatically on USB Set Configuration Request\r
+ */\r
+\r
+#if USB_CONFIGURE_EVENT\r
+void USB_Configure_Event (void) {\r
+\r
+ if (USB_Configuration) { /* Check if USB is configured */\r
+ /* add your code here */\r
+ }\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Set Interface Event Callback\r
+ * Called automatically on USB Set Interface Request\r
+ */\r
+\r
+#if USB_INTERFACE_EVENT\r
+void USB_Interface_Event (void) {\r
+}\r
+#endif\r
+\r
+\r
+/*\r
+ * USB Set/Clear Feature Event Callback\r
+ * Called automatically on USB Set/Clear Feature Request\r
+ */\r
+\r
+#if USB_FEATURE_EVENT\r
+void USB_Feature_Event (void) {\r
+}\r
+#endif\r
+\r
+\r
+#define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)\r
+\r
+/* USB Endpoint Events Callback Pointers */\r
+void (* const USB_P_EP[16]) (uint32_t event) = {\r
+ P_EP(0),\r
+ P_EP(1),\r
+ P_EP(2),\r
+ P_EP(3),\r
+ P_EP(4),\r
+ P_EP(5),\r
+ P_EP(6),\r
+ P_EP(7),\r
+ P_EP(8),\r
+ P_EP(9),\r
+ P_EP(10),\r
+ P_EP(11),\r
+ P_EP(12),\r
+ P_EP(13),\r
+ P_EP(14),\r
+ P_EP(15),\r
+};\r
+\r
+\r
+/*\r
+ * USB Endpoint 1 Event Callback\r
+ * Called automatically on USB Endpoint 1 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint1 (uint32_t event) {\r
+ uint16_t temp;\r
+ static uint16_t serialState;\r
+\r
+ switch (event) {\r
+ case USB_EVT_IN:\r
+ temp = CDC_GetSerialState();\r
+ if (serialState != temp) {\r
+ serialState = temp;\r
+ CDC_NotificationIn(); /* send SERIAL_STATE notification */\r
+ }\r
+ break;\r
+ }\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 2 Event Callback\r
+ * Called automatically on USB Endpoint 2 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint2 (uint32_t event) {\r
+\r
+ switch (event) {\r
+ case USB_EVT_OUT:\r
+ CDC_BulkOut (); /* data received from Host */\r
+ break;\r
+ case USB_EVT_IN:\r
+ CDC_BulkIn (); /* data expected from Host */\r
+ break;\r
+ }\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 3 Event Callback\r
+ * Called automatically on USB Endpoint 3 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint3 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 4 Event Callback\r
+ * Called automatically on USB Endpoint 4 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint4 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 5 Event Callback\r
+ * Called automatically on USB Endpoint 5 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint5 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 6 Event Callback\r
+ * Called automatically on USB Endpoint 6 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint6 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 7 Event Callback\r
+ * Called automatically on USB Endpoint 7 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint7 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 8 Event Callback\r
+ * Called automatically on USB Endpoint 8 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint8 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 9 Event Callback\r
+ * Called automatically on USB Endpoint 9 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint9 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 10 Event Callback\r
+ * Called automatically on USB Endpoint 10 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint10 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 11 Event Callback\r
+ * Called automatically on USB Endpoint 11 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint11 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 12 Event Callback\r
+ * Called automatically on USB Endpoint 12 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint12 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 13 Event Callback\r
+ * Called automatically on USB Endpoint 13 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint13 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 14 Event Callback\r
+ * Called automatically on USB Endpoint 14 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint14 (uint32_t event) {\r
+}\r
+\r
+\r
+/*\r
+ * USB Endpoint 15 Event Callback\r
+ * Called automatically on USB Endpoint 15 Event\r
+ * Parameter: event\r
+ */\r
+\r
+void USB_EndPoint15 (uint32_t event) {\r
+}\r
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * U S B - K e r n e l\r
+ *----------------------------------------------------------------------------\r
+ * Name: usbuser.h\r
+ * Purpose: USB Custom User Definitions\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 family microcontroller devices only. Nothing \r
+ * else gives you the right to use this software.\r
+ *\r
+ * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
+ *---------------------------------------------------------------------------*/\r
+\r
+#ifndef __USBUSER_H__\r
+#define __USBUSER_H__\r
+\r
+\r
+/* USB Device Events Callback Functions */\r
+extern void USB_Power_Event (uint32_t power);\r
+extern void USB_Reset_Event (void);\r
+extern void USB_Suspend_Event (void);\r
+extern void USB_Resume_Event (void);\r
+extern void USB_WakeUp_Event (void);\r
+extern void USB_SOF_Event (void);\r
+extern void USB_Error_Event (uint32_t error);\r
+\r
+/* USB Endpoint Callback Events */\r
+#define USB_EVT_SETUP 1 /* Setup Packet */\r
+#define USB_EVT_OUT 2 /* OUT Packet */\r
+#define USB_EVT_IN 3 /* IN Packet */\r
+#define USB_EVT_OUT_NAK 4 /* OUT Packet - Not Acknowledged */\r
+#define USB_EVT_IN_NAK 5 /* IN Packet - Not Acknowledged */\r
+#define USB_EVT_OUT_STALL 6 /* OUT Packet - Stalled */\r
+#define USB_EVT_IN_STALL 7 /* IN Packet - Stalled */\r
+#define USB_EVT_OUT_DMA_EOT 8 /* DMA OUT EP - End of Transfer */\r
+#define USB_EVT_IN_DMA_EOT 9 /* DMA IN EP - End of Transfer */\r
+#define USB_EVT_OUT_DMA_NDR 10 /* DMA OUT EP - New Descriptor Request */\r
+#define USB_EVT_IN_DMA_NDR 11 /* DMA IN EP - New Descriptor Request */\r
+#define USB_EVT_OUT_DMA_ERR 12 /* DMA OUT EP - Error */\r
+#define USB_EVT_IN_DMA_ERR 13 /* DMA IN EP - Error */\r
+\r
+/* USB Endpoint Events Callback Pointers */\r
+extern void (* const USB_P_EP[16])(uint32_t event);\r
+\r
+/* USB Endpoint Events Callback Functions */\r
+extern void USB_EndPoint0 (uint32_t event);\r
+extern void USB_EndPoint1 (uint32_t event);\r
+extern void USB_EndPoint2 (uint32_t event);\r
+extern void USB_EndPoint3 (uint32_t event);\r
+extern void USB_EndPoint4 (uint32_t event);\r
+extern void USB_EndPoint5 (uint32_t event);\r
+extern void USB_EndPoint6 (uint32_t event);\r
+extern void USB_EndPoint7 (uint32_t event);\r
+extern void USB_EndPoint8 (uint32_t event);\r
+extern void USB_EndPoint9 (uint32_t event);\r
+extern void USB_EndPoint10 (uint32_t event);\r
+extern void USB_EndPoint11 (uint32_t event);\r
+extern void USB_EndPoint12 (uint32_t event);\r
+extern void USB_EndPoint13 (uint32_t event);\r
+extern void USB_EndPoint14 (uint32_t event);\r
+extern void USB_EndPoint15 (uint32_t event);\r
+\r
+/* USB Core Events Callback Functions */\r
+extern void USB_Configure_Event (void);\r
+extern void USB_Interface_Event (void);\r
+extern void USB_Feature_Event (void);\r
+\r
+\r
+#endif /* __USBUSER_H__ */\r
--- /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
--- /dev/null
+/*----------------------------------------------------------------------------\r
+ * Name: vcomdemo.h\r
+ * Purpose: USB virtual COM port Demo Definitions\r
+ * Version: V1.02\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
+/* Push Button Definitions */\r
+#define S2 0x00000400 /* P2.10 */\r
+\r
+/* LED Definitions */\r
+#define LED1 0x00000001 /* P2.00 */\r
+#define LED2 0x00000002 /* P2.01 */\r
+#define LED3 0x00000004 /* P2.02 */\r
+#define LED4 0x00000008 /* P2.03 */\r
+#define LED5 0x00000010 /* P2.04 */\r
+#define LED6 0x00000020 /* P2.05 */\r
+#define LED7 0x00000040 /* P2.06 */\r
+#define LED8 0x00000080 /* P2.07 */\r
+\r
+#define LEDMSK 0x000000FF /* P2.0..7 */\r
+\r