VLSI Solution Oy / MegaLib Documentation

usblowlib.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  usbpkt
struct  USBVARS

Defines

#define AUDIO_ISOC_OUT_EP   0x01
#define MSC_BULK_OUT_ENDPOINT   0x03
#define MSC_BULK_IN_ENDPOINT   0x02
#define ENDPOINT_SIZE_0   64
#define ENDPOINT_SIZE_1   512
#define BRESET_INT   0x8000
#define SOF_INT   0x4000
#define RX_INT   0x2000
#define TX_HOLD_INT   0x1000
#define TX_INT   0x0800
#define NAK_SENT_INT   0x0400
#define SETUP_INFO   0x0080
#define P_SETUP   0x10
#define P_DATA   0x20
#define PID_SOF   0x05
#define PID_SETUP   0x0D
#define PID_IN   0x09
#define PID_OUT   0x01
#define PID_DATA0   0x03
#define PID_DATA1   0x0B
#define PID_ACK   0x02
#define PID_NACK   0x0A
#define PID_STALL   0x0E
#define USB_CONFIG   (USB_BASE)
#define USB_CONTROL   (USB_BASE+1)
#define USB_STATUS   (USB_BASE+2)
#define USB_STF_BUS_RESET   (1<<15)
#define USB_STF_SOF   (1<<14)
#define USB_STF_RX   (1<<13)
#define USB_STF_TX_READY   (1<<12)
#define USB_STF_TX_EMPTY   (1<<11)
#define USB_STF_NAK   (1<<10)
#define USB_STF_SETUP   (1<<7)
#define USB_STM_LAST_EP   (15<<0)
#define USB_RDPTR   (USB_BASE+3)
#define USB_WRPTR   (USB_BASE+4)
#define USB_EP_SEND0   (USB_BASE+8)
#define USB_EP_SEND1   (USB_BASE+9)
#define USB_EP_SEND2   (USB_BASE+10)
#define USB_EP_SEND3   (USB_BASE+11)
#define USB_EP_ST0   (USB_BASE+16)
#define USB_EP_ST1   (USB_BASE+17)
#define USB_EP_ST2   (USB_BASE+18)
#define USB_EP_ST3   (USB_BASE+19)
#define USB_STF_OUT_BULK   (0<<14)
#define USB_STF_OUT_INT   (1<<14)
#define USB_STF_OUT_ISO   (3<<14)
#define USB_STF_OUT_ENABLE   (1<<13)
#define USB_STF_OUT_STALL   (1<<12)
#define USB_STF_OUT_STALL_SENT   (1<<11)
#define USB_STF_OUT_EP_SIZE   (1<<8)
#define USB_STF_IN_BULK   (0<<6)
#define USB_STF_IN_INT   (1<<6)
#define USB_STF_IN_ISO   (3<<6)
#define USB_STF_IN_ENABLE   (1<<5)
#define USB_STF_IN_STALL   (1<<4)
#define USB_STF_IN_STALL_SENT   (1<<3)
#define USB_STF_IN_NACK_SENT   (1<<2)
#define USB_STF_IN_EMPTY   (1<<1)
#define USB_STF_IN_FORCE_NACK   (1<<0)
#define RING_BUF_SIZE   1024
#define DT_LANGUAGES   0
#define DT_VENDOR   1
#define DT_MODEL   2
#define DT_SERIAL   3
#define DT_DEVICE   4
#define DT_CONFIGURATION   5
#define USB_MASS_STORAGE   1
#define USB_AUDIO   2
#define AUDIO_DELAY_FRAMES   12
#define AUDIO_DELAY_FRAMES_STR   "\x0c"

Typedefs

typedef usbpkt USBPacket

Functions

auto void RingBufCopyX (register __i2 u_int16 *d, register __i0 const u_int16 *s, register __a0 u_int16 n)
int USBStartTransmission (u_int16 ep, const void *buf, u_int16 length, u_int16 requestedLength)
void USBContinueTransmission (u_int16 ep)
void InitUSBDescriptors (u_int16 initDescriptors)
void RealInitUSBDescriptors (u_int16 initDescriptors)
void InitUSB (u_int16 initDescriptors)
void USBResetEndpoint (register __c0 int ep)
u_int16 USBReceivePacket (USBPacket *packet)
void USBSendZeroLengthPacketToEndpoint0 (void)
void USBHandler (void)
void RealUSBHandler ()
void DecodeSetupPacket (void)
void RealDecodeSetupPacket (void)
void USBCheckForSetupPacket (void)
u_int16 USBXmitLeft (u_int16 endpoint)
void USBSingleStallEndpoint (register __c0 u_int16 ep)
void USBStallEndpoint (register __c0 int ep)
void USBResetStall (register __c0 int ep)
u_int16 USBIsEndpointStalled (register int ep)
u_int16 SwapWord (register __a1 u_int16 d)
auto u_int16 USBIsAttached (void)
auto u_int16 USBIsDetached (void)
auto u_int16 USBWantsSuspend (void)
void MSCPacketFromPC (USBPacket *setupPacket)
void RealMSCPacketFromPC (USBPacket *setupPacket)
u_int16 MscSendCsw (u_int16 status)
void DiskProtocolError (char errorcode)
void AudioPacketFromUSB (u_int16 *data, s_int16 words)

