Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
USBB Device Driver

USBB low-level driver for USB device mode.

USBB Custom configuration

The following USBB driver configuration must be included in the conf_usb.h file of the application.

UDD_USB_INT_LEVEL
Option to change the interrupt priority (0 to 3) by default 0 (recommended).

UDD_ISOCHRONOUS_NB_BANK(ep)
Feature to reduce or increase isochronous endpoints buffering (1 to 2). Default value 2.

UDD_BULK_NB_BANK(ep)
Feature to reduce or increase bulk endpoints buffering (1 to 2). Default value 2.

UDD_INTERRUPT_NB_BANK(ep)
Feature to reduce or increase interrupt endpoints buffering (1 to 2). Default value 1.

management

The USB driver is fully managed by interrupt and does not request periodic task. Thereby, the USB events use callbacks to transfer the information. The callbacks are declared in static during compilation or in variable during code execution.

Static declarations defined in conf_usb.h:

Dynamic callbacks, called "endpoint job" , are registered in udd_ep_job_t structure via the following functions:

Power

The Sleep modes authorized :

The USBB_SLEEP_MODE_USB_IDLE equals SLEEPMGR_IDLE.

The USBB_SLEEP_MODE_USB_SUSPEND depends on USB Power mode, USB clock startup timing and USB Speed mode: | Power Mode | Speed mode | Clock Startup | Sleep mode authorized | | X | LS, FS | >10ms | SLEEPMGR_STDBY | | X | HS | >3ms | SLEEPMGR_STDBY | | Self-Power | LS, FS | <=10ms | SLEEPMGR_STOP | | Self-Power | HS | <=3ms | SLEEPMGR_STOP | | Bus-Power | LS, FS | <=10ms | SLEEPMGR_STATIC | | Bus-Power | HS | <=3ms | SLEEPMGR_STATIC |

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.

Macros

#define UDD_BULK_NB_BANK(ep)   2
 
#define UDD_BULK_NB_BANK_ERROR
 
#define UDD_EP_BULK_NB_BANK_ERROR(ep)   (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep))
 
#define UDD_EP_BULK_NBANK_ERROR(ep)   ( (UDD_BULK_NB_BANK(ep) < 1) || (UDD_BULK_NB_BANK(ep) > 2) )
 
#define UDD_EP_INT_NB_BANK_ERROR(ep)   (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep))
 
#define UDD_EP_INT_NBANK_ERROR(ep)   ( (UDD_INTERRUPT_NB_BANK(ep) < 1) || (UDD_INTERRUPT_NB_BANK(ep) > 2) )
 
#define UDD_EP_ISO_NB_BANK_ERROR(ep)   (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep))
 
#define UDD_EP_ISO_NBANK_ERROR(ep)
 
#define UDD_EP_NB_BANK_ERROR(ep, type)   (ATPASTE3(UDD_EP_, type, _NB_BANK_ERROR(ep)))
 
#define UDD_EP_USED(ep)   (USB_DEVICE_MAX_EP >= ep)
 
#define UDD_INTERRUPT_NB_BANK(ep)   1
 
#define UDD_INTERRUPT_NB_BANK_ERROR
 
#define UDD_ISO_NB_BANK_ERROR
 
#define UDD_ISOCHRONOUS_NB_BANK(ep)   2
 

Functions

void udd_attach (void)
 Attach device to the bus when possible. More...
 
void udd_detach (void)
 Detaches the device from the bus. More...
 
void udd_disable (void)
 Disables the USB Device mode. More...
 
void udd_enable (void)
 Enables the USB Device mode. More...
 
uint16_t udd_get_frame_number (void)
 Returns the current start of frame number. More...
 
uint16_t udd_get_micro_frame_number (void)
 Returns the current micro start of frame number. More...
 
uint8_t udd_getaddress (void)
 Returns the USB address of device. More...
 
bool udd_include_vbus_monitoring (void)
 Authorizes the VBUS event. More...
 
void udd_interrupt (void)
 Function called by USBB interrupt to manage USB device interrupts. More...
 
bool udd_is_high_speed (void)
 Test whether the USB Device Controller is running at high speed or not. More...
 
void udd_send_remotewakeup (void)
 The USB driver sends a resume signal called Upstream Resume. More...
 
void udd_set_address (uint8_t address)
 Changes the USB address of device. More...
 
void udd_set_setup_payload (uint8_t *payload, uint16_t payload_size)
 Load setup payload. More...
 

