# include/usb/request.h File Reference

USB request structure and associated helper functions. More...

`#include <bitops.h>`
`#include <buffer.h>`
`#include <types.h>`

Include dependency graph for request.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures
struct | usb_request
| A USB request. More...
## Defines
#define | usb_req_for_each_buffer(req, buf) slist_for_each(&req->buf_list, buf, node)
| Iterate over each buffer buf associated with the USB request req.
#define | usb_req_for_each_buffer_safe(req, buf, next) slist_for_each_safe(&req->buf_list, buf, next, node)
| Iterate over each buffer buf associated with the USB request req, allowing removal of buf. next holds the buffer following buf.
## Enumerations
enum | usb_request_flag { USB_REQ_SHORT_PKT }
| Flag bits for indicating that a request needs special treatment. More...
## Functions
void | usb_req_init (struct usb_request *req)
| Initialize a USB request.
static void | usb_req_add_buffer (struct usb_request *req, struct buffer *buf)
| Add a buffer to a USB request.
struct usb_request * | usb_req_alloc (void)
| Allocate and initialize a USB request structure.
void | usb_req_free (struct usb_request *req)
| Free a USB request structure.
void | usb_init (void)
| Initialize the USB core subsystem.
struct usb_request * | usb_req_alloc_single_tx (const void *data, size_t len)
| Allocate a USB request and initialize with a single buffer for transmission.
struct usb_request * | usb_req_alloc_single_rx (void *data, size_t len)
| Allocate a USB request and initialize with a single buffer for reception.
void | usb_req_free_all (struct usb_request *req)
| Free a USB request and all associated buffers.
static struct buffer * | usb_req_get_first_buffer (struct usb_request *req)
| Return the first buffer associated with req.

## Detailed Description

USB request structure and associated helper functions.

A USB request contains one or more data buffers which are used to send and receive data over USB pipes and endpoints.

- Compiler: IAR EWAVR32 and GNU GCC for AVR32
- Supported devices: All devices with a USB host and/or device controller
- AppNote:

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

Definition in file request.h.

## Define Documentation

#define usb_req_for_each_buffer | ( | req,
|  | buf |  | ) | slist_for_each(&req->buf_list, buf, node)

Iterate over each buffer buf associated with the USB request req.

Definition at line 148 of file request.h.

#define usb_req_for_each_buffer_safe | ( | req,
|  | buf,
|  | next |  | ) | slist_for_each_safe(&req->buf_list, buf, next, node)

Iterate over each buffer buf associated with the USB request req, allowing removal of buf. next holds the buffer following buf.

Definition at line 155 of file request.h.

Referenced by usb_req_free_all().

## Enumeration Type Documentation

enum usb_request_flag

Flag bits for indicating that a request needs special treatment.

Enumerator:

  USB_REQ_SHORT_PKT | Last packet must be short. Setting this flag indicates that the last packet sent from this buffer must be short. If this buffer ends on an endpoint boundary, the UDC driver must send a zero-length packet to terminate the transfer.

Definition at line 57 of file request.h.

## Function Documentation

void usb_init | ( | void |  | ) |

Initialize the USB core subsystem.

This function will initialize the USB buffer pool.

Definition at line 179 of file usb_lib.c.

References CONFIG_USB_NR_REQUESTS, cpu_sram_pool, and mem_pool_init_physmem().

Here is the call graph for this function:

static void usb_req_add_buffer | ( | struct usb_request * | req,
|  | struct buffer * | buf |
| ) |  |  | `[inline, static]`

Add a buffer to a USB request.

This will add the buffer buf to the end of the buffer list associated with the USB request req.

Parameters:

  | req | The USB request
  | buf | The buffer to be associated with req

Definition at line 120 of file request.h.

References usb_request::buf_list, buffer::node, and slist_insert_tail().

Referenced by usb_func_get_descriptor(), usb_req_alloc_single_rx(), and usb_req_alloc_single_tx().

Here is the call graph for this function:

struct usb_request* usb_req_alloc | ( | void |  | ) | `[read]`

Allocate and initialize a USB request structure.

Returns:
  A pointer to the newly allocated USB request, or NULL if the pool is exhausted.

Definition at line 75 of file usb_lib.c.

References mem_pool_alloc(), and usb_req_init().

Referenced by msc_submit_write_data_req(), usb_req_alloc_single_rx(), and usb_req_alloc_single_tx().

Here is the call graph for this function:

struct usb_request* usb_req_alloc_single_rx | ( | void * | data,
|  | size_t | len |
| ) |  |  | `[read]`

Allocate a USB request and initialize with a single buffer for reception.

Parameters:

  | data | Data area for the buffer
  | len | Length of the data area in bytes

Returns:
  A new USB request structure, or NULL if the memory pool is exhausted.

Definition at line 137 of file usb_lib.c.

References buffer_init_rx(), usb_req_add_buffer(), and usb_req_alloc().

Here is the call graph for this function:

struct usb_request* usb_req_alloc_single_tx | ( | const void * | data,
|  | size_t | len |
| ) |  |  | `[read]`

Allocate a USB request and initialize with a single buffer for transmission.

Parameters:

  | data | Data area for the buffer
  | len | Length of the data area in bytes

Returns:
  A new USB request structure, or NULL if the memory pool is exhausted.

Definition at line 107 of file usb_lib.c.

References buffer_init_tx(), usb_req_add_buffer(), and usb_req_alloc().

Here is the call graph for this function:

void usb_req_free | ( | struct usb_request * | req | ) |

Free a USB request structure.

Parameters:

  | req | The request to be released back to the pool.

Definition at line 91 of file usb_lib.c.

References mem_pool_free().

Referenced by msc_submit_write_data_req(), and usb_req_free_all().

Here is the call graph for this function:

void usb_req_free_all | ( | struct usb_request * | req | ) |

Free a USB request and all associated buffers.

Parameters:

  | req | The request to be freed

Definition at line 162 of file usb_lib.c.

References dbg_printf, usb_req_for_each_buffer_safe, and usb_req_free().

Here is the call graph for this function:

static struct buffer* usb_req_get_first_buffer | ( | struct usb_request * | req | ) | `[static, read]`

Return the first buffer associated with req.

Definition at line 138 of file request.h.

References usb_request::buf_list, buffer::node, and slist_peek_head.

void usb_req_init | ( | struct usb_request * | req | ) |

Initialize a USB request.

This initializes a USB request and makes sure that it doesn't have any special flags set, and that it doesn't have any other buffers associated with it.

Parameters:

  | req | The USB request to be initialized.

Definition at line 62 of file usb_lib.c.

References usb_request::buf_list, usb_request::bytes_xfered, usb_request::flags, and slist_init().

Referenced by usb_func_get_descriptor(), and usb_req_alloc().

Here is the call graph for this function: