Microchip® Advanced Software Framework

usb_task.c File Reference
#include "compiler.h"
#include "intc.h"
#include "conf_usb.h"
#include "usb_drv.h"
#include "usb_task.h"
#include "usb_descriptors.h"
#include "usb_device_task.h"
#include "usb_host_task.h"
#include "pm_uc3c.h"

Functions

U32 host_get_timeout (void)
 
void host_suspend_action (void)
 
static void usb_general_interrupt (void)
 USB interrupt routine. More...
 
void usb_suspend_action (void)
 
void usb_task (void)
 Entry point of the USB management. More...
 
void usb_task_init (void)
 This function initializes the USB process. More...
 

Variables

static volatile U8 g_old_usb_mode
 
volatile U16 g_usb_event = 0
 Public: U16 g_usb_event usb_connected is used to store USB events detected upon USB general interrupt subroutine Its value is managed by the following macros (See usb_task.h file) Usb_send_event(x) Usb_ack_event(x) Is_usb_event(x) Usb_clear_all_event() More...
 
volatile U8 g_usb_mode = USB_MODE_UNDEFINED
 Public: U8 g_usb_mode Used in dual-role application (both device/host) to store the current mode the USB controller is operating. More...
 
static const char log_device_disconnected [] = "Device disconnected\r\n"
 
static const char log_pin_id_changed [] = "Pin Id changed\r\n"
 
volatile U32 private_sof_counter
 Private: U8 private_sof_counter Incremented by host SOF interrupt subroutine This counter is used to detect time-out in host requests. More...
 
static U8 private_sof_counter_HS = 0
 
volatile bool usb_connected
 Public: bool usb_connected usb_connected is set to true when VBus has been detected usb_connected is set to false otherwise Used with USB_DEVICE_FEATURE == true only. More...
 

static void usb_general_interrupt ( void  )
static

USB interrupt routine.

This function is called each time a USB interrupt occurs. The following USB DEVICE events are taken in charge:

  • VBus On / Off
  • Start-of-Frame
  • Suspend
  • Wake-Up
  • Resume
  • Reset

The following USB HOST events are taken in charge:

  • Device connection
  • Device Disconnection
  • Start-of-Frame
  • ID pin change
  • SOF (or Keep alive in low-speed) sent
  • Wake-up on USB line detected
  • Pipe events

For each event, the user can launch an action by completing the associated #define (see the conf_usb.h file to add actions on events).

Note: Only interrupt events that are enabled are processed.

Warning: If device and host tasks are not tasks in an RTOS, rough events like ID transition, VBus transition, device disconnection, etc. that need to kill then restart these tasks may lead to an undefined state if they occur just before something is activated in the USB macro (e.g. pipe/endpoint transfer...).

Returns
Nothing in the standalone configuration; a boolean indicating whether a task switch is required in the FreeRTOS configuration
Todo:
ID pin hot state change!!!
Todo:
Implement this on the silicon version

References device_state, DEVICE_UNATTACHED, S_pipe_int::enable, EVT_HOST_DISCONNECTION, EVT_HOST_HWUP, EVT_HOST_SOF, EVT_USB_DEVICE_FUNCTION, EVT_USB_HOST_FUNCTION, EVT_USB_POWERED, EVT_USB_RESET, EVT_USB_RESUME, EVT_USB_SUSPEND, EVT_USB_UNPOWERED, EVT_USB_WAKE_UP, g_old_usb_mode, g_usb_mode, S_pipe_int::handler, Host_ack_device_connection, Host_ack_device_disconnection, Host_ack_hwup, Host_ack_sof, Host_device_connection_action, Host_device_disconnection_action, host_disable_all_pipes(), Host_disable_hwup_interrupt, Host_disable_sof_interrupt, Host_get_interrupt_pipe_number, Host_get_pipe_type, Host_hwup_action, Host_reset_pipe, Host_sof_action, Is_host_attached, Is_host_device_connection, Is_host_device_connection_interrupt_enabled, Is_host_device_disconnection, Is_host_device_disconnection_interrupt_enabled, Is_host_hwup, Is_host_hwup_interrupt_enabled, Is_host_sof, Is_host_sof_interrupt_enabled, Is_usb_clock_frozen, Is_usb_device, Is_usb_full_speed_mode, Is_usb_id_device, Is_usb_id_interrupt_enabled, Is_usb_id_transition, Is_usb_reset, Is_usb_reset_interrupt_enabled, Is_usb_resume, Is_usb_resume_interrupt_enabled, Is_usb_sof, Is_usb_sof_interrupt_enabled, Is_usb_suspend, Is_usb_suspend_interrupt_enabled, Is_usb_vbus_high, Is_usb_vbus_interrupt_enabled, Is_usb_vbus_transition, Is_usb_wake_up, Is_usb_wake_up_interrupt_enabled, log_device_disconnected, log_pin_id_changed, LOG_STR, MAX_PEP_NB, PIPE_DELAY_TIMEOUT, private_sof_counter, private_sof_counter_HS, S_pipe_int::status, TIMEOUT_DELAY, TYPE_INTERRUPT, Usb_ack_id_transition, Usb_ack_reset, Usb_ack_resume, Usb_ack_sof, Usb_ack_suspend, Usb_ack_vbus_transition, Usb_ack_wake_up, usb_configuration_nb, usb_connected, Usb_detach, Usb_disable, Usb_disable_otg_pad, Usb_disable_resume_interrupt, Usb_disable_wake_up_interrupt, Usb_enable_wake_up_interrupt, Usb_freeze_clock, Usb_id_transition_action, usb_init_device(), USB_MODE_DEVICE, USB_MODE_HOST, Usb_reset_action, Usb_resume_action, Usb_send_event, Usb_sof_action, usb_start_device(), Usb_suspend_action, Usb_unfreeze_clock, Usb_vbus_off_action, Usb_vbus_on_action, and Usb_wake_up_action.

volatile U8 g_old_usb_mode
static

Referenced by usb_general_interrupt(), and usb_task().

const char log_device_disconnected[] = "Device disconnected\r\n"
static

Referenced by usb_general_interrupt().

const char log_pin_id_changed[] = "Pin Id changed\r\n"
static

Referenced by usb_general_interrupt().

U8 private_sof_counter_HS = 0
static

Referenced by usb_general_interrupt().

volatile bool usb_connected

Public: bool usb_connected usb_connected is set to true when VBus has been detected usb_connected is set to false otherwise Used with USB_DEVICE_FEATURE == true only.

Public: bool usb_connected usb_connected is set to true when VBus has been detected usb_connected is set to false otherwise Used with USB_DEVICE_FEATURE == true only.

Referenced by usb_device_task(), usb_device_task_init(), usb_general_interrupt(), and usb_start_device().