Atmel Software Framework

usbb_host.c File Reference

USB host driver Compliance with common driver UHD.

Copyright (C) 2011 - 2012 Atmel Corporation. All rights reserved.

#include "conf_usb_host.h"
#include "sysclk.h"
#include "uhd.h"
#include "usbb_otg.h"
#include "usbb_host.h"
#include <string.h>
#include <stdlib.h>
#include "sleepmgr.h"

Data Structures

struct  uhd_ctrl_request_t
 Structure to store the high level setup request. More...
 
struct  uhd_pipe_job_t
 Structure definition to store registered jobs on a pipe. More...
 

Macros

#define AVR32_USBB_IRQ_GROUP   AVR32_USB_IRQ_GROUP
 
#define UHC_MODE_CHANGE(arg)
 
#define UHC_SOF_EVENT()
 
#define UHC_VBUS_CHANGE(b_present)
 
#define UHC_VBUS_ERROR()
 
#define UHD_BULK_NB_BANK   2
 
#define UHD_INTERRUPT_NB_BANK   1
 
#define UHD_ISOCHRONOUS_NB_BANK   2
 
#define UHD_USB_INT_LEVEL   0
 

Functions

 ISR (otg_interrupt, AVR32_USBB_IRQ_GROUP, UHD_USB_INT_LEVEL)
 Function called by USBB interrupt handler to manage USB interrupts. More...
 
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...
 
void udc_start (void)
 Start the USB Device stack. More...
 
void udc_stop (void)
 Stop the USB Device stack. More...
 
void udd_interrupt (void)
 Function called by USBB interrupt to manage USB device interrupts. More...
 
static void uhd_ctrl_interrupt (void)
 Manages the events related to control endpoint. More...
 
static void uhd_ctrl_phase_data_in (void)
 Manages the DATA IN phase on control endpoint. More...
 
static void uhd_ctrl_phase_data_in_start (void)
 Starts the DATA IN phase on control endpoint. More...
 
static void uhd_ctrl_phase_data_out (void)
 Manages the DATA OUT phase on control endpoint. More...
 
static void uhd_ctrl_phase_setup (void)
 Sends a USB setup packet to start a control request sequence. More...
 
static void uhd_ctrl_phase_zlp_in (void)
 Starts the ZLP IN phase on control endpoint. More...
 
static void uhd_ctrl_phase_zlp_out (void)
 Starts the ZLP OUT phase on control endpoint. More...
 
static void uhd_ctrl_request_end (uhd_trans_status_t status)
 Call the callback linked to control request and start the next request from the queue. More...
 
void uhd_disable (bool b_id_stop)
 Disables the USB host mode. More...
 
void uhd_enable (void)
 Enables the USB host mode Start the ID pin management if the ID pin is available. More...
 
bool uhd_ep0_alloc (usb_add_t add, uint8_t ep_size)
 Configures and enables a control endpoint 0. More...
 
void uhd_ep_abort (usb_add_t add, usb_ep_t endp)
 Aborts an on-going transfer on an endpoint. More...
 
static void uhd_ep_abort_pipe (uint8_t pipe, uhd_trans_status_t status)
 Aborts the on going transfer on a pipe. More...
 
bool uhd_ep_alloc (usb_add_t add, usb_ep_desc_t *ep_desc)
 Configures and enables an endpoint. More...
 
void uhd_ep_free (usb_add_t add, usb_ep_t endp)
 Disables an endpoint or all endpoint of a device. More...
 
bool uhd_ep_run (usb_add_t add, usb_ep_t endp, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, uint16_t timeout, uhd_callback_trans_t callback)
 Allows to receive or send data on an endpoint. More...
 
uint16_t uhd_get_frame_number (void)
 Returns the current Start Of Frame (SOF) number. More...
 
uint16_t uhd_get_microframe_number (void)
 Returns the current micro start of frame number. More...
 
static uint8_t uhd_get_pipe (usb_add_t add, usb_ep_t endp)
 Returns the pipe number matching a USB endpoint. More...
 
uhd_speed_t uhd_get_speed (void)
 Returns the speed of connected device. More...
 
static void uhd_interrupt (void)
 Function called by USBB interrupt to manage USB host interrupts. More...
 
bool uhd_is_suspend (void)
 Test if the suspend state is enabled on the USB line. More...
 
static void uhd_pipe_finish_job (uint8_t pipe, uhd_trans_status_t status)
 Call the callback linked to the end of pipe transfer. More...
 
static uhd_trans_status_t uhd_pipe_get_error (uint8_t pipe)
 Translates the USBB pipe error to UHD error. More...
 
static void uhd_pipe_interrupt (uint8_t pipe)
 Manages the following pipe interrupts: More...
 
static void uhd_pipe_interrupt_dma (uint8_t pipe)
 Manages the pipe DMA interrupt. More...
 
static void uhd_pipe_trans_complet (uint8_t pipe)
 Computes and starts the next transfer on a pipe. More...
 
void uhd_resume (void)
 Enables the IDLE state on the USB line. More...
 
void uhd_send_reset (uhd_callback_reset_t callback)
 Enables the Reset state on the USB line. More...
 
bool uhd_setup_request (usb_add_t add, usb_setup_req_t *req, uint8_t *payload, uint16_t payload_size, uhd_callback_setup_run_t callback_run, uhd_callback_setup_end_t callback_end)
 Add a setup request in the control endpoint setup queue. More...
 
static void uhd_sof_interrupt (void)
 Manages timeouts and actions based on SOF events. More...
 
void uhd_suspend (void)
 Enables the suspend state on the USB line. More...
 

Variables

static bool otg_initialized = false
 State of USBB OTG initialization. More...
 
static uhd_callback_reset_t uhd_reset_callback = NULL
 Store the callback to be call at the end of reset signal. More...
 
Management of bulk/interrupt/isochronous endpoints

The UHD manages the data transfer on endpoints:

  • Start data transfer on endpoint with USB DMA
  • Send a ZLP packet if requested
  • Call registered callback to signal end of transfer The transfer abort and stall feature are supported.
static uhd_pipe_job_t uhd_pipe_job [AVR32_USBB_EPT_NUM-1]
 Array to register a job on bulk/interrupt/isochronous endpoint. More...
 
static uint8_t uhd_suspend_start
 Variables to manage the suspend/resume sequence. More...
 
static uint8_t uhd_resume_start
 
static uint8_t uhd_pipes_unfreeze
 

Power management

enum  uhd_usbb_state_enum {
  UHD_STATE_OFF = 0,
  UHD_STATE_WAIT_ID_HOST = 1,
  UHD_STATE_NO_VBUS = 2,
  UHD_STATE_DISCONNECT = 3,
  UHD_STATE_SUSPEND = 4,
  UHD_STATE_IDLE = 5
}
 States of USBB interface. More...
 
static void uhd_sleep_mode (enum uhd_usbb_state_enum new_state)
 Manages the sleep mode following the USBB state. More...
 

Control endpoint low level management routine.

This function performs control endpoint management.

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

enum  uhd_ctrl_request_phase_t {
  UHD_CTRL_REQ_PHASE_SETUP = 0,
  UHD_CTRL_REQ_PHASE_DATA_OUT = 1,
  UHD_CTRL_REQ_PHASE_DATA_IN = 2,
  UHD_CTRL_REQ_PHASE_ZLP_IN = 3,
  UHD_CTRL_REQ_PHASE_ZLP_OUT = 4
}
 Bit definitions to store setup request state machine. More...
 
struct uhd_ctrl_request_tuhd_ctrl_request_first
 Entry points of setup request list. More...
 
struct uhd_ctrl_request_tuhd_ctrl_request_last
 
volatile uint16_t uhd_ctrl_request_timeout
 Remaining time for on-going setup request (No request on-going if equal 0) More...
 
uint16_t uhd_ctrl_nb_trans
 Number of transfered byte on DATA phase of current setup request. More...
 
static bool uhd_b_suspend_requested
 Flag to delay a suspend request after all on-going setup request. More...
 
uhd_ctrl_request_phase_t uhd_ctrl_request_phase
 

#define AVR32_USBB_IRQ_GROUP   AVR32_USB_IRQ_GROUP
#define UHC_MODE_CHANGE (   arg)

Referenced by ISR(), and otg_dual_enable().

#define UHC_SOF_EVENT ( )

Referenced by uhd_sof_interrupt().

#define UHC_VBUS_CHANGE (   b_present)

Referenced by uhd_interrupt().

#define UHC_VBUS_ERROR ( )

Referenced by uhd_interrupt().

#define UHD_USB_INT_LEVEL   0

Referenced by otg_dual_enable().