core/usb/lpcusb/target/usbhw_lpc.c File Reference

#include "type.h"
#include "debug.h"
#include "usbhw_lpc.h"
#include "usbapi.h"

Go to the source code of this file.

Defines

#define DEBUG_LED_INIT(x)
#define DEBUG_LED_ON(x)
#define DEBUG_LED_OFF(x)
#define EP2IDX(bEP)   ((((bEP)&0xF)<<1)|(((bEP)&0x80)>>7))
#define IDX2EP(idx)   ((((idx)<<7)&0x80)|(((idx)>>1)&0xF))

Functions

void USBHwEPConfig (U8 bEP, U16 wMaxPacketSize)
void USBHwRegisterEPIntHandler (U8 bEP, TFnEPIntHandler *pfnHandler)
void USBHwRegisterDevIntHandler (TFnDevIntHandler *pfnHandler)
void USBHwRegisterFrameHandler (TFnFrameHandler *pfnHandler)
void USBHwSetAddress (U8 bAddr)
void USBHwConnect (BOOL fConnect)
void USBHwNakIntEnable (U8 bIntBits)
U8 USBHwEPGetStatus (U8 bEP)
void USBHwEPStall (U8 bEP, BOOL fStall)
int USBHwEPWrite (U8 bEP, U8 *pbBuf, int iLen)
int USBHwEPRead (U8 bEP, U8 *pbBuf, int iMaxLen)
int USBHwISOCEPRead (const U8 bEP, U8 *pbBuf, const int iMaxLen)
void USBHwConfigDevice (BOOL fConfigured)
void USBHwISR (void)
BOOL USBHwInit (void)
void USBSetupDMADescriptor (volatile U32 dmaDescriptor[], volatile U32 nextDdPtr[], const U8 isIsocFlag, const U16 maxPacketSize, const U16 dmaLengthIsocNumFrames, void *dmaBufferStartAddress, U32 *isocPacketSizeMemoryAddress)
void USBDisableDMAForEndpoint (const U8 bEndpointNumber)
void USBEnableDMAForEndpoint (const U8 bEndpointNumber)
void USBInitializeISOCFrameArray (U32 isocFrameArr[], const U32 numElements, const U16 startFrameNumber, const U16 defaultFrameLength)
void USBSetHeadDDForDMA (const U8 bEp, volatile U32 *udcaHeadArray[32], volatile const U32 *dmaDescriptorPtr)
void USBInitializeUSBDMA (volatile U32 *udcaHeadArray[32])

Detailed Description

USB hardware layer

Definition in file usbhw_lpc.c.


Define Documentation

#define DEBUG_LED_INIT (  ) 

LED initialisation macro

Definition at line 63 of file usbhw_lpc.c.

#define DEBUG_LED_OFF (  ) 

turn LED off

Definition at line 65 of file usbhw_lpc.c.

#define DEBUG_LED_ON (  ) 

turn LED on

Definition at line 64 of file usbhw_lpc.c.

#define EP2IDX ( bEP   )     ((((bEP)&0xF)<<1)|(((bEP)&0x80)>>7))

convert from endpoint address to endpoint index

Definition at line 76 of file usbhw_lpc.c.

#define IDX2EP ( idx   )     ((((idx)<<7)&0x80)|(((idx)>>1)&0xF))

convert from endpoint index to endpoint address

Definition at line 78 of file usbhw_lpc.c.


Function Documentation

void USBDisableDMAForEndpoint ( const U8  bEndpointNumber  ) 

This function disables DMA for the endpoint indicated by the paramater.

Parameters:
[in] bEndpointNumber the endpoint number to be disabled.
Returns:
void

Definition at line 746 of file usbhw_lpc.c.

void USBEnableDMAForEndpoint ( const U8  bEndpointNumber  ) 

Enables DMA for a particular endpoint.

Parameters:
[in] bEndpontNumber The endpoint to to enable DMA for.
Returns:

