Microchip® Advanced Software Framework

usbb_otg.h File Reference

USBB OTG Driver header file.

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

#include "compiler.h"
#include "preprocessor.h"

Macros

#define USBB_CLR_BITS(reg, bit)
 
#define USBB_RD_BITFIELD(reg, bit)
 
#define USBB_REG_CLR(reg, bit)
 
#define USBB_REG_SET(reg, bit)
 
#define USBB_SET_BITS(reg, bit)
 
#define USBB_TST_BITS(reg, bit)
 
#define USBB_WR_BITFIELD(reg, bit, value)
 
USBB IP properties

These macros give access to IP properties

#define otg_get_ip_name()   (((uint64_t)AVR32_USBB.uname2<<32)|(uint64_t)AVR32_USBB.uname1)
 Get IP name part 1 or 2. More...
 
#define otg_data_memory_barrier()   (AVR32_USBB.uvers)
 Instruction to access at a peripheral register after interrupt clear, see AVR32002 - AVR32UC Technical reference $6.6 Memory barriers. More...
 
#define otg_get_ip_version()   USBB_RD_BITFIELD(UVERS,VERSION_NUM)
 Get IP version. More...
 
#define otg_get_dpram_size()   (128 << USBB_RD_BITFIELD(UFEATURES,FIFO_MAX_SIZE))
 Get DPRAM size (FIFO maximal size) in bytes. More...
 
#define otg_get_ip_paddress_size()   (AVR32_USBB.uaddrsize)
 Get size of USBB PB address space. More...
 
USBB OTG ID pin management

The ID pin come from the USB OTG connector (A and B receptable) and allows to select the USB mode host or device.

The USBB hardware can manage it automatically. This feature is optional. When otg_ID_PIN equals true in conf_usb_host.h, the USB_ID must be defined in board.h.

#define OTG_ID_PIN   ATPASTE2(USB_ID, _PIN)
 Pin and function for OTG_ID according to configuration from USB_ID. More...
 
#define OTG_ID_FUNCTION   ATPASTE2(USB_ID, _FUNCTION)
 
#define otg_input_id_pin()
 Input USB_ID from its pin. More...
 
#define otg_enable_id_pin()   USBB_SET_BITS(USBCON,UIDE)
 
#define otg_disable_id_pin()   USBB_CLR_BITS(USBCON,UIDE)
 
#define otg_force_device_mode()   USBB_SET_BITS(USBCON,UIMOD)
 
#define Is_otg_device_mode_forced()   USBB_TST_BITS(USBCON,UIMOD)
 
#define otg_force_host_mode()   USBB_CLR_BITS(USBCON,UIMOD)
 
#define Is_otg_host_mode_forced()   (!Is_otg_device_mode_forced())
 
USBB OTG ID pin interrupt management

These macros manage the ID pin interrupt

#define otg_enable_id_interrupt()   USBB_SET_BITS(USBCON,IDTE)
 
#define otg_disable_id_interrupt()   USBB_CLR_BITS(USBCON,IDTE)
 
#define Is_otg_id_interrupt_enabled()   USBB_TST_BITS(USBCON,IDTE)
 
#define Is_otg_id_device()   USBB_TST_BITS(USBSTA,ID)
 
#define Is_otg_id_host()   (!Is_otg_id_device())
 
#define otg_ack_id_transition()   USBB_REG_CLR(USBSTA,IDTI)
 
#define Is_otg_id_transition()   USBB_TST_BITS(USBSTA,IDTI)
 
USBB OTG Vbus management
#define otg_enable_vbus_interrupt()   USBB_SET_BITS(USBCON,VBUSTE)
 
#define otg_disable_vbus_interrupt()   USBB_CLR_BITS(USBCON,VBUSTE)
 
#define Is_otg_vbus_interrupt_enabled()   USBB_TST_BITS(USBCON,VBUSTE)
 
#define Is_otg_vbus_high()   USBB_TST_BITS(USBSTA,VBUS)
 
#define Is_otg_vbus_low()   (!Is_otg_vbus_high())
 
#define otg_ack_vbus_transition()   USBB_REG_CLR(USBSTA,VBUSTI)
 
