Microchip® Advanced Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
USB host task module

Modules

 Host controller states
 Defines for device state coding.
 

Data Structures

struct  S_pipe_int
 

Macros

#define Host_ack_request_resume()   (request_resume = false)
 Private ack for resume software event. More...
 
#define Host_ack_request_resume()   (request_resume = false)
 Private ack for resume software event. More...
 
#define Host_request_resume()   (request_resume = true)
 Should be called to request the host controller to resume the USB bus. More...
 
#define Host_request_resume()   (request_resume = true)
 Should be called to request the host controller to resume the USB bus. More...
 
#define Host_request_suspend()   (device_state = DEVICE_SUSPENDED)
 Should be called to make the host controller enter USB suspend mode. More...
 
#define Host_request_suspend()   (device_state = DEVICE_SUSPENDED)
 Should be called to make the host controller enter USB suspend mode. More...
 
#define Is_host_addressed()   (device_state >= DEVICE_ADDRESSED)
 Check if there is a device addressed by the host. More...
 
#define Is_host_addressed()   (device_state >= DEVICE_ADDRESSED)
 Check if there is a device addressed by the host. More...
 
#define Is_host_attached()   (device_state >= DEVICE_ATTACHED)
 Check if there is a device attached to the host. More...
 
#define Is_host_attached()   (device_state >= DEVICE_ATTACHED)
 Check if there is a device attached to the host. More...
 
#define Is_host_detect_unsupported_dev()   (device_state == DEVICE_UNSUPPORTED)
 Check if an unsupported device is detected. More...
 
#define Is_host_error()   (device_state == DEVICE_ERROR)
 Check if there is an error. More...
 
#define Is_host_error()   (device_state == DEVICE_ERROR)
 Check if there is an error. More...
 
#define Is_host_powered()   (device_state >= DEVICE_POWERED)
 Check if there is a device powered by the host. More...
 
#define Is_host_powered()   (device_state >= DEVICE_POWERED)
 Check if there is a device powered by the host. More...
 
#define Is_host_ready()   (device_state == DEVICE_READY)
 Returns true when device connected and correctly enumerated. More...
 
#define Is_host_ready()   (device_state == DEVICE_READY)
 Returns true when device connected and correctly enumerated. More...
 
#define Is_host_request_resume()   (request_resume == true)
 Private check for resume sequence. More...
 
#define Is_host_request_resume()   (request_resume == true)
 Private check for resume sequence. More...
 
#define Is_host_suspended()
 Check if host controller is in suspend mode. More...
 
#define Is_host_suspended()
 Check if host controller is in suspend mode. More...
 
#define PIPE_CRC16   0x10
 
#define PIPE_CRC16   0x10
 
#define PIPE_DATA_PID   0x02
 
#define PIPE_DATA_PID   0x02
 
#define PIPE_DATA_TOGGLE   0x01
 
#define PIPE_DATA_TOGGLE   0x01
 
#define PIPE_DELAY_TIMEOUT   0x80
 
#define PIPE_DELAY_TIMEOUT   0x80
 
#define PIPE_GOOD   0x00
 
#define PIPE_GOOD   0x00
 
#define PIPE_NAK_TIMEOUT   0x40
 
#define PIPE_NAK_TIMEOUT   0x40
 
#define PIPE_PID   0x04
 
#define PIPE_PID   0x04
 
#define PIPE_STALL   0x20
 
#define PIPE_STALL   0x20
 
#define PIPE_TIMEOUT   0x08
 
#define PIPE_TIMEOUT   0x08
 

Typedefs

typedef void Pipe_handler (Status_t status, uint16_t nb_byte)
 
typedef void Pipe_handler (Status_t status, U16 nb_byte)
 

Functions

Status_t host_get_data (uint8_t pipe, uint16_t *nb_data, void *ptr_buf)
 This function receives nb_data bytes pointed to by ptr_buf on the specified pipe. More...
 
bool host_get_data_interrupt (uint8_t pipe, uint16_t nb_data, void *ptr_buf, Pipe_handler *handler)
 This function receives nb_data bytes pointed to by ptr_buf on the specified pipe. More...
 
Status_t host_send_data (uint8_t pipe, uint16_t nb_data, const void *ptr_buf)
 This function sends nb_data bytes pointed to by ptr_buf on the specified pipe. More...
 
bool host_send_data_interrupt (uint8_t pipe, uint16_t nb_data, const void *ptr_buf, Pipe_handler *handler)
 This function sends nb_data bytes pointed to by ptr_buf on the specified pipe. More...
 
