Main Page | Data Structures | Directories | File List | Data Fields | Globals

usbdsc.c

Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  *                Microchip USB C18 Firmware Version 1.0
00004  *
00005  *********************************************************************
00006  * FileName:        usbdsc.c
00007  * Dependencies:    See INCLUDES section below
00008  * Processor:       PIC18
00009  * Compiler:        C18 2.30.01+
00010  * Company:         Microchip Technology, Inc.
00011  *
00012  * Software License Agreement
00013  *
00014  * The software supplied herewith by Microchip Technology Incorporated
00015  * (the “Company”) for its PICmicro® Microcontroller is intended and
00016  * supplied to you, the Company’s customer, for use solely and
00017  * exclusively on Microchip PICmicro Microcontroller products. The
00018  * software is owned by the Company and/or its supplier, and is
00019  * protected under applicable copyright laws. All rights are reserved.
00020  * Any use in violation of the foregoing restrictions may subject the
00021  * user to criminal sanctions under applicable laws, as well as to
00022  * civil liability for the breach of the terms and conditions of this
00023  * license.
00024  *
00025  * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
00026  * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
00027  * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00028  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
00029  * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
00030  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00031  *
00032  ********************************************************************/
00033 
00034 /*********************************************************************
00035  * -usbdsc.c-
00036  * This file contains the USB descriptor information. It is used
00037  * in conjunction with the usbdsc.h file. When a descriptor is added
00038  * or removed from the main configuration descriptor, i.e. CFG01,
00039  * the user must also change the descriptor structure defined in
00040  * the usbdsc.h file. The structure is used to calculate the 
00041  * descriptor size, i.e. sizeof(CFG01).
00042  * 
00043  * A typical configuration descriptor consists of:
00044  * At least one configuration descriptor (USB_CFG_DSC)
00045  * One or more interface descriptors (USB_INTF_DSC)
00046  * One or more endpoint descriptors (USB_EP_DSC)
00047  *
00048  * Naming Convention:
00049  * To resolve ambiguity, the naming convention are as followed:
00050  * - USB_CFG_DSC type should be named cdxx, where xx is the
00051  *   configuration number. This number should match the actual
00052  *   index value of this configuration.
00053  * - USB_INTF_DSC type should be named i<yy>a<zz>, where yy is the
00054  *   interface number and zz is the alternate interface number.
00055  * - USB_EP_DSC type should be named ep<##><d>_i<yy>a<zz>, where
00056  *   ## is the endpoint number and d is the direction of transfer.
00057  *   The interface name should also be listed as a suffix to identify
00058  *   which interface does the endpoint belong to.
00059  *
00060  * Example:
00061  * If a device has one configuration, two interfaces; interface 0
00062  * has two endpoints (in and out), and interface 1 has one endpoint(in).
00063  * Then the CFG01 structure in the usbdsc.h should be:
00064  *
00065  * #define CFG01 rom struct                            \
00066  * {   USB_CFG_DSC             cd01;                   \
00067  *     USB_INTF_DSC            i00a00;                 \
00068  *     USB_EP_DSC              ep01o_i00a00;           \
00069  *     USB_EP_DSC              ep01i_i00a00;           \
00070  *     USB_INTF_DSC            i01a00;                 \
00071  *     USB_EP_DSC              ep02i_i01a00;           \
00072  * } cfg01
00073  * 
00074  * Note the hierarchy of the descriptors above, it follows the USB
00075  * specification requirement. All endpoints belonging to an interface
00076  * should be listed immediately after that interface.
00077  *
00078  * -------------------------------------------------------------------
00079  * Filling in the descriptor values in the usbdsc.c file:
00080  * -------------------------------------------------------------------
00081  * Most items should be self-explanatory, however, a few will be
00082  * explained for clarification.
00083  *
00084  * [Configuration Descriptor(USB_CFG_DSC)]
00085  * The configuration attribute must always have the _DEFAULT
00086  * definition at the minimum. Additional options can be ORed
00087  * to the _DEFAULT attribute. Available options are _SELF and _RWU.
00088  * These definitions are defined in the usbdefs_std_dsc.h file. The
00089  * _SELF tells the USB host that this device is self-powered. The
00090  * _RWU tells the USB host that this device supports Remote Wakeup.
00091  *
00092  * [Endpoint Descriptor(USB_EP_DSC)]
00093  * Assume the following example:
00094  * sizeof(USB_EP_DSC),DSC_EP,_EP01_OUT,_BULK,64,0x00
00095  *
00096  * The first two parameters are self-explanatory. They specify the
00097  * length of this endpoint descriptor (7) and the descriptor type.
00098  * The next parameter identifies the endpoint, the definitions are
00099  * defined in usbdefs_std_dsc.h and has the following naming
00100  * convention:
00101  * _EP<##>_<dir>
00102  * where ## is the endpoint number and dir is the direction of
00103  * transfer. The dir has the value of either 'OUT' or 'IN'.
00104  * The next parameter identifies the type of the endpoint. Available
00105  * options are _BULK, _INT, _ISO, and _CTRL. The _CTRL is not
00106  * typically used because the default control transfer endpoint is
00107  * not defined in the USB descriptors. When _ISO option is used,
00108  * addition options can be ORed to _ISO. Example:
00109  * _ISO|_AD|_FE
00110  * This describes the endpoint as an isochronous pipe with adaptive
00111  * and feedback attributes. See usbdefs_std_dsc.h and the USB
00112  * specification for details. The next parameter defines the size of
00113  * the endpoint. The last parameter in the polling interval.
00114  *
00115  * -------------------------------------------------------------------
00116  * Adding a USB String
00117  * -------------------------------------------------------------------
00118  * A string descriptor array should have the following format:
00119  *
00120  * rom struct{byte bLength;byte bDscType;word string[size];}sdxxx={
00121  * sizeof(sdxxx),DSC_STR,<text>};
00122  *
00123  * The above structure provides a means for the C compiler to
00124  * calculate the length of string descriptor sdxxx, where xxx is the
00125  * index number. The first two bytes of the descriptor are descriptor
00126  * length and type. The rest <text> are string texts which must be
00127  * in the unicode format. The unicode format is achieved by declaring
00128  * each character as a word type. The whole text string is declared
00129  * as a word array with the number of characters equals to <size>.
00130  * <size> has to be manually counted and entered into the array
00131  * declaration. Let's study this through an example:
00132  * if the string is "USB" , then the string descriptor should be:
00133  * (Using index 02)
00134  * rom struct{byte bLength;byte bDscType;word string[3];}sd002={
00135  * sizeof(sd002),DSC_STR,'U','S','B'};
00136  *
00137  * A USB project may have multiple strings and the firmware supports
00138  * the management of multiple strings through a look-up table.
00139  * The look-up table is defined as:
00140  * rom const unsigned char *rom USB_SD_Ptr[]={&sd000,&sd001,&sd002};
00141  *
00142  * The above declaration has 3 strings, sd000, sd001, and sd002.
00143  * Strings can be removed or added. sd000 is a specialized string
00144  * descriptor. It defines the language code, usually this is
00145  * US English (0x0409). The index of the string must match the index
00146  * position of the USB_SD_Ptr array, &sd000 must be in position
00147  * USB_SD_Ptr[0], &sd001 must be in position USB_SD_Ptr[1] and so on.
00148  * The look-up table USB_SD_Ptr is used by the get string handler
00149  * function in usb9.c.
00150  *
00151  * -------------------------------------------------------------------
00152  *
00153  * The look-up table scheme also applies to the configuration
00154  * descriptor. A USB device may have multiple configuration
00155  * descriptors, i.e. CFG01, CFG02, etc. To add a configuration
00156  * descriptor, user must implement a structure similar to CFG01.
00157  * The next step is to add the configuration descriptor name, i.e.
00158  * cfg01, cfg02,.., to the look-up table USB_CD_Ptr. USB_CD_Ptr[0]
00159  * is a dummy place holder since configuration 0 is the un-configured
00160  * state according to the definition in the USB specification.
00161  *
00162  ********************************************************************/
00163  
00164 /*********************************************************************
00165  * Descriptor specific type definitions are defined in:
00166  * system\usb\usbdefs\usbdefs_std_dsc.h
00167  *
00168  * Configuration information is defined in:
00169  * autofiles\usbcfg.h
00170  ********************************************************************/
00171  
00172 /** I N C L U D E S *************************************************/
00173 #include "system\typedefs.h"
00174 #include "system\usb\usb.h"
00175 
00176 /** C O N S T A N T S ************************************************/
00177 #pragma romdata
00178 
00179 /* Device Descriptor */
00180 rom USB_DEV_DSC device_dsc=
00181 {    
00182     sizeof(USB_DEV_DSC),    // Size of this descriptor in bytes
00183     DSC_DEV,                // DEVICE descriptor type
00184     0x0200,                 // USB Spec Release Number in BCD format
00185     CDC_DEVICE,             // Class Code
00186     0x00,                   // Subclass code
00187     0x00,                   // Protocol code
00188     EP0_BUFF_SIZE,          // Max packet size for EP0, see usbcfg.h
00189     0x04D8,                 // Vendor ID
00190     0x000A,                 // Product ID: CDC RS-232 Emulation Demo
00191     0x0000,                 // Device release number in BCD format
00192     0x01,                   // Manufacturer string index
00193     0x02,                   // Product string index
00194     0x00,                   // Device serial number string index
00195     0x01                    // Number of possible configurations
00196 };
00197 
00198 /* Configuration 1 Descriptor */
00199 CFG01=
00200 {
00201     /* Configuration Descriptor */
00202     sizeof(USB_CFG_DSC),    // Size of this descriptor in bytes
00203     DSC_CFG,                // CONFIGURATION descriptor type
00204     sizeof(cfg01),          // Total length of data for this cfg
00205     2,                      // Number of interfaces in this cfg
00206     1,                      // Index value of this configuration
00207     0,                      // Configuration string index
00208     _DEFAULT,               // Attributes, see usbdefs_std_dsc.h
00209     50,                     // Max power consumption (2X mA)
00210     
00211     /* Interface Descriptor */
00212     sizeof(USB_INTF_DSC),   // Size of this descriptor in bytes
00213     DSC_INTF,               // INTERFACE descriptor type
00214     0,                      // Interface Number
00215     0,                      // Alternate Setting Number
00216     1,                      // Number of endpoints in this intf
00217     COMM_INTF,              // Class code
00218     ABSTRACT_CONTROL_MODEL, // Subclass code
00219     V25TER,                 // Protocol code
00220     0,                      // Interface string index
00221 
00222     /* CDC Class-Specific Descriptors */
00223     sizeof(USB_CDC_HEADER_FN_DSC),CS_INTERFACE,DSC_FN_HEADER,0x0110,
00224     sizeof(USB_CDC_ACM_FN_DSC),CS_INTERFACE,DSC_FN_ACM,0x02,
00225     sizeof(USB_CDC_UNION_FN_DSC),CS_INTERFACE,DSC_FN_UNION,CDC_COMM_INTF_ID,CDC_DATA_INTF_ID,
00226     sizeof(USB_CDC_CALL_MGT_FN_DSC),CS_INTERFACE,DSC_FN_CALL_MGT,0x00,CDC_DATA_INTF_ID,
00227 
00228     /* Endpoint Descriptor */
00229     sizeof(USB_EP_DSC),DSC_EP,_EP02_IN,_INT,CDC_INT_EP_SIZE,0x02,
00230     
00231     /* Interface Descriptor */
00232     sizeof(USB_INTF_DSC),   // Size of this descriptor in bytes
00233     DSC_INTF,               // INTERFACE descriptor type
00234     1,                      // Interface Number
00235     0,                      // Alternate Setting Number
00236     2,                      // Number of endpoints in this intf
00237     DATA_INTF,              // Class code
00238     0,                      // Subclass code
00239     NO_PROTOCOL,            // Protocol code
00240     0,                      // Interface string index
00241     
00242     /* Endpoint Descriptors */
00243     sizeof(USB_EP_DSC),DSC_EP,_EP03_OUT,_BULK,CDC_BULK_OUT_EP_SIZE,0x00,
00244     sizeof(USB_EP_DSC),DSC_EP,_EP03_IN,_BULK,CDC_BULK_IN_EP_SIZE,0x00
00245 };
00246 
00247 rom struct{byte bLength;byte bDscType;word string[1];}sd000={
00248 sizeof(sd000),DSC_STR,0x0409};
00249 
00250 rom struct{byte bLength;byte bDscType;word string[25];}sd001={
00251 sizeof(sd001),DSC_STR,
00252 'M','i','c','r','o','c','h','i','p',' ',
00253 'T','e','c','h','n','o','l','o','g','y',' ','I','n','c','.'};
00254 
00255 rom struct{byte bLength;byte bDscType;word string[25];}sd002={
00256 sizeof(sd002),DSC_STR,
00257 'C','D','C',' ','R','S','-','2','3','2',' ',
00258 'E','m','u','l','a','t','i','o','n',' ','D','e','m','o'};
00259 
00260 rom const unsigned char *rom USB_CD_Ptr[]={&cfg01,&cfg01};
00261 rom const unsigned char *rom USB_SD_Ptr[]={&sd000,&sd001,&sd002};
00262 
00263 rom pFunc ClassReqHandler[1]=
00264 {
00265     &USBCheckCDCRequest
00266 };
00267 
00268 #pragma code
00269 
00270 /** EOF usbdsc.c ****************************************************/

Generated on Wed Jun 8 03:49:39 2005 for cdc by  doxygen 1.4.2