Microchip® Advanced Software Framework

usbc_host.c File Reference

USBC host driver Compliance with common driver UHD.

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

#include <string.h>
#include <stdlib.h>
#include "conf_usb_host.h"
#include "sysclk.h"
#include "uhd.h"
#include "usbc_otg.h"
#include "usbc_host.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 dbgp_ctrl(...)
 
#define dbgp_ep(...)
 
#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
 
#define UHD_USB_INT_FUN   USBC_Handler
 
#define UHD_USB_INT_LEVEL   5
 

Functions

 ISR (UHD_USB_INT_FUN)
 Function called by USBC interrupt handler to manage USB interrupts. More...
 
void otg_dual_disable (void)
 Uninitialize the dual role This function is implemented in usbc_host.c file. More...
 
bool otg_dual_enable (void)
 Initialize the dual role This function is implemented in usbc_host.c file. 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)
 
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...
 
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...
 
static void uhd_ep_abort_pipe (uint8_t pipe, uhd_trans_status_t status)
 Aborts the on-going transfer on a pipe. 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...
 
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 USBC 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 USBC pipe error to UHD error. More...
 
static void uhd_pipe_interrupt (uint8_t pipe)
 Manages the following pipe interrupts: More...
 
static void uhd_pipe_trans_complet (uint8_t pipe)
 Computes and starts the next transfer on a pipe. 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...
 
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...
 
USB IO PADs handlers
static void otg_id_handler (void)
 USB ID pin change handler. More...
 
static void uhd_vbus_handler (void)
 USB VBus pin change handler. More...
 
static void uhd_vberr_handler (void)
 USB VBus error pin change handler. More...
 

Variables

static volatile uhd_desc_table_t uhd_g_pipe_table [UHD_PEP_NB]
 USB SRAM data containing pipe descriptor table The content of the USB SRAM can be : More...
 
static bool otg_initialized = false
 State of USBC 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 [UHD_PEP_NB-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
 
static uint8_t uhd_pipes_error
 Variable to manage error on pipes. More...
 

Power management

enum  uhd_usbc_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 USBC interface. More...
 
static void uhd_sleep_mode (enum uhd_usbc_state_enum new_state)
 Manages the sleep mode following the USBC 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...
 
uint32_t uhd_ctrl_buffer [64/4]
 Buffer to store the sent/received data on control endpoint. More...
 
static bool uhd_b_zlp_out_delayed = false
 Flag to delay a ZLP OUT 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 dbg_print (   ...)

Referenced by uhd_interrupt(), and uhd_sof_interrupt().

#define dbgp_ctrl (   ...)
#define dbgp_ep (   ...)
#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_enable(), and uhd_vbus_handler().

#define UHC_VBUS_ERROR ( )

Referenced by uhd_vberr_handler().

#define UHD_BULK_INTERVAL_MIN   1

Referenced by uhd_ep_alloc().

#define UHD_USB_INT_FUN   USBC_Handler
#define UHD_USB_INT_LEVEL   5

Referenced by otg_dual_enable(), and uhd_enable().

void udd_interrupt ( void  )

Referenced by ISR().