Definition at line 758 of file usbhw_lpc.c.

void USBHwConfigDevice ( BOOL  fConfigured  ) 

Sets the 'configured' state.

All registered endpoints are 'realised' and enabled, and the 'configured' bit is set in the device status register.

Parameters:
[in] fConfigured If TRUE, configure device, else unconfigure

Definition at line 496 of file usbhw_lpc.c.

void USBHwConnect ( BOOL  fConnect  ) 

Connects or disconnects from the USB bus

Parameters:
[in] fConnect If TRUE, connect, otherwise disconnect

Definition at line 272 of file usbhw_lpc.c.

void USBHwEPConfig ( U8  bEP,
U16  wMaxPacketSize 
)

Configures an endpoint and enables it

Parameters:
[in] bEP Endpoint number
[in] wMaxPacketSize Maximum packet size for this EP

Definition at line 185 of file usbhw_lpc.c.

U8 USBHwEPGetStatus ( U8  bEP  ) 

Gets the status from a specific endpoint.

Parameters:
[in] bEP Endpoint number
Returns:
Endpoint status byte (containing EP_STATUS_xxx bits)

Definition at line 316 of file usbhw_lpc.c.

int USBHwEPRead ( U8  bEP,
U8 pbBuf,
int  iMaxLen 
)

Reads data from an endpoint buffer

Parameters:
[in] bEP Endpoint number
[in] pbBuf Endpoint data
[in] iMaxLen Maximum number of bytes to read
Returns:
the number of bytes available in the EP (possibly more than iMaxLen), or <0 in case of error.

Definition at line 385 of file usbhw_lpc.c.

void USBHwEPStall ( U8  bEP,
BOOL  fStall 
)

Sets the stalled property of an endpoint

Parameters:
[in] bEP Endpoint number
[in] fStall TRUE to stall, FALSE to unstall

Definition at line 330 of file usbhw_lpc.c.

int USBHwEPWrite ( U8  bEP,
U8 pbBuf,
int  iLen 
)

Writes data to an endpoint buffer

Parameters:
[in] bEP Endpoint number
[in] pbBuf Endpoint data
[in] iLen Number of bytes to write
Returns:
number of bytes written into the endpoint buffer

Definition at line 347 of file usbhw_lpc.c.

BOOL USBHwInit ( void   ) 

Initialises the USB hardware

This function assumes that the hardware is connected as shown in section 10.1 of the LPC2148 data sheet: P0.31 controls a switch to connect a 1.5k pull-up to D+ if low. P0.23 is connected to USB VCC.

Embedded artists board: make sure to disconnect P0.23 LED as it acts as a pull-up and so prevents detection of USB disconnect.

Returns:
TRUE if the hardware was successfully initialised

Definition at line 603 of file usbhw_lpc.c.

void USBHwISR ( void   ) 

USB interrupt handler

Todo:
Get all 11 bits of frame number instead of just 8

Endpoint interrupts are mapped to the slow interrupt

Definition at line 510 of file usbhw_lpc.c.

void USBHwNakIntEnable ( U8  bIntBits  ) 

Enables interrupt on NAK condition

For IN endpoints a NAK is generated when the host wants to read data from the device, but none is available in the endpoint buffer. For OUT endpoints a NAK is generated when the host wants to write data to the device, but the endpoint buffer is still full.

The endpoint interrupt handlers can distinguish regular (ACK) interrupts from NAK interrupt by checking the bits in their bEPStatus argument.

Parameters:
[in] bIntBits Bitmap indicating which NAK interrupts to enable

Definition at line 304 of file usbhw_lpc.c.

void USBHwRegisterDevIntHandler ( TFnDevIntHandler pfnHandler  ) 

Registers an device status callback

Parameters:
[in] pfnHandler Callback function

Definition at line 229 of file usbhw_lpc.c.

void USBHwRegisterEPIntHandler ( U8  bEP,
TFnEPIntHandler pfnHandler 
)

Registers an endpoint event callback

Parameters:
[in] bEP Endpoint number
[in] pfnHandler Callback function

Definition at line 205 of file usbhw_lpc.c.

void USBHwRegisterFrameHandler ( TFnFrameHandler pfnHandler  ) 

Registers the frame callback

Parameters:
[in] pfnHandler Callback function

Definition at line 245 of file usbhw_lpc.c.

void USBHwSetAddress ( U8  bAddr  ) 

Sets the USB address.

Parameters:
[in] bAddr Device address to set

Definition at line 261 of file usbhw_lpc.c.

void USBInitializeISOCFrameArray ( U32  isocFrameArr[],
const U32  numElements,
const U16  startFrameNumber,
const U16  defaultFrameLength 
)

This function is used to initialized an ISOC frame array

Parameters:
[in|out] isocFrameArr The array of ISOC frame descriptors to be set, it should point to some place in DMA RAM.
[in] numElements The number of elements in the isocFrameArr array.
[in] startFrameNumber Number to start at for numbering each frame.
[in] defaultFrameLength The frame length to set all the frame descriptors to.
Returns:
void

Definition at line 773 of file usbhw_lpc.c.

void USBInitializeUSBDMA ( volatile U32 udcaHeadArray[32]  ) 

This function is used to initialize the USB DMA controller

Parameters:
[in|out] udcaHeadArray This is a pointer to the array of DMA descriptor linked-list head pointers, it should point to some place in DMA RAM.
Returns:

Definition at line 803 of file usbhw_lpc.c.

void USBSetHeadDDForDMA ( const U8  bEp,
volatile U32 udcaHeadArray[32],
volatile const U32 dmaDescriptorPtr 
)

This function is used to set the DMA descriptor head for the linked list of a particular endpoint.

Parameters:
[in] bEp The endpoint number to set the DMA linked list head for.
[in|out] udcaHeadArray The array of pointers that point to the head DD elements for each endpoint, it should point to some place in DMA RAM.
[in|out] dmaDescriptorPtr The address of the DMA descriptor that is to be the new head, it should point to some place in DMA RAM.
Returns:

Definition at line 792 of file usbhw_lpc.c.

void USBSetupDMADescriptor ( volatile U32  dmaDescriptor[],
volatile U32  nextDdPtr[],
const U8  isIsocFlag,
const U16  maxPacketSize,
const U16  dmaLengthIsocNumFrames,
void *  dmaBufferStartAddress,
U32 isocPacketSizeMemoryAddress 
)

This function is used to setup and populated the various elements of a LPC2148 DMA desccriptor such that after calling this function, the DMA descriptor could be used as part of a DMA tranfer.

Parameters:
[in] dmaDescriptor A pointer to a 4 or 5 element long array of U32's that the DMA descriptor data is to be stored into, it should point to some place in DMA RAM.
[in] nextDdPtr The value to be placed in the "Next_DD_Pointer" value of the DMA desriptor, set to NULL if there is no next-pointer.
[in] isIsocFlag Flag to indicate if this DMA descriptor is for an ISOC endpoint (with a 5 element dmaDescriptor array pointer), 1 indicates ISOC, 0 indicates non-ISOC.
[in] maxPacketSize The maximum packet size that can be sent/received for the endpoint in question.
[in] dmaLengthIsocNumFrames For non-ISOC endpoints, the number of bytes in the buffer to be transfered, for ISOC endpoints, the number of frames to be transfered.
[in] dmaBufferStartAddress Start address for the dma transfer (location to store data for an OUT endpoint, location to pull data from for an IN endpoint), it should point to some place in DMA RAM.
[in] isocPacketSizeMemoryAddress If a non-ISOC endpoint, set this to NULL, if an ISOC endpoint, then set this to a pointer to an array of U32's that represent how
Returns:
void

Definition at line 712 of file usbhw_lpc.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Defines

Generated by  doxygen 1.6.2