bool is_any_interrupt_pipe_active (void)
 
void reset_it_pipe_str (void)
 
void usb_host_task (void)
 Entry point of the USB host management. More...
 
void usb_host_task_init (void)
 This function initializes the USB host controller. More...
 
void usb_pipe_interrupt (uint8_t pipe)
 USB pipe interrupt subroutine. More...
 

Variables

U8 data_stage [SIZEOF_DATA_STAGE]
 Public: uint8_t data_stage[SIZEOF_DATA_STAGE] Internal RAM buffer for USB data stage content This buffer is required to setup host enumeration process It contains the device descriptors received. More...
 
uint8_t data_stage [SIZEOF_DATA_STAGE]
 Public: uint8_t data_stage[SIZEOF_DATA_STAGE] Internal RAM buffer for USB data stage content This buffer is required to setup host enumeration process It contains the device descriptors received. More...
 
volatile U8 device_state
 Public: uint8_t device_state Its value represents the current state of the device connected to the USB host controller Value can be: More...
 
volatile uint8_t device_state
 Public: uint8_t device_state Its value represents the current state of the device connected to the USB host controller Value can be: More...
 
volatile U8 device_status
 
volatile bool request_resume
 
volatile bool request_resume
 
volatile uint8_t usb_host_device_status
 
volatile S_usb_setup_data usb_request
 For control requests management over control pipe. More...
 
volatile S_usb_setup_data usb_request
 For control requests management over control pipe. More...
 

#define Host_ack_request_resume ( )    (request_resume = false)

Private ack for resume software event.

#define Host_ack_request_resume ( )    (request_resume = false)

Private ack for resume software event.

Referenced by usb_host_task(), and usb_host_task_init().

#define Host_request_resume ( )    (request_resume = true)

Should be called to request the host controller to resume the USB bus.

#define Host_request_resume ( )    (request_resume = true)

Should be called to request the host controller to resume the USB bus.

Referenced by host_template_task(), and ushell_cmdusb_resume().

#define Host_request_suspend ( )    (device_state = DEVICE_SUSPENDED)

Should be called to make the host controller enter USB suspend mode.

#define Host_request_suspend ( )    (device_state = DEVICE_SUSPENDED)

Should be called to make the host controller enter USB suspend mode.

Referenced by host_template_task(), and ushell_cmdusb_suspend().

#define Is_host_addressed ( )    (device_state >= DEVICE_ADDRESSED)

Check if there is a device addressed by the host.

#define Is_host_addressed ( )    (device_state >= DEVICE_ADDRESSED)

Check if there is a device addressed by the host.

#define Is_host_attached ( )    (device_state >= DEVICE_ATTACHED)

Check if there is a device attached to the host.

#define Is_host_attached ( )    (device_state >= DEVICE_ATTACHED)

Check if there is a device attached to the host.

Referenced by ai_usb_ms_get_device_status(), if(), and usb_general_interrupt().

#define Is_host_detect_unsupported_dev ( )    (device_state == DEVICE_UNSUPPORTED)

Check if an unsupported device is detected.

Referenced by ai_usb_ms_get_device_status().

#define Is_host_error ( )    (device_state == DEVICE_ERROR)

Check if there is an error.

#define Is_host_error ( )    (device_state == DEVICE_ERROR)

Check if there is an error.

Referenced by ai_usb_ms_get_device_status().

#define Is_host_powered ( )    (device_state >= DEVICE_POWERED)

Check if there is a device powered by the host.

#define Is_host_powered ( )    (device_state >= DEVICE_POWERED)

Check if there is a device powered by the host.

Referenced by ai_usb_ms_get_device_status().

#define Is_host_ready ( )    (device_state == DEVICE_READY)

Returns true when device connected and correctly enumerated.

The host high-level application should test this before performing any applicative request.

Referenced by e_usbsys_lsusb(), host_audio_task(), host_cdc_task(), host_mass_storage_task(), host_mass_storage_task_sync_drives(), host_mouse_hid_task(), host_template_task(), prv_e_usbsys_sync_cp_ukey(), and ushell_cmdusb_suspend().

#define Is_host_ready ( )    (device_state == DEVICE_READY)

Returns true when device connected and correctly enumerated.

The host high-level application should test this before performing any applicative request.

#define Is_host_request_resume ( )    (request_resume == true)

Private check for resume sequence.

#define Is_host_request_resume ( )    (request_resume == true)

Private check for resume sequence.

