Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
USBC Host Driver

USBC low-level driver for USB host mode.

USBC Host IP properties

These macros give access to IP properties

Get maximal number of endpoints

#define uhd_get_pipe_max_nbr()   otg_get_max_nbr_endpoints()
 
#define UHD_MAX_PEP_NB   USBC_EPT_NBR
 
#define UHD_PEP_NB   (UHD_MAX_PEP_NB+1)
 

Host Misc

Disable all interrupts

#define uhd_disable_all_interrupts()
 
#define uhd_disable_wakeup_interrupts()
 Disable wakeup/resume interrupts. More...
 
#define uhd_ack_all_interrupts()
 Ack all interrupts. More...
 

Host Vbus line control

VBOF is an optional output pin which allows to enable or disable the external VBus generator.

VBOF is managed through GPIO driver. This feature is optional, and it is enabled if USB_VBOF_PIN is defined in board.h and (CONF_BOARD_USB_VBUS_CONTROL) not defined in conf_board.h.

#define UHD_VBUS_CTRL   (defined(CONF_BOARD_USB_VBUS_CONTROL))
 
#define UHD_VBOF_IO   (defined(USB_VBOF_PIN) && UHD_VBUS_CTRL)
 
#define pad_vbus_enable()   ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_ACTIVE_LEVEL)
 
#define pad_vbus_disable()   ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_INACTIVE_LEVEL)
 

Host Vbus line error monitoring

The VBus generator can provide an error signal through a GPIO or EIC pin.

This feature is optional, and it is enabled if USB_VBERR_PIN or USB_VBERR_EIC is defined in board.h and CONF_BOARD_USB_VBUS_ERR_DETECT defined in conf_board.h.

#define UHD_VBUS_ERR_DETECT   (defined(CONF_BOARD_USB_VBUS_ERR_DETECT))
 
#define UHD_VBERR_IO   (defined(USB_VBERR_PIN) && UHD_VBUS_ERR_DETECT)
 
#define UHD_VBERR_EIC   (defined(USB_VBERR_EIC) && UHD_VBUS_ERR_DETECT)
 
#define pad_vbus_error_init()   eic_pad_init(USB_VBERR_EIC_LINE, uhd_vberr_handler, USB_VBERR_EIC_IRQn, USB_VBERR_EIC, UHD_USB_INT_LEVEL);
 
#define pad_vbus_error_interrupt_disable()   eic_line_disable_interrupt(EIC, USB_VBERR_EIC_LINE)
 
#define pad_ack_vbus_error_interrupt()
 
#define Is_pad_vbus_error()   ioport_get_pin_level(USB_VBERR_EIC)
 

USB device connection/disconnection monitoring

#define uhd_enable_connection_int()   USBC_REG_SET(UHINTE,DCONNIE)
 
#define uhd_disable_connection_int()   USBC_REG_CLR(UHINTE,DCONNIE)
 
#define Is_uhd_connection_int_enabled()   USBC_TST_BITS(UHINTE,DCONNIE)
 
#define uhd_raise_connection()   USBC_REG_SET(UHINT,DCONNI);
 
#define uhd_ack_connection()   USBC_REG_CLR(UHINT,DCONNI)
 
#define Is_uhd_connection()   USBC_TST_BITS(UHINT,DCONNI)
 
#define uhd_enable_disconnection_int()   USBC_REG_SET(UHINTE,DDISCIE)
 
#define uhd_disable_disconnection_int()   USBC_REG_CLR(UHINTE,DDISCIE)
 
#define Is_uhd_disconnection_int_enabled()   USBC_TST_BITS(UHINTE,DDISCIE)
 
#define uhd_raise_disconnection()   USBC_REG_SET(UHINT,DDISCI);
 
#define uhd_ack_disconnection()   USBC_REG_CLR(UHINT,DDISCI)
 
#define Is_uhd_disconnection()   USBC_TST_BITS(UHINT,DDISCI)
 

USB device speed control

#define uhd_get_speed_mode()   USBC_RD_BITS(USBSTA,SPEED_Msk)
 