#define otg_raise_vbus_transition()   USBB_REG_SET(USBSTA,VBUSTI)
 
#define Is_otg_vbus_transition()   USBB_TST_BITS(USBSTA,VBUSTI)
 
USBB OTG main management

These macros allows to enable/disable pad and USBB hardware

#define otg_enable()   USBB_SET_BITS(USBCON,USBE)
 
#define otg_disable()   USBB_CLR_BITS(USBCON,USBE)
 
#define otg_enable_pad()   USBB_SET_BITS(USBCON,OTGPADE)
 
#define otg_disable_pad()   USBB_CLR_BITS(USBCON,OTGPADE)
 
#define Is_otg_clock_usable()   USBB_TST_BITS(USBSTA,CLKUSABLE)
 Check USB interface clock usable. More...
 
#define otg_freeze_clock()   USBB_SET_BITS(USBCON,FRZCLK)
 
#define otg_unfreeze_clock()   USBB_CLR_BITS(USBCON, FRZCLK)
 
#define Is_otg_clock_frozen()   USBB_TST_BITS(USBCON,FRZCLK)
 
USBB OTG hardware protocol

These macros manages the hardware OTG protocol

#define otg_configure_timeout(timer, timeout)
 Configure time-out of specified OTG timer. More...
 
#define otg_get_timeout(timer)
 Get configured time-out of specified OTG timer. More...
 
#define otg_get_fsm_drd_state()   USBB_RD_BITFIELD(USBFSM,DRDSTATE)
 Get the dual-role device state of the internal USB finite state machine of the USBB controller. More...
 
#define otg_device_initiate_hnp()   USBB_SET_BITS(USBCON,HNPREQ)
 Host negotiation Protocol. More...
 
#define otg_host_accept_hnp()   USBB_SET_BITS(USBCON,HNPREQ)
 
#define otg_host_reject_hnp()   USBB_CLR_BITS(USBCON,HNPREQ)
 
#define Is_otg_hnp()   USBB_TST_BITS(USBCON,HNPREQ)
 
#define otg_enable_hnp_error_interrupt()   USBB_SET_BITS(USBCON,HNPERRE)
 
#define otg_disable_hnp_error_interrupt()   USBB_CLR_BITS(USBCON,HNPERRE)
 
#define Is_otg_hnp_error_interrupt_enabled()   USBB_TST_BITS(USBCON,HNPERRE)
 
#define otg_ack_hnp_error_interrupt()   USBB_REG_CLR(USBSTA,HNPERRI)
 
#define Is_otg_hnp_error_interrupt()   USBB_TST_BITS(USBSTA,HNPERRI)
 
#define otg_device_initiate_srp()   USBB_SET_BITS(USBCON,SRPREQ)
 Session Request Protocol. More...
 
#define Is_otg_device_srp()   USBB_TST_BITS(USBCON,SRPREQ)
 
#define otg_select_vbus_srp_method()   USBB_SET_BITS(USBCON,SRPSEL)
 
#define Is_otg_vbus_srp_method_selected()   USBB_TST_BITS(USBCON,SRPSEL)
 
#define otg_select_data_srp_method()   USBB_CLR_BITS(USBCON,SRPSEL)
 
#define otg_enable_srp_interrupt()   USBB_SET_BITS(USBCON,SRPE)
 
#define otg_disable_srp_interrupt()   USBB_CLR_BITS(USBCON,SRPE)
 
#define Is_otg_srp_interrupt_enabled()   USBB_TST_BITS(USBCON,SRPE)
 
#define otg_ack_srp_interrupt()   USBB_REG_CLR(USBSTA,SRPI)
 
#define Is_otg_srp_interrupt()   USBB_TST_BITS(USBSTA,SRPI)
 
#define otg_enable_role_exchange_interrupt()   USBB_SET_BITS(USBCON,ROLEEXE)
 Role exchange interrupt. More...
 
#define otg_disable_role_exchange_interrupt()   USBB_CLR_BITS(USBCON,ROLEEXE)
 
#define Is_otg_role_exchange_interrupt_enabled()   USBB_TST_BITS(USBCON,ROLEEXE)
 
#define otg_ack_role_exchange_interrupt()   USBB_REG_CLR(USBSTA,ROLEEXI)
 
