LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Pipe Management (LPC)

Pipe management definitions for the NXP LPC architecture. More...

Data Structures

struct  USB_Pipe_Data_t
 

Macros

#define PIPE_CONTROLPIPE_DEFAULT_SIZE   8
 
#define PIPE_TOTAL_PIPES   HCD_MAX_ENDPOINT
 
#define PIPE_MAX_SIZE   512
 

Functions

static uint8_t Pipe_GetCurrentPipe (const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Returns the pipe address of the currently selected pipe. This is typically used to save the currently selected pipe number so that it can be restored after another pipe has been manipulated.
 
static void Pipe_SelectPipe (const uint8_t corenum, const uint8_t PipeNumber) ATTR_ALWAYS_INLINE
 Selects the given pipe number. Any pipe operations which do not require the pipe number to be indicated will operate on the currently selected pipe.
 
static void Pipe_ResetPipe (const uint8_t corenum, const uint8_t PipeNumber) ATTR_ALWAYS_INLINE
 Resets the desired pipe, including the pipe banks and flags.
 
static void Pipe_EnablePipe (void) ATTR_ALWAYS_INLINE
 
static void Pipe_DisablePipe (void) ATTR_ALWAYS_INLINE
 
static bool Pipe_IsEnabled (void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Determines if the currently selected pipe is enabled, but not necessarily configured.
 
static uint8_t Pipe_GetPipeToken (const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Gets the current pipe token, indicating the pipe's data direction and type.
 
static void Pipe_SetPipeToken (const uint8_t Token) ATTR_DEPRECATED ATTR_ALWAYS_INLINE
 Sets the token for the currently selected pipe to one of the tokens specified by the PIPE_TOKEN_* masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices which have two endpoints of opposite direction sharing the same endpoint address within the device.
 
static void Pipe_SetInfiniteINRequests (void) ATTR_DEPRECATED ATTR_ALWAYS_INLINE
 
static void Pipe_SetFiniteINRequests (const uint8_t TotalINRequests) ATTR_DEPRECATED ATTR_ALWAYS_INLINE
 Configures the currently selected pipe to only allow the specified number of IN requests to be accepted by the pipe before it is automatically frozen.
 
static bool Pipe_IsConfigured (const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Determines if the currently selected pipe is configured.
 
static uint8_t Pipe_GetBoundEndpointAddress (const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Retrieves the endpoint address of the endpoint within the attached device that the currently selected pipe is bound to.
 
static void Pipe_SetInterruptPeriod (const uint8_t Milliseconds) ATTR_ALWAYS_INLINE
 Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.
 
static uint8_t Pipe_GetPipeInterrupts (void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should be serviced.
 
static bool Pipe_HasPipeInterrupted (const uint8_t PipeNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Determines if the specified pipe number has interrupted (valid only for INTERRUPT type pipes).
 
static void Pipe_Unfreeze (void) ATTR_ALWAYS_INLINE
 
static void Pipe_Freeze (void) ATTR_ALWAYS_INLINE
 
static bool Pipe_IsFrozen (void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Determines if the currently selected pipe is frozen, and not able to accept data.
 
static void Pipe_ClearError (void) ATTR_ALWAYS_INLINE
 
static bool Pipe_IsError (void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Determines if the master pipe error flag is set for the currently selected pipe, indicating that some sort of hardware error has occurred on the pipe.
 
static uint8_t Pipe_GetErrorFlags (void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
 Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This value can then be masked against the PIPE_ERRORFLAG_* masks to determine what error has occurred.
 
bool Pipe_ConfigurePipe (const uint8_t corenum, const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber, const uint16_t Size, const uint8_t Banks)
 Configures the specified pipe number with the given pipe type, token, target endpoint number in the attached device, bank size and banking mode.
 
void Pipe_ClosePipe (const uint8_t corenum, uint8_t pipenum)
 
bool Pipe_IsEndpointBound (const uint8_t EndpointAddress) ATTR_WARN_UNUSED_RESULT
 Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given endpoint is found, it is automatically selected.
 

Variables

uint8_t hostselected
 
HCD_USB_SPEED hostportspeed []
 
uint8_t pipeselected [MAX_USB_CORE]
 
USB_Pipe_Data_t PipeInfo [MAX_USB_CORE][PIPE_TOTAL_PIPES]
 

Pipe Error Flag Masks

#define PIPE_ERRORFLAG_OVERFLOW   (1 << 6)
 
#define PIPE_ERRORFLAG_UNDERFLOW   (1 << 5)
 
#define PIPE_ERRORFLAG_CRC16   (1 << 4)
 
#define PIPE_ERRORFLAG_TIMEOUT   (1 << 3)
 
#define PIPE_ERRORFLAG_PID   (1 << 2)
 
#define PIPE_ERRORFLAG_DATAPID   (1 << 1)
 
#define PIPE_ERRORFLAG_DATATGL   (1 << 0)
 

Pipe Token Masks

#define PIPE_TOKEN_SETUP   (0)
 
#define PIPE_TOKEN_IN   (1)
 
#define PIPE_TOKEN_OUT   (2)
 

Pipe Bank Mode Masks

#define PIPE_BANK_SINGLE   (0 << 1)
 
#define PIPE_BANK_DOUBLE   (1 << 1)
 

Detailed Description

Pipe management definitions for the NXP LPC architecture.

This module contains functions, macros and enums related to pipe management when in USB Host mode. This module contains the pipe management macros, as well as pipe interrupt and data send/receive functions for various data types.

Macro Definition Documentation

#define PIPE_BANK_DOUBLE   (1 << 1)

Mask for the bank mode selection for the Pipe_ConfigurePipe() macro. This indicates that the pipe should have two banks, which requires more USB FIFO memory but results in faster transfers as one USB device (the LPC or the attached device) can access one bank while the other accesses the second bank.

Definition at line 152 of file Pipe_LPC.h.

#define PIPE_BANK_SINGLE   (0 << 1)

Mask for the bank mode selection for the Pipe_ConfigurePipe() macro. This indicates that the pipe should have one single bank, which requires less USB FIFO memory but results in slower transfers as only one USB device (the LPC or the attached device) can access the pipe's bank at the one time.

Definition at line 145 of file Pipe_LPC.h.

#define PIPE_CONTROLPIPE_DEFAULT_SIZE   8

Default size of the default control pipe's bank, until altered by the Endpoint0Size value in the device descriptor of the attached device.

Definition at line 158 of file Pipe_LPC.h.

#define PIPE_ERRORFLAG_CRC16   (1 << 4)

Mask for Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data.

Definition at line 106 of file Pipe_LPC.h.

#define PIPE_ERRORFLAG_DATAPID   (1 << 1)

Mask for Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe.

Definition at line 115 of file Pipe_LPC.h.

#define PIPE_ERRORFLAG_DATATGL   (1 << 0)

Mask for Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe.

Definition at line 118 of file Pipe_LPC.h.

#define PIPE_ERRORFLAG_OVERFLOW   (1 << 6)

Mask for Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data.

Definition at line 100 of file Pipe_LPC.h.

#define PIPE_ERRORFLAG_PID   (1 << 2)

Mask for Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe.

Definition at line 112 of file Pipe_LPC.h.

#define PIPE_ERRORFLAG_TIMEOUT   (1 << 3)

Mask for Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe.

Definition at line 109 of file Pipe_LPC.h.

#define PIPE_ERRORFLAG_UNDERFLOW   (1 << 5)

Mask for Pipe_GetErrorFlags(), indicating that an underflow error occurred in the pipe on the received data.

Definition at line 103 of file Pipe_LPC.h.

#define PIPE_MAX_SIZE   512

Size in bytes of the largest pipe bank size possible in the device. Not all banks on each LPC model supports the largest bank size possible on the device; different pipe numbers support different maximum bank sizes. This value reflects the largest possible bank of any pipe on the currently selected USB LPC model.

Definition at line 171 of file Pipe_LPC.h.

#define PIPE_TOKEN_IN   (1)

Token mask for Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes), indicating that the pipe data will flow from device to host.

Definition at line 131 of file Pipe_LPC.h.

#define PIPE_TOKEN_OUT   (2)

Token mask for Pipe_ConfigurePipe(). This sets the pipe as a OUT token (for non-CONTROL type pipes), indicating that the pipe data will flow from host to device.

Definition at line 136 of file Pipe_LPC.h.

#define PIPE_TOKEN_SETUP   (0)

Token mask for Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes), which will trigger a control request on the attached device when data is written to the pipe.

Definition at line 126 of file Pipe_LPC.h.

#define PIPE_TOTAL_PIPES   HCD_MAX_ENDPOINT

Total number of pipes (including the default control pipe at address 0) which may be used in the device. Different USB LPC models support different amounts of pipes, this value reflects the maximum number of pipes for the currently selected LPC model.

Definition at line 164 of file Pipe_LPC.h.

Function Documentation

static void Pipe_ClearError ( void  )
inlinestatic

Clears the error flags for the currently selected pipe.

Definition at line 437 of file Pipe_LPC.h.

void Pipe_ClosePipe ( const uint8_t  corenum,
uint8_t  pipenum 
)

Definition at line 83 of file Pipe_LPC.c.

bool Pipe_ConfigurePipe ( const uint8_t  corenum,
const uint8_t  Number,
const uint8_t  Type,
const uint8_t  Token,
const uint8_t  EndpointNumber,
const uint16_t  Size,
const uint8_t  Banks 
)

Configures the specified pipe number with the given pipe type, token, target endpoint number in the attached device, bank size and banking mode.

Global indicating the maximum packet size of the default control pipe located at address 0 in the device. This value is set to the value indicated in the attached device's device descriptor once the USB interface is initialized into host mode and a device is attached to the USB bus.

Note
This variable should be treated as read-only in the user application, and never manually changed in value. A newly configured pipe is frozen by default, and must be unfrozen before use via the Pipe_Unfreeze() before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite numbers of IN requests without automatic freezing - this can be overridden by a call to Pipe_SetFiniteINRequests().
Parameters
corenum: USB port number
Number: Pipe number to configure. This must be more than 0 and less than PIPE_TOTAL_PIPES.
Type: Type of pipe to configure, an EP_TYPE_* mask. Not all pipe types are available on Low Speed USB devices - refer to the USB 2.0 specification.
Token: Pipe data token, either PIPE_TOKEN_SETUP, PIPE_TOKEN_OUT or PIPE_TOKEN_IN. All pipes (except Control type) are unidirectional - data may only be read from or written to the pipe bank based on its direction, not both.
EndpointNumber: Endpoint index within the attached device that the pipe should interface to.
Size: Size of the pipe's bank, where packets are stored before they are transmitted to the USB device, or after they have been received from the USB device (depending on the pipe's data direction). The bank size must indicate the maximum packet size that the pipe can handle.
Banks: Number of banks to use for the pipe being configured, a PIPE_BANK_* mask. More banks uses more USB DPRAM, but offers better performance. Isochronous type pipes must have at least two banks.
Note
When the ORDERED_EP_CONFIG compile time option is used, Pipes must be configured in ascending order, or bank corruption will occur.

Certain microcontroller model's pipes may have different maximum packet sizes based on the pipe's index - refer to the chosen microcontroller's datasheet to determine the maximum bank size for each pipe.

The default control pipe should not be manually configured by the user application, as it is automatically configured by the library internally.

This routine will automatically select the specified pipe upon success. Upon failure, the pipe which failed to reconfigure correctly will be selected.
Returns
Boolean true if the configuration succeeded, false otherwise.

Definition at line 45 of file Pipe_LPC.c.

static void Pipe_DisablePipe ( void  )
inlinestatic

Disables the currently selected pipe so that data cannot be sent and received through it to and from an attached device.

Definition at line 281 of file Pipe_LPC.h.

static void Pipe_EnablePipe ( void  )
inlinestatic

Enables the currently selected pipe so that data can be sent and received through it to and from an attached device.

Precondition
The currently selected pipe must first be configured properly via Pipe_ConfigurePipe().

Definition at line 271 of file Pipe_LPC.h.

static void Pipe_Freeze ( void  )
inlinestatic

Freezes the selected pipe, preventing it from communicating with an attached device.

Definition at line 418 of file Pipe_LPC.h.

static uint8_t Pipe_GetBoundEndpointAddress ( const uint8_t  corenum)
inlinestatic

Retrieves the endpoint address of the endpoint within the attached device that the currently selected pipe is bound to.

Parameters
corenum: USB port number
Returns
address the currently selected pipe is bound to.

Definition at line 364 of file Pipe_LPC.h.

static uint8_t Pipe_GetCurrentPipe ( const uint8_t  corenum)
inlinestatic

Returns the pipe address of the currently selected pipe. This is typically used to save the currently selected pipe number so that it can be restored after another pipe has been manipulated.

Parameters
corenum: USB port number
Returns
Index of the currently selected pipe

Definition at line 231 of file Pipe_LPC.h.

static uint8_t Pipe_GetErrorFlags ( void  )
inlinestatic

Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This value can then be masked against the PIPE_ERRORFLAG_* masks to determine what error has occurred.

Returns
Mask comprising of PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe.

Definition at line 465 of file Pipe_LPC.h.

static uint8_t Pipe_GetPipeInterrupts ( void  )
inlinestatic

Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should be serviced.

Returns
Mask whose bits indicate which pipes have interrupted.

Definition at line 388 of file Pipe_LPC.h.

static uint8_t Pipe_GetPipeToken ( const uint8_t  corenum)
inlinestatic

Gets the current pipe token, indicating the pipe's data direction and type.

Parameters
corenum: USB port number
Returns
The current pipe token, as a PIPE_TOKEN_* mask.

Definition at line 305 of file Pipe_LPC.h.

static bool Pipe_HasPipeInterrupted ( const uint8_t  PipeNumber)
inlinestatic

Determines if the specified pipe number has interrupted (valid only for INTERRUPT type pipes).

Parameters
PipeNumber: Index of the pipe whose interrupt flag should be tested
Returns
Boolean true if the specified pipe has interrupted, false otherwise.

Definition at line 402 of file Pipe_LPC.h.

static bool Pipe_IsConfigured ( const uint8_t  corenum)
inlinestatic

Determines if the currently selected pipe is configured.

Parameters
corenum: USB port number
Returns
Boolean true if the selected pipe is configured, false otherwise.

Definition at line 350 of file Pipe_LPC.h.

static bool Pipe_IsEnabled ( void  )
inlinestatic

Determines if the currently selected pipe is enabled, but not necessarily configured.

Returns
Boolean true if the currently selected pipe is enabled, false otherwise.

Definition at line 292 of file Pipe_LPC.h.

bool Pipe_IsEndpointBound ( const uint8_t  EndpointAddress)

Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given endpoint is found, it is automatically selected.

Parameters
EndpointAddress: EndpointAddress Address and direction mask of the endpoint within the attached device to check
Returns
Boolean true if a pipe bound to the given endpoint address of the specified direction is found, false otherwise.

Definition at line 97 of file Pipe_LPC.c.

static bool Pipe_IsError ( void  )
inlinestatic

Determines if the master pipe error flag is set for the currently selected pipe, indicating that some sort of hardware error has occurred on the pipe.

See Also
Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.
Returns
Boolean true if an error has occurred on the selected pipe, false otherwise.

Definition at line 452 of file Pipe_LPC.h.

static bool Pipe_IsFrozen ( void  )
inlinestatic

Determines if the currently selected pipe is frozen, and not able to accept data.

Returns
Boolean true if the currently selected pipe is frozen, false otherwise.

Definition at line 429 of file Pipe_LPC.h.

static void Pipe_ResetPipe ( const uint8_t  corenum,
const uint8_t  PipeNumber 
)
inlinestatic

Resets the desired pipe, including the pipe banks and flags.

Parameters
corenum: USB port number
PipeNumber: Index of the pipe to reset
Returns
Nothing

Definition at line 259 of file Pipe_LPC.h.

static void Pipe_SelectPipe ( const uint8_t  corenum,
const uint8_t  PipeNumber 
)
inlinestatic

Selects the given pipe number. Any pipe operations which do not require the pipe number to be indicated will operate on the currently selected pipe.

Parameters
corenum: USB port number
PipeNumber: Index of the pipe to select
Returns
Nothing

Definition at line 246 of file Pipe_LPC.h.

static void Pipe_SetFiniteINRequests ( const uint8_t  TotalINRequests)
inlinestatic

Configures the currently selected pipe to only allow the specified number of IN requests to be accepted by the pipe before it is automatically frozen.

Parameters
TotalINRequests: Total number of IN requests that the pipe may receive before freezing
Returns
Nothing

Definition at line 340 of file Pipe_LPC.h.

static void Pipe_SetInfiniteINRequests ( void  )
inlinestatic

Configures the currently selected pipe to allow for an unlimited number of IN requests.

Definition at line 328 of file Pipe_LPC.h.

static void Pipe_SetInterruptPeriod ( const uint8_t  Milliseconds)
inlinestatic

Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.

Parameters
Milliseconds: Number of milliseconds between each pipe poll.
Returns
Nothing

Definition at line 376 of file Pipe_LPC.h.

static void Pipe_SetPipeToken ( const uint8_t  Token)
inlinestatic

Sets the token for the currently selected pipe to one of the tokens specified by the PIPE_TOKEN_* masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices which have two endpoints of opposite direction sharing the same endpoint address within the device.

Parameters
Token: New pipe token to set the selected pipe to, as a PIPE_TOKEN_* mask.
Returns
Nothing

Definition at line 322 of file Pipe_LPC.h.

static void Pipe_Unfreeze ( void  )
inlinestatic

Unfreezes the selected pipe, allowing it to communicate with an attached device.

Definition at line 410 of file Pipe_LPC.h.

Variable Documentation

HCD_USB_SPEED hostportspeed[]

Definition at line 42 of file Pipe_LPC.c.

uint8_t hostselected

Definition at line 43 of file Pipe_LPC.c.

USB_Pipe_Data_t PipeInfo[MAX_USB_CORE][PIPE_TOTAL_PIPES]

Definition at line 40 of file Pipe_LPC.c.

uint8_t pipeselected[MAX_USB_CORE]

Definition at line 39 of file Pipe_LPC.c.