#define Is_uhd_low_speed_mode()   (USBC_RD_BITS(USBSTA,SPEED_Msk) == USBC_USBSTA_SPEED_LOW)
 
#define Is_uhd_full_speed_mode()   (USBC_RD_BITS(USBSTA,SPEED_Msk) == USBC_USBSTA_SPEED_FULL)
 
#define Is_uhd_high_speed_mode()   false
 

Bus events control

These macros manage the bus events: reset, SOF, resume, wakeup.

#define uhd_start_reset()   USBC_SET_BITS(UHCON,RESET)
 Initiates a reset event. More...
 
#define Is_uhd_starting_reset()   USBC_TST_BITS(UHCON,RESET)
 
#define uhd_stop_reset()   USBC_CLR_BITS(UHCON,RESET)
 
#define uhd_enable_reset_sent_interrupt()   USBC_REG_SET(UHINTE,RSTIE)
 
#define uhd_disable_reset_sent_interrupt()   USBC_REG_CLR(UHINTE,RSTIE)
 
#define Is_uhd_reset_sent_interrupt_enabled()   USBC_TST_BITS(UHINTE,RSTIE)
 
#define uhd_ack_reset_sent()   USBC_REG_CLR(UHINT,RSTI)
 
#define Is_uhd_reset_sent()   USBC_TST_BITS(UHINT,RSTI)
 
#define uhd_enable_sof()   USBC_SET_BITS(UHCON,SOFE)
 Initiates a SOF events. More...
 
#define uhd_disable_sof()   USBC_CLR_BITS(UHCON,SOFE)
 
#define Is_uhd_sof_enabled()   USBC_TST_BITS(UHCON,SOFE)
 
#define uhd_get_sof_number()   USBC_RD_BITFIELD(UHFNUM,FNUM)
 
#define uhd_get_microsof_number()
 
#define uhd_get_frame_position()   USBC_RD_BITFIELD(UHFNUM,FLENHIGH)
 
#define uhd_enable_sof_interrupt()   USBC_REG_SET(UHINTE,HSOFIE)
 
#define uhd_disable_sof_interrupt()   USBC_REG_CLR(UHINTE,HSOFIE)
 
#define Is_uhd_sof_interrupt_enabled()   USBC_TST_BITS(UHINTE,HSOFIE)
 
#define uhd_ack_sof()   USBC_REG_CLR(UHINT,HSOFI)
 
#define Is_uhd_sof()   USBC_TST_BITS(UHINT,HSOFI)
 
#define uhd_send_resume()   USBC_SET_BITS(UHCON,RESUME)
 Initiates a resume event It is called downstream resume event. More...
 
#define Is_uhd_sending_resume()   USBC_TST_BITS(UHCON,RESUME)
 
#define uhd_enable_downstream_resume_interrupt()   USBC_REG_SET(UHINTE,RSMEDIE)
 
#define uhd_disable_downstream_resume_interrupt()   USBC_REG_CLR(UHINTE,RSMEDIE)
 
#define Is_uhd_downstream_resume_interrupt_enabled()   USBC_TST_BITS(UHINTE,RSMEDIE)
 
#define uhd_ack_downstream_resume()   USBC_REG_CLR(UHINT,RSMEDI)
 
#define Is_uhd_downstream_resume()   USBC_TST_BITS(UHINT,RSMEDI)
 
#define uhd_enable_wakeup_interrupt()   USBC_REG_SET(UHINTE,HWUPIE)
 Detection of a wake-up event A wake-up event is received when the host controller is in the suspend mode: More...
 
#define uhd_disable_wakeup_interrupt()   USBC_REG_CLR(UHINTE,HWUPIE)
 
#define Is_uhd_wakeup_interrupt_enabled()   USBC_TST_BITS(UHINTE,HWUPIE)
 
#define uhd_ack_wakeup()   USBC_REG_CLR(UHINT,HWUPI)
 
#define Is_uhd_wakeup()   USBC_TST_BITS(UHINT,HWUPI)
 
