Microchip® Advanced Software Framework

usbc_device.c File Reference

USB Device driver Compliance with common driver UDD.

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

#include "conf_usb.h"
#include "sysclk.h"
#include "sleep.h"
#include "udd.h"
#include "usbc_otg.h"
#include "usbc_device.h"
#include <string.h>
#include "sleepmgr.h"


#define UDD_USB_INT_LEVEL   0


Management of bulk/interrupt/isochronous endpoints

Buffer to store the data received on control endpoint (SETUP/OUT endpoint 0)

Used to avoid a RAM buffer overflow in case of the payload buffer is smaller than control endpoint size

The UDD manages the data transfer on endpoints:

  • Start data transfer on endpoint with USB Device DMA
  • Send a ZLP packet if requested
  • Call callback registered to signal end of transfer The transfer abort and stall feature are supported.
bool udd_include_vbus_monitoring (void)
 Authorizes the VBUS event. More...
void udd_enable (void)
 Enables the USB Device mode. More...
void udd_disable (void)
 Disables the USB Device mode. More...
void udd_attach (void)
 Attach device to the bus when possible. More...
void udd_detach (void)
 Detaches the device from the bus. More...
bool udd_is_high_speed (void)
 Test whether the USB Device Controller is running at high speed or not. More...
void udd_set_address (uint8_t address)
 Changes the USB address of device. More...
uint8_t udd_getaddress (void)
 Returns the USB address of device. More...
uint16_t udd_get_frame_number (void)
 Returns the current start of frame number. More...
uint16_t udd_get_micro_frame_number (void)
 Returns the current micro start of frame number. More...
void udd_send_remotewakeup (void)
 The USB driver sends a resume signal called Upstream Resume. More...
void udd_set_setup_payload (uint8_t *payload, uint16_t payload_size)
 Load setup payload. More...
static void udd_reset_ep_ctrl (void)
static void udd_ctrl_init (void)
static void udd_ctrl_setup_received (void)
static void udd_ctrl_in_sent (void)
static void udd_ctrl_out_received (void)
static void udd_ctrl_underflow (void)
static void udd_ctrl_overflow (void)
static void udd_ctrl_stall_data (void)
static void udd_ctrl_send_zlp_in (void)
static void udd_ctrl_send_zlp_out (void)
static void udd_ctrl_endofrequest (void)
static bool udd_ctrl_interrupt (void)


static volatile usb_desc_table_t udd_g_ep_table [2 *(USB_DEVICE_MAX_EP+1)]
 USB SRAM data about endpoint descriptor table The content of the USB SRAM can be : More...

Power management routine.

 Definition of sleep levels. More...
static bool udd_b_idle
 State of USB line. More...
static void udd_sleep_mode (bool b_idle)
 Authorize or not the CPU powerdown mode. More...

Control endpoint low level management routine.

This function performs control endpoint management.

It handle the SETUP/DATA/HANDSHAKE phases of a control transaction.

enum  udd_ctrl_ep_state_t {
 Bit definitions about endpoint control state machine for udd_ep_control_state. More...
 Global variable to give and record information about setup request management. More...
static udd_ctrl_ep_state_t udd_ep_control_state
 State of the endpoint control management. More...
static uint16_t udd_ctrl_prev_payload_nb_trans
 Total number of data received/sent during data packet phase with previous payload buffers. More...
static uint16_t udd_ctrl_payload_nb_trans
 Number of data received/sent to/from udd_g_ctrlreq.payload buffer. More...

#define UDD_USB_INT_LEVEL   0

Referenced by udd_enable().