usbdrv/usbdrv.c File Reference

#include "iarcompat.h"
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "usbdrv.h"
#include "oddebug.h"

Go to the source code of this file.

Data Structures

union  converter_t

Defines

#define USB_FLG_TX_PACKET   (1<<0)
#define USB_FLG_MSGPTR_IS_ROM   (1<<6)
#define USB_FLG_USE_DEFAULT_RW   (1<<7)
#define USB_CFG_DESCR_PROPS_STRING_0   sizeof(usbDescriptorString0)
#define USB_CFG_DESCR_PROPS_STRING_VENDOR   sizeof(usbDescriptorStringVendor)
#define USB_CFG_DESCR_PROPS_STRING_PRODUCT   sizeof(usbDescriptorStringDevice)
#define USB_CFG_DESCR_PROPS_DEVICE   sizeof(usbDescriptorDevice)
#define USB_CFG_DESCR_PROPS_HID   9
#define USB_CFG_DESCR_PROPS_CONFIGURATION   sizeof(usbDescriptorConfiguration)
#define PRG_RDB(addr)   pgm_read_byte(addr)
#define GET_DESCRIPTOR(cfgProp, staticName)
#define SET_REPLY_LEN(len)   replyLen = (len); usbMsgPtr = replyData

Functions

USB_PUBLIC void usbSetInterrupt (uchar *data, uchar len)
USB_PUBLIC void usbPoll (void)
USB_PUBLIC void usbInit (void)

Variables

uchar usbRxBuf [2 *USB_BUFSIZE]
uchar usbInputBufOffset
uchar usbDeviceAddr
uchar usbNewDeviceAddr
uchar usbConfiguration
volatile schar usbRxLen
uchar usbCurrentTok
uchar usbRxToken
uchar usbMsgLen = 0xff
volatile uchar usbTxLen = USBPID_NAK
uchar usbTxBuf [USB_BUFSIZE]
volatile uchar usbTxLen1 = USBPID_NAK
uchar usbTxBuf1 [USB_BUFSIZE]
uchar * usbMsgPtr
PROGMEM char usbDescriptorString0 []
PROGMEM int usbDescriptorStringVendor []
PROGMEM int usbDescriptorStringDevice []
PROGMEM char usbDescriptorDevice []
PROGMEM char usbDescriptorConfiguration []


Define Documentation

#define GET_DESCRIPTOR ( cfgProp,
staticName   ) 

Value:

if(cfgProp){                                    \
        if((cfgProp) & USB_PROP_IS_RAM)             \
            flags &= ~USB_FLG_MSGPTR_IS_ROM;        \
        if((cfgProp) & USB_PROP_IS_DYNAMIC){        \
            replyLen = usbFunctionDescriptor(rq);   \
        }else{                                      \
            replyData = (uchar *)(staticName);      \
            SET_REPLY_LEN((cfgProp) & 0xff);        \
        }                                           \
    }

Definition at line 303 of file usbdrv.c.

#define PRG_RDB ( addr   )     pgm_read_byte(addr)

Definition at line 191 of file usbdrv.c.

#define SET_REPLY_LEN ( len   )     replyLen = (len); usbMsgPtr = replyData

#define USB_CFG_DESCR_PROPS_CONFIGURATION   sizeof(usbDescriptorConfiguration)

Definition at line 142 of file usbdrv.c.

#define USB_CFG_DESCR_PROPS_DEVICE   sizeof(usbDescriptorDevice)

Definition at line 113 of file usbdrv.c.

#define USB_CFG_DESCR_PROPS_HID   9

Definition at line 137 of file usbdrv.c.

#define USB_CFG_DESCR_PROPS_STRING_0   sizeof(usbDescriptorString0)

Definition at line 74 of file usbdrv.c.

#define USB_CFG_DESCR_PROPS_STRING_PRODUCT   sizeof(usbDescriptorStringDevice)

Definition at line 93 of file usbdrv.c.

#define USB_CFG_DESCR_PROPS_STRING_VENDOR   sizeof(usbDescriptorStringVendor)

Definition at line 84 of file usbdrv.c.

#define USB_FLG_MSGPTR_IS_ROM   (1<<6)

Definition at line 57 of file usbdrv.c.

#define USB_FLG_TX_PACKET   (1<<0)

Definition at line 55 of file usbdrv.c.

#define USB_FLG_USE_DEFAULT_RW   (1<<7)

Definition at line 58 of file usbdrv.c.


Function Documentation

USB_PUBLIC void usbInit ( void   ) 

Definition at line 566 of file usbdrv.c.

Referenced by main().

