Microchip® Advanced Software Framework

usb_host_uhd.c File Reference

USB peripheral host wrapper for ASF Stack USB Host Driver (UHD)

Copyright (c) 2014-2020 Microchip Technology Inc. and its subsidiaries.

#include <string.h>
#include <stdlib.h>
#include "conf_usb_host.h"
#include "uhd.h"
#include "usb.h"
#include "usb_dual.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 dbg_print(...)
 
#define UHC_MODE_CHANGE(arg)
 
#define UHC_SOF_EVENT()
 
#define UHC_VBUS_CHANGE(b_present)
 
#define UHC_VBUS_ERROR()
 
#define UHD_ENDPOINT_MAX_TRANS   ((8 *1024 ) - 1)
 
#define USB_STATUS_PIPE_CRC16ER   (1 << 4)
 
#define USB_STATUS_PIPE_DAPIDER   (1 << 1)
 
#define USB_STATUS_PIPE_DTGLER   (1 << 0)
 
#define USB_STATUS_PIPE_PIDER   (1 << 2)
 
#define USB_STATUS_PIPE_TOUTER   (1 << 3)
 

Functions

static void _uhd_connect (struct usb_module *module_inst)
 Manages connection interrupt. More...
 
static void _uhd_ctrl_phase_data_in (uint16_t nb_byte_received)
 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. More...
 
static void _uhd_disconnect (struct usb_module *module_inst)
 Manages disconnection interrupt. More...
 
static void _uhd_downstream_resume (struct usb_module *module_inst)
 Manages downstream resume interrupt. More...
 
static void _uhd_ep0_error (struct usb_module *module_inst, void *pointer)
 Manages endpoint 0 error interrupt. More...
 
static void _uhd_ep0_setup (struct usb_module *module_inst, void *null)
 Manages endpoint 0 setup interrupt. More...
 
static void _uhd_ep0_stall (struct usb_module *module_inst, void *null)
 Manages endpoint 0 stall interrupt. More...
 
static void _uhd_ep0_transfer_complete (struct usb_module *module_inst, void *pointer)
 Manages endpoint 0 transfer complete interrupt. More...
 
static void _uhd_ep_abort_pipe (uint8_t pipe, uhd_trans_status_t status)
 Aborts the on-going transfer on a pipe. More...
 
static void _uhd_ep_error (struct usb_module *module_inst, void *pointer)
 Manages pipe endpoint error callback. More...
 
static void _uhd_ep_stall (struct usb_module *module_inst, void *pointer)
 Manages pipe endpoint stall interrupt. More...
 
static uint8_t _uhd_get_pipe (usb_add_t add, usb_ep_t endp)
 Returns the pipe number matching a USB endpoint. 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 void _uhd_pipe_trans_complete (struct usb_module *module_inst, void *pointer)
 Computes and starts the next transfer on a pipe. More...
 
static void _uhd_ram_error (struct usb_module *module_inst)
 Manages ram access error interrupt. More...
 
static void _uhd_reset (struct usb_module *module_inst)
 Manages bus reset interrupt. More...
 
static void _uhd_sof_interrupt (struct usb_module *module_inst)
 Manages timeouts and actions based on SOF events. More...
 
static void _uhd_upstream_resume (struct usb_module *module_inst)
 Manages upstream resume interrupt. More...
 
static void _uhd_wakeup (struct usb_module *module_inst)
 Manages wakeup interrupt. More...
 
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...
 
bool uhd_ep0_alloc (usb_add_t add, uint8_t ep_size)
 Configures and enables a control endpoint 0. More...
 
void uhd_ep_abort (usb_add_t add, usb_ep_t endp)
 Aborts an on-going transfer on an endpoint. 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...
 
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...
 
uhd_speed_t uhd_get_speed (void)
 Returns the speed of connected device. More...
 
bool uhd_is_suspend (void)
 Test if the suspend state is enabled on the USB line. More...
 
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...
 
void uhd_suspend (void)
 Enables the suspend state on the USB line. More...
 
bool uhd_suspend_lpm (bool b_remotewakeup, uint8_t hird)
 Enables the suspend L1 state on the USB line. More...
 

Variables

struct usb_module dev
 
static bool uhd_lpm_suspend = false
 Notify that USB Host is enter in suspend LPM state. More...
 
static uhd_callback_reset_t uhd_reset_callback = NULL
 Store the callback to be called 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 [USB_PIPE_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 uint8_t uhd_pipes_unfreeze
 

Power management

enum  uhd_usb_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_SUSPEND_LPM = 5,
  UHD_STATE_IDLE = 6
}
 States of USB interface. More...
 
enum sleepmgr_mode sleep_mode []
 
static enum uhd_usb_state_enum uhd_state = UHD_STATE_OFF
 
static void uhd_sleep_mode (enum uhd_usb_state_enum new_state)
 Manages the sleep mode following the USB 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...
 
uint8_t uhd_ctrl_buffer [64]
 Buffer to store the sent/received data on control endpoint. 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)
#define UHC_SOF_EVENT ( )

Referenced by _uhd_sof_interrupt().

#define UHC_VBUS_CHANGE (   b_present)
#define UHC_VBUS_ERROR ( )