core/usb/lpcusb/target/usbapi.h File Reference

#include "type.h"
#include "usbstruct.h"

Go to the source code of this file.

Defines

#define MAX_PACKET_SIZE0   64
#define EP_STATUS_DATA   (1<<0)
#define EP_STATUS_STALLED   (1<<1)
#define EP_STATUS_SETUP   (1<<2)
#define EP_STATUS_ERROR   (1<<3)
#define EP_STATUS_NACKED   (1<<4)
#define DEV_STATUS_CONNECT   (1<<0)
#define DEV_STATUS_SUSPEND   (1<<2)
#define DEV_STATUS_RESET   (1<<4)
#define INACK_CI   (1<<1)
#define INACK_CO   (1<<2)
#define INACK_II   (1<<3)
#define INACK_IO   (1<<4)
#define INACK_BI   (1<<5)
#define INACK_BO   (1<<6)

Typedefs

typedef void( TFnEPIntHandler )(U8 bEP, U8 bEPStatus)
typedef void( TFnDevIntHandler )(U8 bDevStatus)
typedef void( TFnFrameHandler )(U16 wFrame)
typedef BOOLTFnHandleRequest )(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
typedef BOOLTFnGetDescriptor )(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData)

Functions

void USBHwISR (void)
void USBHwNakIntEnable (U8 bIntBits)
void USBHwConnect (BOOL fConnect)
int USBHwEPRead (U8 bEP, U8 *pbBuf, int iMaxLen)
int USBHwEPWrite (U8 bEP, U8 *pbBuf, int iLen)
void USBHwEPStall (U8 bEP, BOOL fStall)
int USBHwISOCEPRead (const U8 bEP, U8 *pbBuf, const int iMaxLen)
void USBHwRegisterEPIntHandler (U8 bEP, TFnEPIntHandler *pfnHandler)
void USBHwRegisterDevIntHandler (TFnDevIntHandler *pfnHandler)
void USBHwRegisterFrameHandler (TFnFrameHandler *pfnHandler)
BOOL USBInit (void)
void USBRegisterRequestHandler (int iType, TFnHandleRequest *pfnHandler, U8 *pbDataStore)
void USBRegisterCustomReqHandler (TFnHandleRequest *pfnHandler)
BOOL USBHandleStandardRequest (TSetupPacket *pSetup, int *piLen, U8 **ppbData)
void USBHandleControlTransfer (U8 bEP, U8 bEPStat)
void USBRegisterDescriptors (const U8 *pabDescriptors)
BOOL USBGetDescriptor (U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData)
void USBSetupDMADescriptor (volatile U32 dmaDescriptor[], volatile U32 nextDdPtr[], const U8 isIsocFlag, const U16 maxPacketSize, const U16 dmaLengthIsocNumFrames, void *dmaBufferStartAddress, U32 *isocPacketSizeMemoryAddress)
void USBInitializeISOCFrameArray (U32 isocFrameArr[], const U32 numElements, const U16 startFrameNumber, const U16 defaultFrameLength)
void USBInitializeUSBDMA (volatile U32 *udcaHeadArray[32])
void USBSetHeadDDForDMA (const U8 bEp, volatile U32 *udcaHeadArray[32], volatile const U32 *dmaDescriptorPtr)
void USBEnableDMAForEndpoint (const U8 bEndpointNumber)
void USBDisableDMAForEndpoint (const U8 bEndpointNumber)

Detailed Description

Definition in file usbapi.h.


Define Documentation

#define DEV_STATUS_CONNECT   (1<<0)

device just got connected

Definition at line 54 of file usbapi.h.

#define DEV_STATUS_RESET   (1<<4)

device just got reset

Definition at line 56 of file usbapi.h.

#define DEV_STATUS_SUSPEND   (1<<2)

device entered suspend state

Definition at line 55 of file usbapi.h.

#define EP_STATUS_DATA   (1<<0)

EP has data

Definition at line 47 of file usbapi.h.

#define EP_STATUS_ERROR   (1<<3)

EP data was overwritten by setup packet

Definition at line 50 of file usbapi.h.

#define EP_STATUS_NACKED   (1<<4)

EP sent NAK

Definition at line 51 of file usbapi.h.

#define EP_STATUS_SETUP   (1<<2)

EP received setup packet

Definition at line 49 of file usbapi.h.

#define EP_STATUS_STALLED   (1<<1)

EP is stalled

