Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Xmega USB Device Driver

USBC 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 (USB_INTLVL_x_gc) by default USB_INTLVL_LO_gc (recommended).

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:

mode management

The Sleep modes authorized :

The USB_SLEEP_MODE_USB_IDLE equals SLEEPMGR_IDLE.

The USB_SLEEP_MODE_USB_SUSPEND depends on USB clock startup timing: | Clock Startup | Sleep mode authorized | | >10ms | SLEEPMGR_STDBY | | <=10ms | SLEEPMGR_PDOWN |

Data Structures

struct  udd_ep_job_t
 Structure definition about job registered on an endpoint. More...
 
struct  udd_sram_data
 USB SRAM data about fifo, endpoint descriptor table and frame number. More...
 

Functions

 ISR (USB_BUSEVENT_vect)
 Function called by USB bus event interrupt. More...
 
 ISR (USB_TRNCOMPL_vect)
 Function called by USB transfer complete interrupt. More...
 
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...
 
void udd_ep_abort (udd_ep_id_t ep)
 Aborts transfer on going on endpoint. More...
 
bool udd_ep_alloc (udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize)
 Configures and enables an endpoint. More...
 
bool udd_ep_clear_halt (udd_ep_id_t ep)
 Clear the halted state of the endpoint ep. More...
 
void udd_ep_free (udd_ep_id_t ep)
 Disables an endpoint. More...
 
static UDD_EP_tudd_ep_get_ctrl (udd_ep_id_t ep)
 
static void udd_ep_init (udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize)
 
bool udd_ep_is_halted (udd_ep_id_t ep)
 Check if the endpoint ep is halted. More...
 
bool udd_ep_run (udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback)
 Allows to receive or send data on an endpoint. More...
 
bool udd_ep_set_halt (udd_ep_id_t ep)
 Set the halted state of the endpoint ep. More...
 
bool udd_ep_wait_stall_clear (udd_ep_id_t ep, udd_callback_halt_cleared_t callback)
 Registers a callback to call when endpoint halt is cleared. 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...
 
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 USBC_SLEEP_MODE_USB_SUSPEND   SLEEPMGR_PDOWN
 Definition of sleep levels. More...
 
#define USBC_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.

 udd_ctrl_ep_state_t
 
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 uint8_t udd_ctrl_buffer [USB_DEVICE_EP_CTRL_SIZE]
 Buffer to store the data received on control endpoint (SETUP/OUT endpoint 0) 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 It is used to detect a DATA phase stopped by the host via a ZLP request. More...
 
static void udd_ctrl_overflow (void)
 Managed overflow event of OUT packet on control endpoint It is used to detect a DATA phase stopped by the host via a ZLP request. 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_error (void)
 Sub interrupt routine to manage error on control endpoint. More...
 
static bool udd_ctrl_interrupt_tc_setup (void)
 Sub interrupt routine to manage a SETUP transfer complete on control endpoint. More...
 

Management of bulk/interrupt/isochronous endpoints

The UDD manages the data transfer on endpoints:

  • Start data transfer on endpoint with USB Device DMA
  • Send a ZLP packet if requested
  • Call callback registered to signal end of transfer The transfer abort and stall feature are supported.
static udd_ep_job_t udd_ep_job [USB_DEVICE_MAX_EP *2]
 Array to register a job on bulk/interrupt/isochronous endpoint. More...
 
static uint8_t udd_ep_out_cache_buffer [USB_DEVICE_MAX_EP][64]
 Buffer to store the data received on bulk/interrupt endpoints. More...
 
bool udd_ep_is_valid (udd_ep_id_t ep)
 Checks endpoint number. More...
 
static void udd_ep_trans_complet (udd_ep_id_t ep)
 Manages transfer complete on bulk/interrupt/isochronous endpoints. More...
 
static uint16_t udd_ep_get_size (UDD_EP_t *ep_ctrl)
 Returns the size of endpoint. More...
 
static udd_ep_job_tudd_ep_get_job (udd_ep_id_t ep)
 Returns a pointer on endpoint job corresponding at endpoint number. More...
 

USB Device main management

static void usb_pad_init (void)
 Initializes the USB DP/DM buffers. More...
 
#define udd_enable_interface()   (USB_CTRLA |= USB_ENABLE_bm)
 
#define udd_disable_interface()   (USB_CTRLA &= ~USB_ENABLE_bm)
 
#define udd_attach_device()   (USB_CTRLB |= USB_ATTACH_bm)
 
#define udd_detach_device()   (USB_CTRLB &= ~USB_ATTACH_bm)
 
#define udd_gnak_disable()   (USB_CTRLB &= ~USB_GNACK_bm)
 
#define udd_gnak_enable()   (USB_CTRLB |= USB_GNACK_bm)
 
#define udd_gnak_is_enable()   (USB_CTRLB & USB_GNACK_bm)
 
#define udd_set_nb_max_ep(n)   (USB_CTRLA |= n)
 
#define udd_enable_store_frame_number()   (USB_CTRLA |= USB_STFRNUM_bm)
 
#define udd_disable_store_frame_number()   (USB_CTRLA &= ~USB_STFRNUM_bm)
 
#define udd_set_full_speed()   (USB_CTRLA |= USB_SPEED_bm)
 
#define udd_set_low_speed()   (USB_CTRLA &= ~USB_SPEED_bm)
 
#define udd_set_ep_table_addr(n)   (USB.EPPTR = (uint16_t)n)
 
#define udd_get_ep_table_addr()   (USB.EPPTR)
 
#define udd_get_fifo_rp()   (USB_FIFORP)
 
#define udd_reset_fifo()   (USB_FIFORP=0xFF)
 
#define udd_enable_interrupt(level)   (USB_INTCTRLA |= level&(USB_INTLVL1_bm|USB_INTLVL0_bm))
 
#define udd_set_device_address(n)   (USB_ADDR=n)
 
#define udd_get_device_address()   (USB_ADDR)
 
#define udd_enable_fifo()   (USB_CTRLA |= USB_FIFOEN_bm)
 
#define udd_disable_fifo()   (USB_CTRLA &= ~USB_FIFOEN_bm)
 
#define udd_send_remote_wake_up()   (USB_CTRLB &= ~USB_RWAKEUP_bm, USB_CTRLB |= USB_RWAKEUP_bm)
 
#define udd_set_global_nack()   (USB_CTRLB |= USB_GNACK_bm)
 
#define udd_is_crc_event()   (USB_INTFLAGSASET & USB_CRCIF_bm ? true : false)
 
#define udd_ack_crc_event()   (USB_INTFLAGSACLR = USB_CRCIF_bm)
 
#define udd_set_crc_event()   (USB_INTFLAGSASET = USB_CRCIF_bm)
 
#define udd_enable_crc_interrupt()   (USB_INTCTRLA |= USB_CRCIE_bm)
 
#define udd_disable_crc_interrupt()   (USB_INTCTRLA &= ~USB_CRCIE_bm)
 
#define udd_is_start_of_frame_event()   (USB_INTFLAGSASET & USB_SOFIF_bm ? true : false)
 
#define udd_ack_start_of_frame_event()   (USB_INTFLAGSACLR = USB_SOFIF_bm)
 
#define udd_set_start_of_frame_event()   (USB_INTFLAGSASET = USB_SOFIF_bm)
 