Power management routine.

static bool udd_b_idle
 State of USB line. More...
 
static void udd_sleep_mode (bool b_idle)
 Authorize or not the CPU powerdown mode. More...
 
#define USBB_SLEEP_MODE_USB_SUSPEND   SLEEPMGR_STATIC
 Definition of sleep levels. More...
 
#define USBB_SLEEP_MODE_USB_IDLE   SLEEPMGR_IDLE
 

Control endpoint low level management routine.

This function performs control endpoint management.

It handle the SETUP/DATA/HANDSHAKE phases of a control transaction.

enum  udd_ctrl_ep_state_t {
  UDD_EPCTRL_SETUP = 0,
  UDD_EPCTRL_DATA_OUT = 1,
  UDD_EPCTRL_DATA_IN = 2,
  UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP = 3,
  UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP = 4,
  UDD_EPCTRL_STALL_REQ = 5
}
 Bit definitions about endpoint control state machine for udd_ep_control_state. More...
 
COMPILER_WORD_ALIGNED
udd_ctrl_request_t 
udd_g_ctrlreq
 Global variable to give and record information about setup request management. More...
 
static udd_ctrl_ep_state_t udd_ep_control_state
 State of the endpoint control management. More...
 
static uint16_t udd_ctrl_prev_payload_nb_trans
 Total number of data received/sent during data packet phase with previous payload buffers. More...
 
static uint16_t udd_ctrl_payload_nb_trans
 Number of data received/sent to/from udd_g_ctrlreq.payload buffer. More...
 
static void udd_reset_ep_ctrl (void)
 Reset control endpoint. More...
 
static void udd_ctrl_init (void)
 Reset control endpoint management. More...
 
static void udd_ctrl_setup_received (void)
 Managed reception of SETUP packet on control endpoint. More...
 
static void udd_ctrl_in_sent (void)
 Managed reception of IN packet on control endpoint. More...
 
static void udd_ctrl_out_received (void)
 Managed reception of OUT packet on control endpoint. More...
 
static void udd_ctrl_underflow (void)
 Managed underflow event of IN packet on control endpoint. More...
 
static void udd_ctrl_overflow (void)
 Managed overflow event of OUT packet on control endpoint. More...
 
static void udd_ctrl_stall_data (void)
 Managed stall event of IN/OUT packet on control endpoint. More...
 
static void udd_ctrl_send_zlp_in (void)
 Send a ZLP IN on control endpoint. More...
 
static void udd_ctrl_send_zlp_out (void)
 Send a ZLP OUT on control endpoint. More...
 
static void udd_ctrl_endofrequest (void)
 Call callback associated to setup request. More...
 
static bool udd_ctrl_interrupt (void)
 Main interrupt routine for control endpoint. More...
 

USBB Device IP properties

These macros give access to IP properties

#define udd_get_endpoint_max_nbr()
 Get maximal number of endpoints. More...
 

USBB Device speeds management

#define udd_low_speed_enable()   USBB_SET_BITS(UDCON,LS)
 Enable/disable device low-speed mode. More...
 
#define udd_low_speed_disable()   USBB_CLR_BITS(UDCON,LS)
 
#define Is_udd_low_speed_enable()   USBB_TST_BITS(UDCON,LS)
 Test if device low-speed mode is forced. More...
 
#define udd_high_speed_enable()   do { } while (0)
 
#define udd_high_speed_disable()   do { } while (0)
 
#define Is_udd_full_speed_mode()   true
 

USBB device attach control

These macros manage the USBB Device attach.

#define udd_detach_device()   USBB_SET_BITS(UDCON,DETACH)
 detaches from USB bus More...
 
#define udd_attach_device()   USBB_CLR_BITS(UDCON,DETACH)
 attaches to USB bus More...
 
#define Is_udd_detached()   USBB_TST_BITS(UDCON,DETACH)
 test if the device is detached More...
 

USBB device bus events control

These macros manage the USBB Device bus events.

#define udd_initiate_remote_wake_up()   USBB_SET_BITS(UDCON,RMWKUP)
 Initiates a remote wake-up event. More...
 
#define Is_udd_pending_remote_wake_up()   USBB_TST_BITS(UDCON,RMWKUP)
 
#define udd_enable_remote_wake_up_interrupt()   USBB_REG_SET(UDINTE,UPRSME)
 Manage upstream resume event (=remote wakeup from device) The USB driver sends a resume signal called "Upstream Resume". More...
 