00567 {
00568 #if USB_INTR_CFG_SET != 0
00569     USB_INTR_CFG |= USB_INTR_CFG_SET;
00570 #endif
00571 #if USB_INTR_CFG_CLR != 0
00572     USB_INTR_CFG &= ~(USB_INTR_CFG_CLR);
00573 #endif
00574     USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
00575     usbResetDataToggling();
00576 }

USB_PUBLIC void usbPoll ( void   ) 

Definition at line 526 of file usbdrv.c.

Referenced by main().

00527 {
00528 schar   len;
00529 uchar   i;
00530 
00531     if((len = usbRxLen) > 0){
00532 /* We could check CRC16 here -- but ACK has already been sent anyway. If you
00533  * need data integrity checks with this driver, check the CRC in your app
00534  * code and report errors back to the host. Since the ACK was already sent,
00535  * retries must be handled on application level.
00536  * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3);
00537  */
00538         usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len - 3);
00539 #if USB_CFG_HAVE_FLOWCONTROL
00540         if(usbRxLen > 0)    /* only mark as available if not inactivated */
00541             usbRxLen = 0;
00542 #else
00543         usbRxLen = 0;       /* mark rx buffer as available */
00544 #endif
00545     }
00546     if(usbTxLen & 0x10){ /* transmit system idle */
00547         if(usbMsgLen != 0xff){  /* transmit data pending? */
00548             usbBuildTxBlock();
00549         }
00550     }
00551     for(i = 10; i > 0; i--){
00552         if(isNotSE0())
00553             break;
00554     }
00555     if(i == 0){ /* RESET condition, called multiple times during reset */
00556         usbNewDeviceAddr = 0;
00557         usbDeviceAddr = 0;
00558         usbResetStall();
00559         DBG1(0xff, 0, 0);
00560     }
00561     usbHandleResetHook(i);
00562 }

USB_PUBLIC void usbSetInterrupt ( uchar *  data,
uchar  len 
)

Definition at line 229 of file usbdrv.c.

Referenced by main().

00230 {
00231 uchar       *p, i;
00232 
00233 #if USB_CFG_IMPLEMENT_HALT
00234     if(usbTxLen1 == USBPID_STALL)
00235         return;
00236 #endif
00237 #if 0   /* No runtime checks! Caller is responsible for valid data! */
00238     if(len > 8) /* interrupt transfers are limited to 8 bytes */
00239         len = 8;
00240 #endif
00241     if(usbTxLen1 & 0x10){   /* packet buffer was empty */
00242         usbTxBuf1[0] ^= USBPID_DATA0 ^ USBPID_DATA1;    /* toggle token */
00243     }else{
00244         usbTxLen1 = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */
00245     }
00246     p = usbTxBuf1 + 1;
00247     for(i=len;i--;)
00248         *p++ = *data++;
00249     usbCrc16Append(&usbTxBuf1[1], len);
00250     usbTxLen1 = len + 4;    /* len must be given including sync byte */
00251     DBG2(0x21, usbTxBuf1, len + 3);
00252 }


Variable Documentation

Definition at line 32 of file usbdrv.c.

Definition at line 34 of file usbdrv.c.

Definition at line 143 of file usbdrv.c.

Initial value:

 { 
    4,          
    3,          
    0x09, 0x04, 
}

Definition at line 75 of file usbdrv.c.

Initial value:

Definition at line 94 of file usbdrv.c.

Initial value:

Definition at line 85 of file usbdrv.c.

Definition at line 30 of file usbdrv.c.

Referenced by usbPoll().

Definition at line 29 of file usbdrv.c.

Referenced by usbPoll().

uchar usbMsgLen = 0xff

Definition at line 36 of file usbdrv.c.

Referenced by usbPoll().

uchar* usbMsgPtr

Definition at line 52 of file usbdrv.c.

Referenced by usbFunctionSetup().

Definition at line 31 of file usbdrv.c.

Referenced by usbPoll().

uchar usbRxBuf[2 *USB_BUFSIZE]

Definition at line 28 of file usbdrv.c.

Referenced by usbPoll().

volatile schar usbRxLen

Definition at line 33 of file usbdrv.c.

Referenced by usbPoll().

uchar usbRxToken

Definition at line 35 of file usbdrv.c.

uchar usbTxBuf[USB_BUFSIZE]

Definition at line 38 of file usbdrv.c.

uchar usbTxBuf1[USB_BUFSIZE]

Definition at line 44 of file usbdrv.c.

Referenced by usbSetInterrupt().

volatile uchar usbTxLen = USBPID_NAK

Definition at line 37 of file usbdrv.c.

Referenced by usbPoll().

volatile uchar usbTxLen1 = USBPID_NAK

Definition at line 43 of file usbdrv.c.

Referenced by usbSetInterrupt().


Generated on Fri Oct 30 20:43:20 2009 for USB IR HID Device by  doxygen 1.5.8