#define Is_otg_role_exchange_interrupt()   USBB_TST_BITS(USBSTA,ROLEEXI)
 
#define otg_enable_bconnection_error_interrupt()   USBB_SET_BITS(USBCON,BCERRE)
 B-device connection error The B-device connection must occur before 100ms after Vbus enable. More...
 
#define otg_disable_bconnection_error_interrupt()   USBB_CLR_BITS(USBCON,BCERRE)
 
#define Is_otg_bconnection_error_interrupt_enabled()   USBB_TST_BITS(USBCON,BCERRE)
 
#define otg_ack_bconnection_error_interrupt()   USBB_REG_CLR(USBSTA,BCERRI)
 
#define Is_otg_bconnection_error_interrupt()   USBB_TST_BITS(USBSTA,BCERRI)
 
#define otg_enable_suspend_time_out_interrupt()   USBB_SET_BITS(USBCON,STOE)
 Suspend time out The B-device must move in host mode before 200ms after a suspend state. More...
 
#define otg_disable_suspend_time_out_interrupt()   USBB_CLR_BITS(USBCON,STOE)
 
#define Is_otg_suspend_time_out_interrupt_enabled()   USBB_TST_BITS(USBCON,STOE)
 
#define otg_ack_suspend_time_out_interrupt()   USBB_REG_CLR(USBSTA,STOI)
 
#define Is_otg_suspend_time_out_interrupt()   USBB_TST_BITS(USBSTA,STOI)
 

Functions

void otg_dual_disable (void)
 Uninitialize the dual role This function is implemented in usbb_host.c file. More...
 
bool otg_dual_enable (void)
 Initialize the dual role This function is implemented in usbb_host.c file. More...
 

#define Is_otg_bconnection_error_interrupt ( )    USBB_TST_BITS(USBSTA,BCERRI)
#define Is_otg_bconnection_error_interrupt_enabled ( )    USBB_TST_BITS(USBCON,BCERRE)
#define Is_otg_clock_frozen ( )    USBB_TST_BITS(USBCON,FRZCLK)

Referenced by udd_enable().

#define Is_otg_clock_usable ( )    USBB_TST_BITS(USBSTA,CLKUSABLE)

Check USB interface clock usable.

Referenced by if(), and udd_attach().

#define Is_otg_device_srp ( )    USBB_TST_BITS(USBCON,SRPREQ)
#define Is_otg_hnp ( )    USBB_TST_BITS(USBCON,HNPREQ)
#define Is_otg_hnp_error_interrupt ( )    USBB_TST_BITS(USBSTA,HNPERRI)
#define Is_otg_hnp_error_interrupt_enabled ( )    USBB_TST_BITS(USBCON,HNPERRE)
#define Is_otg_role_exchange_interrupt ( )    USBB_TST_BITS(USBSTA,ROLEEXI)
#define Is_otg_role_exchange_interrupt_enabled ( )    USBB_TST_BITS(USBCON,ROLEEXE)
#define Is_otg_srp_interrupt ( )    USBB_TST_BITS(USBSTA,SRPI)
#define Is_otg_srp_interrupt_enabled ( )    USBB_TST_BITS(USBCON,SRPE)
#define Is_otg_suspend_time_out_interrupt ( )    USBB_TST_BITS(USBSTA,STOI)
#define Is_otg_suspend_time_out_interrupt_enabled ( )    USBB_TST_BITS(USBCON,STOE)
#define Is_otg_vbus_high ( )    USBB_TST_BITS(USBSTA,VBUS)

Referenced by if(), and udd_enable().

#define Is_otg_vbus_interrupt_enabled ( )    USBB_TST_BITS(USBCON,VBUSTE)
#define Is_otg_vbus_low ( )    (!Is_otg_vbus_high())
#define Is_otg_vbus_srp_method_selected ( )    USBB_TST_BITS(USBCON,SRPSEL)
#define Is_otg_vbus_transition ( )    USBB_TST_BITS(USBSTA,VBUSTI)
#define otg_ack_bconnection_error_interrupt ( )    USBB_REG_CLR(USBSTA,BCERRI)
#define otg_ack_hnp_error_interrupt ( )    USBB_REG_CLR(USBSTA,HNPERRI)
#define otg_ack_role_exchange_interrupt ( )    USBB_REG_CLR(USBSTA,ROLEEXI)
#define otg_ack_srp_interrupt ( )    USBB_REG_CLR(USBSTA,SRPI)
#define otg_ack_suspend_time_out_interrupt ( )    USBB_REG_CLR(USBSTA,STOI)
#define otg_ack_vbus_transition ( )    USBB_REG_CLR(USBSTA,VBUSTI)

