Microchip® Advanced Software Framework

usbhs_host.c File Reference

USB host driver Compliance with common driver UHD.

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

#include "conf_usb_host.h"
#include "sysclk.h"
#include "uhd.h"
#include "usbhs_otg.h"
#include "usbhs_host.h"
#include "ioport.h"
#include <string.h>
#include <stdlib.h>
#include "sleepmgr.h"

Data Structures

struct  uhd_ctrl_request_t
 Structure to store the high level setup request. More...
 
struct  uhd_pipe_job_t
 Structure definition to store registered jobs on a pipe. More...
 

Macros

#define UHC_MODE_CHANGE(arg)
 
#define UHC_SOF_EVENT()
 
#define UHC_VBUS_CHANGE(b_present)
 
#define UHC_VBUS_ERROR()
 
#define UHD_BULK_INTERVAL_MIN   1
 Minimal bulk interval value. More...
 
#define UHD_BULK_NB_BANK   2
 
#define UHD_INTERRUPT_NB_BANK   1
 
#define UHD_ISOCHRONOUS_NB_BANK   2
 
#define UHD_PIPE_FIFO_SUPPORTED
 
#define UHD_PIPE_USED(pipe)   (USB_HOST_MAX_EP >= pipe)
 
#define UHD_USB_INT_FUN   USBHS_Handler
 
#define UHD_USB_INT_LEVEL   5
 
#define USB_HOST_MAX_EP   9
 

Functions

 ISR (UHD_USB_INT_FUN)
 Function called by USBHS interrupt handler to manage USB interrupts. More...
 
void otg_dual_disable (void)
 Uninitialize the dual role This function is implemented in usbhs_host.c file. More...
 
bool otg_dual_enable (void)
 Initialize the dual role This function is implemented in usbhs_host.c file. More...
 
static void otg_id_handler (uint32_t id, uint32_t mask)
 USB ID pin change handler. More...
 
void udc_start (void)
 Start the USB Device stack. More...
 
void udc_stop (void)
 Stop the USB Device stack. More...
 
void udd_interrupt (void)
 Function called by USBHS interrupt to manage USB Device interrupts. More...
 
static void uhd_ctrl_interrupt (void)
 Manages the events related to control endpoint. More...
 
static void uhd_ctrl_phase_data_in (void)
 Manages the DATA IN phase on control endpoint. More...
 
static void uhd_ctrl_phase_data_in_start (void)
 Starts the DATA IN phase on control endpoint. More...
 
static void uhd_ctrl_phase_data_out (void)
 Manages the DATA OUT phase on control endpoint. More...
 
static void uhd_ctrl_phase_setup (void)
 Sends a USB setup packet to start a control request sequence. More...
 
static void uhd_ctrl_phase_zlp_in (void)
 Starts the ZLP IN phase on control endpoint. More...
 
static void uhd_ctrl_phase_zlp_out (void)
 Starts the ZLP OUT phase on control endpoint. More...
 
static void uhd_ctrl_request_end (uhd_trans_status_t status)
 Call the callback linked to control request and start the next request from the queue. More...
 
static void uhd_ctrl_timeout (void)
 
static void uhd_delayed_resume (void)
 
static void uhd_delayed_suspend (void)
 
void uhd_disable (bool b_id_stop)
 Disables the USB host mode. More...
 
void uhd_enable (void)
 Enables the USB host mode Start the ID pin management if the ID pin is available. More...
 
static void uhd_ep_abort_pipe (uint8_t pipe, uhd_trans_status_t status)
 Aborts the on going transfer on a pipe. More...
 
uint16_t uhd_get_frame_number (void)
 Returns the current Start Of Frame (SOF) number. More...
 
uint16_t uhd_get_microframe_number (void)
 Returns the current micro start of frame number. More...
 
static uint8_t uhd_get_pipe (usb_add_t add, usb_ep_t endp)
 Returns the pipe number matching a USB endpoint. More...
 
uhd_speed_t uhd_get_speed (void)
 Returns the speed of connected device. More...
 
static void uhd_interrupt (void)
 Function called by USBHS interrupt to manage USB host interrupts. More...
 
bool uhd_is_suspend (void)
 Test if the suspend state is enabled on the USB line. More...
 
static void uhd_pipe_finish_job (uint8_t pipe, uhd_trans_status_t status)
 Call the callback linked to the end of pipe transfer. More...
 
static uhd_trans_status_t uhd_pipe_get_error (uint8_t pipe)
 Translates the USBHS pipe error to UHD error. More...
 
static void uhd_pipe_in_received (uint8_t pipe)
 
static void uhd_pipe_interrupt (uint8_t pipe)
 Manages the following pipe interrupts: More...
 
static void uhd_pipe_out_ready (uint8_t pipe)
 
void uhd_resume (void)
 Enables the IDLE state on the USB line. More...
 
void uhd_send_reset (uhd_callback_reset_t callback)
 Enables the Reset state on the USB line. More...
 
bool uhd_setup_request (usb_add_t add, usb_setup_req_t *req, uint8_t *payload, uint16_t payload_size, uhd_callback_setup_run_t callback_run, uhd_callback_setup_end_t callback_end)
 Add a setup request in the control endpoint setup queue. More...
 
static void uhd_sof_interrupt (void)
 Manages timeouts and actions based on SOF events. More...
 
void uhd_suspend (void)
 Enables the suspend state on the USB line. More...
 
static void uhd_vbus_handler (uint32_t id, uint32_t mask)
 USB VBus pin change handler. More...
 
Endpoint Management

The following functions allow drivers to create and remove endpoints, as well as set, clear and query their "halted" and "wedged" states.

bool uhd_ep0_alloc (usb_add_t add, uint8_t ep_size)
 Configures and enables a control endpoint 0. More...
 
bool uhd_ep_alloc (usb_add_t add, usb_ep_desc_t *ep_desc, uhd_speed_t speed)
 Configures and enables an endpoint. More...
 
void uhd_ep_free (usb_add_t add, usb_ep_t endp)
 Disables an endpoint or all endpoint of a device. More...
 
bool uhd_ep_run (usb_add_t add, usb_ep_t endp, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, uint16_t timeout, uhd_callback_trans_t callback)
 Allows to receive or send data on an endpoint. More...
 
void uhd_ep_abort (usb_add_t add, usb_ep_t endp)
 Aborts an on-going transfer on an endpoint. More...
 

Variables

static bool otg_initialized = false
 State of USBHS OTG initialization. More...
 
static uhd_callback_reset_t uhd_reset_callback = NULL
 Store the callback to be call at the end of reset signal. More...
 
Management of bulk/interrupt/isochronous endpoints

The UHD manages the data transfer on endpoints:

  • Start data transfer on endpoint with USB DMA
  • Send a ZLP packet if requested
  • Call registered callback to signal end of transfer The transfer abort and stall feature are supported.
static uhd_pipe_job_t uhd_pipe_job [USBHS_EPT_NUM-1]
 Array to register a job on bulk/interrupt/isochronous endpoint. More...
 
static uint8_t uhd_suspend_start
 Variables to manage the suspend/resume sequence. More...
 
static uint8_t uhd_resume_start
 
static uint16_t uhd_pipes_unfreeze
 

Power management

enum  uhd_usbhs_state_enum {
  UHD_STATE_OFF = 0,
  UHD_STATE_WAIT_ID_HOST = 1,
  UHD_STATE_NO_VBUS = 2,
  UHD_STATE_DISCONNECT = 3,
  UHD_STATE_SUSPEND = 4,
  UHD_STATE_IDLE = 5
}
 States of USBHS interface. More...
 
static void uhd_sleep_mode (enum uhd_usbhs_state_enum new_state)
 Manages the sleep mode following the USBHS state. More...
 

Control endpoint low level management routine.

This function performs control endpoint management.

It handles the SETUP/DATA/HANDSHAKE phases of a control transaction.

enum  uhd_ctrl_request_phase_t {
  UHD_CTRL_REQ_PHASE_SETUP = 0,
  UHD_CTRL_REQ_PHASE_DATA_OUT = 1,
  UHD_CTRL_REQ_PHASE_DATA_IN = 2,
  UHD_CTRL_REQ_PHASE_ZLP_IN = 3,
  UHD_CTRL_REQ_PHASE_ZLP_OUT = 4
}
 Bit definitions to store setup request state machine. More...
 
struct uhd_ctrl_request_tuhd_ctrl_request_first
 Entry points of setup request list. More...
 
struct uhd_ctrl_request_tuhd_ctrl_request_last
 
volatile uint16_t uhd_ctrl_request_timeout
 Remaining time for on-going setup request (No request on-going if equal 0) More...
 
uint16_t uhd_ctrl_nb_trans
 Number of transfered byte on DATA phase of current setup request. More...
 
static bool uhd_b_suspend_requested
 Flag to delay a suspend request after all on-going setup request. More...
 
uhd_ctrl_request_phase_t uhd_ctrl_request_phase
 

#define UHC_MODE_CHANGE (   arg)

Referenced by otg_dual_enable(), and otg_id_handler().

#define UHC_SOF_EVENT ( )

Referenced by uhd_sof_interrupt().

#define UHC_VBUS_CHANGE (   b_present)

Referenced by uhd_vbus_handler().

#define UHC_VBUS_ERROR ( )
#define UHD_PIPE_FIFO_SUPPORTED
#define UHD_PIPE_USED (   pipe)    (USB_HOST_MAX_EP >= pipe)
#define UHD_USB_INT_FUN   USBHS_Handler
#define UHD_USB_INT_LEVEL   5

Referenced by otg_dual_enable(), and uhd_enable().

#define USB_HOST_MAX_EP   9