# drivers/usb/usbb_core.c File Reference

USBB driver: Core/Transceiver part. More...

`#include <assert.h>`
`#include <debug.h>`
`#include <irq_handler.h>`
`#include <physmem.h>`
`#include <stdbool.h>`
`#include <chip/clk.h>`
`#include <chip/memory-map.h>`
`#include <chip/irq-map.h>`
`#include <chip/portmux.h>`
`#include <chip/usbb.h>`
`#include <usb/udc.h>`
`#include <app/config_dmapool.h>`
`#include <app/config_usb.h>`
`#include "usbb_internal.h"`
`#include "usbb_regs.h"`

Include dependency graph for usbb_core.c:

Go to the source code of this file.

## Functions
static void | usbb_enter_device_mode (struct usbb_controller *usbb)
| Enter USB device mode.
static void | usbb_check_id (struct usbb_controller *usbb)
| Check the state of the USB OTG ID pin.
static void | usbb_interrupt (void *data)
| USBB main interrupt handler.
static struct usbb_controller * | usbb_init (void)
| Initialize the USBB controller.
struct udc * | udc_init (void)
| Initialize the USB Device Controller.

## Detailed Description

USBB driver: Core/Transceiver part.

This file implements a driver for the transceiver logic in the USBB hardware controller. It is responsible for enabling the host- and device parts of the driver depending on configuration options, transceiver states and USB On-The-Go events originating from HNP and SRP.

If the driver is configured as host-only or device-only, the OTG logic will be disabled. This file is still responsible for detecting connection/disconnection events, and generating/detecting Vbus.

- Compiler: IAR EWAVR32 and GNU GCC for AVR32
- Supported devices: All AVR32 devices with a USBB module can be used.
- AppNote:

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file usbb_core.c.

## Function Documentation

struct udc* udc_init | ( | void |  | ) | `[read]`

Initialize the USB Device Controller.

This will initialize the USB Device Controller, making it ready to attach to the bus. The controller won't attach automatically until udc_attach() has been called as well.

If the UDC is part of a dual-role (OTG) controller, and dual-role configuration is enabled, this function will initialize the whole controller if it hasn't been initialized before.

Returns:
  The USB Device Controller object

Definition at line 342 of file usbb_core.c.

References usbb_init().

Here is the call graph for this function:

static void usbb_check_id | ( | struct usbb_controller * | usbb | ) | `[static]`

Check the state of the USB OTG ID pin.

Check the state of the USB OTG ID pin and enable host/device functionality as appropriate.

Parameters:

  | usbb | The controller

Definition at line 175 of file usbb_core.c.

References usbb_enter_device_mode(), and USBB_USBSTA_ID.

Referenced by usbb_init(), and usbb_interrupt().

Here is the call graph for this function:

static void usbb_enter_device_mode | ( | struct usbb_controller * | usbb | ) | `[static]`

Enter USB device mode.

Disable the host driver (if any), enable the UDC driver and start watching the state of the Vbus line.

Definition at line 132 of file usbb_core.c.

References dbg_printf, and USBB_VBUSTI.

Referenced by usbb_check_id(), and usbb_init().

static struct usbb_controller* usbb_init | ( | void |  | ) | `[static, read]`

Initialize the USBB controller.

For internal use only.

This function will initialize and enable the USBB controller. Depending on the configuration, this may involve one or more of the following steps:

- Initialize the host and device parts of the driver.
- Start monitoring the ID pin.
- Switch the controller into host or device mode.
- Start monitoring the Vbus pin.

Returns:
  A USBB controller instance.

Todo:
  Add support for host and OTG modes.

Definition at line 262 of file usbb_core.c.

References clk_enable_usbb(), setup_irq_handler, usbb_check_id(), usbb_enter_device_mode(), USBB_IDTI, usbb_udc_init(), usbb_udc_shutdown(), USBB_USBCON_OTGPADE, USBB_USBCON_UIDE, USBB_USBCON_UIMOD_DEVICE, USBB_USBCON_UIMOD_HOST, and USBB_USBCON_USBE.

Referenced by udc_init().

Here is the call graph for this function:

static void usbb_interrupt | ( | void * | data | ) | `[static]`

USBB main interrupt handler.

This is the main interrupt handler for the USBB controller. It handles OTG and Vbus events, and calls the host- or device-specific interrupt handler, depending on the configuration and/or ID pin state.

Parameters:

  | data | Data associated with this interrupt.

Definition at line 193 of file usbb_core.c.

References usbb_check_id(), USBB_IDTI, usbb_udc_interrupt(), and USBB_VBUSTI.

Here is the call graph for this function: