| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Modules | Macros | Enumerations | Functions
Host Controller Drivers
Host Management

## Detailed Description

## Modules
| Enhanced Host Controller Interface Driver
| Open Host Controller Interface Driver

## Macros
#define | HCD_ENDPOINT_MAXPACKET_XFER_LEN 0xFFEEFFEE
#define | YES 1
#define | NO 0
#define | HCD_MAX_ENDPOINT 8
#define | HC_RESET_TIMEOUT 10
#define | TRANSFER_TIMEOUT_MS 1000
#define | PORT_RESET_PERIOD_MS 100
#define | INTERRUPT_LIST_ENABLE YES
#define | ISO_LIST_ENABLE YES
#define | hcd_printf(...)
#define | assert_status_ok_message(...)
#define | ASSERT_STATUS_OK_MESSAGE(sts, message)
#define | ASSERT_STATUS_OK(sts) ASSERT_STATUS_OK_MESSAGE(sts, NULL)

## Enumerations
enum | HCD_TRANSFER_TYPE { CONTROL_TRANSFER, ISOCHRONOUS_TRANSFER, BULK_TRANSFER, INTERRUPT_TRANSFER }
enum | HCD_TRANSFER_DIR { SETUP_TRANSFER, IN_TRANSFER, OUT_TRANSFER }
enum | HCD_USB_SPEED { FULL_SPEED = 0, LOW_SPEED, HIGH_SPEED }
enum | HCD_STATUS { HCD_STATUS_OK = 0, HCD_STATUS_TRANSFER_CRC, HCD_STATUS_TRANSFER_BitStuffing, HCD_STATUS_TRANSFER_DataToggleMismatch, HCD_STATUS_TRANSFER_Stall, HCD_STATUS_TRANSFER_DeviceNotResponding, HCD_STATUS_TRANSFER_PIDCheckFailure, HCD_STATUS_TRANSFER_UnexpectedPID, HCD_STATUS_TRANSFER_DataOverrun, HCD_STATUS_TRANSFER_DataUnderrun, HCD_STATUS_TRANSFER_CC_Reserved1, HCD_STATUS_TRANSFER_CC_Reserved2, HCD_STATUS_TRANSFER_BufferOverrun, HCD_STATUS_TRANSFER_BufferUnderrun, HCD_STATUS_TRANSFER_NotAccessed, HCD_STATUS_TRANSFER_Reserved, HCD_STATUS_STRUCTURE_IS_FREE, HCD_STATUS_TO_BE_REMOVED, HCD_STATUS_TRANSFER_QUEUED, HCD_STATUS_TRANSFER_COMPLETED, HCD_STATUS_TRANSFER_ERROR, HCD_STATUS_NOT_ENOUGH_MEMORY, HCD_STATUS_NOT_ENOUGH_ENDPOINT, HCD_STATUS_NOT_ENOUGH_GTD, HCD_STATUS_NOT_ENOUGH_ITD, HCD_STATUS_NOT_ENOUGH_QTD, HCD_STATUS_NOT_ENOUGH_HS_ITD, HCD_STATUS_NOT_ENOUGH_SITD, HCD_STATUS_DATA_OVERFLOW, HCD_STATUS_DEVICE_DISCONNECTED, HCD_STATUS_TRANSFER_TYPE_NOT_SUPPORTED, HCD_STATUS_PIPEHANDLE_INVALID, HCD_STATUS_PARAMETER_INVALID }