#define udd_disable_remote_wake_up_interrupt()   USBB_REG_CLR(UDINTE,UPRSME)
 
#define Is_udd_remote_wake_up_interrupt_enabled()   USBB_TST_BITS(UDINTE,UPRSME)
 
#define udd_ack_remote_wake_up_start()   USBB_REG_CLR(UDINT,UPRSM)
 
#define udd_raise_remote_wake_up_start()   USBB_REG_SET(UDINT,UPRSM)
 
#define Is_udd_remote_wake_up_start()   USBB_TST_BITS(UDINT,UPRSM)
 
#define udd_enable_resume_interrupt()   USBB_REG_SET(UDINTE,EORSME)
 Manage downstream resume event (=remote wakeup from host) The USB controller detects a valid "End of Resume" signal initiated by the host. More...
 
#define udd_disable_resume_interrupt()   USBB_REG_CLR(UDINTE,EORSME)
 
#define Is_udd_resume_interrupt_enabled()   USBB_TST_BITS(UDINTE,EORSME)
 
#define udd_ack_resume()   USBB_REG_CLR(UDINT,EORSM)
 
#define udd_raise_resume()   USBB_REG_SET(UDINT,EORSM)
 
#define Is_udd_resume()   USBB_TST_BITS(UDINT,EORSM)
 
#define udd_enable_wake_up_interrupt()   USBB_REG_SET(UDINTE,WAKEUPE)
 Manage wake-up event (=usb line activity) The USB controller is reactivated by a filtered non-idle signal from the lines. More...
 
#define udd_disable_wake_up_interrupt()   USBB_REG_CLR(UDINTE,WAKEUPE)
 
#define Is_udd_wake_up_interrupt_enabled()   USBB_TST_BITS(UDINTE,WAKEUPE)
 
#define udd_ack_wake_up()   USBB_REG_CLR(UDINT,WAKEUP)
 
#define udd_raise_wake_up()   USBB_REG_SET(UDINT,WAKEUP)
 
#define Is_udd_wake_up()   USBB_TST_BITS(UDINT,WAKEUP)
 
#define udd_enable_reset_interrupt()   USBB_REG_SET(UDINTE,EORSTE)
 Manage reset event Set when a USB "End of Reset" has been detected. More...
 
#define udd_disable_reset_interrupt()   USBB_REG_CLR(UDINTE,EORSTE)
 
#define Is_udd_reset_interrupt_enabled()   USBB_TST_BITS(UDINTE,EORSTE)
 
#define udd_ack_reset()   USBB_REG_CLR(UDINT,EORST)
 
#define udd_raise_reset()   USBB_REG_SET(UDINT,EORST)
 
#define Is_udd_reset()   USBB_TST_BITS(UDINT,EORST)
 
#define udd_enable_sof_interrupt()   USBB_REG_SET(UDINTE,SOFE)
 Manage start of frame event. More...
 
#define udd_disable_sof_interrupt()   USBB_REG_CLR(UDINTE,SOFE)
 
#define Is_udd_sof_interrupt_enabled()   USBB_TST_BITS(UDINTE,SOFE)
 
#define udd_ack_sof()   USBB_REG_CLR(UDINT,SOF)
 
#define udd_raise_sof()   USBB_REG_SET(UDINT,SOF)
 
#define Is_udd_sof()   USBB_TST_BITS(UDINT,SOF)
 
#define udd_frame_number()   (USBB_RD_BITFIELD(UDFNUM,FNUM))
 
#define Is_udd_frame_number_crc_error()   USBB_TST_BITS(UDFNUM,FNCERR)
 
#define udd_enable_msof_interrupt()   USBB_REG_SET(UDINTE,MSOFE)
 Manage Micro start of frame event (High Speed Only) More...
 
#define udd_disable_msof_interrupt()   USBB_REG_CLR(UDINTE,MSOFE)
 
#define Is_udd_msof_interrupt_enabled()   USBB_TST_BITS(UDINTE,MSOFE)
 
#define udd_ack_msof()   USBB_REG_CLR(UDINT,MSOF)
 
#define udd_raise_msof()   USBB_REG_SET(UDINT,MSOF)
 
#define Is_udd_msof()   USBB_TST_BITS(UDINT,MSOF)
 
#define udd_micro_frame_number()
 
