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

usbdrv.h

Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  *                Microchip USB C18 Firmware Version 1.0
00004  *
00005  *********************************************************************
00006  * FileName:        usbdrv.h
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  * Author               Date        Comment
00033  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00034  * Rawin Rojvanit       11/19/04    Original.
00035  ********************************************************************/
00036 
00037 #ifndef USBDRV_H
00038 #define USBDRV_H
00039 
00040 /** I N C L U D E S **********************************************************/
00041 #include "system\typedefs.h"
00042 #include "system\usb\usb.h"
00043 
00044 /** D E F I N I T I O N S ****************************************************/
00045 
00046 /* UCFG Initialization Parameters */
00047 #define _PPBM0      0x00            // Pingpong Buffer Mode 0
00048 #define _PPBM1      0x01            // Pingpong Buffer Mode 1
00049 #define _PPBM2      0x02            // Pingpong Buffer Mode 2
00050 #define _LS         0x00            // Use Low-Speed USB Mode
00051 #define _FS         0x04            // Use Full-Speed USB Mode
00052 #define _TRINT      0x00            // Use internal transceiver
00053 #define _TREXT      0x08            // Use external transceiver
00054 #define _PUEN       0x10            // Use internal pull-up resistor
00055 #define _OEMON      0x40            // Use SIE output indicator
00056 #define _UTEYE      0x80            // Use Eye-Pattern test
00057 
00058 /* UEPn Initialization Parameters */
00059 #define EP_CTRL     0x06            // Cfg Control pipe for this ep
00060 #define EP_OUT      0x0C            // Cfg OUT only pipe for this ep
00061 #define EP_IN       0x0A            // Cfg IN only pipe for this ep
00062 #define EP_OUT_IN   0x0E            // Cfg both OUT & IN pipes for this ep
00063 #define HSHK_EN     0x10            // Enable handshake packet
00064                                     // Handshake should be disable for isoch
00065 
00066 /******************************************************************************
00067  * USB - PICmicro Endpoint Definitions
00068  * PICmicro EP Address Format: X:EP3:EP2:EP1:EP0:DIR:PPBI:X
00069  * This is used when checking the value read from USTAT
00070  *
00071  * NOTE: These definitions are not used in the descriptors.
00072  * EP addresses used in the descriptors have different format and
00073  * are defined in: "system\usb\usbdefs\usbdefs_std_dsc.h"
00074  *****************************************************************************/
00075 #define OUT         0
00076 #define IN          1
00077 
00078 #define PIC_EP_NUM_MASK 0b01111000
00079 #define PIC_EP_DIR_MASK 0b00000100
00080 
00081 #define EP00_OUT    (0x00<<3)|(OUT<<2)
00082 #define EP00_IN     (0x00<<3)|(IN<<2)
00083 #define EP01_OUT    (0x01<<3)|(OUT<<2)
00084 #define EP01_IN     (0x01<<3)|(IN<<2)
00085 #define EP02_OUT    (0x02<<3)|(OUT<<2)
00086 #define EP02_IN     (0x02<<3)|(IN<<2)
00087 #define EP03_OUT    (0x03<<3)|(OUT<<2)
00088 #define EP03_IN     (0x03<<3)|(IN<<2)
00089 #define EP04_OUT    (0x04<<3)|(OUT<<2)
00090 #define EP04_IN     (0x04<<3)|(IN<<2)
00091 #define EP05_OUT    (0x05<<3)|(OUT<<2)
00092 #define EP05_IN     (0x05<<3)|(IN<<2)
00093 #define EP06_OUT    (0x06<<3)|(OUT<<2)
00094 #define EP06_IN     (0x06<<3)|(IN<<2)
00095 #define EP07_OUT    (0x07<<3)|(OUT<<2)
00096 #define EP07_IN     (0x07<<3)|(IN<<2)
00097 #define EP08_OUT    (0x08<<3)|(OUT<<2)
00098 #define EP08_IN     (0x08<<3)|(IN<<2)
00099 #define EP09_OUT    (0x09<<3)|(OUT<<2)
00100 #define EP09_IN     (0x09<<3)|(IN<<2)
00101 #define EP10_OUT    (0x0A<<3)|(OUT<<2)
00102 #define EP10_IN     (0x0A<<3)|(IN<<2)
00103 #define EP11_OUT    (0x0B<<3)|(OUT<<2)
00104 #define EP11_IN     (0x0B<<3)|(IN<<2)
00105 #define EP12_OUT    (0x0C<<3)|(OUT<<2)
00106 #define EP12_IN     (0x0C<<3)|(IN<<2)
00107 #define EP13_OUT    (0x0D<<3)|(OUT<<2)
00108 #define EP13_IN     (0x0D<<3)|(IN<<2)
00109 #define EP14_OUT    (0x0E<<3)|(OUT<<2)
00110 #define EP14_IN     (0x0E<<3)|(IN<<2)
00111 #define EP15_OUT    (0x0F<<3)|(OUT<<2)
00112 #define EP15_IN     (0x0F<<3)|(IN<<2)
00113 
00114 /******************************************************************************
00115  * Macro:           void mInitializeUSBDriver(void)
00116  *
00117  * PreCondition:    None
00118  *
00119  * Input:           None
00120  *
00121  * Output:          None
00122  *
00123  * Side Effects:    None
00124  *
00125  * Overview:        Configures the USB module, definition of UCFG_VAL can be
00126  *                  found in autofiles\usbcfg.h
00127  *
00128  *                  This register determines: USB Speed, On-chip pull-up
00129  *                  resistor selection, On-chip tranceiver selection, bus
00130  *                  eye pattern generation mode, Ping-pong buffering mode
00131  *                  selection.
00132  *
00133  * Note:            None
00134  *****************************************************************************/
00135 #define mInitializeUSBDriver()      {UCFG = UCFG_VAL;                       \
00136                                      usb_device_state = DETACHED_STATE;     \
00137                                      usb_stat._byte = 0x00;                 \
00138                                      usb_active_cfg = 0x00;}
00139 
00140 /******************************************************************************
00141  * Macro:           void mDisableEP1to15(void)
00142  *
00143  * PreCondition:    None
00144  *
00145  * Input:           None
00146  *
00147  * Output:          None
00148  *
00149  * Side Effects:    None
00150  *
00151  * Overview:        This macro disables all endpoints except EP0.
00152  *                  This macro should be called when the host sends a RESET
00153  *                  signal or a SET_CONFIGURATION request.
00154  *
00155  * Note:            None
00156  *****************************************************************************/
00157 #define mDisableEP1to15()       ClearArray((byte*)&UEP1,15);
00158 /*
00159 #define mDisableEP1to15()       UEP1=0x00;UEP2=0x00;UEP3=0x00;\
00160                                 UEP4=0x00;UEP5=0x00;UEP6=0x00;UEP7=0x00;\
00161                                 UEP8=0x00;UEP9=0x00;UEP10=0x00;UEP11=0x00;\
00162                                 UEP12=0x00;UEP13=0x00;UEP14=0x00;UEP15=0x00;
00163 */
00164 
00165 /******************************************************************************
00166  * Macro:           void mUSBBufferReady(buffer_dsc)
00167  *
00168  * PreCondition:    IN Endpoint: Buffer is loaded and ready to be sent.
00169  *                  OUT Endpoint: Buffer is free to be written to by SIE.
00170  *
00171  * Input:           byte buffer_dsc: Root name of the buffer descriptor group.
00172  *                  i.e. ep0Bo, ep1Bi, ... Declared in usbmmap.c
00173  *                  Names can be remapped for readability, see examples in
00174  *                  usbcfg.h (#define HID_BD_OUT      ep1Bo)
00175  *
00176  * Output:          None
00177  *
00178  * Side Effects:    None
00179  *
00180  * Overview:        This macro should be called each time after:
00181  *                  1. A non-EP0 IN endpoint buffer is populated with data.
00182  *                  2. A non-EP0 OUT endpoint buffer is read.
00183  *                  This macro turns the buffer ownership to SIE for servicing.
00184  *                  It also toggles the DTS bit for synchronization.
00185  *
00186  * Note:            None
00187  *****************************************************************************/
00188 #define mUSBBufferReady(buffer_dsc)                                         \
00189 {                                                                           \
00190     buffer_dsc.Stat._byte &= _DTSMASK;          /* Save only DTS bit */     \
00191     buffer_dsc.Stat.DTS = !buffer_dsc.Stat.DTS; /* Toggle DTS bit    */     \
00192     buffer_dsc.Stat._byte |= _USIE|_DTSEN;      /* Turn ownership to SIE */ \
00193 }
00194 
00195 /** T Y P E S ****************************************************************/
00196 
00197 /** E X T E R N S ************************************************************/
00198 
00199 /** P U B L I C  P R O T O T Y P E S *****************************************/
00200 void USBCheckBusStatus(void);
00201 void USBDriverService(void);
00202 void USBRemoteWakeup(void);
00203 void USBSoftDetach(void); 
00204 
00205 void ClearArray(byte* startAdr,byte count);
00206 #endif //USBDRV_H

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