Texas Instruments TMS320DM357 Switch User Manual


 
www.ti.com
Introduction
Example4.ProgrammingtheUSBDMAController(continued)
usbRegs->CHANNEL[i].RCPPIDMASTATEW6=0;
tx_desc[i]=0;
rx_desc[i]=0;
}
//RoutinetoflushTXfifo.
//Mustcallthisroutinetwicefordouble-bufferedFIFO
voidflush_tx_fifo(intep){
intindex_save;
intstatus;
index_save=usbRegs->INDEX;//Savetheindextorestorelater
usbRegs->INDEX=ep;//Settheindextothedesiredendpoint
status=usbRegs->PERI_TXCSR&3;//IsolatetheTxPktRdyandFIFONotEmptybits
if(!(status)){//NothingshowinginFIFO
usbRegs->PERI_TXCSR|=1;//SetTxPktRdyincasethereisapartial
packetalreadyinFIFO
}
usbRegs->PERI_TXCSR=((usbRegs->PERI_TXCSR&0xFFFC)|8);//WriteTXCSRwithflush
bitset,FIFONotEmpty=0,andTxPktRdy=0.
while(usbRegs->PERI_TXCSR&8);//Keeploopinguntiltheflushbitclears
usbRegs->INDEX=index_save;//Restoretheindextopreviousvalue
}
//RoutinetostarttheTXDMAforagivenchannel
voidstart_tx_dma(intch){
//MusthaveatleastonedescriptorbeforeturningonTXDMA
if(rx_desc[ch]<1){error++;}else{
//FlushFIFO(2timesincaseitisdouble-buffered)
flush_tx_fifo(ch+1);
flush_tx_fifo(ch+1);
//StarttheDMA
usbRegs->TCPPICR=1;//EnableTxCPPIDMA
usbRegs->CHANNEL[ch].TCPPIDMASTATEW0=(Uint32)(&tx_bufferDesc[ch][0]);
CSL_FINS(usbRegs->PERI_TXCSR,USB_PERI_TXCSR_DMAEN,1);//TXCSR,bitDMAReqEnab
}
}
//RoutinetoaddaTXdescriptor
voidadd_tx_descriptor(intch,unsignedchar*inBuf,intbytes){
if((bytes<0)||(bytes>65535)){bytes=64;error++;}
//Linkpreviousbuffertothisoneifthisisnotthefirstdescriptorofthechannel
if(tx_desc[ch]>0)tx_bufferDesc[ch][4*(tx_desc[ch]-1)]=
(Uint32)(&tx_bufferDesc[ch][4*tx_desc[ch]]);
//SetupDMAbufferdescriptors
tx_bufferDesc[ch][4*tx_desc[ch]+0]=(Uint32)(0x00000000);//NextDescriptorpointer
tx_bufferDesc[ch][4*tx_desc[ch]+1]=(Uint32)inBuf;//Bufferpointer
tx_bufferDesc[ch][4*tx_desc[ch]+2]=(0x0000<<16)|bytes;//[31:16]Bufferoffset
[15:0]Bufferlength
if(bytes==0)bytes=ZERO_BYTE|1;//SettheZERO_BYTEbitandsize1byte
tx_bufferDesc[ch][4*tx_desc[ch]+3]=SOP|EOP|OWNER|bytes;//[31]=SOP,[30]=EOP,
[29]=owner,[28]=EOQ,[23]=zero-byte,[19]=rxabort,[15:0]=packetlength
//IfDMAalreadyenabledandhasstopped,writethistotheTXQueueheadpointer
if((usbRegs->TCPPICR==1)&&(usbRegs->CHANNEL[ch].TCPPIDMASTATEW0==0))
usbRegs->CHANNEL[ch].TCPPIDMASTATEW0=(Uint32)(&tx_bufferDesc[ch][4*tx_desc[ch]+0]);
SPRUGH3November2008UniversalSerialBus(USB)Controller21
SubmitDocumentationFeedback