#define udd_enable_suspend_interrupt()   USBB_REG_SET(UDINTE,SUSPE)
 Manage suspend event. More...
 
#define udd_disable_suspend_interrupt()   USBB_REG_CLR(UDINTE,SUSPE)
 
#define Is_udd_suspend_interrupt_enabled()   USBB_TST_BITS(UDINTE,SUSPE)
 
#define udd_ack_suspend()   USBB_REG_CLR(UDINT,SUSP)
 
#define udd_raise_suspend()   USBB_REG_SET(UDINT,SUSP)
 
#define Is_udd_suspend()   USBB_TST_BITS(UDINT,SUSP)
 

#define Is_udd_detached ( )    USBB_TST_BITS(UDCON,DETACH)

test if the device is detached

#define Is_udd_frame_number_crc_error ( )    USBB_TST_BITS(UDFNUM,FNCERR)
#define Is_udd_full_speed_mode ( )    true

Referenced by udd_interrupt(), and udd_is_high_speed().

#define Is_udd_low_speed_enable ( )    USBB_TST_BITS(UDCON,LS)

Test if device low-speed mode is forced.

#define Is_udd_msof ( )    USBB_TST_BITS(UDINT,MSOF)

Referenced by udd_interrupt().

#define Is_udd_msof_interrupt_enabled ( )    USBB_TST_BITS(UDINTE,MSOFE)
#define Is_udd_pending_remote_wake_up ( )    USBB_TST_BITS(UDCON,RMWKUP)
#define Is_udd_remote_wake_up_interrupt_enabled ( )    USBB_TST_BITS(UDINTE,UPRSME)
#define Is_udd_remote_wake_up_start ( )    USBB_TST_BITS(UDINT,UPRSM)
#define Is_udd_reset ( )    USBB_TST_BITS(UDINT,EORST)

Referenced by udd_interrupt().

#define Is_udd_reset_interrupt_enabled ( )    USBB_TST_BITS(UDINTE,EORSTE)
#define Is_udd_resume ( )    USBB_TST_BITS(UDINT,EORSM)
#define Is_udd_resume_interrupt_enabled ( )    USBB_TST_BITS(UDINTE,EORSME)
#define Is_udd_sof ( )    USBB_TST_BITS(UDINT,SOF)

Referenced by udd_interrupt().

#define Is_udd_sof_interrupt_enabled ( )    USBB_TST_BITS(UDINTE,SOFE)
#define Is_udd_suspend ( )    USBB_TST_BITS(UDINT,SUSP)

Referenced by udd_interrupt().

#define Is_udd_suspend_interrupt_enabled ( )    USBB_TST_BITS(UDINTE,SUSPE)

Referenced by udd_interrupt().

#define Is_udd_wake_up ( )    USBB_TST_BITS(UDINT,WAKEUP)

Referenced by udd_interrupt().

#define Is_udd_wake_up_interrupt_enabled ( )    USBB_TST_BITS(UDINTE,WAKEUPE)

Referenced by udd_interrupt().

#define udd_ack_msof ( )    USBB_REG_CLR(UDINT,MSOF)

Referenced by udd_attach(), and udd_interrupt().

#define udd_ack_remote_wake_up_start ( )    USBB_REG_CLR(UDINT,UPRSM)
#define udd_ack_reset ( )    USBB_REG_CLR(UDINT,EORST)

Referenced by udd_attach(), and udd_interrupt().

#define udd_ack_resume ( )    USBB_REG_CLR(UDINT,EORSM)
#define udd_ack_sof ( )    USBB_REG_CLR(UDINT,SOF)

Referenced by udd_attach(), and udd_interrupt().

#define udd_ack_suspend ( )    USBB_REG_CLR(UDINT,SUSP)

Referenced by udd_attach().

#define udd_ack_wake_up ( )    USBB_REG_CLR(UDINT,WAKEUP)

Referenced by udd_attach().

#define udd_attach_device ( )    USBB_CLR_BITS(UDCON,DETACH)

attaches to USB bus

Referenced by udd_attach().

