Microchip® Advanced Software Framework

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

USBC low-level driver for USB host mode.

Warning
Bit-masks are used instead of bit-fields because PB registers require 32-bit write accesses while AVR32-GCC 4.0.2 builds 8-bit accesses even when volatile unsigned int bit-fields are specified.

USBC Host IP properties

These macros give access to IP properties

Get maximal number of endpoints

#define uhd_get_pipe_max_nbr()
 

Host Vbus line control

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

Enables hardware control of USB_VBOF output pin when a Vbus error occur

#define uhd_enable_vbus_error_hw_control()   USBC_CLR_BITS(USBCON,VBUSHWC)
 
#define uhd_disable_vbus_error_hw_control()   USBC_SET_BITS(USBCON,VBUSHWC)
 Disables hardware control of USB_VBOF output pin when a Vbus error occur. More...
 
#define USB_VBOF_PIN   ATPASTE2(USB_VBOF, _PIN)
 Pin and function for USB_VBOF according to configuration from USB_VBOF. More...
 
#define USB_VBOF_FUNCTION   ATPASTE2(USB_VBOF, _FUNCTION)
 
#define uhd_output_vbof_pin()
 Output USB_VBOF onto its pin. More...
 
#define uhd_set_vbof_active_high()   USBC_CLR_BITS(USBCON,VBUSPO)
 Set USB_VBOF output pin polarity. More...
 
#define uhd_set_vbof_active_low()   USBC_SET_BITS(USBCON,VBUSPO)
 
#define uhd_enable_vbus()   USBC_REG_SET(USBSTA,VBUSRQ)
 Requests VBus activation. More...
 
#define uhd_disable_vbus()   USBC_REG_CLR(USBSTA,VBUSRQ)
 Requests VBus deactivation. More...
 
#define Is_uhd_vbus_enabled()   USBC_TST_BITS(USBSTA,VBUSRQ)
 Tests if VBus activation has been requested. More...
 

Host Vbus line monitoring

The VBus level is always checked by USBC hardware.

#define uhd_enable_vbus_error_interrupt()   USBC_SET_BITS(USBCON,VBERRE)
 
#define uhd_disable_vbus_error_interrupt()   USBC_CLR_BITS(USBCON,VBERRE)
 
#define Is_uhd_vbus_error_interrupt_enabled()   USBC_TST_BITS(USBCON,VBERRE)
 
#define uhd_ack_vbus_error_interrupt()   USBC_REG_CLR(USBSTA,VBERRI)
 
#define Is_uhd_vbus_error_interrupt()   USBC_TST_BITS(USBSTA,VBERRI)
 

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_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_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_BITFIELD(USBSTA,SPEED)
 
#define Is_uhd_low_speed_mode()   (USBC_RD_BITFIELD(USBSTA,SPEED) == AVR32_USBC_USBSTA_SPEED_LOW)
 
#define Is_uhd_full_speed_mode()   (USBC_RD_BITFIELD(USBSTA,SPEED) == AVR32_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_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_BITFIELD(USBSTA,SPEED) == AVR32_USBC_USBSTA_SPEED_FULL)
#define Is_uhd_high_speed_mode ( )    false

Referenced by uhd_interrupt().

#define Is_uhd_low_speed_mode ( )    (USBC_RD_BITFIELD(USBSTA,SPEED) == AVR32_USBC_USBSTA_SPEED_LOW)

Referenced by 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)

Referenced by uhd_is_suspend(), and uhd_resume().

#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_vbus_enabled ( )    USBC_TST_BITS(USBSTA,VBUSRQ)

Tests if VBus activation has been requested.

#define Is_uhd_vbus_error_interrupt ( )    USBC_TST_BITS(USBSTA,VBERRI)

Referenced by uhd_interrupt().

#define Is_uhd_vbus_error_interrupt_enabled ( )    USBC_TST_BITS(USBCON,VBERRE)
#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 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_vbus_error_interrupt ( )    USBC_REG_CLR(USBSTA,VBERRI)

Referenced by uhd_interrupt().

#define uhd_ack_wakeup ( )    USBC_REG_CLR(UHINT,HWUPI)
#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_vbus ( )    USBC_REG_CLR(USBSTA,VBUSRQ)

Requests VBus deactivation.

Referenced by uhd_disable().

#define uhd_disable_vbus_error_hw_control ( )    USBC_SET_BITS(USBCON,VBUSHWC)

