Texas Instruments TMS320DM357 User Manual

Page 17

Advertising
background image

www.ti.com

Introduction

User Case 2: An example of how to program the USB Endpoints in peripheral mode

Example 2. Programming the USB Endpoints in Peripheral Mode

// DMA channel number.

Valid values are 0, 1, 2, or 3.

int CHAN_NUM = 0;

// Fifo sizes: uncomment the desired size.
// This example uses 64-byte fifo.
// int fifosize = 0;

// 8 bytes

// int fifosize = 1;

// 16 bytes

// int fifosize = 2;

// 32 bytes

int fifosize = 3;

// 64 bytes

// int fifosize = 4;

// 128 bytes

// int fifosize = 5;

// 256 bytes

// int fifosize = 6;

// 512 bytes

// int fifosize = 7;

// 1024 bytes

// int fifosize = 8;

// 2048 bytes

// int fifosize = 9;

// 4096 bytes

// FIFO address.

Leave 64-bytes for endpoint 0.

int fifo_start_address = 8;

// Uncomment the desired buffering.

If double-buffer is selected, actual

// FIFO space will be twice the value listed above for fifosize.
// This example uses single buffer.

int double_buffer = 0;

// Single-buffer

// int double_buffer = 1;

// Double-buffer

// For maximum packet size this formula will usually work, but it can also be
// set to another value if needed.

If non power of 2 value is needed (such as

// 1023) set it explicitly.
#define FIFO_MAXP 8*(1<<fifosize);

// Set the following variable to the device address.
int device_address = 0;

// The following code should be run after receiving a USB reset from the host.

// Initialize the endpoint FIFO.

RX and TX will be allocated the same sizes.

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;

// Force Data Toggle is optional for interrupt traffic.

Uncomment if needed.

// CSL_FINS(usbRegs->PERI_TXCSR,USB_PERI_TXCSR_FRCDATATOG,1);

// Uncomment below to configure the endpoint for ISO and not respond with a
// handshake packet.
// CSL_FINS(usbRegs->PERI_RXCSR,USB_PERI_RXCSR_ISO,1);
// CSL_FINS(usbRegs->PERI_TXCSR,USB_PERI_TXCSR_ISO,1);

// After receiving a successful set-address command, set the following register
// to the specified address immediately following the status stage.
usbRegs->FADDR = device_address;

SPRUGH3 – November 2008

Universal Serial Bus (USB) Controller

17

Submit Documentation Feedback

Advertising