#define udd_enable_start_of_frame_interrupt()   (USB_INTCTRLA |= USB_SOFIE_bm)
 
#define udd_disable_start_of_frame_interrupt()   (USB_INTCTRLA &= ~USB_SOFIE_bm)
 
#define udd_is_enable_start_of_frame_interrupt()   (0!=(USB_INTCTRLA|USB_SOFIE_bm))
 
#define udd_is_reset_event()   (USB_INTFLAGSASET & USB_RSTIF_bm ? true : false)
 
#define udd_ack_reset_event()   (USB_INTFLAGSACLR = USB_RSTIF_bm)
 
#define udd_set_reset_event()   (USB_INTFLAGSASET = USB_RSTIF_bm)
 
#define udd_is_suspend_event()   (USB_INTFLAGSASET & USB_SUSPENDIF_bm ? true : false)
 
#define udd_ack_suspend_event()   (USB_INTFLAGSACLR = USB_SUSPENDIF_bm)
 
#define udd_set_suspend_event()   (USB_INTFLAGSASET = USB_SUSPENDIF_bm)
 
#define udd_is_resume_event()   (USB_INTFLAGSASET & USB_RESUMEIF_bm ? true : false)
 
#define udd_ack_resume_event()   (USB_INTFLAGSACLR = USB_RESUMEIF_bm)
 
#define udd_set_resume_event()   (USB_INTFLAGSASET = USB_RESUMEIF_bm)
 
#define udd_enable_busevt_interrupt()   (USB_INTCTRLA |= USB_BUSEVIE_bm)
 
#define udd_disable_busevt_interrupt()   (USB_INTCTRLA &= ~USB_BUSEVIE_bm)
 
#define udd_is_setup_event()   (USB_INTFLAGSBCLR & USB_SETUPIF_bm ? true : false)
 
#define udd_ack_setup_event()   (USB_INTFLAGSBCLR = USB_SETUPIF_bm)
 
#define udd_set_setup_event()   (USB_INTFLAGSBSET = USB_SETUPIF_bm)
 
#define udd_enable_setup_interrupt()   (USB_INTCTRLB |= USB_SETUPIE_bm)
 
#define udd_disable_setup_interrupt()   (USB_INTCTRLB &= ~USB_SETUPIE_bm)
 
#define udd_is_tc_event()   (USB_INTFLAGSBCLR & USB_TRNIF_bm ? true : false)
 
#define udd_ack_tc_event()   (USB_INTFLAGSBCLR = USB_TRNIF_bm)
 
#define udd_set_tc_event()   (USB_INTFLAGSBSET = USB_TRNIF_bm)
 
#define udd_enable_tc_interrupt()   (USB_INTCTRLB |= USB_TRNIE_bm)
 
#define udd_disable_tc_interrupt()   (USB_INTCTRLB &= ~USB_TRNIE_bm)
 
#define udd_is_overflow_event()   (USB_INTFLAGSASET & USB_OVFIF_bm ? true : false)
 
#define udd_ack_overflow_event()   (USB_INTFLAGSACLR = USB_OVFIF_bm)
 
#define udd_set_overflow_event()   (USB_INTFLAGSASET = USB_OVFIF_bm)
 
#define udd_enable_overflow_interrupt()   (USB_INTCTRLA |= USB_BUSERRIE_bm)
 
#define udd_disable_overflow_interrupt()   (USB_INTCTRLA &= ~USB_BUSERRIE_bm)
 
#define udd_is_enable_overflow_interrupt()   (USB_INTCTRLA&USB_BUSERRIE_bm ? true : false)
 
#define udd_is_underflow_event()   (USB_INTFLAGSASET & USB_UNFIF_bm ? true : false)
 
#define udd_ack_underflow_event()   (USB_INTFLAGSACLR = USB_UNFIF_bm)
 
#define udd_set_underflow_event()   (USB_INTFLAGSASET = USB_UNFIF_bm)
 
#define udd_enable_underflow_interrupt()   (USB_INTCTRLA |= USB_BUSERRIE_bm)
 
#define udd_disable_underflow_interrupt()   (USB_INTCTRLA &= ~USB_BUSERRIE_bm)
 
#define udd_is_enable_underflow_interrupt()   (USB_INTCTRLA&USB_BUSERRIE_bm ? true : false)
 
#define udd_is_stall_event()   (USB_INTFLAGSASET & USB_STALLIF_bm ? true : false)
 
#define udd_ack_stall_event()   (USB_INTFLAGSACLR = USB_STALLIF_bm)
 
#define udd_set_stall_event()   (USB_INTFLAGSASET = USB_STALLIF_bm)
 
#define udd_enable_stall_interrupt()   (USB_INTCTRLA |= USB_STALLIE_bm)
 
#define udd_disable_stall_interrupt()   (USB_INTCTRLA &= ~USB_STALLIE_bm)
 
#define udd_is_enable_stall_interrupt()   (USB_INTCTRLA&USB_STALLIE_bm ? true : false)
 

USB Device read/modify/write management

#define LACR16(addr, msk)
 
#define LASR16(addr, msk)
 
#define XCHR16(addr, msk)
 
#define LATR16(addr, msk)
 

USB Device endpoints table management

#define udd_endpoint_set_control(ep_ctrl, val)   (ep_ctrl->CTRL=val)
 
#define udd_endpoint_get_control(ep_ctrl)   (ep_ctrl->CTRL)
 
#define udd_endpoint_disable(ep_ctrl)   udd_endpoint_set_control(ep_ctrl,0)
 
#define udd_endpoint_is_enable(ep_ctrl)   (USB_EP_TYPE_DISABLE_gc!=udd_endpoint_get_type(ep_ctrl))
 
#define udd_endpoint_enable_stall(ep_ctrl)   (ep_ctrl->CTRL |= USB_EP_STALL_bm)
 
#define udd_endpoint_disable_stall(ep_ctrl)   (ep_ctrl->CTRL &= ~USB_EP_STALL_bm)
 
#define udd_endpoint_is_stall(ep_ctrl)   (ep_ctrl->CTRL &USB_EP_STALL_bm ? true : false)
 
#define udd_endpoint_set_multipacket(ep_ctrl)   (ep_ctrl->CTRL |= USB_EP_MULTIPKT_bm)
 
#define udd_endpoint_TC_int_disable(ep_ctrl)   (ep_ctrl->CTRL |= USB_EP_INTDSBL_bm)
 
#define udd_endpoint_set_pingpong(ep_ctrl)   (ep_ctrl->CTRL |= USB_EP_PINGPONG_bm)
 
#define udd_endpoint_get_size_field(ep_ctrl)   (ep_ctrl->CTRL & USB_EP_BUFSIZE_gm)
 
#define udd_endpoint_get_type(ep_ctrl)   (ep_ctrl->CTRL & USB_EP_TYPE_gm)
 
#define udd_endpoint_get_status(ep_ctrl)   (ep_ctrl->STATUS)
 
#define udd_endpoint_clear_status(ep_ctrl)   (ep_ctrl->STATUS=USB_EP_BUSNACK0_bm|USB_EP_BUSNACK1_bm)
 
#define udd_endpoint_setup_received(ep_ctrl)   (ep_ctrl->STATUS&USB_EP_SETUP_bm ? true : false)
 
#define udd_endpoint_ack_setup_received(ep_ctrl)   LACR16(&ep_ctrl->STATUS, USB_EP_SETUP_bm)
 
