bootloader_firmware/usbdrv/usbdrv.h File Reference

#include "usbconfig.h"
#include "iarcompat.h"

Go to the source code of this file.

Data Structures

union  usbWord
struct  usbRequest

Defines

#define USBDRV_VERSION   20060314
#define uchar   unsigned char
#define schar   signed char
#define usbInterruptIsReady()   (usbTxLen1 == -1)
#define USB_STRING_DESCRIPTOR_HEADER(stringLength)   ((2*(stringLength)+2) | (3<<8))
#define USB_BUFFER_SECTION   ".bss"
#define USBOUT   USB_CFG_IOPORT
#define USB_PULLUP_OUT   USB_CFG_PULLUP_IOPORT
#define USBIN   (*(&USB_CFG_IOPORT - 2))
#define USBDDR   (*(&USB_CFG_IOPORT - 1))
#define USB_PULLUP_DDR   (*(&USB_CFG_PULLUP_IOPORT - 1))
#define USBMINUS   0
#define USBIDLE   0x01
#define USBMASK   ((1<<USB_CFG_DPLUS_BIT) | 1)
#define USB_BUFSIZE   11
#define USB_INTR_CFG   MCUCR
#define USB_INTR_CFG_SET   ((1 << ISC00) | (1 << ISC01))
#define USB_INTR_CFG_CLR   0
#define USB_INTR_ENABLE   GICR
#define USB_INTR_ENABLE_BIT   INT0
#define USB_INTR_PENDING   GIFR
#define USB_INTR_PENDING_BIT   INTF0
#define USBPID_SETUP   0x2d
#define USBPID_OUT   0xe1
#define USBPID_IN   0x69
#define USBPID_DATA0   0xc3
#define USBPID_DATA1   0x4b
#define USBPID_ACK   0xd2
#define USBPID_NAK   0x5a
#define USBPID_STALL   0x1e
#define USBRQ_RCPT_MASK   0x1f
#define USBRQ_RCPT_DEVICE   0
#define USBRQ_RCPT_INTERFACE   1
#define USBRQ_RCPT_ENDPOINT   2
#define USBRQ_TYPE_MASK   0x60
#define USBRQ_TYPE_STANDARD   (0<<5)
#define USBRQ_TYPE_CLASS   (1<<5)
#define USBRQ_TYPE_VENDOR   (2<<5)
#define USBRQ_DIR_MASK   0x80
#define USBRQ_DIR_HOST_TO_DEVICE   (0<<7)
#define USBRQ_DIR_DEVICE_TO_HOST   (1<<7)
#define USBRQ_GET_STATUS   0
#define USBRQ_CLEAR_FEATURE   1
#define USBRQ_SET_FEATURE   3
#define USBRQ_SET_ADDRESS   5
#define USBRQ_GET_DESCRIPTOR   6
#define USBRQ_SET_DESCRIPTOR   7
#define USBRQ_GET_CONFIGURATION   8
#define USBRQ_SET_CONFIGURATION   9
#define USBRQ_GET_INTERFACE   10
#define USBRQ_SET_INTERFACE   11
#define USBRQ_SYNCH_FRAME   12
#define USBDESCR_DEVICE   1
#define USBDESCR_CONFIG   2
#define USBDESCR_STRING   3
#define USBDESCR_INTERFACE   4
#define USBDESCR_ENDPOINT   5
#define USBDESCR_HID   0x21
#define USBDESCR_HID_REPORT   0x22
#define USBDESCR_HID_PHYS   0x23
#define USBATTR_BUSPOWER   0x80
#define USBATTR_SELFPOWER   0x40
#define USBATTR_REMOTEWAKE   0x20
#define USBRQ_HID_GET_REPORT   0x01
#define USBRQ_HID_GET_IDLE   0x02
#define USBRQ_HID_GET_PROTOCOL   0x03
#define USBRQ_HID_SET_REPORT   0x09
#define USBRQ_HID_SET_IDLE   0x0a
#define USBRQ_HID_SET_PROTOCOL   0x0b

Typedefs

typedef union usbWord usbWord_t
typedef struct usbRequest usbRequest_t

Functions