Referenced by usb_host_task().

#define Is_host_suspended ( )
Value:
#define DEVICE_WAIT_RESUME
Definition: drivers/usbb/_asf_v1/enum/host/usb_host_task.h:139
#define DEVICE_SUSPENDED
Definition: drivers/usbb/_asf_v1/enum/host/usb_host_task.h:138
volatile uint8_t device_state
Public: uint8_t device_state Its value represents the current state of the device connected to the US...
Definition: applications/uc3-audio-player/usb_host_task.c:95

Check if host controller is in suspend mode.

#define Is_host_suspended ( )
Value:
#define DEVICE_WAIT_RESUME
Definition: applications/uc3-audio-player/usb_host_task.h:144
#define DEVICE_SUSPENDED
Definition: applications/uc3-audio-player/usb_host_task.h:143
volatile uint8_t device_state
Public: uint8_t device_state Its value represents the current state of the device connected to the US...
Definition: applications/uc3-audio-player/usb_host_task.c:95

Check if host controller is in suspend mode.

Referenced by e_usbsys_lsusb(), host_template_task(), prv_e_usbsys_sync_cp_ukey(), and ushell_cmdusb_resume().

#define PIPE_CRC16   0x10
#define PIPE_CRC16   0x10
#define PIPE_DATA_PID   0x02
#define PIPE_DATA_PID   0x02
#define PIPE_DATA_TOGGLE   0x01
#define PIPE_DATA_TOGGLE   0x01
#define PIPE_DELAY_TIMEOUT   0x80
#define PIPE_DELAY_TIMEOUT   0x80
#define PIPE_GOOD   0x00
#define PIPE_NAK_TIMEOUT   0x40
#define PIPE_NAK_TIMEOUT   0x40
#define PIPE_PID   0x04
#define PIPE_PID   0x04
#define PIPE_STALL   0x20
#define PIPE_TIMEOUT   0x08
#define PIPE_TIMEOUT   0x08

typedef void Pipe_handler(Status_t status, uint16_t nb_byte)
typedef void Pipe_handler(Status_t status, U16 nb_byte)

Status_t host_get_data ( U8  pipe,
U16 nb_data,
void *  ptr_buf 
)

This function receives nb_data bytes pointed to by ptr_buf on the specified pipe.

*nb_data is updated with the final number of data bytes received.

Note
This function activates the host SOF interrupt to detect time-outs. The initial enable state of this interrupt will be restored.
Parameters
pipe
nb_data
ptr_buf
Returns
Status_t: Pipe status
Todo:
Error code management
Todo:
Error code management
Todo:
Error code management
Todo:
Error code management

References cpu_irq_disable, cpu_irq_enable, cpu_irq_is_enabled, Disable_global_interrupt, Enable_global_interrupt, EVT_HOST_SOF, Host_ack_all_errors, Host_ack_in_received, Host_ack_nak_received, Host_ack_sof, Host_ack_stall, Host_byte_count, Host_configure_pipe_token, Host_disable_sof_interrupt, Host_enable_continuous_in_mode, Host_enable_sof_interrupt, Host_error_status, Host_free_in, Host_freeze_pipe, Host_get_pipe_size, host_read_p_rxpacket(), Host_reset_pipe, Host_reset_pipe_fifo_access, Host_unfreeze_pipe, i, Is_global_interrupt_enabled, Is_host_emergency_exit, Is_host_in_received, Is_host_nak_received, Is_host_pipe_error, Is_host_sof_interrupt_enabled, Is_host_stall, Is_usb_event, Is_usb_low_speed_mode, n, NAK_RECEIVE_TIMEOUT, PIPE_DELAY_TIMEOUT, PIPE_GOOD, PIPE_NAK_TIMEOUT, PIPE_STALL, private_sof_counter, status, TIMEOUT_DELAY, TOKEN_IN, and Usb_ack_event.

Referenced by host_ms_inquiry(), host_ms_request_sense(), host_ms_stall_management(), host_read_10_extram(), host_read_10_ram(), host_read_10_ram_stop(), host_read_capacity(), host_template_task(), host_test_unit_ready(), host_wr_protect(), and host_write_10_extram().

bool is_any_interrupt_pipe_active ( void  )
void reset_it_pipe_str ( void  )
void usb_host_task ( void  )

Entry point of the USB host management.

The aim is to manage the target device connection and enumeration. Depending on device_state, the function performs the required operations to get the device enumerated and configured. Once the device is operational, device_state is DEVICE_READY. This state should be tested by the host task before sending any applicative request to the device. This function is called from the usb_task function depending on the USB operating mode (device or host) currently engaged.

