usb.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *  $Id: usb.h 150 2008-06-16 20:17:25Z merdmann $
00003  *
00004  *  Thu Nov 29 20:55:57 2007
00005  *  Copyright  2007 Michael Erdmann
00006  *  Email: michael.erdmann@snafu.de
00007  ****************************************************************************/
00008 /*
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00029 #include "typedefs.h"
00030 
00031 #ifndef _USB_H
00032 #define _USB_H
00033 
00034 
00036 typedef union {
00037     struct {
00038         byte bmRequestType;
00039         byte bRequest; 
00040         word wValue;
00041         word wIndex;
00042         word wLength;
00043     };
00044     struct {
00045         unsigned :8;
00046         unsigned :8;
00047         WORD W_Value;
00048         WORD W_Index;
00049         WORD W_Length;
00050     };
00051     struct {
00052         unsigned Recipient:5;           //Device,Interface,Endpoint,Other
00053         unsigned RequestType:2;         //Standard,Class,Vendor,Reserved
00054         unsigned DataDir:1;             //Host-to-device,Device-to-host
00055 
00056         unsigned :8;
00057         byte bFeature;                  //DEVICE_REMOTE_WAKEUP,ENDPOINT_HALT
00058         unsigned :8;
00059         unsigned :8;
00060         unsigned :8;
00061         unsigned :8;
00062         unsigned :8;
00063     };
00064     struct {
00065         unsigned :8;
00066         unsigned :8;
00067         byte bDscIndex;                 //For Configuration and String DSC Only
00068         byte bDscType;                  //Device,Configuration,String
00069         word wLangID;                   //Language ID
00070         unsigned :8;
00071         unsigned :8;
00072     };
00073     struct {
00074         unsigned :8;
00075         unsigned :8;
00076         byte bDevADR;                   //Device Address 0-127
00077         byte bDevADRH;                  //Must equal zero
00078         unsigned :8;
00079         unsigned :8;
00080         unsigned :8;
00081         unsigned :8;
00082     };
00083     struct {
00084         unsigned :8;
00085         unsigned :8;
00086         byte bCfgValue;                 //Configuration Value 0-255
00087         byte bCfgRSD;                   //Must equal zero (Reserved)
00088         unsigned :8;
00089         unsigned :8;
00090         unsigned :8;
00091         unsigned :8;
00092     };
00093     struct {
00094         unsigned :8;
00095         unsigned :8;
00096         byte bAltID;                    //Alternate Setting Value 0-255
00097         byte bAltID_H;                  //Must equal zero
00098         byte bIntfID;                   //Interface Number Value 0-255
00099         byte bIntfID_H;                 //Must equal zero
00100         unsigned :8;
00101         unsigned :8;
00102     };
00103     struct {
00104         unsigned :8;
00105         unsigned :8;
00106         unsigned :8;
00107         unsigned :8;
00108         byte bEPID;                     //Endpoint ID (Number & Direction)
00109         byte bEPID_H;                   //Must equal zero
00110         unsigned :8;
00111         unsigned :8;
00112     };
00113     struct{
00114         unsigned :8;
00115         unsigned :8;
00116         unsigned :8;
00117         unsigned :8;
00118         unsigned EPNum:4;               //Endpoint Number 0-15
00119         unsigned :3;
00120         unsigned EPDir:1;               //Endpoint Direction: 0-OUT, 1-IN
00121         unsigned :8;
00122         unsigned :8;
00123         unsigned :8;
00124     };
00125 } t_setup;
00126 
00127 
00128 #define _BSTALL     0x04                //Buffer Stall enable
00129 #define _DTSEN      0x08                //Data Toggle Synch enable
00130 #define _INCDIS     0x10                //Address increment disable
00131 #define _KEN        0x20                //SIE keeps buff descriptors enable
00132 #define _DAT0       0x00                //DATA0 packet expected next
00133 #define _DAT1       0x40                //DATA1 packet expected next
00134 #define _DTSMASK    0x40                //DTS Mask
00135 #define _USIE       0x80                //SIE owns buffer
00136 #define _UCPU       0x00                //CPU owns buffer
00137 
00138 
00139 /* Endpoint parameters */
00140 #define EP_CTRL     0x06            // Cfg Control pipe for this ep
00141 #define EP_OUT      0x0C            // Cfg OUT only pipe for this ep
00142 #define EP_IN       0x0A            // Cfg IN only pipe for this ep
00143 #define EP_OUT_IN   0x0E            // Cfg both OUT & IN pipes for this ep
00144 #define HSHK_EN     0x10            // Enable handshake packet
00145                                     // Handshake should be disable for isoch
00146 
00147 /* UCFG Parameters */
00148 #define _PPBM0      0x00            // Pingpong Buffer Mode 0
00149 #define _PPBM1      0x01            // Pingpong Buffer Mode 1
00150 #define _PPBM2      0x02            // Pingpong Buffer Mode 2
00151 #define _LS         0x00            // Use Low-Speed USB Mode
00152 #define _FS         0x04            // Use Full-Speed USB Mode
00153 #define _TRINT      0x00            // Use internal transceiver
00154 #define _TREXT      0x08            // Use external transceiver
00155 #define _PUEN       0x10            // Use internal pull-up resistor
00156 #define _OEMON      0x40            // Use SIE output indicator
00157 #define _UTEYE      0x80            // Use Eye-Pattern test
00158 
00159 #define OUT         0
00160 #define IN          1
00161 
00162 #define SETUP_TOKEN         0x0d          //0b00001101
00163 #define OUT_TOKEN           0x01          //0b00000001
00164 #define IN_TOKEN            0x09          //0b00001001
00165 
00166 #define GET_STATUS  0
00167 #define CLR_FEATURE 1
00168 #define SET_FEATURE 3
00169 #define SET_ADR     5
00170 #define GET_DSC     6
00171 #define SET_DSC     7
00172 #define GET_CFG     8
00173 #define SET_CFG     9
00174 #define GET_INTF    10
00175 #define SET_INTF    11
00176 #define SYNCH_FRAME 12
00177 
00178 /* bmRequestType Definitions */
00179 #define HOST_TO_DEVICE         0
00180 #define DEVICE_TO_HOST         1
00181 
00182 #define STANDARD            0x00
00183 #define CLASS               0x01
00184 #define VENDOR              0x02
00185 
00186 #define RCPT_DEV            0
00187 #define RCPT_INTF           1
00188 #define RCPT_EP             2
00189 #define RCPT_OTH            3
00190 
00191 /* Descriptor Types */
00192 #define DSC_DEV     0x01
00193 #define DSC_CFG     0x02
00194 #define DSC_STR     0x03
00195 #define DSC_INTF    0x04
00196 #define DSC_EP      0x05
00197 
00198 
00199 #define _EP01_OUT   0x01
00200 #define _EP01_IN    0x81
00201 #define _EP02_OUT   0x02
00202 #define _EP02_IN    0x82
00203 #define _EP03_OUT   0x03
00204 #define _EP03_IN    0x83
00205 #define _EP04_OUT   0x04
00206 #define _EP04_IN    0x84
00207 #define _EP05_OUT   0x05
00208 #define _EP05_IN    0x85
00209 #define _EP06_OUT   0x06
00210 #define _EP06_IN    0x86
00211 #define _EP07_OUT   0x07
00212 #define _EP07_IN    0x87
00213 #define _EP08_OUT   0x08
00214 #define _EP08_IN    0x88
00215 #define _EP09_OUT   0x09
00216 #define _EP09_IN    0x89
00217 #define _EP10_OUT   0x0A
00218 #define _EP10_IN    0x8A
00219 #define _EP11_OUT   0x0B
00220 #define _EP11_IN    0x8B
00221 #define _EP12_OUT   0x0C
00222 #define _EP12_IN    0x8C
00223 #define _EP13_OUT   0x0D
00224 #define _EP13_IN    0x8D
00225 #define _EP14_OUT   0x0E
00226 #define _EP14_IN    0x8E
00227 #define _EP15_OUT   0x0F
00228 #define _EP15_IN    0x8F
00229 
00230 
00231 /* USB 2.0 Table 8.9 */
00232 typedef struct {
00233     byte bLength;       byte bDescriptorType;           word bcdUSB;
00234     byte bDeviceCls;    byte bDeviceSubCls;                     byte bDeviceProtocol;
00235     byte bMaxPktSize0;  word idVendor;                  word idProduct;
00236     word bcdDevice;     byte iManufacturer;         byte iProduct;
00237     byte iSerialNum;    byte bNumCconfigurations;
00238 } t_usb_dev_dsc;
00239 
00240 /******************************************************************************
00241  * USB Configuration Descriptor Structure
00242  *****************************************************************************/
00243 typedef struct {
00244     byte bLength;       byte bDscType;      word wTotalLength;
00245     byte bNumIntf;      byte bCfgValue;     byte iCfg;
00246     byte bmAttributes;  byte bMaxPower;
00247 } t_usb_cfg_dsc;
00248 
00249 /******************************************************************************
00250  * USB Interface Descriptor Structure
00251  *****************************************************************************/
00252 typedef struct _USB_INTF_DSC
00253 {
00254     byte bLength;       byte bDscType;      byte bIntfNum;
00255     byte bAltSetting;   byte bNumEPs;       byte bIntfCls;
00256     byte bIntfSubCls;   byte bIntfProtocol; byte iIntf;
00257 } USB_INTF_DSC;
00258 
00259 /******************************************************************************
00260  * USB Endpoint Descriptor Structure
00261  *****************************************************************************/
00262 typedef struct _USB_EP_DSC
00263 {
00264     byte bLength;       byte bDscType;      byte bEPAdr;
00265     byte bmAttributes;  word wMaxPktSize;   byte bInterval;
00266 } USB_EP_DSC;
00267 
00268 /* Configuration Attributes */
00269 #define _DEFAULT    0x01<<7         //Default Value (Bit 7 is set)
00270 #define _SELF       0x01<<6         //Self-powered (Supports if set)
00271 #define _RWU        0x01<<5         //Remote Wakeup (Supports if set)
00272 
00273 /* Endpoint Transfer Type */
00274 #define _CTRL       0x00            //Control Transfer
00275 #define _ISO        0x01            //Isochronous Transfer
00276 #define _BULK       0x02            //Bulk Transfer
00277 #define _INT        0x03            //Interrupt Transfer
00278 
00279 /* Isochronous Endpoint Synchronization Type */
00280 #define _NS         0x00<<2         //No Synchronization
00281 #define _AS         0x01<<2         //Asynchronous
00282 #define _AD         0x02<<2         //Adaptive
00283 #define _SY         0x03<<2         //Synchronous
00284 
00285 /* Isochronous Endpoint Usage Type */
00286 #define _DE         0x00<<4         //Data endpoint
00287 #define _FE         0x01<<4         //Feedback endpoint
00288 #define _IE         0x02<<4         //Implicit feedback Data endpoint
00289 
00290 #define OUT         0
00291 #define IN          1
00292 
00293 #define PIC_EP_NUM_MASK 0b01111000
00294 #define PIC_EP_DIR_MASK 0b00000100
00295 
00296 #define EP00_OUT    (0x00<<3)|(OUT<<2)
00297 #define EP00_IN     (0x00<<3)|(IN<<2)
00298 #define EP01_OUT    (0x01<<3)|(OUT<<2)
00299 #define EP01_IN     (0x01<<3)|(IN<<2)
00300 #define EP02_OUT    (0x02<<3)|(OUT<<2)
00301 #define EP02_IN     (0x02<<3)|(IN<<2)
00302 #define EP03_OUT    (0x03<<3)|(OUT<<2)
00303 #define EP03_IN     (0x03<<3)|(IN<<2)
00304 #define EP04_OUT    (0x04<<3)|(OUT<<2)
00305 #define EP04_IN     (0x04<<3)|(IN<<2)
00306 #define EP05_OUT    (0x05<<3)|(OUT<<2)
00307 #define EP05_IN     (0x05<<3)|(IN<<2)
00308 #define EP06_OUT    (0x06<<3)|(OUT<<2)
00309 #define EP06_IN     (0x06<<3)|(IN<<2)
00310 #define EP07_OUT    (0x07<<3)|(OUT<<2)
00311 #define EP07_IN     (0x07<<3)|(IN<<2)
00312 #define EP08_OUT    (0x08<<3)|(OUT<<2)
00313 #define EP08_IN     (0x08<<3)|(IN<<2)
00314 #define EP09_OUT    (0x09<<3)|(OUT<<2)
00315 #define EP09_IN     (0x09<<3)|(IN<<2)
00316 #define EP10_OUT    (0x0A<<3)|(OUT<<2)
00317 #define EP10_IN     (0x0A<<3)|(IN<<2)
00318 #define EP11_OUT    (0x0B<<3)|(OUT<<2)
00319 #define EP11_IN     (0x0B<<3)|(IN<<2)
00320 #define EP12_OUT    (0x0C<<3)|(OUT<<2)
00321 #define EP12_IN     (0x0C<<3)|(IN<<2)
00322 #define EP13_OUT    (0x0D<<3)|(OUT<<2)
00323 #define EP13_IN     (0x0D<<3)|(IN<<2)
00324 #define EP14_OUT    (0x0E<<3)|(OUT<<2)
00325 #define EP14_IN     (0x0E<<3)|(IN<<2)
00326 #define EP15_OUT    (0x0F<<3)|(OUT<<2)
00327 #define EP15_IN     (0x0F<<3)|(IN<<2)
00328 
00329 
00330 #endif /* _USB_H */

Generated on Mon Sep 29 19:56:47 2008 for mKernel by  doxygen 1.4.6