Referenced by if(), and udd_enable().

#define otg_configure_timeout (   timer,
  timeout 
)
Value:
(USBB_SET_BITS(USBCON,UNLOCK),\
USBB_WR_BITFIELD(USBCON,TIMPAGE, timer),\
USBB_WR_BITFIELD(USBCON,TIMVALUE, timeout),\
USBB_CLR_BITS(USBCON,UNLOCK))
#define USBB_WR_BITFIELD(reg, bit, value)
Definition: usbb_otg.h:56
#define USBB_CLR_BITS(reg, bit)
Definition: usbb_otg.h:44
#define USBB_SET_BITS(reg, bit)
Definition: usbb_otg.h:47

Configure time-out of specified OTG timer.

#define otg_device_initiate_hnp ( )    USBB_SET_BITS(USBCON,HNPREQ)

Host negotiation Protocol.

#define otg_device_initiate_srp ( )    USBB_SET_BITS(USBCON,SRPREQ)

Session Request Protocol.

#define otg_disable ( )    USBB_CLR_BITS(USBCON,USBE)

Referenced by udd_disable().

#define otg_disable_bconnection_error_interrupt ( )    USBB_CLR_BITS(USBCON,BCERRE)
#define otg_disable_hnp_error_interrupt ( )    USBB_CLR_BITS(USBCON,HNPERRE)
#define otg_disable_pad ( )    USBB_CLR_BITS(USBCON,OTGPADE)

Referenced by udd_disable().

#define otg_disable_role_exchange_interrupt ( )    USBB_CLR_BITS(USBCON,ROLEEXE)
#define otg_disable_srp_interrupt ( )    USBB_CLR_BITS(USBCON,SRPE)
#define otg_disable_suspend_time_out_interrupt ( )    USBB_CLR_BITS(USBCON,STOE)
#define otg_disable_vbus_interrupt ( )    USBB_CLR_BITS(USBCON,VBUSTE)
#define otg_enable ( )    USBB_SET_BITS(USBCON,USBE)

Referenced by udd_enable().

#define otg_enable_bconnection_error_interrupt ( )    USBB_SET_BITS(USBCON,BCERRE)

B-device connection error The B-device connection must occur before 100ms after Vbus enable.

#define otg_enable_hnp_error_interrupt ( )    USBB_SET_BITS(USBCON,HNPERRE)
#define otg_enable_pad ( )    USBB_SET_BITS(USBCON,OTGPADE)

Referenced by udd_enable().

#define otg_enable_role_exchange_interrupt ( )    USBB_SET_BITS(USBCON,ROLEEXE)

Role exchange interrupt.

#define otg_enable_srp_interrupt ( )    USBB_SET_BITS(USBCON,SRPE)
#define otg_enable_suspend_time_out_interrupt ( )    USBB_SET_BITS(USBCON,STOE)

Suspend time out The B-device must move in host mode before 200ms after a suspend state.

#define otg_enable_vbus_interrupt ( )    USBB_SET_BITS(USBCON,VBUSTE)

Referenced by udd_enable().

#define otg_freeze_clock ( )    USBB_SET_BITS(USBCON,FRZCLK)

Referenced by if(), udd_attach(), udd_detach(), and udd_enable().

#define otg_get_fsm_drd_state ( )    USBB_RD_BITFIELD(USBFSM,DRDSTATE)

Get the dual-role device state of the internal USB finite state machine of the USBB controller.