#define uhd_enable_upstream_resume_interrupt()   USBC_REG_SET(UHINTE,RXRSMIE)
 
#define uhd_disable_upstream_resume_interrupt()   USBC_REG_CLR(UHINTE,RXRSMIE)
 
#define Is_uhd_upstream_resume_interrupt_enabled()   USBC_TST_BITS(UHINTE,RXRSMIE)
 
#define uhd_ack_upstream_resume()   USBC_REG_CLR(UHINT,RXRSMI)
 
#define Is_uhd_upstream_resume()   USBC_TST_BITS(UHINT,RXRSMI)
 

#define Is_pad_vbus_error ( )    ioport_get_pin_level(USB_VBERR_EIC)

Referenced by uhd_vberr_handler().

#define Is_uhd_connection ( )    USBC_TST_BITS(UHINT,DCONNI)

Referenced by uhd_interrupt().

#define Is_uhd_connection_int_enabled ( )    USBC_TST_BITS(UHINTE,DCONNIE)

Referenced by uhd_interrupt().

#define Is_uhd_disconnection ( )    USBC_TST_BITS(UHINT,DDISCI)

Referenced by uhd_interrupt(), and uhd_sof_interrupt().

#define Is_uhd_disconnection_int_enabled ( )    USBC_TST_BITS(UHINTE,DDISCIE)

Referenced by uhd_interrupt().

#define Is_uhd_downstream_resume ( )    USBC_TST_BITS(UHINT,RSMEDI)

Referenced by uhd_interrupt().

#define Is_uhd_downstream_resume_interrupt_enabled ( )    USBC_TST_BITS(UHINTE,RSMEDIE)
#define Is_uhd_full_speed_mode ( )    (USBC_RD_BITS(USBSTA,SPEED_Msk) == USBC_USBSTA_SPEED_FULL)
#define Is_uhd_high_speed_mode ( )    false

Referenced by uhd_interrupt().

#define Is_uhd_low_speed_mode ( )    (USBC_RD_BITS(USBSTA,SPEED_Msk) == USBC_USBSTA_SPEED_LOW)

Referenced by uhd_interrupt(), and uhd_sof_interrupt().

#define Is_uhd_reset_sent ( )    USBC_TST_BITS(UHINT,RSTI)

Referenced by uhd_interrupt().

#define Is_uhd_reset_sent_interrupt_enabled ( )    USBC_TST_BITS(UHINTE,RSTIE)
#define Is_uhd_sending_resume ( )    USBC_TST_BITS(UHCON,RESUME)
#define Is_uhd_sof ( )    USBC_TST_BITS(UHINT,HSOFI)

Referenced by uhd_interrupt().

#define Is_uhd_sof_enabled ( )    USBC_TST_BITS(UHCON,SOFE)
#define Is_uhd_sof_interrupt_enabled ( )    USBC_TST_BITS(UHINTE,HSOFIE)
#define Is_uhd_starting_reset ( )    USBC_TST_BITS(UHCON,RESET)
#define Is_uhd_upstream_resume ( )    USBC_TST_BITS(UHINT,RXRSMI)

Referenced by uhd_interrupt().

#define Is_uhd_upstream_resume_interrupt_enabled ( )    USBC_TST_BITS(UHINTE,RXRSMIE)
#define Is_uhd_wakeup ( )    USBC_TST_BITS(UHINT,HWUPI)

Referenced by uhd_interrupt().

#define Is_uhd_wakeup_interrupt_enabled ( )    USBC_TST_BITS(UHINTE,HWUPIE)

Referenced by uhd_interrupt().

#define pad_ack_vbus_error_interrupt ( )
Value:
(eic_line_change_config(USB_VBERR_EIC_LINE, !ioport_get_pin_level(USB_VBERR_EIC)), \
eic_line_clear_interrupt(EIC, USB_VBERR_EIC_LINE))
static bool ioport_get_pin_level(ioport_pin_t pin)
Get current value of an IOPORT pin, which has been configured as an input.
Definition: ioport.h:301
static __always_inline void eic_line_change_config(uint8_t line, bool b_high)
Definition: usbc_otg.h:74
static void eic_line_clear_interrupt(Eic *eic, uint8_t line_number)
Clear the interrupt flag of specified pin.
Definition: eic.h:315