#define udd_endpoint_transfer_complete(ep_ctrl)   (ep_ctrl->STATUS&USB_EP_TRNCOMPL0_bm ? true : false)
 
#define udd_endpoint_ack_transfer_complete(ep_ctrl)   LACR16(&(ep_ctrl->STATUS), USB_EP_TRNCOMPL0_bm)
 
#define udd_endpoint_transfer_complete_bank0(ep_ctrl)   (ep_ctrl->STATUS&USB_EP_TRNCOMPL0_bm ? true : false)
 
#define udd_endpoint_ack_transfer_complete_bankO(ep_ctrl)   LACR16(&ep_ctrl->STATUS, USB_EP_TRNCOMPL0_bm)
 
#define udd_endpoint_transfer_complete_bank1(ep_ctrl)   (ep_ctrl->STATUS&USB_EP_SETUP_bm ? true : false)
 
#define udd_endpoint_ack_transfer_complete_bank1(ep_ctrl)   LACR16(&ep_ctrl->STATUS, USB_EP_SETUP_bm)
 
#define udd_endpoint_get_bank(ep_ctrl)   (ep_ctrl->STATUS & USB_EP_BANK_bm ? true : false)
 
#define udd_endpoint_set_bank(ep_ctrl)   LASR16(&ep_ctrl->STATUS, USB_EP_BANK_bm)
 
#define udd_endpoint_clear_bank(ep_ctrl)   LACR16(&ep_ctrl->STATUS, USB_EP_BANK_bm)
 
#define udd_endpoint_set_dtgl(ep_ctrl)   LASR16(&ep_ctrl->STATUS,USB_EP_TOGGLE_bm)
 
#define udd_endpoint_clear_dtgl(ep_ctrl)   LACR16(&ep_ctrl->STATUS, USB_EP_TOGGLE_bm )
 
#define udd_endpoint_get_dtgl(ep_ctrl)   ((ep_ctrl->STATUS)&USB_EP_TOGGLE_bm ? true : false)
 
#define udd_endpoint_toggle_dtgl(ep_ctrl)   LATR16(&ep_ctrl->STATUS, USB_EP_TOGGLE_bm)
 
#define udd_endpoint_set_NACK0(ep_ctrl)   LASR16(&ep_ctrl->STATUS,USB_EP_BUSNACK0_bm)
 
#define udd_endpoint_set_NACK1(ep_ctrl)   LASR16(&ep_ctrl->STATUS,USB_EP_BUSNACK1_bm)
 
#define udd_endpoint_clear_NACK0(ep_ctrl)   LACR16(&ep_ctrl->STATUS, USB_EP_BUSNACK0_bm)
 
#define udd_endpoint_clear_NACK1(ep_ctrl)   LACR16(&ep_ctrl->STATUS, USB_EP_BUSNACK1_bm)
 
#define udd_endpoint_get_NACK1(ep_ctrl)   ((ep_ctrl->STATUS&USB_EP_BUSNACK1_bm) ? true : false)
 
#define udd_endpoint_get_NACK0(ep_ctrl)   ((ep_ctrl->STATUS&USB_EP_BUSNACK0_bm) ? true : false)
 
#define udd_endpoint_overflow(ep_ctrl)   (ep_ctrl->STATUS&USB_EP_OVF_bm ? true : false)
 
#define udd_endpoint_underflow(ep_ctrl)   (ep_ctrl->STATUS&USB_EP_UNF_bm ? true : false)
 
#define UDD_ENDPOINT_MAX_TRANS   (0x3FF)
 
#define udd_endpoint_out_nb_receiv(ep_ctrl)   (ep_ctrl->CNT)
 
#define udd_endpoint_out_reset_nb_received(ep_ctrl)   (ep_ctrl->CNT = 0)
 
#define udd_endpoint_in_set_bytecnt(ep_ctrl, n)   (ep_ctrl->CNT = n)
 
#define udd_endpoint_set_azlp(ep_ctrl)   (ep_ctrl->CNT |= 0x8000)
 
#define udd_endpoint_clear_azlp(ep_ctrl)   (ep_ctrl->CNT &= ~0x8000)
 
#define udd_endpoint_set_buf(ep_ctrl, buf)   (ep_ctrl->DATAPTR = (uint16_t) buf)
 
#define udd_endpoint_in_nb_sent(ep_ctrl)   (ep_ctrl->AUXDATA)
 
#define udd_endpoint_in_reset_nb_sent(ep_ctrl)   (ep_ctrl->AUXDATA = 0)
 
#define udd_endpoint_out_set_nbbyte(ep_ctrl, nb)   (ep_ctrl->AUXDATA = nb)
 
#define udd_endpoint_out_get_nbbyte_requested(ep_ctrl)   (ep_ctrl->AUXDATA)
 
#define udd_endpoint_set_aux(ep_ctrl, buf)   (ep_ctrl->AUXDATA = (uint16_t) buf)
 

USB Device endpoint control setup field management

#define udd_control_setup()   (udd_sram.ep_ctrl[0].STATUS&USB_EP_SETUP_bm ? true : false)
 
#define udd_control_ack_setup()   LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_SETUP_bm)
 

USB Device endpoint control OUT field management

#define udd_control_out_is_enable_stall()   (udd_sram.ep_ctrl[0].CTRL&USB_EP_STALL_bm ? true : false)
 
#define udd_control_out_enable_stall()   LASR16(&udd_sram.ep_ctrl[0].CTRL,USB_EP_STALL_bm)
 
#define udd_control_out_disable_stall()   LACR16(&udd_sram.ep_ctrl[0].CTRL,USB_EP_STALL_bm)
 
#define udd_control_out_is_stalled()   (udd_sram.ep_ctrl[0].STATUS&USB_EP_STALLF_bm ? true : false)
 
#define udd_control_out_ack_stall()   LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_STALLF_bm)
 
#define udd_control_out_set_NACK0()   LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_BUSNACK0_bm)
 
#define udd_control_out_clear_NACK0()   LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_BUSNACK0_bm)
 
#define udd_control_out_overflow()   (udd_sram.ep_ctrl[0].STATUS&USB_EP_OVF_bm ? true : false)
 
#define udd_control_ack_out_overflow()   LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_OVF_bm)
 
#define udd_control_out_tc()   (udd_sram.ep_ctrl[0].STATUS&USB_EP_TRNCOMPL0_bm ? true : false)
 
#define udd_control_out_ack_tc()   LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TRNCOMPL0_bm)
 
#define udd_control_out_set_tc()   LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TRNCOMPL0_bm)
 
#define udd_control_out_dt_get()   (udd_sram.ep_ctrl[0].STATUS&USB_EP_TOGGLE_bm ? true : false)
 
#define udd_control_out_dt_set()   LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm )
 
#define udd_control_out_dt_clear()   LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm )
 
#define udd_control_out_dt_toggle()   LATR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm)
 
#define udd_control_out_set_buf(buf)   (udd_sram.ep_ctrl[0].DATAPTR = (uint16_t) buf)
 
#define udd_control_out_get_bytecnt()   (udd_sram.ep_ctrl[0].CNT)
 

USB Device endpoint control IN field management

#define udd_control_in_is_enable_stall()   (udd_sram.ep_ctrl[1].CTRL&USB_EP_STALL_bm ? true : false)
 
#define udd_control_in_enable_stall()   LASR16(&udd_sram.ep_ctrl[1].CTRL,USB_EP_STALL_bm)
 
#define udd_control_in_disable_stall()   LACR16(&udd_sram.ep_ctrl[1].CTRL,USB_EP_STALL_bm)
 
#define udd_control_in_is_stalled()   (udd_sram.ep_ctrl[1].STATUS&USB_EP_STALLF_bm ? true : false)
 
#define udd_control_in_ack_stall()   LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_STALLF_bm)
 
#define udd_control_in_set_NACK0()   LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_BUSNACK0_bm)
 
#define udd_control_in_clear_NACK0()   LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_BUSNACK0_bm)
 
#define udd_control_in_underflow()   (udd_sram.ep_ctrl[1].STATUS&USB_EP_UNF_bm ? true : false)
 
#define udd_control_ack_in_underflow()   LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_UNF_bm)
 
#define udd_control_in_tc()   (udd_sram.ep_ctrl[1].STATUS&USB_EP_TRNCOMPL0_bm ? true : false)
 
#define udd_control_in_ack_tc()   LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TRNCOMPL0_bm)
 
#define udd_control_in_set_tc()   LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TRNCOMPL0_bm)
 
#define udd_control_in_dt_get()   (udd_sram.ep_ctrl[1].STATUS&USB_EP_TOGGLE_bm ? true : false)
 
#define udd_control_in_dt_set()   LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm )
 
#define udd_control_in_dt_clear()   LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm )
 
#define udd_control_in_dt_toggle()   LATR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm)
 
#define udd_control_in_set_buf(buf)   (udd_sram.ep_ctrl[1].DATAPTR = (uint16_t) buf)
 
#define udd_control_in_set_bytecnt(n)   (udd_sram.ep_ctrl[1].CNT = n)
 

#define LACR16 (   addr,
  msk 
)
Value:
__asm__ __volatile__ ( \
"ldi r16, %1" "\n\t" \
".dc.w 0x9306" "\n\t"\
::"z" (addr), "M" (msk):"r16")
#define LASR16 (   addr,
  msk 
)
Value:
__asm__ __volatile__ ( \
"ldi r16, %1" "\n\t" \
".dc.w 0x9305" "\n\t"\
::"z" (addr), "M" (msk):"r16")
#define LATR16 (   addr,
  msk 
)
Value:
__asm__ __volatile__ ( \
"ldi r16, %1" "\n\t" \
".dc.w 0x9307" "\n\t"\
::"z" (addr), "M" (msk):"r16")
#define udd_ack_crc_event ( )    (USB_INTFLAGSACLR = USB_CRCIF_bm)
#define udd_ack_overflow_event ( )    (USB_INTFLAGSACLR = USB_OVFIF_bm)
#define udd_ack_reset_event ( )    (USB_INTFLAGSACLR = USB_RSTIF_bm)

Referenced by ISR().

#define udd_ack_resume_event ( )    (USB_INTFLAGSACLR = USB_RESUMEIF_bm)

Referenced by ISR(), and udd_attach().

#define udd_ack_setup_event ( )    (USB_INTFLAGSBCLR = USB_SETUPIF_bm)
#define udd_ack_stall_event ( )    (USB_INTFLAGSACLR = USB_STALLIF_bm)
#define udd_ack_start_of_frame_event ( )    (USB_INTFLAGSACLR = USB_SOFIF_bm)

Referenced by ISR().

#define udd_ack_suspend_event ( )    (USB_INTFLAGSACLR = USB_SUSPENDIF_bm)

Referenced by ISR(), and udd_attach().

#define udd_ack_tc_event ( )    (USB_INTFLAGSBCLR = USB_TRNIF_bm)

Referenced by ISR().

#define udd_ack_underflow_event ( )    (USB_INTFLAGSACLR = USB_UNFIF_bm)
#define udd_attach_device ( )    (USB_CTRLB |= USB_ATTACH_bm)

Referenced by udd_attach().

#define udd_control_ack_in_underflow ( )    LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_UNF_bm)

Referenced by udd_ctrl_init().

#define udd_control_ack_out_overflow ( )    LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_OVF_bm)

Referenced by udd_ctrl_init().

#define udd_control_ack_setup ( )    LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_SETUP_bm)
#define udd_control_in_ack_stall ( )    LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_STALLF_bm)
#define udd_control_in_ack_tc ( )    LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TRNCOMPL0_bm)

Referenced by udd_ctrl_init().

#define udd_control_in_clear_NACK0 ( )    LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_BUSNACK0_bm)
#define udd_control_in_disable_stall ( )    LACR16(&udd_sram.ep_ctrl[1].CTRL,USB_EP_STALL_bm)
#define udd_control_in_dt_clear ( )    LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm )
#define udd_control_in_dt_get ( )    (udd_sram.ep_ctrl[1].STATUS&USB_EP_TOGGLE_bm ? true : false)
#define udd_control_in_dt_set ( )    LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm )
#define udd_control_in_dt_toggle ( )    LATR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm)
#define udd_control_in_enable_stall ( )    LASR16(&udd_sram.ep_ctrl[1].CTRL,USB_EP_STALL_bm)
#define udd_control_in_is_enable_stall ( )    (udd_sram.ep_ctrl[1].CTRL&USB_EP_STALL_bm ? true : false)
#define udd_control_in_is_stalled ( )    (udd_sram.ep_ctrl[1].STATUS&USB_EP_STALLF_bm ? true : false)
#define udd_control_in_set_buf (   buf)    (udd_sram.ep_ctrl[1].DATAPTR = (uint16_t) buf)

Referenced by udd_ctrl_in_sent().

#define udd_control_in_set_bytecnt (   n)    (udd_sram.ep_ctrl[1].CNT = n)
#define udd_control_in_set_NACK0 ( )    LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_BUSNACK0_bm)

Referenced by udd_ctrl_init().

#define udd_control_in_set_tc ( )    LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TRNCOMPL0_bm)
#define udd_control_in_tc ( )    (udd_sram.ep_ctrl[1].STATUS&USB_EP_TRNCOMPL0_bm ? true : false)
#define udd_control_in_underflow ( )    (udd_sram.ep_ctrl[1].STATUS&USB_EP_UNF_bm ? true : false)
#define udd_control_out_ack_stall ( )    LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_STALLF_bm)
#define udd_control_out_ack_tc ( )    LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TRNCOMPL0_bm)
#define udd_control_out_clear_NACK0 ( )    LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_BUSNACK0_bm)
#define udd_control_out_disable_stall ( )    LACR16(&udd_sram.ep_ctrl[0].CTRL,USB_EP_STALL_bm)
#define udd_control_out_dt_clear ( )    LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm )
#define udd_control_out_dt_get ( )    (udd_sram.ep_ctrl[0].STATUS&USB_EP_TOGGLE_bm ? true : false)
#define udd_control_out_dt_set ( )    LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm )
#define udd_control_out_dt_toggle ( )    LATR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm)
#define udd_control_out_enable_stall ( )    LASR16(&udd_sram.ep_ctrl[0].CTRL,USB_EP_STALL_bm)
#define udd_control_out_get_bytecnt ( )    (udd_sram.ep_ctrl[0].CNT)
#define udd_control_out_is_enable_stall ( )    (udd_sram.ep_ctrl[0].CTRL&USB_EP_STALL_bm ? true : false)
#define udd_control_out_is_stalled ( )    (udd_sram.ep_ctrl[0].STATUS&USB_EP_STALLF_bm ? true : false)
#define udd_control_out_overflow ( )    (udd_sram.ep_ctrl[0].STATUS&USB_EP_OVF_bm ? true : false)
#define udd_control_out_set_buf (   buf)    (udd_sram.ep_ctrl[0].DATAPTR = (uint16_t) buf)

Referenced by ISR().

#define udd_control_out_set_NACK0 ( )    LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_BUSNACK0_bm)
#define udd_control_out_set_tc ( )    LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TRNCOMPL0_bm)
#define udd_control_out_tc ( )    (udd_sram.ep_ctrl[0].STATUS&USB_EP_TRNCOMPL0_bm ? true : false)
#define udd_control_setup ( )    (udd_sram.ep_ctrl[0].STATUS&USB_EP_SETUP_bm ? true : false)
#define udd_detach_device ( )    (USB_CTRLB &= ~USB_ATTACH_bm)

Referenced by udd_detach(), and udd_disable().

#define udd_disable_busevt_interrupt ( )    (USB_INTCTRLA &= ~USB_BUSEVIE_bm)
#define udd_disable_crc_interrupt ( )    (USB_INTCTRLA &= ~USB_CRCIE_bm)
#define udd_disable_fifo ( )    (USB_CTRLA &= ~USB_FIFOEN_bm)
#define udd_disable_interface ( )    (USB_CTRLA &= ~USB_ENABLE_bm)
#define udd_disable_overflow_interrupt ( )    (USB_INTCTRLA &= ~USB_BUSERRIE_bm)

Referenced by udd_ctrl_init().

#define udd_disable_setup_interrupt ( )    (USB_INTCTRLB &= ~USB_SETUPIE_bm)
#define udd_disable_stall_interrupt ( )    (USB_INTCTRLA &= ~USB_STALLIE_bm)
#define udd_disable_start_of_frame_interrupt ( )    (USB_INTCTRLA &= ~USB_SOFIE_bm)
#define udd_disable_store_frame_number ( )    (USB_CTRLA &= ~USB_STFRNUM_bm)
#define udd_disable_tc_interrupt ( )    (USB_INTCTRLB &= ~USB_TRNIE_bm)
#define udd_disable_underflow_interrupt ( )    (USB_INTCTRLA &= ~USB_BUSERRIE_bm)

Referenced by udd_ctrl_init().

#define udd_enable_busevt_interrupt ( )    (USB_INTCTRLA |= USB_BUSEVIE_bm)

Referenced by udd_attach().

#define udd_enable_crc_interrupt ( )    (USB_INTCTRLA |= USB_CRCIE_bm)
#define udd_enable_fifo ( )    (USB_CTRLA |= USB_FIFOEN_bm)

Referenced by udd_enable().

#define udd_enable_interface ( )    (USB_CTRLA |= USB_ENABLE_bm)

Referenced by udd_enable().

#define udd_enable_interrupt (   level)    (USB_INTCTRLA |= level&(USB_INTLVL1_bm|USB_INTLVL0_bm))

Referenced by udd_enable().

#define udd_enable_overflow_interrupt ( )    (USB_INTCTRLA |= USB_BUSERRIE_bm)

Referenced by udd_ctrl_setup_received().

#define udd_enable_setup_interrupt ( )    (USB_INTCTRLB |= USB_SETUPIE_bm)

Referenced by udd_attach().

#define udd_enable_stall_interrupt ( )    (USB_INTCTRLA |= USB_STALLIE_bm)
#define udd_enable_start_of_frame_interrupt ( )    (USB_INTCTRLA |= USB_SOFIE_bm)

Referenced by udd_attach().

#define udd_enable_store_frame_number ( )    (USB_CTRLA |= USB_STFRNUM_bm)

Referenced by udd_enable().

#define udd_enable_tc_interrupt ( )    (USB_INTCTRLB |= USB_TRNIE_bm)

Referenced by udd_attach().

#define udd_enable_underflow_interrupt ( )    (USB_INTCTRLA |= USB_BUSERRIE_bm)

Referenced by udd_ctrl_setup_received().

#define udd_endpoint_ack_setup_received (   ep_ctrl)    LACR16(&ep_ctrl->STATUS, USB_EP_SETUP_bm)
#define udd_endpoint_ack_transfer_complete (   ep_ctrl)    LACR16(&(ep_ctrl->STATUS), USB_EP_TRNCOMPL0_bm)

Referenced by ISR().

#define udd_endpoint_ack_transfer_complete_bank1 (   ep_ctrl)    LACR16(&ep_ctrl->STATUS, USB_EP_SETUP_bm)
#define udd_endpoint_ack_transfer_complete_bankO (   ep_ctrl)    LACR16(&ep_ctrl->STATUS, USB_EP_TRNCOMPL0_bm)
#define udd_endpoint_clear_azlp (   ep_ctrl)    (ep_ctrl->CNT &= ~0x8000)
#define udd_endpoint_clear_bank (   ep_ctrl)    LACR16(&ep_ctrl->STATUS, USB_EP_BANK_bm)
#define udd_endpoint_clear_dtgl (   ep_ctrl)    LACR16(&ep_ctrl->STATUS, USB_EP_TOGGLE_bm )

Referenced by udd_ep_clear_halt().

#define udd_endpoint_clear_NACK0 (   ep_ctrl)    LACR16(&ep_ctrl->STATUS, USB_EP_BUSNACK0_bm)

Referenced by udd_ep_trans_complet().

#define udd_endpoint_clear_NACK1 (   ep_ctrl)    LACR16(&ep_ctrl->STATUS, USB_EP_BUSNACK1_bm)
#define udd_endpoint_clear_status (   ep_ctrl)    (ep_ctrl->STATUS=USB_EP_BUSNACK0_bm|USB_EP_BUSNACK1_bm)

Referenced by udd_ep_init().

#define udd_endpoint_disable (   ep_ctrl)    udd_endpoint_set_control(ep_ctrl,0)

Referenced by udd_ep_free(), and udd_ep_init().

#define udd_endpoint_disable_stall (   ep_ctrl)    (ep_ctrl->CTRL &= ~USB_EP_STALL_bm)

Referenced by udd_ep_clear_halt().

#define udd_endpoint_enable_stall (   ep_ctrl)    (ep_ctrl->CTRL |= USB_EP_STALL_bm)

Referenced by udd_ep_set_halt().

#define udd_endpoint_get_bank (   ep_ctrl)    (ep_ctrl->STATUS & USB_EP_BANK_bm ? true : false)
#define udd_endpoint_get_control (   ep_ctrl)    (ep_ctrl->CTRL)
#define udd_endpoint_get_dtgl (   ep_ctrl)    ((ep_ctrl->STATUS)&USB_EP_TOGGLE_bm ? true : false)
#define udd_endpoint_get_NACK0 (   ep_ctrl)    ((ep_ctrl->STATUS&USB_EP_BUSNACK0_bm) ? true : false)
#define udd_endpoint_get_NACK1 (   ep_ctrl)    ((ep_ctrl->STATUS&USB_EP_BUSNACK1_bm) ? true : false)
#define udd_endpoint_get_size_field (   ep_ctrl)    (ep_ctrl->CTRL & USB_EP_BUFSIZE_gm)

Referenced by udd_ep_alloc(), and udd_ep_get_size().

#define udd_endpoint_get_status (   ep_ctrl)    (ep_ctrl->STATUS)
#define udd_endpoint_get_type (   ep_ctrl)    (ep_ctrl->CTRL & USB_EP_TYPE_gm)

Referenced by udd_ep_alloc(), and udd_ep_run().

#define udd_endpoint_in_nb_sent (   ep_ctrl)    (ep_ctrl->AUXDATA)
#define udd_endpoint_in_reset_nb_sent (   ep_ctrl)    (ep_ctrl->AUXDATA = 0)

Referenced by udd_ep_run(), and udd_ep_trans_complet().

#define udd_endpoint_in_set_bytecnt (   ep_ctrl,
 
)    (ep_ctrl->CNT = n)

Referenced by udd_ep_trans_complet().

#define udd_endpoint_is_enable (   ep_ctrl)    (USB_EP_TYPE_DISABLE_gc!=udd_endpoint_get_type(ep_ctrl))

Referenced by udd_ep_alloc(), and udd_ep_run().

#define udd_endpoint_is_stall (   ep_ctrl)    (ep_ctrl->CTRL &USB_EP_STALL_bm ? true : false)
#define UDD_ENDPOINT_MAX_TRANS   (0x3FF)

Referenced by udd_ep_trans_complet().

#define udd_endpoint_out_get_nbbyte_requested (   ep_ctrl)    (ep_ctrl->AUXDATA)

Referenced by udd_ep_trans_complet().

#define udd_endpoint_out_nb_receiv (   ep_ctrl)    (ep_ctrl->CNT)
#define udd_endpoint_out_reset_nb_received (   ep_ctrl)    (ep_ctrl->CNT = 0)

Referenced by udd_ep_run(), and udd_ep_trans_complet().

#define udd_endpoint_out_set_nbbyte (   ep_ctrl,
  nb 
)    (ep_ctrl->AUXDATA = nb)

Referenced by udd_ep_run(), and udd_ep_trans_complet().

#define udd_endpoint_overflow (   ep_ctrl)    (ep_ctrl->STATUS&USB_EP_OVF_bm ? true : false)
#define udd_endpoint_set_aux (   ep_ctrl,
  buf 
)    (ep_ctrl->AUXDATA = (uint16_t) buf)
#define udd_endpoint_set_azlp (   ep_ctrl)    (ep_ctrl->CNT |= 0x8000)
#define udd_endpoint_set_bank (   ep_ctrl)    LASR16(&ep_ctrl->STATUS, USB_EP_BANK_bm)
#define udd_endpoint_set_buf (   ep_ctrl,
  buf 
)    (ep_ctrl->DATAPTR = (uint16_t) buf)

Referenced by udd_ep_trans_complet().

#define udd_endpoint_set_control (   ep_ctrl,
  val 
)    (ep_ctrl->CTRL=val)

Referenced by udd_ep_init().

#define udd_endpoint_set_dtgl (   ep_ctrl)    LASR16(&ep_ctrl->STATUS,USB_EP_TOGGLE_bm)
#define udd_endpoint_set_multipacket (   ep_ctrl)    (ep_ctrl->CTRL |= USB_EP_MULTIPKT_bm)

Referenced by udd_ep_alloc().

#define udd_endpoint_set_NACK0 (   ep_ctrl)    LASR16(&ep_ctrl->STATUS,USB_EP_BUSNACK0_bm)

Referenced by udd_ep_abort().

#define udd_endpoint_set_NACK1 (   ep_ctrl)    LASR16(&ep_ctrl->STATUS,USB_EP_BUSNACK1_bm)
#define udd_endpoint_set_pingpong (   ep_ctrl)    (ep_ctrl->CTRL |= USB_EP_PINGPONG_bm)
#define udd_endpoint_setup_received (   ep_ctrl)    (ep_ctrl->STATUS&USB_EP_SETUP_bm ? true : false)
#define udd_endpoint_TC_int_disable (   ep_ctrl)    (ep_ctrl->CTRL |= USB_EP_INTDSBL_bm)
#define udd_endpoint_toggle_dtgl (   ep_ctrl)    LATR16(&ep_ctrl->STATUS, USB_EP_TOGGLE_bm)
#define udd_endpoint_transfer_complete (   ep_ctrl)    (ep_ctrl->STATUS&USB_EP_TRNCOMPL0_bm ? true : false)

Referenced by ISR().

#define udd_endpoint_transfer_complete_bank0 (   ep_ctrl)    (ep_ctrl->STATUS&USB_EP_TRNCOMPL0_bm ? true : false)
#define udd_endpoint_transfer_complete_bank1 (   ep_ctrl)    (ep_ctrl->STATUS&USB_EP_SETUP_bm ? true : false)
#define udd_endpoint_underflow (   ep_ctrl)    (ep_ctrl->STATUS&USB_EP_UNF_bm ? true : false)
#define udd_get_device_address ( )    (USB_ADDR)

Referenced by udd_getaddress().

#define udd_get_ep_table_addr ( )    (USB.EPPTR)
#define udd_get_fifo_rp ( )    (USB_FIFORP)

Referenced by ISR().

#define udd_gnak_disable ( )    (USB_CTRLB &= ~USB_GNACK_bm)
#define udd_gnak_enable ( )    (USB_CTRLB |= USB_GNACK_bm)
#define udd_gnak_is_enable ( )    (USB_CTRLB & USB_GNACK_bm)
#define udd_is_crc_event ( )    (USB_INTFLAGSASET & USB_CRCIF_bm ? true : false)
#define udd_is_enable_overflow_interrupt ( )    (USB_INTCTRLA&USB_BUSERRIE_bm ? true : false)
#define udd_is_enable_stall_interrupt ( )    (USB_INTCTRLA&USB_STALLIE_bm ? true : false)
#define udd_is_enable_start_of_frame_interrupt ( )    (0!=(USB_INTCTRLA|USB_SOFIE_bm))
#define udd_is_enable_underflow_interrupt ( )    (USB_INTCTRLA&USB_BUSERRIE_bm ? true : false)
#define udd_is_overflow_event ( )    (USB_INTFLAGSASET & USB_OVFIF_bm ? true : false)
#define udd_is_reset_event ( )    (USB_INTFLAGSASET & USB_RSTIF_bm ? true : false)

Referenced by ISR().

#define udd_is_resume_event ( )    (USB_INTFLAGSASET & USB_RESUMEIF_bm ? true : false)

Referenced by ISR().

#define udd_is_setup_event ( )    (USB_INTFLAGSBCLR & USB_SETUPIF_bm ? true : false)
#define udd_is_stall_event ( )    (USB_INTFLAGSASET & USB_STALLIF_bm ? true : false)
#define udd_is_start_of_frame_event ( )    (USB_INTFLAGSASET & USB_SOFIF_bm ? true : false)

Referenced by ISR().

#define udd_is_suspend_event ( )    (USB_INTFLAGSASET & USB_SUSPENDIF_bm ? true : false)

Referenced by ISR().

#define udd_is_tc_event ( )    (USB_INTFLAGSBCLR & USB_TRNIF_bm ? true : false)
#define udd_is_underflow_event ( )    (USB_INTFLAGSASET & USB_UNFIF_bm ? true : false)
#define udd_reset_fifo ( )    (USB_FIFORP=0xFF)

Referenced by udd_enable().

#define udd_send_remote_wake_up ( )    (USB_CTRLB &= ~USB_RWAKEUP_bm, USB_CTRLB |= USB_RWAKEUP_bm)

Referenced by udd_send_remotewakeup().

#define udd_set_crc_event ( )    (USB_INTFLAGSASET = USB_CRCIF_bm)
#define udd_set_device_address (   n)    (USB_ADDR=n)

Referenced by ISR(), and udd_set_address().

#define udd_set_ep_table_addr (   n)    (USB.EPPTR = (uint16_t)n)

Referenced by udd_enable().

#define udd_set_full_speed ( )    (USB_CTRLA |= USB_SPEED_bm)

Referenced by udd_enable().

#define udd_set_global_nack ( )    (USB_CTRLB |= USB_GNACK_bm)
#define udd_set_low_speed ( )    (USB_CTRLA &= ~USB_SPEED_bm)

Referenced by udd_enable().

#define udd_set_nb_max_ep (   n)    (USB_CTRLA |= n)

Referenced by udd_enable().

#define udd_set_overflow_event ( )    (USB_INTFLAGSASET = USB_OVFIF_bm)
#define udd_set_reset_event ( )    (USB_INTFLAGSASET = USB_RSTIF_bm)
#define udd_set_resume_event ( )    (USB_INTFLAGSASET = USB_RESUMEIF_bm)
#define udd_set_setup_event ( )    (USB_INTFLAGSBSET = USB_SETUPIF_bm)
#define udd_set_stall_event ( )    (USB_INTFLAGSASET = USB_STALLIF_bm)
#define udd_set_start_of_frame_event ( )    (USB_INTFLAGSASET = USB_SOFIF_bm)
#define udd_set_suspend_event ( )    (USB_INTFLAGSASET = USB_SUSPENDIF_bm)
#define udd_set_tc_event ( )    (USB_INTFLAGSBSET = USB_TRNIF_bm)
#define udd_set_underflow_event ( )    (USB_INTFLAGSASET = USB_UNFIF_bm)
#define USBC_SLEEP_MODE_USB_IDLE   SLEEPMGR_IDLE

Referenced by udd_sleep_mode().

#define USBC_SLEEP_MODE_USB_SUSPEND   SLEEPMGR_PDOWN

Definition of sleep levels.

Referenced by udd_disable(), and udd_enable().

#define XCHR16 (   addr,
  msk 
)
Value:
__asm__ __volatile__ ( \
"ldi r16, %1" "\n\t" \
".dc.w 0x9304" "\n\t"\
::"z" (addr), "M" (msk):"r16")

ISR ( USB_TRNCOMPL_vect  )
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(), udd_ack_resume_event, udd_ack_suspend_event, udd_attach_device, udd_enable_busevt_interrupt, udd_enable_setup_interrupt, udd_enable_start_of_frame_interrupt, udd_enable_tc_interrupt, and udd_sleep_mode().

Referenced by udc_attach(), and udd_enable().

static void udd_ctrl_endofrequest ( void  )
static

Call callback associated to setup request.

References udd_ctrl_request_t::callback.

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

static bool udd_ctrl_interrupt_error ( void  )
static

Sub interrupt routine to manage error on control endpoint.

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

References udd_ack_overflow_event, udd_ack_underflow_event, udd_control_in_underflow, udd_control_out_overflow, udd_ctrl_overflow(), udd_ctrl_underflow(), udd_is_overflow_event, and udd_is_underflow_event.

Referenced by ISR().

static bool udd_ctrl_interrupt_tc_setup ( void  )
static

Sub interrupt routine to manage a SETUP transfer complete on control endpoint.

Returns
1 if an SETUP transfer complete about control endpoint is occurred, otherwise 0.

References Assert, udd_ack_setup_event, udd_ack_stall_event, udd_control_ack_setup, udd_control_in_ack_stall, udd_control_out_ack_stall, udd_control_setup, udd_ctrl_setup_received(), and udd_is_setup_event.

Referenced by ISR(), udd_ctrl_overflow(), and udd_ctrl_underflow().

static void udd_ctrl_overflow ( void  )
static

Managed overflow event of OUT packet on control endpoint It is used to detect a DATA phase stopped by the host via a ZLP request.

This is mandatory for chapter 8 compliance

References udd_control_in_enable_stall, udd_control_out_enable_stall, udd_ctrl_interrupt_tc_setup(), udd_ctrl_send_zlp_out(), and udd_is_tc_event.

Referenced by udd_ctrl_interrupt_error().

static void udd_ctrl_send_zlp_in ( void  )
static
static void udd_ctrl_send_zlp_out ( void  )
static

Send a ZLP OUT on control endpoint.

References udd_control_out_clear_NACK0.

Referenced by udd_ctrl_in_sent(), and udd_ctrl_overflow().

static void udd_ctrl_stall_data ( void  )
static

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

References udd_control_in_enable_stall, and udd_control_out_enable_stall.

Referenced by udd_ctrl_out_received(), and udd_ctrl_setup_received().

static void udd_ctrl_underflow ( void  )
static

Managed underflow event of IN packet on control endpoint It is used to detect a DATA phase stopped by the host via a ZLP request.

This is mandatory for chapter 8 compliance

References udd_control_in_enable_stall, udd_control_out_enable_stall, udd_ctrl_interrupt_tc_setup(), udd_ctrl_send_zlp_in(), and udd_is_tc_event.

Referenced by udd_ctrl_interrupt_error().

void udd_detach ( void  )

Detaches the device from the bus.

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

References udd_detach_device.

Referenced by udc_detach().

void udd_disable ( void  )
void udd_ep_abort ( udd_ep_id_t  ep)

Aborts transfer on going on endpoint.

If a transfer is on going, then it is stopped and the callback registered is called to signal the end of transfer. Note: The control endpoint is not authorized.

Parameters
epEndpoint to abort

References Assert, udd_ep_job_t::busy, udd_ep_job_t::call_trans, udd_endpoint_in_nb_sent, udd_endpoint_out_nb_receiv, udd_endpoint_set_NACK0, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_is_valid(), UDD_EP_t, UDD_EP_TRANSFER_ABORT, and USB_EP_DIR_IN.

Referenced by ISR(), udc_req_std_ep_set_feature(), udd_ep_free(), and udd_ep_set_halt().

bool udd_ep_alloc ( udd_ep_id_t  ep,
uint8_t  bmAttributes,
uint16_t  MaxEndpointSize 
)

Configures and enables an endpoint.

Parameters
epEndpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT).
bmAttributesAttributes of endpoint declared in the descriptor.
MaxEndpointSizeEndpoint maximum size
Returns
1 if the endpoint is enabled, otherwise 0.

References Assert, udd_endpoint_get_size_field, udd_endpoint_get_type, udd_endpoint_is_enable, udd_endpoint_set_multipacket, udd_ep_get_ctrl(), udd_ep_init(), udd_ep_is_valid(), and UDD_EP_t.

Referenced by udc_iface_enable().

bool udd_ep_clear_halt ( udd_ep_id_t  ep)

Clear the halted state of the endpoint ep.

After calling this function, any transaction on ep will be handled normally, i.e. a STALL handshake will not be sent, and the data toggle sequence will start at DATA0.

Parameters
epThe ID of the endpoint to be un-halted
Returns
1 if function was successfully done, otherwise 0.

References Assert, udd_ep_job_t::busy, udd_ep_job_t::call_nohalt, udd_endpoint_clear_dtgl, udd_endpoint_disable_stall, udd_endpoint_is_stall, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_is_valid(), and UDD_EP_t.

Referenced by udc_req_std_ep_clear_feature().

void udd_ep_free ( udd_ep_id_t  ep)

Disables an endpoint.

Parameters
epEndpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT).

References Assert, udd_endpoint_disable, udd_ep_abort(), udd_ep_get_ctrl(), udd_ep_is_valid(), and UDD_EP_t.

Referenced by udc_iface_disable().

static udd_ep_job_t * udd_ep_get_job ( udd_ep_id_t  ep)
static

Returns a pointer on endpoint job corresponding at endpoint number.

Parameters
epEndpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT).

References USB_EP_ADDR_MASK, and USB_EP_DIR_IN.

Referenced by udd_ep_abort(), udd_ep_clear_halt(), udd_ep_run(), udd_ep_trans_complet(), and udd_ep_wait_stall_clear().

static uint16_t udd_ep_get_size ( UDD_EP_t ep_ctrl)
static

Returns the size of endpoint.

Returns
the size of current selected endpoint

References udd_endpoint_get_size_field.

Referenced by udd_ep_run(), and udd_ep_trans_complet().

static void udd_ep_init ( udd_ep_id_t  ep,
uint8_t  bmAttributes,
uint16_t  MaxEndpointSize 
)
static
bool udd_ep_is_halted ( udd_ep_id_t  ep)

Check if the endpoint ep is halted.

Parameters
epThe ID of the endpoint to check.
Returns
1 if ep is halted, otherwise 0.

References Assert, udd_endpoint_is_stall, udd_ep_get_ctrl(), udd_ep_is_valid(), and UDD_EP_t.

Referenced by udc_req_std_ep_get_status().

bool udd_ep_is_valid ( udd_ep_id_t  ep)
bool udd_ep_run ( udd_ep_id_t  ep,
bool  b_shortpacket,
uint8_t *  buf,
iram_size_t  buf_size,
udd_callback_trans_t  callback 
)

Allows to receive or send data on an endpoint.

The driver uses a specific DMA USB to transfer data from internal RAM to endpoint, if this one is available. When the transfer is finished or aborted (stall, reset, ...), the callback is called. The callback returns the transfer status and eventually the number of byte transfered. Note: The control endpoint is not authorized.

Parameters
epThe ID of the endpoint to use
b_shortpacketEnabled automatic short packet
bufBuffer on Internal RAM to send or fill. It must be align, then use COMPILER_WORD_ALIGNED.
buf_sizeBuffer size to send or fill
callbackNULL or function to call at the end of transfer
Warning
About b_shortpacket, for IN endpoint it means that a short packet (or a Zero Length Packet) will be sent to the USB line to properly close the usb transfer at the end of the data transfer. For Bulk and Interrupt OUT endpoint, it will automatically stop the transfer at the end of the data transfer (received short packet).
Returns
1 if function was successfully done, otherwise 0.

References Assert, udd_ep_job_t::b_shortpacket, udd_ep_job_t::b_use_out_cache_buffer, udd_ep_job_t::buf, udd_ep_job_t::buf_size, udd_ep_job_t::busy, udd_ep_job_t::call_trans, cpu_irq_restore(), cpu_irq_save(), udd_ep_job_t::nb_trans, udd_endpoint_get_type, udd_endpoint_in_reset_nb_sent, udd_endpoint_is_enable, udd_endpoint_is_stall, udd_endpoint_out_reset_nb_received, udd_endpoint_out_set_nbbyte, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_get_size(), udd_ep_is_valid(), UDD_EP_t, udd_ep_trans_complet(), and USB_EP_DIR_IN.

Referenced by udi_cdc_ctrl_state_notify(), udi_cdc_data_received(), udi_cdc_rx_start(), and udi_cdc_tx_send().

bool udd_ep_set_halt ( udd_ep_id_t  ep)

Set the halted state of the endpoint ep.

After calling this function, any transaction on ep will result in a STALL handshake being sent. Any pending transactions will be performed first, however.

Parameters
epThe ID of the endpoint to be halted
Returns
1 if ep is halted, otherwise 0.

References Assert, udd_endpoint_enable_stall, udd_ep_abort(), udd_ep_get_ctrl(), udd_ep_is_valid(), and UDD_EP_t.

Referenced by udc_req_std_ep_set_feature().

bool udd_ep_wait_stall_clear ( udd_ep_id_t  ep,
udd_callback_halt_cleared_t  callback 
)

Registers a callback to call when endpoint halt is cleared.

Parameters
epThe ID of the endpoint to use
callbackNULL or function to call when endpoint halt is cleared
Warning
if the endpoint is not halted then the callback is called immediately.
Returns
1 if the register is accepted, otherwise 0.

References Assert, udd_ep_job_t::busy, udd_ep_job_t::call_nohalt, udd_endpoint_is_stall, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_is_valid(), and UDD_EP_t.

uint16_t udd_get_frame_number ( void  )

Returns the current start of frame number.

Returns
current start of 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.

Referenced by udi_cdc_tx_send().

uint8_t udd_getaddress ( void  )

Returns the USB address of device.

Returns
USB address

References udd_get_device_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().

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.

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 udd_b_idle, udd_send_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_set_device_address.

Referenced by udc_valid_address().

void udd_set_setup_payload ( uint8_t *  payload,
uint16_t  payload_size 
)
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 USBC_SLEEP_MODE_USB_IDLE.

Referenced by ISR(), udd_attach(), udd_disable(), and udd_send_remotewakeup().

static void usb_pad_init ( void  )
inlinestatic

Initializes the USB DP/DM buffers.

This functions initializes the USB buffer using the calibration value stored in production raw. If the calibration value is not found (0xFF) value, a default typical value is applied. Alternatively user can force calibration values using USB_PAD_USER_CAL0 and USB_PAD_USER_CAL1

References nvm_get_production_signature_row_offset, and nvm_read_production_signature_row().

Referenced by udd_enable().

bool udd_b_idle
static

State of USB line.

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

uint8_t udd_ctrl_buffer[USB_DEVICE_EP_CTRL_SIZE]
static

Buffer to store the data received on control endpoint (SETUP/OUT endpoint 0)

Used to avoid a RAM buffer overflow in case of the payload buffer is smaller than control endpoint size

udd_ctrl_ep_state_t
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(), and udd_ctrl_out_received().

uint16_t udd_ctrl_prev_payload_nb_trans
static

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

udd_ctrl_ep_state_t udd_ep_control_state
static

State of the endpoint control management.

udd_ep_job_t udd_ep_job[USB_DEVICE_MAX_EP *2]
static

Array to register a job on bulk/interrupt/isochronous endpoint.

uint8_t udd_ep_out_cache_buffer[USB_DEVICE_MAX_EP][64]
static

Buffer to store the data received on bulk/interrupt endpoints.

Used to avoid a RAM buffer overflow in case of the user buffer is smaller than endpoint size

Warning
The isochronous endpoint is not protected by this system and the user must always use a buffer corresponding at endpoint size