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_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 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_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_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_suspended()
 Check if host controller is in suspend mode. More...
 
#define PIPE_CRC16   0x10
 
#define PIPE_DATA_PID   0x02
 
#define PIPE_DATA_TOGGLE   0x01
 
#define PIPE_DELAY_TIMEOUT   0x80
 
#define PIPE_GOOD   0x00
 
#define PIPE_NAK_TIMEOUT   0x40
 
#define PIPE_PID   0x04
 
#define PIPE_STALL   0x20
 
#define PIPE_TIMEOUT   0x08
 

Typedefs

typedef void Pipe_handler (Status_t status, U16 nb_byte)
 

Functions

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. More...
 
bool host_get_data_interrupt (U8 pipe, U16 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 (U8 pipe, U16 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 (U8 pipe, U16 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 (U8 pipe)
 USB pipe interrupt subroutine. More...
 

Variables

U8 data_stage [SIZEOF_DATA_STAGE]
 Public: U8 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: U8 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 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.

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.

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.

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_attached ( )    (device_state >= DEVICE_ATTACHED)

Check if there is a device attached to the host.

Referenced by ai_usb_ms_get_device_status(), and usb_general_interrupt().

#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.

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 host_cdc_task(), host_mass_storage_task(), host_mouse_hid_task(), host_template_task(), and ushell_cmdusb_suspend().

#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: usb_host_task.h:139
#define DEVICE_SUSPENDED
Definition: usb_host_task.h:138
volatile U8 device_state
Public: U8 device_state Its value represents the current state of the device connected to the USB hos...
Definition: usb_host_task.c:91

Check if host controller is in suspend mode.

Referenced by host_template_task(), and ushell_cmdusb_resume().

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

typedef void Pipe_handler(Status_t status, U16 nb_byte)

Status_t host_get_data ( U8  pipe,
U16 nb_data,
void *  ptr_buf 
)
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
Todo:
Todo:
Implement this on the silicon version
Todo:
Implement this on the silicon version

References configTSK_USB_HST_PERIOD, CONTROL_GOOD, data_stage, DEVICE_ADDRESS, DEVICE_ADDRESSED, DEVICE_ATTACHED, DEVICE_CONFIGURED, DEVICE_DEFAULT, DEVICE_ERROR, DEVICE_POWERED, DEVICE_READY, device_state, DEVICE_SUSPENDED, DEVICE_UNATTACHED, DEVICE_WAIT_RESUME, Disable_global_interrupt, Enable_global_interrupt, EP_CONTROL, 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_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_enable_vbus, Usb_freeze_clock, 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: U8 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_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(), and usb_host_task().

volatile U8 device_state

Public: U8 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(), usb_general_interrupt(), usb_host_task(), and usb_host_task_init().

volatile U8 device_status
volatile bool request_resume