Texas Instruments TMS320DM357 Switch User Manual


 
Introduction
www.ti.com
UserCase3:AnexampleofhowtoprogramtheUSBendpointsinhostmode
Example3.ProgrammingtheUSBEndpointsinHostMode
//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
//Setthefollowingvariabletothedeviceendpointtype:CONTROLISOBULKorIN
intdevice_protocol=BULK;
//intdevice_protocol=ISO;
//intdevice_protocol=INT;
//USBspeeds
#defineLOW_SPEED0
#defineFULL_SPEED1
#defineHIGH_SPEED2
//TXTYPEprotocol
#defineCONTROL0
#defineISO1
#defineBULK2
#defineINT3
//Formaximumpacketsizethisformulawillusuallywork,butitcanalsobe
//settoanothervalueifneeded.Ifnonpowerof2valueisneeded(suchas
//1023)setitexplicitly.
#defineFIFO_MAXP8*(1<<fifosize);
//Setthefollowingvariabletothedeviceaddress.
intdevice_address=1;
//Setthefollowingvariabletothedeviceendpointnumber.
intdevice_ep=1;
//Variableusedforendpointconfiguration
Uint8type=0;
//Variabletokeeptrackoferrors
interror=0;
//Thefollowingcodeshouldberunafterresettingtheattacheddevice
//InitializetheendpointFIFO.RXandTXwillbeallocatedthesamesizes.
usbRegs->INDEX=CHAN_NUM+1;
usbRegs->RXFIFOSZ=fifosize|((double_buffer&1)<<4);
usbRegs->RXFIFOADDR=fifo_start_address;
18UniversalSerialBus(USB)ControllerSPRUGH3November2008
SubmitDocumentationFeedback