#define UDD_BULK_NB_BANK (   ep)    2
#define UDD_BULK_NB_BANK_ERROR
Value:
( UDD_EP_NB_BANK_ERROR( 1, BULK) \
|| UDD_EP_NB_BANK_ERROR( 2, BULK) \
|| UDD_EP_NB_BANK_ERROR( 3, BULK) \
|| UDD_EP_NB_BANK_ERROR( 4, BULK) \
|| UDD_EP_NB_BANK_ERROR( 5, BULK) \
|| UDD_EP_NB_BANK_ERROR( 6, BULK) \
|| UDD_EP_NB_BANK_ERROR( 7, BULK) \
|| UDD_EP_NB_BANK_ERROR( 8, BULK) \
|| UDD_EP_NB_BANK_ERROR( 9, BULK) \
|| UDD_EP_NB_BANK_ERROR(10, BULK) \
|| UDD_EP_NB_BANK_ERROR(11, BULK) \
|| UDD_EP_NB_BANK_ERROR(12, BULK) \
|| UDD_EP_NB_BANK_ERROR(13, BULK) \
|| UDD_EP_NB_BANK_ERROR(14, BULK) \
|| UDD_EP_NB_BANK_ERROR(15, BULK) )
#define UDD_EP_NB_BANK_ERROR(ep, type)
Definition: usbb_device.c:171
#define udd_detach_device ( )    USBB_SET_BITS(UDCON,DETACH)

detaches from USB bus

Referenced by udd_detach().

#define udd_disable_msof_interrupt ( )    USBB_REG_CLR(UDINTE,MSOFE)
#define udd_disable_remote_wake_up_interrupt ( )    USBB_REG_CLR(UDINTE,UPRSME)
#define udd_disable_reset_interrupt ( )    USBB_REG_CLR(UDINTE,EORSTE)
#define udd_disable_resume_interrupt ( )    USBB_REG_CLR(UDINTE,EORSME)
#define udd_disable_sof_interrupt ( )    USBB_REG_CLR(UDINTE,SOFE)
#define udd_disable_suspend_interrupt ( )    USBB_REG_CLR(UDINTE,SUSPE)

Referenced by udd_interrupt().

#define udd_disable_wake_up_interrupt ( )    USBB_REG_CLR(UDINTE,WAKEUPE)

Referenced by udd_interrupt().

#define udd_enable_msof_interrupt ( )    USBB_REG_SET(UDINTE,MSOFE)

Manage Micro start of frame event (High Speed Only)

Referenced by udd_attach().

#define udd_enable_remote_wake_up_interrupt ( )    USBB_REG_SET(UDINTE,UPRSME)

Manage upstream resume event (=remote wakeup from device) The USB driver sends a resume signal called "Upstream Resume".

#define udd_enable_reset_interrupt ( )    USBB_REG_SET(UDINTE,EORSTE)

Manage reset event Set when a USB "End of Reset" has been detected.

Referenced by udd_attach().

#define udd_enable_resume_interrupt ( )    USBB_REG_SET(UDINTE,EORSME)

Manage downstream resume event (=remote wakeup from host) The USB controller detects a valid "End of Resume" signal initiated by the host.

#define udd_enable_sof_interrupt ( )    USBB_REG_SET(UDINTE,SOFE)

Manage start of frame event.

Referenced by udd_attach().

#define udd_enable_suspend_interrupt ( )    USBB_REG_SET(UDINTE,SUSPE)

Manage suspend event.

Referenced by udd_attach(), and udd_interrupt().

#define udd_enable_wake_up_interrupt ( )    USBB_REG_SET(UDINTE,WAKEUPE)

Manage wake-up event (=usb line activity) The USB controller is reactivated by a filtered non-idle signal from the lines.

Referenced by udd_attach(), and udd_interrupt().

#define UDD_EP_BULK_NB_BANK_ERROR (   ep)    (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep))
#define UDD_EP_BULK_NBANK_ERROR (   ep)    ( (UDD_BULK_NB_BANK(ep) < 1) || (UDD_BULK_NB_BANK(ep) > 2) )
#define UDD_EP_INT_NB_BANK_ERROR (   ep)    (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep))
#define UDD_EP_INT_NBANK_ERROR (   ep)    ( (UDD_INTERRUPT_NB_BANK(ep) < 1) || (UDD_INTERRUPT_NB_BANK(ep) > 2) )
#define UDD_EP_ISO_NB_BANK_ERROR (   ep)    (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep))
#define UDD_EP_ISO_NBANK_ERROR (   ep)
Value:
|| (UDD_ISOCHRONOUS_NB_BANK(ep) > 2) )
#define UDD_ISOCHRONOUS_NB_BANK(ep)
Definition: usbb_device.c:224
#define UDD_EP_NB_BANK_ERROR (   ep,
  type 
)    (ATPASTE3(UDD_EP_, type, _NB_BANK_ERROR(ep)))
#define UDD_EP_USED (   ep)    (USB_DEVICE_MAX_EP >= ep)
#define udd_frame_number ( )    (USBB_RD_BITFIELD(UDFNUM,FNUM))