Definition at line 48 of file usbapi.h.

#define INACK_BI   (1<<5)

interrupt on NACK for bulk in

Definition at line 64 of file usbapi.h.

#define INACK_BO   (1<<6)

interrupt on NACK for bulk out

Definition at line 65 of file usbapi.h.

#define INACK_CI   (1<<1)

interrupt on NACK for control in

Definition at line 60 of file usbapi.h.

#define INACK_CO   (1<<2)

interrupt on NACK for control out

Definition at line 61 of file usbapi.h.

#define INACK_II   (1<<3)

interrupt on NACK for interrupt in

Definition at line 62 of file usbapi.h.

#define INACK_IO   (1<<4)

interrupt on NACK for interrupt out

Definition at line 63 of file usbapi.h.

#define MAX_PACKET_SIZE0   64

maximum packet size for EP 0

Definition at line 40 of file usbapi.h.


Typedef Documentation

typedef void( TFnDevIntHandler)(U8 bDevStatus)

Device status handler callback

Definition at line 82 of file usbapi.h.

typedef void( TFnEPIntHandler)(U8 bEP, U8 bEPStatus)

Endpoint interrupt handler callback

Definition at line 78 of file usbapi.h.

typedef void( TFnFrameHandler)(U16 wFrame)

Frame event handler callback

Definition at line 86 of file usbapi.h.

typedef BOOL( TFnGetDescriptor)(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData)

Descriptor handler callback

Definition at line 103 of file usbapi.h.

typedef BOOL( TFnHandleRequest)(TSetupPacket *pSetup, int *piLen, U8 **ppbData)

Request handler callback (standard, vendor, class)

Definition at line 98 of file usbapi.h.


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.

BOOL USBGetDescriptor ( U16  wTypeIndex,
U16  wLangID,
int *  piLen,
U8 **  ppbData 
)

Parses the list of installed USB descriptors and attempts to find the specified USB descriptor.

Parameters:
[in] wTypeIndex Type and index of the descriptor
[in] wLangID Language ID of the descriptor (currently unused)
[out] *piLen Descriptor length
[out] *ppbData Descriptor data
Returns:
TRUE if the descriptor was found, FALSE otherwise

Definition at line 104 of file usbstdreq.c.

void USBHandleControlTransfer ( U8  bEP,
U8  bEPStat 
)

Default EP0 handler

Handles IN/OUT transfers on EP0

Parameters:
[in] bEP Endpoint address
[in] bEPStat Endpoint status

Definition at line 145 of file usbcontrol.c.

BOOL USBHandleStandardRequest ( TSetupPacket pSetup,
int *  piLen,
U8 **  ppbData 
)

Default standard request handler

Default handler for standard ('chapter 9') requests

If a custom request handler was installed, this handler is called first.

Parameters:
[in] pSetup The setup packet
[in,out] *piLen Pointer to data length
[in] ppbData Data buffer.
Returns:
TRUE if the request was handled successfully

Definition at line 400 of file usbstdreq.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.

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.

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.

BOOL USBInit ( void   ) 

Initialises the USB hardware and sets up the USB stack by installing default callbacks.

Returns:
TRUE if initialisation was successful

Definition at line 63 of file usbinit.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 USBRegisterCustomReqHandler ( TFnHandleRequest pfnHandler  ) 

Registers a callback for custom device requests

In USBHandleStandardRequest, the custom request handler gets a first chance at handling the request before it is handed over to the 'chapter 9' request handler.

This can be used for example in HID devices, where a REQ_GET_DESCRIPTOR request is sent to an interface, which is not covered by the 'chapter 9' specification.

Parameters:
[in] pfnHandler Callback function pointer

Definition at line 429 of file usbstdreq.c.

void USBRegisterDescriptors ( const U8 pabDescriptors  ) 

Descriptor handling

Registers a pointer to a descriptor block containing all descriptors for the device.

Parameters:
[in] pabDescriptors The descriptor byte array

Definition at line 87 of file usbstdreq.c.

void USBRegisterRequestHandler ( int  iType,
TFnHandleRequest pfnHandler,
U8 pbDataStore 
)

Registers a callback for handling requests

Parameters:
[in] iType Type of request, e.g. REQTYPE_TYPE_STANDARD
[in] *pfnHandler Callback function pointer
[in] *pbDataStore Data storage area for this type of request

Definition at line 224 of file usbcontrol.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 
)

DMA descriptor setup

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