Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Implementation of UDC

Internal implementation.

Data Structures

struct  udc_string_desc_t
 USB device string descriptor Structure used to transfer ASCII strings to USB String descriptor structure. More...
 

Functions

static usb_conf_desc_t
UDC_DESC_STORAGE
udc_get_eof_conf (void)
 Returns a value to check the end of USB Configuration descriptor. More...
 
usb_iface_desc_t UDC_DESC_STORAGEudc_get_interface_desc (void)
 Returns a pointer on the current interface descriptor. More...
 
static bool udc_iface_disable (uint8_t iface_num)
 Disables an usb device interface (UDI) This routine call the UDI corresponding to interface number. More...
 
static bool udc_iface_enable (uint8_t iface_num, uint8_t setting_num)
 Enables an usb device interface (UDI) This routine calls the UDI corresponding to the interface and setting number. More...
 
bool udc_process_setup (void)
 Main routine to manage the USB SETUP request. More...
 
static bool udc_req_ep (void)
 Send the SETUP interface request to UDI. More...
 
static bool udc_req_iface (void)
 Send the SETUP interface request to UDI. More...
 
static bool udc_req_std_dev_clear_feature (void)
 Standard device request to change device status. More...
 
static bool udc_req_std_dev_get_configuration (void)
 Standard device request to get configuration number. More...
 
static bool udc_req_std_dev_get_descriptor (void)
 Standard device request to get descriptors about USB device. More...
 
static bool udc_req_std_dev_get_status (void)
 Standard device request to get device status. More...
 
static bool udc_req_std_dev_get_str_desc (void)
 Standard device request to get device string descriptor. More...
 
static bool udc_req_std_dev_set_address (void)
 Standard device request to set device address. More...
 
static bool udc_req_std_dev_set_configuration (void)
 Standard device request to enable a configuration. More...
 
static bool udc_req_std_dev_set_feature (void)
 Standard device request to set a feature. More...
 
static bool udc_req_std_iface_get_setting (void)
 Standard interface request to get the alternate setting number of an interface. More...
 
static bool udc_req_std_iface_set_setting (void)
 Standard interface request to set an alternate setting of an interface. More...
 
static bool udc_reqstd (void)
 Main routine to manage the standard USB SETUP request. More...
 
void udc_reset (void)
 Reset the current configuration of the USB device, This routines can be called by UDD when a RESET on the USB line occurs. More...
 
void udc_sof_notify (void)
 To signal that a SOF is occurred. More...
 
void udc_start (void)
 Start the USB Device stack. More...
 
void udc_stop (void)
 Stop the USB Device stack. More...
 
static bool udc_update_iface_desc (uint8_t iface_num, uint8_t setting_num)
 Search an interface descriptor This routine updates the internal pointer udc_ptr_iface. More...
 
static void udc_valid_address (void)
 Standard endpoint request to halt an endpoint. More...
 

Internal variables to manage the USB device

static le16_t udc_device_status
 Device status state (see enum usb_device_status in usb_protocol.h) More...
 
static uint8_t udc_num_configuration = 0
 Device Configuration number selected by the USB host. More...
 
static udc_config_speed_t
UDC_DESC_STORAGE
udc_ptr_conf
 Pointer on the selected speed device configuration. More...
 
static usb_iface_desc_t
UDC_DESC_STORAGE
udc_ptr_iface
 Pointer on interface descriptor used by SETUP request. More...
 

Internal structure to store the USB device main strings

static COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE
usb_str_lgid_desc_t 
udc_string_desc_languageid
 Language ID of USB device (US ID by default) More...
 
static COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE struct
udc_string_desc_t 
udc_string_desc
 
#define USB_DEVICE_MANUFACTURE_NAME_SIZE   0
 USB device manufacture name storage String is allocated only if USB_DEVICE_MANUFACTURE_NAME is declared by usb application configuration. More...
 
#define USB_DEVICE_PRODUCT_NAME_SIZE   0
 USB device product name storage String is allocated only if USB_DEVICE_PRODUCT_NAME is declared by usb application configuration. More...
 