Disables hardware control of USB_VBOF output pin when a Vbus error occur.

#define uhd_disable_vbus_error_interrupt ( )    USBC_CLR_BITS(USBCON,VBERRE)
#define uhd_disable_wakeup_interrupt ( )    USBC_REG_CLR(UHINTE,HWUPIE)
#define uhd_enable_connection_int ( )    USBC_REG_SET(UHINTE,DCONNIE)

Referenced by 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)
#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)
#define uhd_enable_upstream_resume_interrupt ( )    USBC_REG_SET(UHINTE,RXRSMIE)
#define uhd_enable_vbus ( )    USBC_REG_SET(USBSTA,VBUSRQ)

Requests VBus activation.

Referenced by uhd_enable(), and uhd_interrupt().

#define uhd_enable_vbus_error_hw_control ( )    USBC_CLR_BITS(USBCON,VBUSHWC)
#define uhd_enable_vbus_error_interrupt ( )    USBC_SET_BITS(USBCON,VBERRE)
#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.
#define uhd_get_frame_position ( )    USBC_RD_BITFIELD(UHFNUM,FLENHIGH)

Referenced by uhd_sof_interrupt().

#define uhd_get_microsof_number ( )
Value:
(Rd_bitfield(AVR32_USBC.uhfnum, \
AVR32_USBC_UHFNUM_FNUM_MASK|AVR32_USBC_UHFNUM_MFNUM_MASK))
#define Rd_bitfield(value, mask)
Reads the bit-field of a value specified by a given bit-mask.
Definition: compiler.h:507

Referenced by uhd_get_microframe_number().

#define uhd_get_pipe_max_nbr ( )
Value:
(((USBC_RD_BITFIELD(UFEATURES_EPT_NBR,MAX) - 1) \
& ((1 << AVR32_USBC_UFEATURES_EPT_NBR_MAX_SIZE) - 1)) + 1)
#define USBC_RD_BITFIELD(reg, bit)
Definition: usbc_otg.h:58
#define MAX(a, b)
Definition: jpegint.h:267
#define uhd_get_sof_number ( )    USBC_RD_BITFIELD(UHFNUM,FNUM)

Referenced by uhd_get_frame_number().

#define uhd_get_speed_mode ( )    USBC_RD_BITFIELD(USBSTA,SPEED)

Referenced by uhd_get_speed().

#define uhd_output_vbof_pin ( )
Value:
{\
(AVR32_GPIO.port[USB_VBOF_PIN >> 5].pmr0s = 1 << (USB_VBOF_PIN & 0x1F)) :\
(AVR32_GPIO.port[USB_VBOF_PIN >> 5].pmr0c = 1 << (USB_VBOF_PIN & 0x1F)); \
(AVR32_GPIO.port[USB_VBOF_PIN >> 5].pmr1s = 1 << (USB_VBOF_PIN & 0x1F)) :\
(AVR32_GPIO.port[USB_VBOF_PIN >> 5].pmr1c = 1 << (USB_VBOF_PIN & 0x1F)); \
AVR32_GPIO.port[USB_VBOF_PIN >> 5].gperc = 1 << (USB_VBOF_PIN & 0x1F);\
AVR32_GPIO.port[USB_VBOF_PIN >> 5].odmerc = 1 << (USB_VBOF_PIN & 0x1F);\
AVR32_GPIO.port[USB_VBOF_PIN >> 5].puerc = 1 << (USB_VBOF_PIN & 0x1F); }
#define USB_VBOF_FUNCTION
Definition: usbc_host.h:84
#define Tst_bits(value, mask)
Tests the bits of a value specified by a given bit-mask.
Definition: compiler.h:471
#define USB_VBOF_PIN
Pin and function for USB_VBOF according to configuration from USB_VBOF.
Definition: usbc_host.h:83

Output USB_VBOF onto its pin.

Referenced by uhd_enable().

#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_set_vbof_active_high ( )    USBC_CLR_BITS(USBCON,VBUSPO)

Set USB_VBOF output pin polarity.

Referenced by uhd_enable().

#define uhd_set_vbof_active_low ( )    USBC_SET_BITS(USBCON,VBUSPO)

Referenced by uhd_enable().

#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 USB_VBOF_FUNCTION   ATPASTE2(USB_VBOF, _FUNCTION)
#define USB_VBOF_PIN   ATPASTE2(USB_VBOF, _PIN)

Pin and function for USB_VBOF according to configuration from USB_VBOF.