#define otg_get_timeout (   timer)
Value:
(USBB_SET_BITS(USBCON,UNLOCK),\
USBB_WR_BITFIELD(USBCON,TIMPAGE, timer),\
USBB_CLR_BITS(USBCON,UNLOCK),\
USBB_RD_BITFIELD(USBCON,TIMVALUE))
#define USBB_WR_BITFIELD(reg, bit, value)
Definition: usbb_otg.h:56
#define USBB_CLR_BITS(reg, bit)
Definition: usbb_otg.h:44
#define USBB_RD_BITFIELD(reg, bit)
Definition: usbb_otg.h:53
#define USBB_SET_BITS(reg, bit)
Definition: usbb_otg.h:47

Get configured time-out of specified OTG timer.

#define otg_host_accept_hnp ( )    USBB_SET_BITS(USBCON,HNPREQ)
#define otg_host_reject_hnp ( )    USBB_CLR_BITS(USBCON,HNPREQ)
#define otg_raise_vbus_transition ( )    USBB_REG_SET(USBSTA,VBUSTI)

Referenced by udd_enable().

#define otg_select_data_srp_method ( )    USBB_CLR_BITS(USBCON,SRPSEL)
#define otg_select_vbus_srp_method ( )    USBB_SET_BITS(USBCON,SRPSEL)
#define otg_unfreeze_clock ( )    USBB_CLR_BITS(USBCON, FRZCLK)
#define USBB_CLR_BITS (   reg,
  bit 
)
Value:
(Clr_bits(*(volatile unsigned long*)(&AVR32_USBB.reg),\
TPASTE5(AVR32_USBB_,reg,_,bit,_MASK)))
#define Clr_bits(lvalue, mask)
Clears the bits of a C lvalue specified by a given bit-mask.
Definition: compiler.h:480
#define TPASTE5(a, b, c, d, e)
Definition: tpaste.h:64
#define USBB_RD_BITFIELD (   reg,
  bit 
)
Value:
(Rd_bitfield(*(volatile unsigned long*)(&AVR32_USBB.reg),\
TPASTE5(AVR32_USBB_,reg,_,bit,_MASK)))
#define Rd_bitfield(value, mask)
Reads the bit-field of a value specified by a given bit-mask.
Definition: compiler.h:507
#define TPASTE5(a, b, c, d, e)
Definition: tpaste.h:64
#define USBB_REG_CLR (   reg,
  bit 
)
Value:
((*(volatile unsigned long*)(&AVR32_USBB.TPASTE2(reg,CLR)) =\
TPASTE5(AVR32_USBB_,reg,CLR_,bit,C_MASK)))
#define TPASTE5(a, b, c, d, e)
Definition: tpaste.h:64
#define USBB_REG_SET (   reg,
  bit 
)
Value:
((*(volatile unsigned long*)(&AVR32_USBB.TPASTE2(reg,SET)) =\
TPASTE5(AVR32_USBB_,reg,SET_,bit,S_MASK)))
#define TPASTE5(a, b, c, d, e)
Definition: tpaste.h:64
#define USBB_SET_BITS (   reg,
  bit 
)
Value:
(Set_bits(*(volatile unsigned long*)(&AVR32_USBB.reg),\
TPASTE5(AVR32_USBB_,reg,_,bit,_MASK)))
#define Set_bits(lvalue, mask)
Sets the bits of a C lvalue specified by a given bit-mask.
Definition: compiler.h:489
#define TPASTE5(a, b, c, d, e)
Definition: tpaste.h:64
#define USBB_TST_BITS (   reg,
  bit 
)
Value:
(Tst_bits(*(volatile unsigned long*)(&AVR32_USBB.reg),\
TPASTE5(AVR32_USBB_,reg,_,bit,_MASK)))
#define TPASTE5(a, b, c, d, e)
Definition: tpaste.h:64
#define Tst_bits(value, mask)
Tests the bits of a value specified by a given bit-mask.
Definition: compiler.h:471
#define USBB_WR_BITFIELD (   reg,
  bit,
  value 
)
Value:
(Wr_bitfield(*(volatile unsigned long*)(&AVR32_USBB.reg),\
TPASTE5(AVR32_USBB_,reg,_,bit,_MASK),value))
#define Wr_bitfield(lvalue, mask, bitfield)
Writes the bit-field of a C lvalue specified by a given bit-mask.
Definition: compiler.h:517
#define TPASTE5(a, b, c, d, e)
Definition: tpaste.h:64