• Main Page
  • Data Structures
  • Files
  • File List
  • Globals

usb.h

Go to the documentation of this file.
00001 //******************************************************************************
00002 //THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
00003 //REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
00004 //INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
00005 //FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
00006 //COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
00007 //TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
00008 //POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
00009 //INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
00010 //YOUR USE OF THE PROGRAM.
00011 //
00012 //IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
00013 //CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
00014 //THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
00015 //OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
00016 //OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
00017 //EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
00018 //REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
00019 //OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
00020 //USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
00021 //AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
00022 //YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
00023 //(U.S.$500).
00024 //
00025 //Unless otherwise stated, the Program written and copyrighted
00026 //by Texas Instruments is distributed as "freeware".  You may,
00027 //only under TI's copyright in the Program, use and modify the
00028 //Program without any charge or restriction.  You may
00029 //distribute to third parties, provided that you transfer a
00030 //copy of this license to the third party and the third party
00031 //agrees to these terms by its first use of the Program. You
00032 //must reproduce the copyright notice and any other legend of
00033 //ownership on each copy or partial copy, of the Program.
00034 //
00035 //You acknowledge and agree that the Program contains
00036 //copyrighted material, trade secrets and other TI proprietary
00037 //information and is protected by copyright laws,
00038 //international copyright treaties, and trade secret laws, as
00039 //well as other intellectual property laws.  To protect TI's
00040 //rights in the Program, you agree not to decompile, reverse
00041 //engineer, disassemble or otherwise translate any object code
00042 //versions of the Program to a human-readable form.  You agree
00043 //that in no event will you alter, remove or destroy any
00044 //copyright notice included in the Program.  TI reserves all
00045 //rights not specifically granted under this license. Except
00046 //as specifically provided herein, nothing in this agreement
00047 //shall be construed as conferring by implication, estoppel,
00048 //or otherwise, upon you, any license or other right under any
00049 //TI patents, copyrights or trade secrets.
00050 // 
00051 //You may not use the Program in non-TI devices.
00063 // (c)2009 by Texas Instruments Incorporated, All Rights Reserved.
00064 /*----------------------------------------------------------------------------+
00065 |                                                                             |
00066 |                              Texas Instruments                              |
00067 |                                                                             |
00068 |                          MSP430 USB-Example (CDC/HID Driver)                |
00069 |                                                                             |
00070 +-----------------------------------------------------------------------------+
00071 |  Source: Usb.h, v1.18 2009/06/11                                            |
00072 |  Author: RSTO                                                               |
00073 |                                                                             |
00074 |  WHO          WHEN         WHAT                                             |
00075 |  ---          ----------   ------------------------------------------------ |
00076 |  RSTO         2008/09/03   born                                             |
00077 |  RSTO         2008/12/23   enhancements of CDC API                          |
00078 |  RSTO         2009/05/15   changed USB_connectionStatus()                   |
00079 |                            to USB_connectionInfo()                          |
00080 |  RSTO         2009/05/26   remove kUSB_failedEnumEvent                      |
00081 |  RSTO         2009/07/17   added __data16 qualifier for USB buffers         |
00082 |  RSTO         2009/11/05   added event ST_NOENUM_SUSPENDED                  |
00083 +----------------------------------------------------------------------------*/
00084 
00085 #ifndef _USB_H_
00086 #define _USB_H_
00087 
00088 #ifdef __cplusplus
00089 extern "C"
00090 {
00091 #endif
00092 
00093 /*----------------------------------------------------------------------------+
00094 | Constant Definition                                                         |
00095 +----------------------------------------------------------------------------*/
00096 #define USB_RETURN_DATA_LENGTH  8
00097 #define SIZEOF_DEVICE_REQUEST   0x08
00098 
00099 //  Bit definitions for DEVICE_REQUEST.bmRequestType
00100 //  Bit 7:   Data direction
00101 #define USB_REQ_TYPE_OUTPUT     0x00    // 0 = Host sending data to device
00102 #define USB_REQ_TYPE_INPUT      0x80    // 1 = Device sending data to host
00103 
00104 //  Bit 6-5: Type
00105 #define USB_REQ_TYPE_MASK       0x60    // Mask value for bits 6-5
00106 #define USB_REQ_TYPE_STANDARD   0x00    // 00 = Standard USB request
00107 #define USB_REQ_TYPE_CLASS      0x20    // 01 = Class specific
00108 #define USB_REQ_TYPE_VENDOR     0x40    // 10 = Vendor specific
00109 
00110 //  Bit 4-0: Recipient
00111 #define USB_REQ_TYPE_RECIP_MASK 0x1F    // Mask value for bits 4-0
00112 #define USB_REQ_TYPE_DEVICE     0x00    // 00000 = Device
00113 #define USB_REQ_TYPE_INTERFACE  0x01    // 00001 = Interface
00114 #define USB_REQ_TYPE_ENDPOINT   0x02    // 00010 = Endpoint
00115 #define USB_REQ_TYPE_OTHER      0x03    // 00011 = Other
00116 
00117 //  Values for DEVICE_REQUEST.bRequest
00118 // Standard Device Requests
00119 #define USB_REQ_GET_STATUS              0
00120 #define USB_REQ_CLEAR_FEATURE           1
00121 #define USB_REQ_SET_FEATURE             3
00122 #define USB_REQ_SET_ADDRESS             5
00123 #define USB_REQ_GET_DESCRIPTOR          6
00124 #define USB_REQ_SET_DESCRIPTOR          7
00125 #define USB_REQ_GET_CONFIGURATION       8
00126 #define USB_REQ_SET_CONFIGURATION       9
00127 #define USB_REQ_GET_INTERFACE           10
00128 #define USB_REQ_SET_INTERFACE           11
00129 #define USB_REQ_SYNCH_FRAME             12
00130 
00131 // CDC CLASS Requests
00132 #define USB_CDC_GET_LINE_CODING         0x21
00133 #define USB_CDC_SET_LINE_CODING         0x20
00134 #define USB_CDC_SET_CONTROL_LINE_STATE  0x22
00135 
00136 // HID CLASS Requests
00137 #define USB_HID_REQ                     0x81
00138 #define USB_REQ_GET_REPORT                      0x01
00139 #define USB_REQ_GET_IDLE                        0x02
00140 #define USB_REQ_SET_REPORT                      0x09
00141 #define USB_REQ_SET_IDLE                        0x0A
00142 #define USB_REQ_SET_PROTOCOL            0x0B
00143 #define USB_REQ_GET_PROTOCOL            0x03
00144 
00145 //HID Values for HID Report Types (tSetup.bValueH)
00146 #define USB_REQ_HID_INPUT               0x01
00147 #define USB_REQ_HID_OUTPUT              0x02
00148 #define USB_REQ_HID_FEATURE             0x03
00149 
00150 
00151 //  Descriptor Type Values
00152 #define DESC_TYPE_DEVICE                1       // Device Descriptor (Type 1)
00153 #define DESC_TYPE_CONFIG                2       // Configuration Descriptor (Type 2)
00154 #define DESC_TYPE_STRING                3       // String Descriptor (Type 3)
00155 #define DESC_TYPE_INTERFACE             4       // Interface Descriptor (Type 4)
00156 #define DESC_TYPE_ENDPOINT              5       // Endpoint Descriptor (Type 5)
00157 #define DESC_TYPE_DEVICE_QUALIFIER      6       // Endpoint Descriptor (Type 6)
00158 #define DESC_TYPE_HUB                   0x29    // Hub Descriptor (Type 6)
00159 #define DESC_TYPE_HID                           0x21    // HID Descriptor
00160 #define DESC_TYPE_REPORT                        0x22    // Report Descriptor
00161 #define DESC_TYPE_PHYSICAL                      0x23    // Physical Descriptor
00162 
00163 //  Feature Selector Values
00164 #define FEATURE_REMOTE_WAKEUP           1       // Remote wakeup (Type 1)
00165 #define FEATURE_ENDPOINT_STALL          0       // Endpoint stall (Type 0)
00166 
00167 // Device Status Values
00168 #define DEVICE_STATUS_REMOTE_WAKEUP     0x02
00169 #define DEVICE_STATUS_SELF_POWER        0x01
00170 
00171 //  Maximum descriptor size
00172 #define MAX_DESC_SIZE                   256
00173 
00174 //  DEVICE_DESCRIPTOR structure
00175 #define SIZEOF_DEVICE_DESCRIPTOR        0x12
00176 #define OFFSET_DEVICE_DESCRIPTOR_VID_L  0x08
00177 #define OFFSET_DEVICE_DESCRIPTOR_VID_H  0x09
00178 #define OFFSET_DEVICE_DESCRIPTOR_PID_L  0x0A
00179 #define OFFSET_DEVICE_DESCRIPTOR_PID_H  0x0B
00180 #define OFFSET_CONFIG_DESCRIPTOR_POWER  0x07
00181 #define OFFSET_CONFIG_DESCRIPTOR_CURT   0x08
00182 
00183 //  CONFIG_DESCRIPTOR structure
00184 #define SIZEOF_CONFIG_DESCRIPTOR 0x09
00185 
00186 //  HID DESCRIPTOR structure
00187 //#define SIZEOF_HID_DESCRIPTOR 0x09
00188 
00189 //  Bit definitions for CONFIG_DESCRIPTOR.bmAttributes
00190 #define CFG_DESC_ATTR_SELF_POWERED  0x40    // Bit 6: If set, device is self powered
00191 #define CFG_DESC_ATTR_BUS_POWERED   0x80    // Bit 7: If set, device is bus powered
00192 #define CFG_DESC_ATTR_REMOTE_WAKE   0x20    // Bit 5: If set, device supports remote wakeup
00193 
00194 //  INTERFACE_DESCRIPTOR structure
00195 #define SIZEOF_INTERFACE_DESCRIPTOR 0x09
00196 
00197 //  ENDPOINT_DESCRIPTOR structure
00198 #define SIZEOF_ENDPOINT_DESCRIPTOR 0x07
00199 
00200 //  Bit definitions for EndpointDescriptor.EndpointAddr
00201 #define EP_DESC_ADDR_EP_NUM     0x0F    // Bit 3-0: Endpoint number
00202 #define EP_DESC_ADDR_DIR_IN     0x80    // Bit 7: Direction of endpoint, 1/0 = In/Out
00203 
00204 //  Bit definitions for EndpointDescriptor.EndpointFlags
00205 #define EP_DESC_ATTR_TYPE_MASK  0x03    // Mask value for bits 1-0
00206 #define EP_DESC_ATTR_TYPE_CONT  0x00    // Bit 1-0: 00 = Endpoint does control transfers
00207 #define EP_DESC_ATTR_TYPE_ISOC  0x01    // Bit 1-0: 01 = Endpoint does isochronous transfers
00208 #define EP_DESC_ATTR_TYPE_BULK  0x02    // Bit 1-0: 10 = Endpoint does bulk transfers
00209 #define EP_DESC_ATTR_TYPE_INT   0x03    // Bit 1-0: 11 = Endpoint does interrupt transfers
00210 
00211 
00212 extern __no_init tDEVICE_REQUEST __data16 tSetupPacket;
00213 extern __no_init BYTE __data16 abIEP0Buffer[];
00214 extern __no_init BYTE __data16 abOEP0Buffer[];
00215 extern __no_init BYTE __data16 pbXBufferAddressEp1[];
00216 extern __no_init BYTE __data16 pbYBufferAddressEp1[];
00217 extern __no_init BYTE __data16 pbXBufferAddressEp81[];
00218 extern __no_init BYTE __data16 pbYBufferAddressEp81[];
00219 extern __no_init BYTE __data16 pbXBufferAddressEp2[];
00220 extern __no_init BYTE __data16 pbYBufferAddressEp2[];
00221 extern __no_init BYTE __data16 pbXBufferAddressEp82[];
00222 extern __no_init BYTE __data16 pbYBufferAddressEp82[];
00223 
00224 extern WORD wBytesRemainingOnIEP0;
00225 extern WORD wBytesRemainingOnOEP0;
00226 extern BYTE abUsbRequestReturnData[];
00227 extern BYTE abUsbRequestIncomingData[];
00228 extern BYTE bEnumerationStatus;
00229 extern BYTE bFunctionSuspended;
00230 
00231 //Function return values
00232 #define kUSB_succeed        0x00
00233 #define kUSB_generalError   0x01
00234 #define kUSB_notEnabled     0x02
00235 //#define kUSB_VbusNotPresent 0x03
00236 
00237 //return values USB_connectionInfo(), USB_connect()
00238 #define kUSB_vbusPresent    0x01
00239 #define kUSB_busActive      0x02    // frame sync packets are being received
00240 #define kUSB_ConnectNoVBUS  0x04
00241 #define kUSB_suspended      0x08
00242 #define kUSB_NotSuspended   0x10
00243 #define kUSB_Enumerated     0x20
00244 #define kUSB_purHigh        0x40
00245 
00246 // Parameters for function USB_setEnabledEvents()
00247 #define kUSB_clockFaultEvent        0x0001
00248 #define kUSB_VbusOnEvent            0x0002
00249 #define kUSB_VbusOffEvent           0x0004
00250 #define kUSB_UsbResetEvent          0x0008
00251 #define kUSB_UsbSuspendEvent        0x0010
00252 #define kUSB_UsbResumeEvent         0x0020
00253 #define kUSB_dataReceivedEvent      0x0040
00254 #define kUSB_sendCompletedEvent     0x0080
00255 #define kUSB_receiveCompletedEvent  0x0100
00256 
00257 // USB connection states
00258 #define ST_USB_DISCONNECTED         0x80
00259 #define ST_USB_CONNECTED_NO_ENUM    0x81
00260 #define ST_ENUM_IN_PROGRESS         0x82
00261 #define ST_ENUM_ACTIVE              0x83
00262 #define ST_ENUM_SUSPENDED           0x84
00263 //#define ST_FAILED_ENUM              0x85
00264 #define ST_ERROR                    0x86
00265 #define ST_NOENUM_SUSPENDED         0x87
00266 
00267 
00268 
00269 /*----------------------------------------------------------------------------
00270 These functions can be used in application
00271 +----------------------------------------------------------------------------*/
00272 
00273 /*
00274 MSP430 USB Module Management functions
00275 */
00276 
00280 BYTE USB_init(VOID);
00281 
00285 BYTE USB_enable();
00286 
00290 BYTE USB_disable(VOID);
00291 
00292 /*
00293 Enables/disables various USB events.
00294 */
00295 BYTE USB_setEnabledEvents(WORD events);
00296 
00297 /*
00298 Returns which events are enabled and which are disabled.
00299 */
00300 WORD USB_getEnabledEvents();
00301 
00302 /*
00303 Instruct USB module to make itself available to the PC for connection, by pulling PUR high.
00304 */
00305 BYTE USB_connect();
00306 
00307 /*
00308 Force a disconnect from the PC by pulling PUR low.
00309 */
00310 BYTE USB_disconnect();
00311 
00315 BYTE USB_reset();
00316 
00320 BYTE USB_suspend(VOID);
00321 
00325 BYTE USB_resume(VOID);
00326 
00327 /*
00328 Force a remote wakeup of the USB host.
00329        This method can be generated only if device supports
00330        remote wake-up feature in some of its configurations.
00331        The method wakes-up the USB bus only if wake-up feature is enabled by the host.
00332 */
00333 BYTE USB_forceRemoteWakeup();
00334 
00335 /*
00336 Returns the status of the USB connection.
00337 */
00338 BYTE USB_connectionInfo();
00339 
00340 /*
00341 Returns the state of the USB connection.
00342 */
00343 BYTE USB_connectionState();
00344 
00345 
00346 /*
00347 Event-Handling routines
00348 */
00349 
00350 /*
00351 If this function gets executed, it's a sign that the output of the USB PLL has failed.
00352 returns TRUE to keep CPU awake
00353 */
00354 BYTE USB_handleClockEvent();
00355 
00356 /*
00357 If this function gets executed, it indicates that a valid voltage has just been applied to the VBUS pin.
00358 returns TRUE to keep CPU awake
00359 */
00360 BYTE USB_handleVbusOnEvent();
00361 
00362 /*
00363 If this function gets executed, it indicates that a valid voltage has just been removed from the VBUS pin.
00364 returns TRUE to keep CPU awake
00365 */
00366 BYTE USB_handleVbusOffEvent();
00367 
00368 /*
00369 If this function gets executed, it indicates that the USB host has issued a USB reset event to the device.
00370 returns TRUE to keep CPU awake
00371 */
00372 BYTE USB_handleResetEvent();
00373 
00374 /*
00375 If this function gets executed, it indicates that the USB host has chosen to suspend this device after a period of active operation.
00376 returns TRUE to keep CPU awake
00377 */
00378 BYTE USB_handleSuspendEvent();
00379 
00380 /*
00381 If this function gets executed, it indicates that the USB host has chosen to resume this device after a period of suspended operation.
00382 returns TRUE to keep CPU awake
00383 */
00384 BYTE USB_handleResumeEvent();
00385 
00386 /*
00387 If this function gets executed, it indicates that the USB host has enumerated this device :
00388 after host assigned the address to the device. 
00389 returns TRUE to keep CPU awake
00390 */
00391 BYTE USB_handleEnumCompleteEvent();
00392 
00393 /*----------------------------------------------------------------------------
00394 These functions is to be used ONLY by USB stack, and not by application
00395 +----------------------------------------------------------------------------*/
00396 
00397 
00401 VOID usbStallEndpoint0(VOID);
00402 
00406 VOID usbClearOEP0ByteCount(VOID);
00407 
00411 VOID usbStallOEP0(VOID);
00412 
00417 VOID usbSendNextPacketOnIEP0(VOID);
00418 
00424 VOID usbSendDataPacketOnEP0(PBYTE pbBuffer);
00425 
00430 VOID usbReceiveNextPacketOnOEP0(VOID);
00431 
00437 VOID usbReceiveDataPacketOnEP0(PBYTE pbBuffer);
00438 
00442 VOID usbSendZeroLengthPacketOnIEP0(VOID);
00443 
00449 BYTE usbDecodeAndProcessUsbRequest(VOID);
00450 
00451 
00452 #define ENUMERATION_COMPLETE 0x01
00453 
00454 /*----------------------------------------------------------------------------+
00455 | End of header file                                                          |
00456 +----------------------------------------------------------------------------*/
00457 #ifdef __cplusplus
00458 }
00459 #endif
00460 #endif /* _USB_H */
00461 /*------------------------ Nothing Below This Line --------------------------*/

Generated on Fri Dec 17 2010 12:08:31 for Multi-cell Lithium-Ion Battery Manager System using MSP430 and BQ76PL536 by  doxygen 1.7.1