void usbInit (void)
void usbPoll (void)
uchar usbFunctionSetup (uchar data[8])
void usbSetInterrupt (uchar *data, uchar len)
unsigned usbCrc16 (uchar *data, uchar len)
unsigned usbCrc16Append (unsigned char *data, unsigned char len)

Variables

uchar * usbMsgPtr
volatile schar usbTxLen1
PROGMEM const char usbHidReportDescriptor []
uchar usbConfiguration


Define Documentation

#define schar   signed char

Definition at line 139 of file usbdrv.h.

Referenced by usbPoll().

#define uchar   unsigned char

Definition at line 136 of file usbdrv.h.

#define USB_BUFFER_SECTION   ".bss"

Definition at line 305 of file usbdrv.h.

#define USB_BUFSIZE   11

Definition at line 327 of file usbdrv.h.

Referenced by usbPoll().

#define USB_INTR_CFG   MCUCR

Definition at line 334 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_CFG_CLR   0

Definition at line 337 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_CFG_SET   ((1 << ISC00) | (1 << ISC01))

Definition at line 336 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_ENABLE   GICR

Definition at line 344 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_ENABLE_BIT   INT0

Definition at line 346 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_PENDING   GIFR

Definition at line 351 of file usbdrv.h.

#define USB_INTR_PENDING_BIT   INTF0

Definition at line 353 of file usbdrv.h.

#define USB_PULLUP_DDR   (*(&USB_CFG_PULLUP_IOPORT - 1))

Definition at line 318 of file usbdrv.h.

#define USB_PULLUP_OUT   USB_CFG_PULLUP_IOPORT

Definition at line 310 of file usbdrv.h.

#define USB_STRING_DESCRIPTOR_HEADER ( stringLength   )     ((2*(stringLength)+2) | (3<<8))

Definition at line 271 of file usbdrv.h.

#define USBATTR_BUSPOWER   0x80

Definition at line 445 of file usbdrv.h.

#define USBATTR_REMOTEWAKE   0x20

Definition at line 447 of file usbdrv.h.

#define USBATTR_SELFPOWER   0x40

Definition at line 446 of file usbdrv.h.

#define USBDDR   (*(&USB_CFG_IOPORT - 1))

Definition at line 317 of file usbdrv.h.

#define USBDESCR_CONFIG   2

Definition at line 437 of file usbdrv.h.

#define USBDESCR_DEVICE   1

Definition at line 436 of file usbdrv.h.

#define USBDESCR_ENDPOINT   5

Definition at line 440 of file usbdrv.h.

#define USBDESCR_HID   0x21

Definition at line 441 of file usbdrv.h.

#define USBDESCR_HID_PHYS   0x23

Definition at line 443 of file usbdrv.h.

#define USBDESCR_HID_REPORT   0x22

Definition at line 442 of file usbdrv.h.

#define USBDESCR_INTERFACE   4

Definition at line 439 of file usbdrv.h.

#define USBDESCR_STRING   3

Definition at line 438 of file usbdrv.h.

#define USBDRV_VERSION   20060314

Definition at line 125 of file usbdrv.h.

#define USBIDLE   0x01

Definition at line 324 of file usbdrv.h.

#define USBIN   (*(&USB_CFG_IOPORT - 2))

Definition at line 316 of file usbdrv.h.

 
#define usbInterruptIsReady (  )     (usbTxLen1 == -1)

Definition at line 195 of file usbdrv.h.

Referenced by main().

#define USBMASK   ((1<<USB_CFG_DPLUS_BIT) | 1)

Definition at line 325 of file usbdrv.h.

#define USBMINUS   0

Definition at line 323 of file usbdrv.h.

#define USBOUT   USB_CFG_IOPORT

Definition at line 309 of file usbdrv.h.

#define USBPID_ACK   0xd2

Definition at line 378 of file usbdrv.h.

Referenced by __attribute__().

#define USBPID_DATA0   0xc3

Definition at line 375 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBPID_DATA1   0x4b

Definition at line 376 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBPID_IN   0x69

Definition at line 374 of file usbdrv.h.

#define USBPID_NAK   0x5a

Definition at line 379 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBPID_OUT   0xe1

Definition at line 373 of file usbdrv.h.

#define USBPID_SETUP   0x2d

Definition at line 372 of file usbdrv.h.