Referenced by udd_get_frame_number().

#define udd_get_endpoint_max_nbr ( )
Value:
(((USBB_RD_BITFIELD(UFEATURES_EPT_NBR,MAX) - 1) \
& ((1 << AVR32_USBB_UFEATURES_EPT_NBR_MAX_SIZE) - 1)) + 1)
#define USBB_RD_BITFIELD(reg, bit)
Definition: usbb_otg.h:60
#define MAX(a, b)
Definition: jpegint.h:267

Get maximal number of endpoints.

#define udd_high_speed_disable ( )    do { } while (0)

Referenced by udd_enable().

#define udd_high_speed_enable ( )    do { } while (0)

Referenced by udd_enable().

#define udd_initiate_remote_wake_up ( )    USBB_SET_BITS(UDCON,RMWKUP)

Initiates a remote wake-up event.

Referenced by udd_send_remotewakeup().

#define UDD_INTERRUPT_NB_BANK (   ep)    1
#define UDD_INTERRUPT_NB_BANK_ERROR
Value:
|| UDD_EP_NB_BANK_ERROR( 2, INT) \
|| UDD_EP_NB_BANK_ERROR( 3, INT) \
|| UDD_EP_NB_BANK_ERROR( 4, INT) \
|| UDD_EP_NB_BANK_ERROR( 5, INT) \
|| UDD_EP_NB_BANK_ERROR( 6, INT) \
|| UDD_EP_NB_BANK_ERROR( 7, INT) \
|| UDD_EP_NB_BANK_ERROR( 8, INT) \
|| UDD_EP_NB_BANK_ERROR( 9, INT) \
|| UDD_EP_NB_BANK_ERROR(10, INT) \
|| UDD_EP_NB_BANK_ERROR(11, INT) \
|| UDD_EP_NB_BANK_ERROR(12, INT) \
|| UDD_EP_NB_BANK_ERROR(13, INT) \
|| UDD_EP_NB_BANK_ERROR(14, INT) \
|| UDD_EP_NB_BANK_ERROR(15, INT) )
#define UDD_EP_NB_BANK_ERROR(ep, type)
Definition: usbb_device.c:171
#define UDD_ISO_NB_BANK_ERROR
Value:
|| UDD_EP_NB_BANK_ERROR( 2, ISO) \
|| UDD_EP_NB_BANK_ERROR( 3, ISO) \
|| UDD_EP_NB_BANK_ERROR( 4, ISO) \
|| UDD_EP_NB_BANK_ERROR( 5, ISO) \
|| UDD_EP_NB_BANK_ERROR( 6, ISO) \
|| UDD_EP_NB_BANK_ERROR( 7, ISO) \
|| UDD_EP_NB_BANK_ERROR( 8, ISO) \
|| UDD_EP_NB_BANK_ERROR( 9, ISO) \
|| UDD_EP_NB_BANK_ERROR(10, ISO) \
|| UDD_EP_NB_BANK_ERROR(11, ISO) \
|| UDD_EP_NB_BANK_ERROR(12, ISO) \
|| UDD_EP_NB_BANK_ERROR(13, ISO) \
|| UDD_EP_NB_BANK_ERROR(14, ISO) \
|| UDD_EP_NB_BANK_ERROR(15, ISO) )
#define UDD_EP_NB_BANK_ERROR(ep, type)
Definition: usbb_device.c:171
#define UDD_ISOCHRONOUS_NB_BANK (   ep)    2
#define udd_low_speed_disable ( )    USBB_CLR_BITS(UDCON,LS)

Referenced by udd_enable().

#define udd_low_speed_enable ( )    USBB_SET_BITS(UDCON,LS)

Enable/disable device low-speed mode.

Referenced by udd_enable().

#define udd_micro_frame_number ( )
Value:
(Rd_bitfield(AVR32_USBB.udfnum, \
(AVR32_USBB_UDFNUM_FNUM_MASK|AVR32_USBB_UDFNUM_MFNUM_MASK)))
#define Rd_bitfield(value, mask)
Reads the bit-field of a value specified by a given bit-mask.
Definition: compiler.h:514

