Microchip® Advanced Software Framework

uhc.c File Reference

USB Host Controller (UHC)

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include "conf_usb_host.h"
#include "usb_protocol.h"
#include "uhd.h"
#include "uhi.h"
#include "uhc.h"
#include <stdlib.h>

Macros

#define UHC_CONNECTION_EVENT(dev, b_present)
 
#define UHC_DEVICE_CONF(dev)   1
 
#define UHC_ENUM_EVENT(dev, event)
 
#define UHC_WAKEUP_EVENT()
 

Functions

static void uhc_remotewakeup (bool b_enable)
 Enables or disables the remote wakeup feature of all devices connected. More...
 
static void uhc_setup_request_callback (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Callback used to signal the end of a setup request. More...
 
Internal functions to manage the USB device enumeration
static void uhc_enable_timeout_callback (uint8_t timeout, uhc_sof_timeout_callback_t callback)
 Enable a internal timeout on SOF events. More...
 
static void uhc_enumeration_suspend (void)
 Enters a specific device in USB suspend mode Suspend the USB line or a port on USB hub. More...
 
static void uhc_enumeration_reset (uhd_callback_reset_t callback)
 Sends the USB Reset signal on the USB line of a device. More...
 
static void uhc_connection_tree (bool b_plug, uhc_device_t *dev)
 Manage a device plug or unplug on the USB tree. More...
 
static void uhc_enumeration_step1 (void)
 Device enumeration step 1 Reset USB line. More...
 
static void uhc_enumeration_step2 (void)
 Device enumeration step 2 Lets USB line in IDLE state during 20ms. More...
 
static void uhc_enumeration_step3 (void)
 Device enumeration step 3 Reset USB line. More...
 
static void uhc_enumeration_step4 (void)
 Device enumeration step 4 Lets USB line in IDLE state during 100ms. More...
 
static void uhc_enumeration_step5 (void)
 Device enumeration step 5 Requests the USB device descriptor. More...
 
static void uhc_enumeration_step6 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Device enumeration step 6 End of Get device descriptor request. More...
 
static void uhc_enumeration_step7 (void)
 Device enumeration step 7 Reset USB line. More...
 
static void uhc_enumeration_step8 (void)
 Device enumeration step 8 Lets USB line in IDLE state during 100ms. More...
 
static void uhc_enumeration_step9 (void)
 Device enumeration step 9 Send a Set address setup request. More...
 
static void uhc_enumeration_step10 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Device enumeration step 10 End of Set address request. More...
 
static void uhc_enumeration_step11 (void)
 Device enumeration step 11 Updates USB host pipe with the new USB address. More...
 
static void uhc_enumeration_step12 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Device enumeration step 12 Requests the first USB structure of the USB configuration descriptor. More...
 
static void uhc_enumeration_step13 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Device enumeration step 13 Requests a complete Get configuration descriptor. More...
 
static void uhc_enumeration_step14 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Device enumeration step 14 Enable USB configuration, if unless one USB interface is supported by UHIs. More...
 
static void uhc_enumeration_step15 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Device enumeration step 15 Enables UHI interfaces. More...
 
static void uhc_enumeration_error (uhc_enum_status_t status)
 Manage error during device enumeration. More...
 
Callbacks used by USB Host Driver (UHD) to notify events
void uhc_notify_connection (bool b_plug)
 Notify device connection or disconnection. More...
 
void uhc_notify_sof (bool b_micro)
 Notify each start of frame sent by driver. More...
 
void uhc_notify_resume (void)
 Notify that a resume bus occurs A resume can occur after a downstream or an upstream resume. More...
 
Functions to control the USB host stack
void uhc_start (void)
 Starts the host mode. More...
 
void uhc_stop (bool b_id_stop)
 Stops the host mode. More...
 
void uhc_suspend (bool b_remotewakeup)
 Suspends a USB line. More...
 
bool uhc_is_suspend (void)
 Test if the suspend state is enabled on the USB line. More...
 
void uhc_resume (void)
 Resumes the USB line. More...
 
User functions to manage the devices
uint8_t uhc_get_device_number (void)
 Returns the number of connected devices. More...
 
char * uhc_dev_get_string_manufacturer (uhc_device_t *dev)
 Gets the USB string manufacturer from a USB device. More...
 
char * uhc_dev_get_string_product (uhc_device_t *dev)
 Gets the USB string product from a USB device. More...
 
char * uhc_dev_get_string_serial (uhc_device_t *dev)
 Gets the USB string serial from a USB device. More...
 
char * uhc_dev_get_string (uhc_device_t *dev, uint8_t str_id)
 Gets a USB string from a USB device. More...
 
uint16_t uhc_dev_get_power (uhc_device_t *dev)
 Gets the maximum consumption of a device (mA) More...
 
uhd_speed_t uhc_dev_get_speed (uhc_device_t *dev)
 Returns the current device speed. More...
 
bool uhc_dev_is_high_speed_support (uhc_device_t *dev)
 Tests if the device supports the USB high speed This function can wait the end of a setup request and the timing can be long (1ms to 5s). More...
 
void uhc_dev_reset (uhc_device_t *dev)
 Reset to re-enumerate. More...
 

Internal variables to manage the USB host stack

#define UHC_ENUM_NB_TRY   4
 Maximum try to enumerate a device. More...
 
#define UHC_USB_ADD_NOT_VALID   0xFF
 Entry point of all devices connected on USB tree. More...
 
#define UHC_DEVICE_ENUM_ADD   1
 USB address of the USB device under enumeration process. More...
 
#define uhc_dev_enum   (&g_uhc_device_root)
 Device under enumeration process. More...
 
#define uhc_power_running   0
 Total power of the devices connected. More...
 
#define UHC_NB_UHI   (sizeof(uhc_uhis)/sizeof(uhc_uhis[0]))
 Number of UHI available. More...
 
typedef void(* uhc_sof_timeout_callback_t )(void)
 Type of callback on a SOF timeout. More...
 
static uhc_device_t g_uhc_device_root
 Entry point of all devices connected on USB tree. More...
 
static uint8_t uhc_enum_try
 Number of enumeration try. More...
 
static uhc_sof_timeout_callback_t uhc_sof_timeout_callback
 Callback currently registered on a SOF timeout. More...
 
uint8_t uhc_sof_timeout
 Number of SOF remaining before call uhc_sof_timeout_callback callback. More...
 
static uhi_api_t uhc_uhis [] = {USB_HOST_UHI}
 Array of all UHI available. More...
 
static volatile bool uhc_setup_request_finish
 Volatile flag to pool the end of Get USB string setup request. More...
 
static volatile bool uhc_setup_request_finish_status
 Volatile flag to know the status of Get USB string setup request. More...
 

#define UHC_CONNECTION_EVENT (   dev,
  b_present 
)

Referenced by uhc_connection_tree().

#define UHC_DEVICE_CONF (   dev)    1

Referenced by uhc_enumeration_step12().

#define UHC_WAKEUP_EVENT ( )

Referenced by uhc_notify_resume().