drivers/usb/at90usb/at90usb_udc.c File Reference

AT90USB driver: Device part. More...

#include <assert.h>
#include <byteorder.h>
#include <bitops.h>
#include <debug.h>
#include <interrupt.h>
#include <io.h>
#include <status_codes.h>
#include <string.h>
#include <util.h>
#include <workqueue.h>
#include <usb/request.h>
#include <usb/dev.h>
#include <usb/udc.h>
#include <usb/udc_lib.h>
#include <chip/regs.h>
#include <chip/memory-map.h>
#include <chip/at90usb.h>
#include <app/usb.h>
#include "at90usb_internal.h"
#include "at90usb_regs.h"

Go to the source code of this file.

Functions

static void copy_from_fifo (uint8_t *dest, const unsigned int len)
 Helper function to read data from the USB fifo.
static void copy_to_fifo (const uint8_t *source, const unsigned int len)
 Helper function to write data to the USB fifo.
static struct at90usb_udcat90usb_udc_of (struct udc *udc)
 Helper function get the AT90USB UDC instance from the UDC instance.
static struct at90usb_udcat90usb_udc_task_of (struct workqueue_task *task)
 Helper function get the AT90USB UDC instance from the work queue task.
static struct at90usb_udc_epat90usb_ep_task_of (struct workqueue_task *task)
 Helper function get the AT90USB UDC endpoint instance from the work queue task.
static void at90usb_udc_req_done (struct udc *udc, struct usb_request *req, enum status_code status)
 Helper function to complete USB requests.
static void at90usb_udc_kill_last_in_bank (void)
 Kill last bank for an IN endpoint.
static void at90usb_udc_kill_first_out_bank (void)
 Kill first bank for an OUT endpoint.
static void at90usb_udc_kill_all_banks (struct udc *udc, usb_ep_id_t ep_id)
 Kill all banks for an endpoint.
static void at90usb_udc_submit_out_queue (struct workqueue_task *task)
 Submit queued buffers on a non-control OUT endpoint.
static void at90usb_udc_submit_in_queue (struct workqueue_task *task)
 Submit queued buffers on a non-control IN endpoint.
static status_t at90usb_udc_configure_ep (uint8_t id, unsigned int size, enum usb_ep_xfer_type type, bool is_in, uint8_t nr_banks)
static void at90usb_udc_ep_flush (struct at90usb_udc *udc90, struct at90usb_udc_ep *ep)
 Flush a non-control endpoint.
static struct at90usb_udc_epat90usb_ep_alloc (struct udc *udc, uint8_t addr, uint16_t max_packet_size)
 Allocate a non-control endpoint.
static usb_ep_id_t at90usb_ep_enable (struct at90usb_udc_ep *ep, uint8_t addr, uint16_t max_packet_size, enum usb_ep_xfer_type type, unsigned int nr_banks)
 Enable a non-control endpoint.
static void at90usb_ep0_tx_complete (struct udc *udc, struct at90usb_udc_ep *ep)
 Helper function to complete control endpoint USB requests.
static void at90usb_ep0_tx_flush (struct udc *udc, struct at90usb_udc_ep *ep)
 Flush a control endpoint.
static void at90usb_udc_ep0_worker (struct workqueue_task *task)
 The AT90USB UDC endpoint 0 work task handler.
static void at90usb_udc_device_worker (struct workqueue_task *task)
 The AT90USB device-mode device work task handler.
static void at90usb_udc_maybe_attach (struct at90usb_udc *udc90)
 Helper function to let the UDC maybe attach to the USB bus.
static void at90usb_udc_detach (struct at90usb_udc *udc90)
 Helper function to let the UDC detach from the USB bus.
void at90usb_udc_vbus_on (struct at90usb_udc *udc90)
 Signal that a high Vbus level has been detected.
void at90usb_udc_vbus_off (struct at90usb_udc *udc90)
 Signal that a low Vbus level has been detected.
struct at90usb_udcat90usb_udc_init (void)
 Initialize the device part of the AT90USB controller.
void at90usb_udc_shutdown (struct at90usb_udc *udc90)
 Shut down the device part of the AT90USB controller.
Control Transfer

The following functions are used to send and receive packets over the default control endpoint, ep0. Most functions are asynchronous and will call a callback function after the transfer is done. The only exception is udc_ep0_write_sync(), which will write the data to the FIFO immediately and busy-wait until it has been sent.