Referenced by udd_get_micro_frame_number().

#define udd_raise_msof ( )    USBB_REG_SET(UDINT,MSOF)
#define udd_raise_remote_wake_up_start ( )    USBB_REG_SET(UDINT,UPRSM)
#define udd_raise_reset ( )    USBB_REG_SET(UDINT,EORST)
#define udd_raise_resume ( )    USBB_REG_SET(UDINT,EORSM)
#define udd_raise_sof ( )    USBB_REG_SET(UDINT,SOF)
#define udd_raise_suspend ( )    USBB_REG_SET(UDINT,SUSP)

Referenced by udd_attach().

#define udd_raise_wake_up ( )    USBB_REG_SET(UDINT,WAKEUP)
#define USBB_SLEEP_MODE_USB_IDLE   SLEEPMGR_IDLE

Referenced by udd_sleep_mode().

#define USBB_SLEEP_MODE_USB_SUSPEND   SLEEPMGR_STATIC

Definition of sleep levels.

Referenced by udd_disable(), and udd_enable().

Bit definitions about endpoint control state machine for udd_ep_control_state.

Enumerator
UDD_EPCTRL_SETUP 

Wait a SETUP packet.

UDD_EPCTRL_DATA_OUT 

Wait a OUT data packet.

UDD_EPCTRL_DATA_IN 

Wait a IN data packet.

UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP 

Wait a IN ZLP packet.

UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP 

Wait a OUT ZLP packet.

UDD_EPCTRL_STALL_REQ 

STALL enabled on IN & OUT packet.

void udd_attach ( void  )

Attach device to the bus when possible.

Warning
If a VBus control is included in driver, then it will attach device when an acceptable Vbus level from the host is detected.

References cpu_irq_restore(), cpu_irq_save(), Is_otg_clock_usable, otg_freeze_clock, otg_unfreeze_clock, udd_ack_msof, udd_ack_reset, udd_ack_sof, udd_ack_suspend, udd_ack_wake_up, udd_attach_device, udd_enable_msof_interrupt, udd_enable_reset_interrupt, udd_enable_sof_interrupt, udd_enable_suspend_interrupt, udd_enable_wake_up_interrupt, udd_raise_suspend, and udd_sleep_mode().

Referenced by udc_attach(), and udd_interrupt().

static void udd_ctrl_endofrequest ( void  )
static

Call callback associated to setup request.

References udd_ctrl_request_t::callback, and udd_g_ctrlreq.

Referenced by udd_ctrl_in_sent(), udd_ctrl_out_received(), and udd_ctrl_setup_received().

static void udd_ctrl_init ( void  )
static
static bool udd_ctrl_interrupt ( void  )
static

Main interrupt routine for control endpoint.

This switches control endpoint events to correct sub function.

Returns
1 if an event about control endpoint is occurred, otherwise 0.

References Is_udd_endpoint_interrupt, Is_udd_in_send, Is_udd_in_send_interrupt_enabled, Is_udd_nak_in, Is_udd_nak_out, Is_udd_out_received, Is_udd_setup_received, udd_ack_nak_in, udd_ack_nak_out, udd_ctrl_in_sent(), udd_ctrl_out_received(), udd_ctrl_overflow(), udd_ctrl_setup_received(), udd_ctrl_underflow(), udd_disable_nak_in_interrupt, and udd_disable_nak_out_interrupt.

Referenced by udd_interrupt().

static void udd_ctrl_overflow ( void  )
static

Managed overflow event of OUT packet on control endpoint.

References Is_udd_in_send, udd_enable_stall_handshake, udd_ep_control_state, and UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP.

Referenced by udd_ctrl_interrupt().

static void udd_ctrl_send_zlp_out ( void  )
static
static void udd_ctrl_stall_data ( void  )
static

Managed stall event of IN/OUT packet on control endpoint.

References udd_enable_stall_handshake, udd_ep_control_state, and UDD_EPCTRL_STALL_REQ.

Referenced by udd_ctrl_out_received(), and udd_ctrl_setup_received().

static void udd_ctrl_underflow ( void  )
static
void udd_detach ( void  )

Detaches the device from the bus.

The driver must remove pull-up on USB line D- or D+.

References otg_freeze_clock, otg_unfreeze_clock, udd_detach_device, and udd_sleep_mode().

Referenced by udc_detach(), udd_disable(), and udd_interrupt().