Referenced by uhd_vberr_handler().

#define pad_vbus_disable ( )    ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_INACTIVE_LEVEL)

Referenced by uhd_disable().

#define pad_vbus_enable ( )    ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_ACTIVE_LEVEL)

Referenced by uhd_enable().

#define pad_vbus_error_init ( )    eic_pad_init(USB_VBERR_EIC_LINE, uhd_vberr_handler, USB_VBERR_EIC_IRQn, USB_VBERR_EIC, UHD_USB_INT_LEVEL);

Referenced by uhd_enable().

#define pad_vbus_error_interrupt_disable ( )    eic_line_disable_interrupt(EIC, USB_VBERR_EIC_LINE)

Referenced by uhd_disable().

#define uhd_ack_all_interrupts ( )
Value:
do {\
USBC->USBC_UHINTCLR = USBC_UHINTCLR_DCONNIC\
| USBC_UHINTCLR_DDISCIC | USBC_UHINTCLR_HSOFIC\
| USBC_UHINTCLR_HWUPIC | USBC_UHINTCLR_RSMEDIC\
| USBC_UHINTCLR_RSTIC | USBC_UHINTCLR_RXRSMIC;\
} while (0)

Ack all interrupts.

Referenced by uhd_enable().

#define uhd_ack_connection ( )    USBC_REG_CLR(UHINT,DCONNI)

Referenced by uhd_interrupt().

#define uhd_ack_disconnection ( )    USBC_REG_CLR(UHINT,DDISCI)

Referenced by uhd_interrupt().

#define uhd_ack_downstream_resume ( )    USBC_REG_CLR(UHINT,RSMEDI)
#define uhd_ack_reset_sent ( )    USBC_REG_CLR(UHINT,RSTI)

Referenced by uhd_interrupt().

#define uhd_ack_sof ( )    USBC_REG_CLR(UHINT,HSOFI)

Referenced by uhd_interrupt().

#define uhd_ack_upstream_resume ( )    USBC_REG_CLR(UHINT,RXRSMI)
#define uhd_ack_wakeup ( )    USBC_REG_CLR(UHINT,HWUPI)

Referenced by uhd_interrupt().

#define uhd_disable_all_interrupts ( )
Value:
do {\
USBC->USBC_UHINTECLR = USBC_UHINTECLR_DCONNIEC\
| USBC_UHINTECLR_DDISCIEC\
| USBC_UHINTECLR_HSOFIEC\
| USBC_UHINTECLR_RSTIEC\
| USBC_UHINTECLR_HWUPIEC\
| USBC_UHINTECLR_RSMEDIEC\
| USBC_UHINTECLR_RXRSMIEC;\
} while (0)

Referenced by uhd_disable().

#define uhd_disable_connection_int ( )    USBC_REG_CLR(UHINTE,DCONNIE)

Referenced by uhd_interrupt().

#define uhd_disable_disconnection_int ( )    USBC_REG_CLR(UHINTE,DDISCIE)

Referenced by uhd_interrupt().

#define uhd_disable_downstream_resume_interrupt ( )    USBC_REG_CLR(UHINTE,RSMEDIE)
#define uhd_disable_reset_sent_interrupt ( )    USBC_REG_CLR(UHINTE,RSTIE)
#define uhd_disable_sof ( )    USBC_CLR_BITS(UHCON,SOFE)

Referenced by uhd_disable(), and uhd_sof_interrupt().

#define uhd_disable_sof_interrupt ( )    USBC_REG_CLR(UHINTE,HSOFIE)
#define uhd_disable_upstream_resume_interrupt ( )    USBC_REG_CLR(UHINTE,RXRSMIE)
#define uhd_disable_wakeup_interrupt ( )    USBC_REG_CLR(UHINTE,HWUPIE)

Referenced by uhd_interrupt().