Variables

USBVARS USB


Detailed Description

VS1000 low-level USB definitions.

Definition in file usblowlib.h.


Define Documentation

#define AUDIO_DELAY_FRAMES   12
 

Definition at line 311 of file usblowlib.h.

#define AUDIO_DELAY_FRAMES_STR   "\x0c"
 

Definition at line 312 of file usblowlib.h.

#define AUDIO_ISOC_OUT_EP   0x01
 

OUT endpoint used for audio.

Definition at line 8 of file usblowlib.h.

#define BRESET_INT   0x8000
 

Bus reset interrupt

Definition at line 18 of file usblowlib.h.

#define DT_CONFIGURATION   5
 

Definition at line 147 of file usblowlib.h.

#define DT_DEVICE   4
 

Definition at line 146 of file usblowlib.h.

#define DT_LANGUAGES   0
 

Definition at line 142 of file usblowlib.h.

#define DT_MODEL   2
 

Definition at line 144 of file usblowlib.h.

#define DT_SERIAL   3
 

Definition at line 145 of file usblowlib.h.

#define DT_VENDOR   1
 

Definition at line 143 of file usblowlib.h.

#define ENDPOINT_SIZE_0   64
 

The endpoint size supported for IN.

Definition at line 12 of file usblowlib.h.

#define ENDPOINT_SIZE_1   512
 

The max OUT packet size, mainly for audio.

Definition at line 13 of file usblowlib.h.

#define MSC_BULK_IN_ENDPOINT   0x02
 

IN endpoint used for SCSI.

Definition at line 10 of file usblowlib.h.

#define MSC_BULK_OUT_ENDPOINT   0x03
 

OUT endpoint used for SCSI.

Definition at line 9 of file usblowlib.h.

#define NAK_SENT_INT   0x0400
 

Packet NAKed

Definition at line 23 of file usblowlib.h.

#define P_DATA   0x20
 

Definition at line 30 of file usblowlib.h.

#define P_SETUP   0x10
 

Definition at line 29 of file usblowlib.h.

#define PID_ACK   0x02
 

Definition at line 37 of file usblowlib.h.

#define PID_DATA0   0x03
 

Definition at line 35 of file usblowlib.h.

#define PID_DATA1   0x0B
 

Definition at line 36 of file usblowlib.h.

#define PID_IN   0x09
 

Definition at line 33 of file usblowlib.h.

#define PID_NACK   0x0A
 

Definition at line 38 of file usblowlib.h.

#define PID_OUT   0x01
 

Definition at line 34 of file usblowlib.h.

#define PID_SETUP   0x0D
 

Definition at line 32 of file usblowlib.h.

#define PID_SOF   0x05
 

Definition at line 31 of file usblowlib.h.

#define PID_STALL   0x0E
 

Definition at line 39 of file usblowlib.h.

#define RING_BUF_SIZE   1024
 

Definition at line 97 of file usblowlib.h.

#define RX_INT   0x2000
 

OUT packet received

Definition at line 20 of file usblowlib.h.

#define SETUP_INFO   0x0080
 

Setup packet

Definition at line 24 of file usblowlib.h.

#define SOF_INT   0x4000
 

Start of Frame interrupt

Definition at line 19 of file usblowlib.h.

#define TX_HOLD_INT   0x1000
 

Copied packet to IN registers

Definition at line 21 of file usblowlib.h.

#define TX_INT   0x0800
 

Successfully transmitted packet

Definition at line 22 of file usblowlib.h.

#define USB_AUDIO   2
 

Definition at line 298 of file usblowlib.h.

#define USB_CONFIG   (USB_BASE)
 

Definition at line 45 of file usblowlib.h.

#define USB_CONTROL   (USB_BASE+1)
 

Definition at line 46 of file usblowlib.h.

#define USB_EP_SEND0   (USB_BASE+8)
 

Definition at line 61 of file usblowlib.h.

#define USB_EP_SEND1   (USB_BASE+9)
 

Definition at line 62 of file usblowlib.h.

#define USB_EP_SEND2   (USB_BASE+10)
 

Definition at line 63 of file usblowlib.h.

#define USB_EP_SEND3   (USB_BASE+11)
 