#define USBPID_STALL   0x1e

Definition at line 380 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBRQ_CLEAR_FEATURE   1

Definition at line 424 of file usbdrv.h.

#define USBRQ_DIR_DEVICE_TO_HOST   (1<<7)

Definition at line 420 of file usbdrv.h.

#define USBRQ_DIR_HOST_TO_DEVICE   (0<<7)

Definition at line 419 of file usbdrv.h.

#define USBRQ_DIR_MASK   0x80

Definition at line 418 of file usbdrv.h.

#define USBRQ_GET_CONFIGURATION   8

Definition at line 429 of file usbdrv.h.

#define USBRQ_GET_DESCRIPTOR   6

Definition at line 427 of file usbdrv.h.

#define USBRQ_GET_INTERFACE   10

Definition at line 431 of file usbdrv.h.

#define USBRQ_GET_STATUS   0

Definition at line 423 of file usbdrv.h.

#define USBRQ_HID_GET_IDLE   0x02

Definition at line 451 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_HID_GET_PROTOCOL   0x03

Definition at line 452 of file usbdrv.h.

#define USBRQ_HID_GET_REPORT   0x01

Definition at line 450 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_HID_SET_IDLE   0x0a

Definition at line 454 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_HID_SET_PROTOCOL   0x0b

Definition at line 455 of file usbdrv.h.

#define USBRQ_HID_SET_REPORT   0x09

Definition at line 453 of file usbdrv.h.

#define USBRQ_RCPT_DEVICE   0

Definition at line 407 of file usbdrv.h.

#define USBRQ_RCPT_ENDPOINT   2

Definition at line 409 of file usbdrv.h.

#define USBRQ_RCPT_INTERFACE   1

Definition at line 408 of file usbdrv.h.

#define USBRQ_RCPT_MASK   0x1f

Definition at line 406 of file usbdrv.h.

#define USBRQ_SET_ADDRESS   5

Definition at line 426 of file usbdrv.h.

#define USBRQ_SET_CONFIGURATION   9

Definition at line 430 of file usbdrv.h.

#define USBRQ_SET_DESCRIPTOR   7

Definition at line 428 of file usbdrv.h.

#define USBRQ_SET_FEATURE   3

Definition at line 425 of file usbdrv.h.

#define USBRQ_SET_INTERFACE   11

Definition at line 432 of file usbdrv.h.

#define USBRQ_SYNCH_FRAME   12

Definition at line 433 of file usbdrv.h.

#define USBRQ_TYPE_CLASS   (1<<5)

Definition at line 414 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_TYPE_MASK   0x60

Definition at line 412 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_TYPE_STANDARD   (0<<5)

Definition at line 413 of file usbdrv.h.

#define USBRQ_TYPE_VENDOR   (2<<5)

Definition at line 415 of file usbdrv.h.


Typedef Documentation

typedef struct usbRequest usbRequest_t

typedef union usbWord usbWord_t


Function Documentation

unsigned usbCrc16 ( uchar *  data,
uchar  len 
)

unsigned usbCrc16Append ( unsigned char *  data,
unsigned char  len 
)

uchar usbFunctionSetup ( uchar  data[8]  ) 

Definition at line 55 of file main.c.

00056 {
00057     uchar len = 0;
00058     
00059     if (data[1] == USBBOOT_FUNC_LEAVE_BOOT) {
00060       leaveBootloader();
00061     } else if (data[1] == USBBOOT_FUNC_WRITE_PAGE) {
00062 
00063       state = STATE_WRITE_PAGE;
00064 
00065       page_address = (data[3] << 8) | data[2]; /* page address */
00066       page_offset = 0;
00067 
00068       eeprom_busy_wait();
00069       cli();
00070       boot_page_erase(page_address); /* erase page */
00071       sei();
00072       boot_spm_busy_wait(); /* wait until page is erased */
00073 
00074       len = 0xff; /* multiple out */
00075 
00076     } else if (data[1] == USBBOOT_FUNC_GET_PAGESIZE) {
00077 
00078       replyBuffer[0] = SPM_PAGESIZE >> 8;
00079       replyBuffer[1] = SPM_PAGESIZE & 0xff;
00080       len = 2;
00081 
00082     }
00083 
00084     usbMsgPtr = replyBuffer;
00085 
00086     return len;
00087 }