void udc_ep0_submit_out_req (struct udc *udc, struct usb_request *req)
 Submit an OUT request on the default control endpoint.
void udc_ep0_submit_in_req (struct udc *udc, struct usb_request *req)
 Submit an IN request on the default control endpoint.
status_t udc_ep0_write_sync (struct udc *udc, const void *data, size_t len)
 Transmit IN data on the default control endpoint synchronously.
void udc_ep0_send_status (struct udc *udc)
 Send a status IN packet on the default control endpoint.
void udc_ep0_expect_status (struct udc *udc)
 Signal that a status OUT packet is expected on the default control endpoint.
Data Transfer

The following functions are used to do non-control transfers, i.e. bulk, interrupt and isochronous transfers. Note that no synchronous functions are available -- the caller must always provide a callback if needed.

void udc_ep_submit_out_req (struct udc *udc, usb_ep_id_t ep, struct usb_request *req)
 Submit an OUT request on a non-control endpoint.
void udc_ep_submit_in_req (struct udc *udc, usb_ep_id_t ep, struct usb_request *req)
 Submit an IN request on a non-control endpoint.
Endpoint Management

The following functions allow drivers to create and destroy endpoints, as well as set, clear and query their "halted" and "wedged" states.

Wedging an endpoint is useful when encountering errors that need some sort of error recovery procedure to be performed by the host. A wedged endpoint behaves like one that is halted, except that the host is prevented from clearing the halted state through the standard ClearFeature(HALT) request. This behaviour is required by the USB Mass Storage Bulk-Only Transport specification.

status_t udc_ep_is_halted (struct udc *udc, usb_ep_id_t ep)
 Check if the endpoint ep is halted.
status_t udc_ep_set_halt (struct udc *udc, usb_ep_id_t ep)
 Set the halted state of the endpoint ep.
status_t udc_ep_clear_halt (struct udc *udc, usb_ep_id_t ep)
 Clear the halted state of the endpoint ep.
bool udc_ep_is_wedged (struct udc *udc, usb_ep_id_t ep)
 Check if a given endpoint is wedged.
void udc_ep_set_wedge (struct udc *udc, usb_ep_id_t ep)
 Set the wedged state of an endpoint.
void udc_ep_clear_wedge (struct udc *udc, usb_ep_id_t ep)
 Clear the wedged state of an endpoint.
void udc_ep_flush (struct udc *udc, usb_ep_id_t ep)
 Terminate all pending requests on an endpoint.
usb_ep_id_t udc_ep_create_bulk (struct udc *udc, uint8_t addr, uint16_t max_packet_size)
 Create a new Bulk endpoint.
usb_ep_id_t udc_ep_create_interrupt (struct udc *udc, uint8_t addr, uint16_t max_packet_size)
 Create a new Interrupt endpoint.
void udc_ep_destroy (struct udc *udc, usb_ep_id_t ep)
 Destroy a previously created endpoint.
UDC Library Interface

The following functions make up the interface between the UDC driver and the optional UDC library. The UDC library contains common helper functions for UDC drivers.

status_t udc_enter_test_mode (struct udc *udc, unsigned int mode)
 Enter Test Mode.
Device State

The following functions are used to query and modify the state of the USB device as a whole.

void udc_attach (struct udc *udc)
 Attach udc to the bus when possible.
void udc_detach (struct udc *udc)
 Detach udc from the bus.

Detailed Description

AT90USB driver: Device part.

This file implements a USB Device Controller (UDC) driver utilizing the AT90USB controller hardware.

Copyright (C) 2009 Atmel Corporation. All rights reserved.

Definition in file at90usb_udc.c.


Function Documentation

static void copy_from_fifo ( uint8_t dest,
const unsigned int  len 
) [static]

Helper function to read data from the USB fifo.

For internal use only.

Parameters:
dest The destination to copy to.
len Number of bytes to read from the FIFO.

Definition at line 92 of file at90usb_udc.c.

Referenced by at90usb_udc_ep0_worker(), and at90usb_udc_submit_out_queue().

static void copy_to_fifo ( const uint8_t source,
const unsigned int  len 
) [static]

Helper function to write data to the USB fifo.

For internal use only.

Parameters:
source The destination to copy from.
len Number of bytes to write to the FIFO.

Definition at line 107 of file at90usb_udc.c.

Referenced by at90usb_udc_ep0_worker(), and at90usb_udc_submit_in_queue().

Generated on Thu Apr 29 14:10:34 2010 for xplain-bc by  doxygen 1.6.3