## Functions
HCD_STATUS | HcdInitDriver (uint8_t HostID)
| Initiate host driver.
HCD_STATUS | HcdDeInitDriver (uint8_t HostID)
| De-initiate host driver.
void | HcdIrqHandler (uint8_t HostID)
| Interrupt service routine for host mode This function must be called in chip's USB interrupt routine.
HCD_STATUS | HcdRhPortReset (uint8_t HostID)
| Perform USB bus reset.
HCD_STATUS | HcdRhPortEnable (uint8_t HostID)
| Turn on 5V USB VBUS.
HCD_STATUS | HcdRhPortDisable (uint8_t HostID)
| Turn off 5V USB VBUS.
HCD_STATUS | HcdGetDeviceSpeed (uint8_t HostID, HCD_USB_SPEED *DeviceSpeed)
| Get operation speed of connected device.
uint32_t | HcdGetFrameNumber (uint8_t HostID)
| Get current frame number.
HCD_STATUS | HcdOpenPipe (uint8_t HostID, uint8_t DeviceAddr, HCD_USB_SPEED DeviceSpeed, uint8_t EndpointNo, HCD_TRANSFER_TYPE TransferType, HCD_TRANSFER_DIR TransferDir, uint16_t MaxPacketSize, uint8_t Interval, uint8_t Mult, uint8_t HSHubDevAddr, uint8_t HSHubPortNum, uint32_t *const PipeHandle)
| Setup a pipe to connect to device's logical endpoint.
HCD_STATUS | HcdClosePipe (uint32_t PipeHandle)
| Delete the link between USB host and device's logical endpoint.
HCD_STATUS | HcdCancelTransfer (uint32_t PipeHandle)
| Cancel a processing transfer.
HCD_STATUS | HcdClearEndpointHalt (uint32_t PipeHandle)
| Clear stall status for connected endpoint.
HCD_STATUS | HcdControlTransfer (uint32_t PipeHandle, const USB_Request_Header_t *const pDeviceRequest, uint8_t *const buffer)
| Perform a control transfer.
HCD_STATUS | HcdDataTransfer (uint32_t PipeHandle, uint8_t *const buffer, uint32_t const length, uint16_t *const pActualTransferred)
| Perform a non-control transfer.
HCD_STATUS | HcdGetPipeStatus (uint32_t PipeHandle)
| Get current pipe status.
void | HcdSetStreamPacketSize (uint32_t PipeHandle, uint16_t packetsize)
| Set size of each packet in a continuous data transfer.

## Macro Definition Documentation

#define ASSERT_STATUS_OK | ( |  | sts | ) | ASSERT_STATUS_OK_MESSAGE(sts, NULL)

Definition at line 339 of file HCD.h.

#define assert_status_ok_message | ( |  | ... | ) |

Definition at line 327 of file HCD.h.

#define ASSERT_STATUS_OK_MESSAGE | ( |  | sts,
|  |  | message
| ) |  |

Value:
do { \
HCD_STATUS status = (sts); \
assert_status_ok_message(status, message, __func__, __FILE__, __LINE__); \
if (HCD_STATUS_OK != status) { \
return status; \
} \
} while (0)

Definition at line 330 of file HCD.h.

#define HC_RESET_TIMEOUT 10

Pre-defined counter value for reseting USB host core

Definition at line 63 of file HCD.h.

#define HCD_ENDPOINT_MAXPACKET_XFER_LEN 0xFFEEFFEE

Used with HcdDataTransfer() to set maximum endpoint size for transfer length

Definition at line 47 of file HCD.h.

#define HCD_MAX_ENDPOINT 8

Maximum number of endpoints/pipes that a single USB host core can support

Definition at line 59 of file HCD.h.

#define hcd_printf | ( |  | ... | ) |

Definition at line 326 of file HCD.h.

#define INTERRUPT_LIST_ENABLE YES

Flag to enable processing for interrupt transfer Select YES to enable or NO if disable

Definition at line 77 of file HCD.h.

#define ISO_LIST_ENABLE YES

Flag to enable processing for isochronous transfer Select YES to enable or NO if disable

Definition at line 82 of file HCD.h.

#define NO 0

Similar to boolean type

Definition at line 55 of file HCD.h.

#define PORT_RESET_PERIOD_MS 100

Pre-defined counter value for reseting USB port

Definition at line 71 of file HCD.h.

#define TRANSFER_TIMEOUT_MS 1000

Pre-defined counter value for transferring

Definition at line 67 of file HCD.h.

#define YES 1

Similar to boolean type

Definition at line 51 of file HCD.h.

## Enumeration Type Documentation

enum HCD_STATUS

Declare status/completion code for host processing