The aim is to manage the target device connection and enumeration. Depending on device_state, the function performs the required operations to get the device enumerated and configured. Once the device is operational, device_state is DEVICE_READY. This state should be tested by the host task before sending any applicative request to the device. This function is called from the usb_task function depending on the USB operating mode (device or host) currently engaged.

usb_host_task.jpg
USB Host Task Overview

The aim is to manage the target device connection and enumeration. Depending on device_state, the function performs the required operations to get the device enumerated and configured. Once the device is operational, device_state is DEVICE_READY. This state should be tested by the host task before sending any applicative request to the device. This function is called from the usb_task function depending on the USB operating mode (device or host) currently engaged.

The aim is to manage the target device connection and enumeration. Depending on device_state, the function performs the required operations to get the device enumerated and configured. Once the device is operational, device_state is DEVICE_READY. This state should be tested by the host task before sending any applicative request to the device. This function is called from the usb_task function depending on the USB operating mode (device or host) currently engaged.

usb_host_task.jpg
USB Host Task Overview
Todo:
Todo:
Implement this on the silicon version
Todo:
Implement this on the silicon version
Todo:
Todo:
Implement this on the silicon version
Todo:
Implement this on the silicon version

References configTSK_USB_HST_PERIOD, CONTROL_GOOD, cpu_irq_disable, cpu_irq_enable, cpu_is_timeout(), data_stage, DEVICE_ADDRESS, DEVICE_ADDRESSED, DEVICE_ATTACHED, DEVICE_CONFIGURED, DEVICE_DEFAULT, DEVICE_DEFAULT_MAX_ERROR_COUNT, DEVICE_ERROR, DEVICE_POWERED, DEVICE_READY, device_state, DEVICE_SUSPENDED, DEVICE_UNATTACHED, DEVICE_UNSUPPORTED, DEVICE_VBUS_LOW, DEVICE_WAIT_RESUME, Disable_global_interrupt, Enable_global_interrupt, EP_CONTROL, EVT_HOST_CONNECTION, EVT_HOST_HWUP, EVT_HOST_SOF, Host_ack_device_connection, Host_ack_device_disconnection, Host_ack_down_stream_resume, Host_ack_hwup, Host_ack_remote_wakeup, Host_ack_request_resume, Host_ack_reset_sent, Host_ack_sof, host_check_class(), host_check_VID_PID(), Host_clear_device_status, Host_configure_address, Host_configure_pipe, Host_device_class_not_supported_action, Host_device_connection_action, Host_device_error_action, Host_device_not_supported_action, Host_device_supported_action, host_disable_all_pipes(), Host_disable_device_disconnection_interrupt, Host_disable_hwup_interrupt, Host_disable_pipe, Host_disable_sof, Host_disable_sof_interrupt, Host_enable_device_disconnection_interrupt, Host_enable_hwup_interrupt, Host_enable_pipe, Host_enable_sof, Host_enable_sof_interrupt, host_get_configuration_descriptor, host_get_device_descriptor, host_get_device_descriptor_incomplete, Host_new_device_connection_action, Host_send_reset, Host_send_resume, host_set_address, host_set_configuration, Host_set_configured, Host_set_device_supported, host_set_feature_remote_wakeup, Host_stop_sending_reset, Host_suspend_action, Host_unallocate_memory, Is_device_supports_remote_wakeup, Is_host_configured, Is_host_device_connection, Is_host_device_disconnection, Is_host_down_stream_resume, Is_host_emergency_exit, Is_host_hwup_interrupt_enabled, Is_host_request_resume, Is_host_sending_reset, Is_host_sof_interrupt_enabled, Is_usb_bconnection_error_interrupt, Is_usb_clock_frozen, Is_usb_event, Is_usb_vbus_error_interrupt, Is_usb_vbus_high, Is_usb_vbus_low, log_device_connected, log_device_enumerated, LOG_STR, log_unsupported_device, log_usb_resumed, log_usb_suspended, MAX_PEP_NB, nb_interface_supported, OFFSET_FIELD_CONFIGURATION_NB, OFFSET_FIELD_MAXPACKETSIZE, P_CONTROL, SINGLE_BANK, sof_cnt, TOKEN_SETUP, TYPE_CONTROL, Usb_ack_bconnection_error_interrupt, Usb_ack_event, Usb_ack_vbus_error_interrupt, Usb_clear_all_event, Usb_disable_vbus, Usb_enable_vbus, Usb_freeze_clock, usb_host_task_init(), Usb_unfreeze_clock, User_configure_endpoint, vTaskDelayUntil(), and xTaskGetTickCount().