void usbInit ( void   ) 

Definition at line 501 of file usbdrv.c.

00502 {
00503     usbInputBuf = (uchar)usbRxBuf[0];
00504     usbAppBuf = (uchar)usbRxBuf[1];
00505 #if USB_INTR_CFG_SET != 0
00506     USB_INTR_CFG |= USB_INTR_CFG_SET;
00507 #endif
00508 #if USB_INTR_CFG_CLR != 0
00509     USB_INTR_CFG &= ~(USB_INTR_CFG_CLR);
00510 #endif
00511     USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
00512 }

void usbPoll ( void   ) 

Definition at line 452 of file usbdrv.c.

00453 {
00454 uchar   len;
00455 
00456     if((len = usbRxLen) > 0){
00457 /* We could check CRC16 here -- but ACK has already been sent anyway. If you
00458  * need data integrity checks with this driver, check the CRC in your app
00459  * code and report errors back to the host. Since the ACK was already sent,
00460  * retries must be handled on application level.
00461  * unsigned crc = usbCrc16((uchar *)(unsigned)(usbAppBuf + 1), usbRxLen - 3);
00462  */
00463         len -= 3;       /* remove PID and CRC */
00464         if(len < 128){  /* no overflow */
00465             converter_t appBuf;
00466             appBuf.ptr = (uchar *)usbRxBuf;
00467             appBuf.bytes[0] = usbAppBuf;
00468             appBuf.bytes[0]++;
00469             usbProcessRx(appBuf.ptr, len);
00470         }
00471         usbRxLen = 0;   /* mark rx buffer as available */
00472     }
00473     if(usbMsgLen != 0xff){  /* transmit data pending? */
00474         if(usbTxLen < 0)    /* transmit system idle */
00475             usbBuildTxBlock();
00476     }
00477     if(isNotSE0()){ /* SE0 state */
00478         usbIsReset = 0;
00479     }else{
00480         /* check whether SE0 lasts for more than 2.5us (3.75 bit times) */
00481         if(!usbIsReset){
00482             uchar i;
00483             for(i=100;i;i--){
00484                 if(isNotSE0())
00485                     goto notUsbReset;
00486             }
00487             usbIsReset = 1;
00488             usbNewDeviceAddr = 0;
00489             usbDeviceAddr = 0;
00490 #if USB_CFG_IMPLEMENT_HALT
00491             usbHalted1 = 0;
00492 #endif
00493             DBG1(0xff, 0, 0);
00494 notUsbReset:;
00495         }
00496     }
00497 }

void usbSetInterrupt ( uchar *  data,
uchar  len 
)

Definition at line 196 of file usbdrv.c.

00197 {
00198 uchar       *p, i;
00199 
00200 #if USB_CFG_IMPLEMENT_HALT
00201     if(usbHalted1)
00202         return;
00203 #endif
00204     if(len > 8) /* interrupt transfers are limited to 8 bytes */
00205         len = 8;
00206     i = USBPID_DATA1;
00207     if(usbTxPacketCnt1 & 1)
00208         i = USBPID_DATA0;
00209     if(usbTxLen1 < 0){      /* packet buffer was empty */
00210         usbTxPacketCnt1++;
00211     }else{
00212         usbTxLen1 = -1;     /* avoid sending incomplete interrupt data */
00213     }
00214     p = usbTxBuf1;
00215     *p++ = i;
00216     for(i=len;i--;)
00217         *p++ = *data++;
00218     usbCrc16Append(&usbTxBuf1[1], len);
00219     usbTxLen1 = len + 4;    /* len must be given including sync byte */
00220 #if DEBUG_LEVEL > 1
00221     DBG2(0x21, usbTxBuf1, usbTxLen1-1);
00222 #else
00223     DBG1(0x21, usbTxBuf1 + 1, 2);
00224 #endif
00225 }


Variable Documentation

Definition at line 32 of file usbdrv.c.

uchar* usbMsgPtr

Definition at line 58 of file usbdrv.c.

volatile schar usbTxLen1

Definition at line 43 of file usbdrv.c.

Referenced by usbSetInterrupt().


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