Definition at line 64 of file usblowlib.h.

#define USB_EP_ST0   (USB_BASE+16)
 

Definition at line 70 of file usblowlib.h.

#define USB_EP_ST1   (USB_BASE+17)
 

Definition at line 71 of file usblowlib.h.

#define USB_EP_ST2   (USB_BASE+18)
 

Definition at line 72 of file usblowlib.h.

#define USB_EP_ST3   (USB_BASE+19)
 

Definition at line 73 of file usblowlib.h.

#define USB_MASS_STORAGE   1
 

Definition at line 297 of file usblowlib.h.

#define USB_RDPTR   (USB_BASE+3)
 

USB receive buffer read pointer.

Definition at line 58 of file usblowlib.h.

#define USB_STATUS   (USB_BASE+2)
 

Definition at line 47 of file usblowlib.h.

#define USB_STF_BUS_RESET   (1<<15)
 

Definition at line 49 of file usblowlib.h.

#define USB_STF_IN_BULK   (0<<6)
 

Definition at line 86 of file usblowlib.h.

#define USB_STF_IN_EMPTY   (1<<1)
 

Definition at line 93 of file usblowlib.h.

#define USB_STF_IN_ENABLE   (1<<5)
 

Definition at line 89 of file usblowlib.h.

#define USB_STF_IN_FORCE_NACK   (1<<0)
 

Definition at line 94 of file usblowlib.h.

#define USB_STF_IN_INT   (1<<6)
 

Definition at line 87 of file usblowlib.h.

#define USB_STF_IN_ISO   (3<<6)
 

Definition at line 88 of file usblowlib.h.

#define USB_STF_IN_NACK_SENT   (1<<2)
 

Definition at line 92 of file usblowlib.h.

#define USB_STF_IN_STALL   (1<<4)
 

Definition at line 90 of file usblowlib.h.

#define USB_STF_IN_STALL_SENT   (1<<3)
 

Definition at line 91 of file usblowlib.h.

#define USB_STF_NAK   (1<<10)
 

Definition at line 54 of file usblowlib.h.

#define USB_STF_OUT_BULK   (0<<14)
 

Definition at line 79 of file usblowlib.h.

#define USB_STF_OUT_ENABLE   (1<<13)
 

Definition at line 82 of file usblowlib.h.

#define USB_STF_OUT_EP_SIZE   (1<<8)
 

Definition at line 85 of file usblowlib.h.

#define USB_STF_OUT_INT   (1<<14)
 

Definition at line 80 of file usblowlib.h.

#define USB_STF_OUT_ISO   (3<<14)
 

Definition at line 81 of file usblowlib.h.

#define USB_STF_OUT_STALL   (1<<12)
 

Definition at line 83 of file usblowlib.h.

#define USB_STF_OUT_STALL_SENT   (1<<11)
 

Definition at line 84 of file usblowlib.h.

#define USB_STF_RX   (1<<13)
 

Definition at line 51 of file usblowlib.h.

#define USB_STF_SETUP   (1<<7)
 

Definition at line 55 of file usblowlib.h.

#define USB_STF_SOF   (1<<14)
 

Definition at line 50 of file usblowlib.h.

#define USB_STF_TX_EMPTY   (1<<11)
 

Definition at line 53 of file usblowlib.h.

#define USB_STF_TX_READY   (1<<12)
 

Definition at line 52 of file usblowlib.h.

#define USB_STM_LAST_EP   (15<<0)
 

Definition at line 56 of file usblowlib.h.

#define USB_WRPTR   (USB_BASE+4)
 

USB receive buffer write pointer.

Definition at line 59 of file usblowlib.h.


Typedef Documentation

typedef struct usbpkt USBPacket
 

Holding space for one received USB packet.


Function Documentation

void AudioPacketFromUSB u_int16 data,
s_int16  words
 

Called each time a packet is received to the audio endpoint. The function must be provided.

void DecodeSetupPacket void   ) 
 

Hook: handles setup packets. Default: DecodeSetupPacket.

void DiskProtocolError char  errorcode  ) 
 

void InitUSB u_int16  initDescriptors  ) 
 

Initializes USB subsystem.

Parameters:
initDescriptors 0=no init, 1=Mass Storage, 2=Audio

void InitUSBDescriptors u_int16  initDescriptors  ) 
 

Hook: Initializes USB descriptor table. Default: RealInitUSBDescriptors.

Parameters:
initDescriptors 0=no init, 1=Mass Storage, 2=Audio

void MSCPacketFromPC USBPacket setupPacket  ) 
 

Hook: handle a mass storage packet. Default: RealMSCPacketFromPC.

u_int16 MscSendCsw u_int16  status  ) 
 