Referenced by usb_host_task_init(), and usb_task().

U8 data_stage[SIZEOF_DATA_STAGE]

Public: uint8_t data_stage[SIZEOF_DATA_STAGE] Internal RAM buffer for USB data stage content This buffer is required to setup host enumeration process It contains the device descriptors received.

Depending on the device descriptors length, its size can be optimized with the SIZEOF_DATA_STAGE define of conf_usb.h file

Public: uint8_t data_stage[SIZEOF_DATA_STAGE] Internal RAM buffer for USB data stage content This buffer is required to setup host enumeration process It contains the device descriptors received.

Depending on the device descriptors length, its size can be optimized with the SIZEOF_DATA_STAGE define of conf_usb.h file

Referenced by host_audio_get_max(), host_audio_set_cur(), host_audio_set_cur_mute(), host_cdc_get_encapsulated_response(), host_cdc_get_line_coding(), host_cdc_send_encapsulated_command(), host_cdc_set_line_coding(), host_check_class(), host_check_VID_PID(), host_get_lun(), host_hid_get_descriptor(), host_hid_get_idle(), host_hid_get_protocol(), host_hid_get_report(), host_hid_set_descriptor(), host_hid_set_idle(), host_hid_set_protocol(), host_hid_set_report(), host_set_sampling_rate(), and usb_host_task().

uint8_t data_stage[SIZEOF_DATA_STAGE]

Public: uint8_t data_stage[SIZEOF_DATA_STAGE] Internal RAM buffer for USB data stage content This buffer is required to setup host enumeration process It contains the device descriptors received.

Depending on the device descriptors length, its size can be optimized with the SIZEOF_DATA_STAGE define of conf_usb.h file

Public: uint8_t data_stage[SIZEOF_DATA_STAGE] Internal RAM buffer for USB data stage content This buffer is required to setup host enumeration process It contains the device descriptors received.

Depending on the device descriptors length, its size can be optimized with the SIZEOF_DATA_STAGE define of conf_usb.h file

volatile U8 device_state

Public: uint8_t device_state Its value represents the current state of the device connected to the USB host controller Value can be:

  • DEVICE_ATTACHED
  • DEVICE_POWERED
  • DEVICE_SUSPENDED
  • DEVICE_DEFAULT
  • DEVICE_ADDRESSED
  • DEVICE_CONFIGURED
  • DEVICE_ERROR
  • DEVICE_UNATTACHED
  • DEVICE_READY
  • DEVICE_WAIT_RESUME

Public: uint8_t device_state Its value represents the current state of the device connected to the USB host controller Value can be:

  • DEVICE_ATTACHED
  • DEVICE_POWERED
  • DEVICE_SUSPENDED
  • DEVICE_DEFAULT
  • DEVICE_ADDRESSED
  • DEVICE_CONFIGURED
  • DEVICE_ERROR
  • DEVICE_UNATTACHED
  • DEVICE_READY
  • DEVICE_WAIT_RESUME

Referenced by host_mass_storage_task(), if(), usb_general_interrupt(), usb_host_task(), and usb_host_task_init().

volatile uint8_t device_state

Public: uint8_t device_state Its value represents the current state of the device connected to the USB host controller Value can be:

  • DEVICE_ATTACHED
  • DEVICE_POWERED
  • DEVICE_SUSPENDED
  • DEVICE_DEFAULT
  • DEVICE_ADDRESSED
  • DEVICE_CONFIGURED
  • DEVICE_ERROR
  • DEVICE_UNATTACHED
  • DEVICE_READY
  • DEVICE_WAIT_RESUME

Public: uint8_t device_state Its value represents the current state of the device connected to the USB host controller Value can be:

  • DEVICE_ATTACHED
  • DEVICE_POWERED
  • DEVICE_SUSPENDED
  • DEVICE_DEFAULT
  • DEVICE_ADDRESSED
  • DEVICE_CONFIGURED
  • DEVICE_ERROR
  • DEVICE_UNATTACHED
  • DEVICE_READY
  • DEVICE_WAIT_RESUME
volatile U8 device_status
volatile bool request_resume
volatile bool request_resume
volatile uint8_t usb_host_device_status
volatile S_usb_setup_data usb_request

For control requests management over control pipe.