Enumerator:

  HCD_STATUS_OK | Transfer/process completion normal
  HCD_STATUS_TRANSFER_CRC | Transfer/process completion fail: CRC error
  HCD_STATUS_TRANSFER_BitStuffing | Transfer/process completion fail: bit stuffing error
  HCD_STATUS_TRANSFER_DataToggleMismatch | Transfer/process completion fail: data toggle error
  HCD_STATUS_TRANSFER_Stall | Transfer/process completion fail: endpoint stall
  HCD_STATUS_TRANSFER_DeviceNotResponding | Transfer/process completion fail: connected device hung or ...
  HCD_STATUS_TRANSFER_PIDCheckFailure | Transfer/process completion fail: PID error
  HCD_STATUS_TRANSFER_UnexpectedPID | Transfer/process completion fail: PID error
  HCD_STATUS_TRANSFER_DataOverrun | Transfer/process completion fail: data over run
  HCD_STATUS_TRANSFER_DataUnderrun | Transfer/process completion fail: data under run
  HCD_STATUS_TRANSFER_CC_Reserved1 | Transfer/process completion fail: Reserved
  HCD_STATUS_TRANSFER_CC_Reserved2 | Transfer/process completion fail: Reserved
  HCD_STATUS_TRANSFER_BufferOverrun | Transfer/process completion fail: buffer over run
  HCD_STATUS_TRANSFER_BufferUnderrun | Transfer/process completion fail: buffer under run
  HCD_STATUS_TRANSFER_NotAccessed | Transfer/process completion fail: Reserved
  HCD_STATUS_TRANSFER_Reserved | Transfer/process completion fail: Reserved
  HCD_STATUS_STRUCTURE_IS_FREE | USB transfer status: USB data structure is free to use
  HCD_STATUS_TO_BE_REMOVED | USB transfer status: USB data structure need to be freed
  HCD_STATUS_TRANSFER_QUEUED | USB transfer status: transfer descriptor has been set up and queued
  HCD_STATUS_TRANSFER_COMPLETED | USB transfer status: transfer descriptor finished
  HCD_STATUS_TRANSFER_ERROR | USB transfer status: transfer descriptor finished with error
  HCD_STATUS_NOT_ENOUGH_MEMORY | USB transfer set up status: not enough memory
  HCD_STATUS_NOT_ENOUGH_ENDPOINT | USB transfer set up status: not enough endpoint
  HCD_STATUS_NOT_ENOUGH_GTD | USB transfer set up status: not enough general transfer descriptor (OHCI)
  HCD_STATUS_NOT_ENOUGH_ITD | USB transfer set up status: not enough isochronous transfer descriptor
  HCD_STATUS_NOT_ENOUGH_QTD | USB transfer set up status: not enough queue transfer descrptor (EHCI)
  HCD_STATUS_NOT_ENOUGH_HS_ITD | USB transfer set up status: not enough high speed isochronous trsfer descriptor
  HCD_STATUS_NOT_ENOUGH_SITD | USB transfer set up status: not enough split isochronous transfer descriptor
  HCD_STATUS_DATA_OVERFLOW | USB transfer set up status: data over flow
  HCD_STATUS_DEVICE_DISCONNECTED | USB transfer set up status: device disconnected
  HCD_STATUS_TRANSFER_TYPE_NOT_SUPPORTED | USB transfer set up status: transfer is not supported
  HCD_STATUS_PIPEHANDLE_INVALID | USB transfer set up status: pipe handle information is not valid
  HCD_STATUS_PARAMETER_INVALID | USB transfer set up status: wrong supply parameters

Definition at line 111 of file HCD.h.

enum HCD_TRANSFER_DIR

Declare labels for all USB transfer direction

Enumerator:

  SETUP_TRANSFER |
  IN_TRANSFER |
  OUT_TRANSFER |

Definition at line 95 of file HCD.h.

enum HCD_TRANSFER_TYPE

Declare labels for all USB transfer types

Enumerator:

  CONTROL_TRANSFER |
  ISOCHRONOUS_TRANSFER |
  BULK_TRANSFER |
  INTERRUPT_TRANSFER |

Definition at line 86 of file HCD.h.

enum HCD_USB_SPEED

Declare labels for supported USB transfer speeds

Enumerator:

  FULL_SPEED |
  LOW_SPEED |
  HIGH_SPEED |

Definition at line 103 of file HCD.h.

## Function Documentation

HCD_STATUS HcdCancelTransfer | ( | uint32_t | PipeHandle | ) |

Cancel a processing transfer.

Parameters

  PipeHandle | : encoded pipe handle information

Returns
  HCD_STATUS code

HCD_STATUS HcdClearEndpointHalt | ( | uint32_t | PipeHandle | ) |

Clear stall status for connected endpoint.

Parameters

  PipeHandle | : encoded pipe handle information

Returns
  HCD_STATUS code

HCD_STATUS HcdClosePipe | ( | uint32_t | PipeHandle | ) |

Delete the link between USB host and device's logical endpoint.

Parameters

  PipeHandle | : encoded pipe handle information

Returns
  HCD_STATUS code

HCD_STATUS HcdControlTransfer | ( | uint32_t | PipeHandle,
|  | const USB_Request_Header_t *const | pDeviceRequest,
|  | uint8_t *const | buffer
| ) |  |