#define USB_DEVICE_SERIAL_NAME_SIZE   0
 Get USB device serial number. More...
 

#define USB_DEVICE_MANUFACTURE_NAME_SIZE   0

USB device manufacture name storage String is allocated only if USB_DEVICE_MANUFACTURE_NAME is declared by usb application configuration.

Referenced by udc_req_std_dev_get_str_desc().

#define USB_DEVICE_PRODUCT_NAME_SIZE   0

USB device product name storage String is allocated only if USB_DEVICE_PRODUCT_NAME is declared by usb application configuration.

Referenced by udc_req_std_dev_get_str_desc().

#define USB_DEVICE_SERIAL_NAME_SIZE   0

Get USB device serial number.

Use the define USB_DEVICE_SERIAL_NAME to set static serial number.

For dynamic serial number set the define USB_DEVICE_GET_SERIAL_NAME_POINTER to a suitable pointer. This will also require the serial number length define USB_DEVICE_GET_SERIAL_NAME_LENGTH.

Referenced by udc_req_std_dev_get_str_desc().

static usb_conf_desc_t UDC_DESC_STORAGE* udc_get_eof_conf ( void  )
static

Returns a value to check the end of USB Configuration descriptor.

Returns
address after the last byte of USB Configuration descriptor

References udc_config_speed_t::desc, le16_to_cpu, UDC_DESC_STORAGE, udc_ptr_conf, and usb_conf_desc_t::wTotalLength.

Referenced by udc_update_iface_desc().

usb_iface_desc_t UDC_DESC_STORAGE* udc_get_interface_desc ( void  )

Returns a pointer on the current interface descriptor.

Returns
pointer on the current interface descriptor.

References udc_ptr_iface.

Referenced by udi_hid_reqstdifaceget_descriptor(), and udi_vendor_enable().

static bool udc_iface_disable ( uint8_t  iface_num)
static

Disables an usb device interface (UDI) This routine call the UDI corresponding to interface number.

Parameters
iface_numInterface number to disable
Returns
1 if it is done or 0 if interface is not found

References NULL, UDC_DESC_STORAGE, udc_ptr_conf, udc_ptr_iface, udc_update_iface_desc(), udc_config_speed_t::udi_apis, and USB_DT_ENDPOINT.

Referenced by udc_req_std_iface_set_setting(), and udc_reset().

static bool udc_iface_enable ( uint8_t  iface_num,
uint8_t  setting_num 
)
static

Enables an usb device interface (UDI) This routine calls the UDI corresponding to the interface and setting number.

Parameters
iface_numInterface number to enable
setting_numSetting number to enable
Returns
1 if it is done or 0 if interface is not found

References udi_api_t::enable, le16_to_cpu, NULL, UDC_DESC_STORAGE, udc_ptr_conf, udc_ptr_iface, udc_update_iface_desc(), udc_config_speed_t::udi_apis, and USB_DT_ENDPOINT.

Referenced by udc_req_std_dev_set_configuration(), and udc_req_std_iface_set_setting().

bool udc_process_setup ( void  )

Main routine to manage the USB SETUP request.

Decodes and manages a setup request.

This function parses a USB SETUP request and submits an appropriate response back to the host or, in the case of SETUP OUT requests with data, sets up a buffer for receiving the data payload.

The main standard requests defined by the USB 2.0 standard are handled internally. The interface requests are sent to UDI, and the specific request sent to a specific application callback.

Returns
true if the request is supported, else the request is stalled by UDD

Referenced by udd_ctrl_setup_received().

static bool udc_req_ep ( void  )
static
static bool udc_req_iface ( void  )
static
static bool udc_req_std_dev_clear_feature ( void  )
static
static bool udc_req_std_dev_get_configuration ( void  )
static

Standard device request to get configuration number.

Returns
true if success

References udd_ctrl_request_t::req, udc_num_configuration, udd_g_ctrlreq, udd_set_setup_payload(), and usb_setup_req_t::wLength.

Referenced by udc_reqstd().

static bool udc_req_std_dev_get_status ( void  )
static

Standard device request to get device status.

Returns
true if success

References udd_ctrl_request_t::req, udc_device_status, udd_g_ctrlreq, udd_set_setup_payload(), and usb_setup_req_t::wLength.

Referenced by udc_reqstd().

static bool udc_req_std_dev_set_address ( void  )
static

Standard device request to set device address.

Returns
true if success

References udd_ctrl_request_t::callback, udd_ctrl_request_t::req, udc_valid_address(), udd_g_ctrlreq, and usb_setup_req_t::wLength.

Referenced by udc_reqstd().

static bool udc_req_std_iface_get_setting ( void  )
static
static bool udc_req_std_iface_set_setting ( void  )
static

Standard interface request to set an alternate setting of an interface.

Returns
true if success

References udd_ctrl_request_t::req, udc_iface_disable(), udc_iface_enable(), udc_num_configuration, udd_g_ctrlreq, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.

Referenced by udc_reqstd().

void udc_reset ( void  )

Reset the current configuration of the USB device, This routines can be called by UDD when a RESET on the USB line occurs.

Reset the UDC.

Referenced by udc_req_std_dev_set_configuration(), udc_req_std_dev_set_feature(), udc_stop(), and udd_interrupt().

void udc_sof_notify ( void  )

To signal that a SOF is occurred.

The UDC must send the signal to all UDIs enabled

Referenced by udd_interrupt().

void udc_start ( void  )

Start the USB Device stack.

References udd_enable().

void udc_stop ( void  )

Stop the USB Device stack.

References udc_reset(), and udd_disable().

static bool udc_update_iface_desc ( uint8_t  iface_num,
uint8_t  setting_num 
)
static

Search an interface descriptor This routine updates the internal pointer udc_ptr_iface.

Parameters
iface_numInterface number to find in Configuration Descriptor
setting_numSetting number of interface to find
Returns
1 if found or 0 if not found

References usb_iface_desc_t::bAlternateSetting, usb_iface_desc_t::bDescriptorType, usb_iface_desc_t::bInterfaceNumber, usb_iface_desc_t::bLength, usb_conf_desc_t::bNumInterfaces, udc_config_speed_t::desc, UDC_DESC_STORAGE, udc_get_eof_conf(), udc_num_configuration, udc_ptr_conf, udc_ptr_iface, and USB_DT_INTERFACE.

Referenced by udc_iface_disable(), udc_iface_enable(), udc_req_ep(), udc_req_iface(), and udc_req_std_iface_get_setting().

static void udc_valid_address ( void  )
static

Standard endpoint request to halt an endpoint.

Returns
true if success Change the address of device Callback called at the end of request set address

References udd_ctrl_request_t::req, udd_g_ctrlreq, udd_set_address(), and usb_setup_req_t::wValue.

Referenced by udc_req_std_dev_set_address().

le16_t udc_device_status
static

Device status state (see enum usb_device_status in usb_protocol.h)

Referenced by udc_req_std_dev_clear_feature(), udc_req_std_dev_get_status(), udc_req_std_dev_set_feature(), and udc_reset().

usb_iface_desc_t UDC_DESC_STORAGE* udc_ptr_iface
static

Pointer on interface descriptor used by SETUP request.

Referenced by udc_get_interface_desc(), udc_iface_disable(), udc_iface_enable(), and udc_update_iface_desc().

Initial value:
= {
.header.bDescriptorType = USB_DT_STRING
}
Definition: usb_protocol.h:199
COMPILER_WORD_ALIGNED UDC_DESC_STORAGE usb_str_lgid_desc_t udc_string_desc_languageid
static
Initial value:
= {
.desc.bLength = sizeof(usb_str_lgid_desc_t),
.desc.bDescriptorType = USB_DT_STRING,
.string = {LE16(USB_LANGID_EN_US)}
}
English (United States)
Definition: usb_protocol.h:274
#define LE16(x)
Definition: compiler.h:1112
Definition: usb_protocol.h:199
Definition: usb_protocol.h:493

Language ID of USB device (US ID by default)

Referenced by udc_req_std_dev_get_str_desc().