#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]) |
USB hardware layer
Definition in file usbhw_lpc.c.
#define DEBUG_LED_INIT | ( | x | ) |
LED initialisation macro
Definition at line 63 of file usbhw_lpc.c.
#define DEBUG_LED_OFF | ( | x | ) |
turn LED off
Definition at line 65 of file usbhw_lpc.c.
#define DEBUG_LED_ON | ( | x | ) |
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.
void USBDisableDMAForEndpoint | ( | const U8 | bEndpointNumber | ) |
This function disables DMA for the endpoint indicated by the paramater.
[in] | bEndpointNumber | the endpoint number to be disabled. |
Definition at line 746 of file usbhw_lpc.c.
void USBEnableDMAForEndpoint | ( | const U8 | bEndpointNumber | ) |
Enables DMA for a particular endpoint.
[in] | bEndpontNumber | The endpoint to to enable DMA for. |
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.
[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
[in] | fConnect | If TRUE, connect, otherwise disconnect |
Definition at line 272 of file usbhw_lpc.c.
Configures an endpoint and enables it
[in] | bEP | Endpoint number |
[in] | wMaxPacketSize | Maximum packet size for this EP |
Definition at line 185 of file usbhw_lpc.c.
Gets the status from a specific endpoint.
[in] | bEP | Endpoint number |
Definition at line 316 of file usbhw_lpc.c.
Reads data from an endpoint buffer
[in] | bEP | Endpoint number |
[in] | pbBuf | Endpoint data |
[in] | iMaxLen | Maximum number of bytes to read |
Definition at line 385 of file usbhw_lpc.c.
Sets the stalled property of an endpoint
[in] | bEP | Endpoint number |
[in] | fStall | TRUE to stall, FALSE to unstall |
Definition at line 330 of file usbhw_lpc.c.
Writes data to an endpoint buffer
[in] | bEP | Endpoint number |
[in] | pbBuf | Endpoint data |
[in] | iLen | Number of bytes to write |
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.
Definition at line 603 of file usbhw_lpc.c.
void USBHwISR | ( | void | ) |
USB interrupt handler
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.
[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
[in] | pfnHandler | Callback function |
Definition at line 229 of file usbhw_lpc.c.
void USBHwRegisterEPIntHandler | ( | U8 | bEP, | |
TFnEPIntHandler * | pfnHandler | |||
) |
Registers an endpoint event callback
[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
[in] | pfnHandler | Callback function |
Definition at line 245 of file usbhw_lpc.c.
void USBHwSetAddress | ( | U8 | bAddr | ) |
Sets the USB address.
[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
[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. |
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
[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. |
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.
[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. |
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.
[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 |
Definition at line 712 of file usbhw_lpc.c.