Perform a control transfer.

Parameters

  PipeHandle | : encoded pipe handle information
  pDeviceRequest,: | pointer to USB_Request_Header_t structure
  buffer | : pointer to share buffer used in data phase

Returns
  HCD_STATUS code

HCD_STATUS HcdDataTransfer | ( | uint32_t | PipeHandle,
|  | uint8_t *const | buffer,
|  | uint32_t const | length,
|  | uint16_t *const | pActualTransferred
| ) |  |

Perform a non-control transfer.

Parameters

  PipeHandle | : encoded pipe handle information
  buffer | : pointer to transferred data buffer
  length | : size of this transfer
  pActualTransferred,: | return actual transfer bytes through pointer

Returns
  HCD_STATUS code

HCD_STATUS HcdDeInitDriver | ( | uint8_t | HostID | ) |

De-initiate host driver.

Parameters

  HostID | : USB port number

Returns
  HCD_STATUS code

HCD_STATUS HcdGetDeviceSpeed | ( | uint8_t | HostID,
|  | HCD_USB_SPEED * | DeviceSpeed
| ) |  |

Get operation speed of connected device.

Parameters

  HostID | : USB port number
  DeviceSpeed | : return device speed through pointer of type HCD_USB_SPEED

Returns
  HCD_STATUS code

uint32_t HcdGetFrameNumber | ( | uint8_t | HostID | ) |

Get current frame number.

Parameters

  HostID | : USB port number

Returns
  frame number

HCD_STATUS HcdGetPipeStatus | ( | uint32_t | PipeHandle | ) |

Get current pipe status.

Parameters

  PipeHandle | : encoded pipe handle information

Returns
  HCD_STATUS code

HCD_STATUS HcdInitDriver | ( | uint8_t | HostID | ) |

Initiate host driver.

Parameters

  HostID | : USB port number

Returns
  HCD_STATUS code

void HcdIrqHandler | ( | uint8_t | HostID | ) |

Interrupt service routine for host mode This function must be called in chip's USB interrupt routine.

Parameters

  HostID | : USB port number

Returns
  nothing

HCD_STATUS HcdOpenPipe | ( | uint8_t | HostID,
|  | uint8_t | DeviceAddr,
|  | HCD_USB_SPEED | DeviceSpeed,
|  | uint8_t | EndpointNo,
|  | HCD_TRANSFER_TYPE | TransferType,
|  | HCD_TRANSFER_DIR | TransferDir,
|  | uint16_t | MaxPacketSize,
|  | uint8_t | Interval,
|  | uint8_t | Mult,
|  | uint8_t | HSHubDevAddr,
|  | uint8_t | HSHubPortNum,
|  | uint32_t *const | PipeHandle
| ) |  |

Setup a pipe to connect to device's logical endpoint.

Parameters

  HostID | : USB port number
  DeviceAddr | : address of connected device
  DeviceSpeed | : speed of connected device in format HCD_USB_SPEED
  EndpointNo | : connected logical endpoint number
  TransferType | : transfer type of this link in format HCD_TRANSFER_TYPE
  TransferDir | : direction of this link in format HCD_TRANSFER_DIR
  MaxPacketSize,: | maximum size of connected endpoint
  Interval | : polling frequency for this transfer type, only apply for period transfer
  Mult | : used for isochronous transfer to determine number of packets sent in one transaction
  HSHubDevAddr | : currently not use this parameter
  HSHubPortNum | : currently not use this parameter
  PipeHandle | : pointer to return pipe handle information

Returns
  HCD_STATUS code

HCD_STATUS HcdRhPortDisable | ( | uint8_t | HostID | ) |

Turn off 5V USB VBUS.

Parameters

  HostID | : USB port number

Returns
  HCD_STATUS code

HCD_STATUS HcdRhPortEnable | ( | uint8_t | HostID | ) |

Turn on 5V USB VBUS.

Parameters

  HostID | : USB port number

Returns
  HCD_STATUS code

HCD_STATUS HcdRhPortReset | ( | uint8_t | HostID | ) |

Perform USB bus reset.

Parameters

  HostID | : USB port number

Returns
  HCD_STATUS code

void HcdSetStreamPacketSize | ( | uint32_t | PipeHandle,
|  | uint16_t | packetsize
| ) |  |

Set size of each packet in a continuous data transfer.

Parameters

  PipeHandle | : encoded pipe handle information
  packetsize | : packet size

Returns
  HCD_STATUS code