uint16_t udd_get_frame_number ( void  )

Returns the current start of frame number.

Returns
current start of frame number.

References udd_frame_number.

Referenced by main_sof_action(), and udi_cdc_tx_send().

uint16_t udd_get_micro_frame_number ( void  )

Returns the current micro start of frame number.

Returns
current micro start of frame number required in high speed mode.

References udd_micro_frame_number.

Referenced by udi_cdc_tx_send().

uint8_t udd_getaddress ( void  )

Returns the USB address of device.

Returns
USB address

References udd_get_configured_address.

Referenced by udc_req_std_dev_set_configuration().

bool udd_include_vbus_monitoring ( void  )

Authorizes the VBUS event.

Returns
true, if the VBUS monitoring is possible.

Referenced by udc_include_vbus_monitoring().

void udd_interrupt ( void  )

Function called by USBB interrupt to manage USB device interrupts.

USB Device interrupt events are split in three parts:

  • USB line events (SOF, reset, suspend, resume, wakeup)
  • control endpoint events (setup reception, end of data transfer, underflow, overflow, stall)
  • bulk/interrupt/isochronous endpoints events (end of data transfer)

Note: Here, the global interrupt mask is not clear when an USB interrupt is enabled because this one can not be occurred during the USB ISR (=during INTX is masked). See Technical reference $3.8.3 Masking interrupt requests in peripheral modules.

References Is_otg_clock_usable, Is_otg_vbus_high, Is_otg_vbus_transition, Is_udd_full_speed_mode, Is_udd_msof, Is_udd_reset, Is_udd_sof, Is_udd_suspend, Is_udd_suspend_interrupt_enabled, Is_udd_wake_up, Is_udd_wake_up_interrupt_enabled, otg_ack_vbus_transition, otg_data_memory_barrier, otg_freeze_clock, otg_unfreeze_clock, pdTRUE, udc_reset(), UDC_RESUME_EVENT, UDC_SOF_EVENT, udc_sof_notify(), UDC_SUSPEND_EVENT, UDC_VBUS_EVENT, udd_ack_msof, udd_ack_reset, udd_ack_sof, udd_attach(), udd_ctrl_init(), udd_ctrl_interrupt(), udd_detach(), udd_disable_suspend_interrupt, udd_disable_wake_up_interrupt, udd_enable_suspend_interrupt, udd_enable_wake_up_interrupt, udd_reset_ep_ctrl(), and udd_sleep_mode().

Referenced by ISR(), and udd_enable().

bool udd_is_high_speed ( void  )

Test whether the USB Device Controller is running at high speed or not.

Returns
true if the Device is running at high speed mode, otherwise false.

References Is_udd_full_speed_mode.

Referenced by udc_req_std_dev_get_descriptor(), udc_req_std_dev_set_configuration(), udc_req_std_dev_set_feature(), and udi_cdc_tx_send().

void udd_send_remotewakeup ( void  )

The USB driver sends a resume signal called Upstream Resume.

References otg_unfreeze_clock, udd_b_idle, udd_initiate_remote_wake_up, and udd_sleep_mode().

Referenced by udc_remotewakeup().

void udd_set_address ( uint8_t  address)

Changes the USB address of device.

Parameters
addressNew USB address

References udd_configure_address, udd_disable_address, and udd_enable_address.

Referenced by udc_valid_address().

static void udd_sleep_mode ( bool  b_idle)
static

Authorize or not the CPU powerdown mode.

Parameters
b_enabletrue to authorize powerdown mode

References sleepmgr_lock_mode(), sleepmgr_unlock_mode(), udd_b_idle, and USBB_SLEEP_MODE_USB_IDLE.

Referenced by udd_attach(), udd_detach(), udd_interrupt(), and udd_send_remotewakeup().

bool udd_b_idle
static

State of USB line.

Referenced by udd_enable(), udd_send_remotewakeup(), and udd_sleep_mode().

uint16_t udd_ctrl_payload_nb_trans
static

Number of data received/sent to/from udd_g_ctrlreq.payload buffer.

Referenced by udd_ctrl_in_sent(), udd_ctrl_out_received(), and udd_ctrl_setup_received().

uint16_t udd_ctrl_prev_payload_nb_trans
static

Total number of data received/sent during data packet phase with previous payload buffers.

Referenced by udd_ctrl_in_sent(), udd_ctrl_out_received(), and udd_ctrl_setup_received().