www.ti.com
Introduction
UserCase2:AnexampleofhowtoprogramtheUSBEndpointsinperipheralmode
Example2.ProgrammingtheUSBEndpointsinPeripheralMode
//DMAchannelnumber.Validvaluesare0,1,2,or3.
intCHAN_NUM=0;
//Fifosizes:uncommentthedesiredsize.
//Thisexampleuses64-bytefifo.
//intfifosize=0;//8bytes
//intfifosize=1;//16bytes
//intfifosize=2;//32bytes
intfifosize=3;//64bytes
//intfifosize=4;//128bytes
//intfifosize=5;//256bytes
//intfifosize=6;//512bytes
//intfifosize=7;//1024bytes
//intfifosize=8;//2048bytes
//intfifosize=9;//4096bytes
//FIFOaddress.Leave64-bytesforendpoint0.
intfifo_start_address=8;
//Uncommentthedesiredbuffering.Ifdouble-bufferisselected,actual
//FIFOspacewillbetwicethevaluelistedaboveforfifosize.
//Thisexampleusessinglebuffer.
intdouble_buffer=0;//Single-buffer
//intdouble_buffer=1;//Double-buffer
//Formaximumpacketsizethisformulawillusuallywork,butitcanalsobe
//settoanothervalueifneeded.Ifnonpowerof2valueisneeded(suchas
//1023)setitexplicitly.
#defineFIFO_MAXP8*(1<<fifosize);
//Setthefollowingvariabletothedeviceaddress.
intdevice_address=0;
//ThefollowingcodeshouldberunafterreceivingaUSBresetfromthehost.
//InitializetheendpointFIFO.RXandTXwillbeallocatedthesamesizes.
usbRegs->INDEX=CHAN_NUM+1;
usbRegs->RXFIFOSZ=fifosize|((double_buffer&1)<<4);
usbRegs->RXFIFOADDR=fifo_start_address;
usbRegs->TXFIFOSZ=fifosize|((double_buffer&1)<<4);
usbRegs->TXFIFOADDR=fifo_start_address+(1<<(fifosize+double_buffer));
usbRegs->RXMAXP=FIFO_MAXP;
usbRegs->TXMAXP=FIFO_MAXP;
//ForceDataToggleisoptionalforinterrupttraffic.Uncommentifneeded.
//CSL_FINS(usbRegs->PERI_TXCSR,USB_PERI_TXCSR_FRCDATATOG,1);
//UncommentbelowtoconfiguretheendpointforISOandnotrespondwitha
//handshakepacket.
//CSL_FINS(usbRegs->PERI_RXCSR,USB_PERI_RXCSR_ISO,1);
//CSL_FINS(usbRegs->PERI_TXCSR,USB_PERI_TXCSR_ISO,1);
//Afterreceivingasuccessfulset-addresscommand,setthefollowingregister
//tothespecifiedaddressimmediatelyfollowingthestatusstage.
usbRegs->FADDR=device_address;
SPRUGH3–November2008UniversalSerialBus(USB)Controller17
SubmitDocumentationFeedback