#define uhd_disable_wakeup_interrupts ( )
Value:
do {\
USBC->USBC_UHINTECLR = USBC_UHINTECLR_HWUPIEC\
| USBC_UHINTECLR_RSMEDIEC\
| USBC_UHINTECLR_RXRSMIEC;\
} while (0)

Disable wakeup/resume interrupts.

Referenced by uhd_interrupt().

#define uhd_enable_connection_int ( )    USBC_REG_SET(UHINTE,DCONNIE)

Referenced by uhd_enable(), and uhd_interrupt().

#define uhd_enable_disconnection_int ( )    USBC_REG_SET(UHINTE,DDISCIE)

Referenced by uhd_interrupt().

#define uhd_enable_downstream_resume_interrupt ( )    USBC_REG_SET(UHINTE,RSMEDIE)
#define uhd_enable_reset_sent_interrupt ( )    USBC_REG_SET(UHINTE,RSTIE)

Referenced by uhd_enable().

#define uhd_enable_sof ( )    USBC_SET_BITS(UHCON,SOFE)

Initiates a SOF events.

Referenced by uhd_interrupt(), and uhd_resume().

#define uhd_enable_sof_interrupt ( )    USBC_REG_SET(UHINTE,HSOFIE)

Referenced by uhd_enable().

#define uhd_enable_upstream_resume_interrupt ( )    USBC_REG_SET(UHINTE,RXRSMIE)
#define uhd_enable_wakeup_interrupt ( )    USBC_REG_SET(UHINTE,HWUPIE)

Detection of a wake-up event A wake-up event is received when the host controller is in the suspend mode:

  • and an upstream resume from the peripheral is detected.
  • and a peripheral disconnection is detected.

Referenced by uhd_enable(), uhd_interrupt(), and uhd_vbus_handler().

#define uhd_get_frame_position ( )    USBC_RD_BITFIELD(UHFNUM,FLENHIGH)

Referenced by uhd_sof_interrupt().

#define uhd_get_microsof_number ( )
Value:
(Rd_bitfield(USBC->USBC_UHFNUM, \
USBC_UHFNUM_FNUM_Msk|USBC_UHFNUM_MFNUM_Msk))
#define Rd_bitfield(value, mask)
Reads the bit-field of a value specified by a given bit-mask.
Definition: compiler.h:539

Referenced by uhd_get_microframe_number().

#define uhd_get_pipe_max_nbr ( )    otg_get_max_nbr_endpoints()
#define uhd_get_sof_number ( )    USBC_RD_BITFIELD(UHFNUM,FNUM)

Referenced by uhd_get_frame_number().

#define uhd_get_speed_mode ( )    USBC_RD_BITS(USBSTA,SPEED_Msk)

Referenced by uhd_get_speed().

#define UHD_MAX_PEP_NB   USBC_EPT_NBR
#define uhd_raise_connection ( )    USBC_REG_SET(UHINT,DCONNI);
#define uhd_raise_disconnection ( )    USBC_REG_SET(UHINT,DDISCI);
#define uhd_send_resume ( )    USBC_SET_BITS(UHCON,RESUME)

Initiates a resume event It is called downstream resume event.

Referenced by uhd_interrupt(), and uhd_resume().

#define uhd_start_reset ( )    USBC_SET_BITS(UHCON,RESET)

Initiates a reset event.

Referenced by uhd_send_reset().

#define uhd_stop_reset ( )    USBC_CLR_BITS(UHCON,RESET)

Referenced by uhd_interrupt().

#define UHD_VBERR_EIC   (defined(USB_VBERR_EIC) && UHD_VBUS_ERR_DETECT)
#define UHD_VBERR_IO   (defined(USB_VBERR_PIN) && UHD_VBUS_ERR_DETECT)
#define UHD_VBOF_IO   (defined(USB_VBOF_PIN) && UHD_VBUS_CTRL)
#define UHD_VBUS_CTRL   (defined(CONF_BOARD_USB_VBUS_CONTROL))
#define UHD_VBUS_ERR_DETECT   (defined(CONF_BOARD_USB_VBUS_ERR_DETECT))