void RealDecodeSetupPacket void   ) 
 

Processes setup packets.

void RealInitUSBDescriptors u_int16  initDescriptors  ) 
 

Initializes USB descriptor table.

Parameters:
initDescriptors 0=no init, 1=Mass Storage, 2=Audio

void RealMSCPacketFromPC USBPacket setupPacket  ) 
 

Handles a mass storage packet.

void RealUSBHandler  ) 
 

Polled handling of USB packets. Both Mass Storage and Audio are processed, but the descriptor decides which one the host uses.

auto void RingBufCopyX register __i2 u_int16 d,
register __i0 const u_int16 s,
register __a0 u_int16  n
 

Copies packet from USB receive memory ring buffer to X memory buffer. The data is in big-endian format, i.e. the high 8 bits of a word are the first byte, the low 8 bits the second byte. Does not touch USB peripheral registers.

Parameters:
d Destination pointer.
s Source pointer, must point to the USB receive memory.
n The number of words to copy.

u_int16 SwapWord register __a1 u_int16  d  ) 
 

Swaps byte order

void USBCheckForSetupPacket void   ) 
 

Checks if any setup packets are waiting and discards any packets that appear before it in the input queue.

void USBContinueTransmission u_int16  ep  ) 
 

Continues sending a packet.

Parameters:
ep The endpoint.

void USBHandler void   ) 
 

Hook: polled handling of USB packets. Default: RealUSBHandler.

auto u_int16 USBIsAttached void   ) 
 

Uses USB pull-up enable and USB_DN to detect if USB is attached. USB is attached if the USB pull-up is enabled. USB is not attached if USB_DN is high for every sampling in 20000 clock cycles, and is attached if USB_DN is low for even one sampling.

Returns:
0 is USB is not attached, non-zero if USB is attached.

auto u_int16 USBIsDetached void   ) 
 

Checks USB_DP and USB_DN. If both are high, the unit is probably detached. You MUST also use the USBWantsSuspend() function to see that there has not been SOF's for a while. Otherwise you will get false detections.

Returns:
0 is USB is still attached, non-zero if it might be detached.

u_int16 USBIsEndpointStalled register int  ep  ) 
 

Returns the stall state of an endpoint.

Parameters:
ep 0x80|endpoint for IN endpoints.
Returns:
non-zero if endpoint is stalled.

u_int16 USBReceivePacket USBPacket packet  ) 
 

Fetches a packet from USB receive FIFO. Also clears RX_INT and SETUP_INFO.

Parameters:
packet pointer to the packet structure
Returns:
endpoint number

void USBResetEndpoint register __c0 int  ep  ) 
 

Resets an endpoint. Data toggles are also reset and possible IN packets waiting for transmit are discarded.

Parameters:
ep 0 for control endpoint, 0x80|endpoint for IN.

void USBResetStall register __c0 int  ep  ) 
 

Resets the stall state of an endpoint.

Parameters:
ep 0x80|endpoint for IN endpoints.

void USBSendZeroLengthPacketToEndpoint0 void   ) 
 

Sends an empty packet to the control endpoint. Returns when the packet has been sent or a bus reset is received.

Bug:
: currently is satisfied if any active IN is finished.

void USBSingleStallEndpoint register __c0 u_int16  ep  ) 
 

Sends (at least) one STALL to the specified endpoint.

Parameters:
ep 0x80|endpoint for IN endpoints.

void USBStallEndpoint register __c0 int  ep  ) 
 

Sets the endpoint to stall state.

Parameters:
ep Endpoint number for OUT endpoint, 0x80|endpoint for IN endpoints.

int USBStartTransmission u_int16  ep,
const void *  buf,
u_int16  length,
u_int16  requestedLength
 

Starts transmission of data in endpoint-size -sized parts. Internall calls USBContinueTransmission once to start the transfer.

Parameters:
ep The endpoint to use.
buf Data to send.
length Length of data to send in bytes.
requestedLength Data size that was requested in bytes.
Returns:
0 if successful, non-zero if endpoint was busy.

auto u_int16 USBWantsSuspend void   ) 
 

Checks if there has been no SOF for 10..20ms.

Bug:
USB suspend time is 3ms. Because of our software timer accurary we detect suspend when there has been no SOF for 10..20ms.

This routine requires that the unit is configured before returning non-zero.

Returns:
0 if the communication is proceeding normally, non-zero if suspend state is detected.

u_int16 USBXmitLeft u_int16  endpoint  ) 
 

Checks how many bytes of a packet are waiting to be sent.

Parameters:
endpoint the endpoint to check.
Returns:
the number of bytes left


Variable Documentation

struct USBVARS USB
 


All software copyright 2005-2006 VLSI Solution OY. Redistribution of this software is strictly forbidden.