dnx RTOS 2.2.0 "Eagle"
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
USBD Driver

Detailed Description

Description

Driver handles USB Device peripheral. All data read from specified Endpoints should be handled by application. Incoming data is controlled by host device and slave device is responsible for correct handling USB protocol. There is no possibility to send RAW data. To obtain more information please read USB protocol specification. There are example applications that can be used to implement own USB device:

Supported architectures

Details

Meaning of major and minor numbers

The major number selects USB peripheral. The minor number selects USB Endpoint.

Numeration restrictions

Maximum major number depends on number of USB peripherals in microcontroller. The minor number depends on count of USB Endpoints.

Driver initialization

To initialize driver the following code can be used:

driver_init("USBD", 0, 0, "/dev/usb0_ep0"); // SETUP Endpoint
driver_init("USBD", 0, 1, "/dev/usb0_ep1");
driver_init("USBD", 0, 2, "/dev/usb0_ep2");
driver_init("USBD", 0, 3, "/dev/usb0_ep3");
driver_init("USBD", 0, 4, "/dev/usb0_ep4");

Driver release

To release driver the following code can be used:

driver_release("USBD", 0, 2);
driver_release("USBD", 0, 3);

Driver configuration

A moment when driver should be configured depends on USB protocol. User should read commands from Endpoint 0 and do requested commands. One of first commands is configuration request. To start USB peripheral one should send specified command:

After this operation a USB host will send several commands. Commands should be handled by application code.

Data write

In most cases writing data to Endpoint is the same as writing to regular file. One should keep in mind that data flow is controlled directly by host device and selected device class. Writing is possible only when Endpoint is set to write (regulated by device-type class). In this case driver is waiting for data to be readout by host.

Data read

In most cases reading data from Endpoint is the same as reading to regular file. One should keep in mind that data flow is controlled directly by host device and selected device class. Reading is possible only when Endpoint is set to read (regulated by device-type class). IN this case driver is waiting for host data write.

Data Structures

struct  usbd_ep_config
 
struct  USBD_ep_config_t
 
struct  USBD_setup_container_t
 

Macros

#define _USBD_NUMBER_OF_ENDPOINTS   8
 
#define USBD_EP0_SIZE   8
 
#define USBD_EP_CONFIG_IN(usbd_transfer_t__transfer, u16_t__size)   {.IN_enabled = true, .OUT_enabled = false, .transfer_type = usbd_transfer_t__transfer, .IN_buffer_size = u16_t__size, .OUT_buffer_size = 0}
 Macro set configuration IN for selected endpoint (an item of usb_ep_config_t) More...
 
#define USBD_EP_CONFIG_OUT(usbd_transfer_t__transfer, u16_t__size)   {.IN_enabled = false, .OUT_enabled = true, .transfer_type = usbd_transfer_t__transfer, .IN_buffer_size = 0, .OUT_buffer_size = u16_t__size}
 Macro set configuration OUT for selected endpoint (an item of usb_ep_config_t) More...
 
#define USBD_EP_CONFIG_IN_OUT(usbd_transfer_t__transfer, u16_t__in_size, u16_t__out_size)   {.IN_enabled = true, .OUT_enabled = true, .transfer_type = usbd_transfer_t__transfer, .IN_buffer_size = u16_t__in_size, .OUT_buffer_size = u16_t__out_size}
 Macro set configuration IN & OUT for selected endpoint (an item of usb_ep_config_t) More...
 
#define USBD_EP_CONFIG_DISABLED()   {.IN_enabled = false, .OUT_enabled = false, .transfer_type = 0, .IN_buffer_size = 0, .OUT_buffer_size = 0}
 Macro disable selected endpoint (an item of usb_ep_config_t) More...
 
#define IOCTL_USBD__START   _IO (USBD, 0x00)
 The request starts the USB device (the device will be visible by the host). More...
 
#define IOCTL_USBD__STOP   _IO (USBD, 0x01)
 The request stops the USB device (the device will not be visible by the host). More...
 
#define IOCTL_USBD__CONFIGURE_EP_1_7   _IOW(USBD, 0x02, const usbd_ep_config_t*)
 The request configures Endpoints 1 to 7. The settings of the Endpoint 0 from given configuration are ignored. More...
 
#define IOCTL_USBD__SET_ADDRESS   _IOW(USBD, 0x03, uint16_t*)
 The request sets the address of the device (received from host in the SETUP packet). More...
 
#define IOCTL_USBD__SEND_ZLP   _IO (USBD, 0x04)
 The request sends the ZLP by the selected endpoint. More...
 
#define IOCTL_USBD__SET_EP_STALL   _IOW(USBD, 0x05, uint16_t*)
 The request sets a STALL status in the selected endpoint. More...
 
#define IOCTL_USBD__SET_EP_VALID   _IOW(USBD, 0x06, uint16_t*)
 The request sets a VALID (ACK) status in the selected endpoint. More...
 
#define IOCTL_USBD__WAS_RESET   _IOR(USBD, 0x07, bool*)
 The request returns a USB reset status. More...
 
#define IOCTL_USBD__GET_SETUP_PACKET   _IOR(USBD, 0x08, usbd_setup_container_t*)
 The request wait for the SETUP packet. More...
 
#define IOCTL_USBD__SET_ERROR_STATUS   _IO (USBD, 0x09)
 The request sets the error status (IN STALL, OUT STALL) in the selected endpoint. More...
 
#define IOCTL_USBD__GET_ERROR_COUNTER   _IOR(USBD, 0x0A, uint16_t*)
 The request gets the error counter. The counter is cleared after read operation. More...
 

Data Structure Documentation

struct usbd_ep_config

Endpoint configuration structure.

Data Fields
u16_t IN_buffer_size

IN buffer size.

bool IN_enabled

IN enabled.

u16_t OUT_buffer_size

OUT buffer size.

bool OUT_enabled

OUT enabled.

usb_transfer_t transfer_type

Transfer type.

struct USBD_ep_config_t

Endpoints configurations (the ENDP0 configuration is ignored).

Data Fields
struct usbd_ep_config ep[_USBD_NUMBER_OF_ENDPOINTS]
struct USBD_setup_container_t

SETUP packet container and receive timeout.

Data Fields
usb_setup_packet_t packet

Setup packet.

int timeout

Timeout in milliseconds.

Macro Definition Documentation

#define _USBD_NUMBER_OF_ENDPOINTS   8
#define IOCTL_USBD__CONFIGURE_EP_1_7   _IOW(USBD, 0x02, const usbd_ep_config_t*)
Parameters
[WR]usbd_ep_config_t endpoint configuration
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__GET_ERROR_COUNTER   _IOR(USBD, 0x0A, uint16_t*)
Parameters
[RD]The pointer to integer of 'uint16_t' type
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__GET_SETUP_PACKET   _IOR(USBD, 0x08, usbd_setup_container_t*)
Parameters
[RD]The pointer to the usb_setup_container_t that contains setup packet buffer and read-timeout configuration.
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__SEND_ZLP   _IO (USBD, 0x04)
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__SET_ADDRESS   _IOW(USBD, 0x03, uint16_t*)
Parameters
[WR]uint16_t address
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__SET_EP_STALL   _IOW(USBD, 0x05, uint16_t*)
Parameters
[WR]The endpoint number determined by the 'uint16_t' type. The IN/OUT endpoint is recognized by most significant bit as is defined by the USB standard
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__SET_EP_VALID   _IOW(USBD, 0x06, uint16_t*)
Parameters
[WR]The endpoint number determined by the 'uint16_t' type. The IN/OUT endpoint is recognized by most significant bit as is defined by the USB standard.
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__SET_ERROR_STATUS   _IO (USBD, 0x09)
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__START   _IO (USBD, 0x00)
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__STOP   _IO (USBD, 0x01)
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_USBD__WAS_RESET   _IOR(USBD, 0x07, bool*)
Parameters
[RD]The pointer to the bool that indicate that reset was occurred.
Returns
On success 0 is returned, otherwise -1.
#define USBD_EP0_SIZE   8
#define USBD_EP_CONFIG_DISABLED ( )    {.IN_enabled = false, .OUT_enabled = false, .transfer_type = 0, .IN_buffer_size = 0, .OUT_buffer_size = 0}
#define USBD_EP_CONFIG_IN (   usbd_transfer_t__transfer,
  u16_t__size 
)    {.IN_enabled = true, .OUT_enabled = false, .transfer_type = usbd_transfer_t__transfer, .IN_buffer_size = u16_t__size, .OUT_buffer_size = 0}
Parameters
usbd_transfer_t__transfertransfer type
u16_t__sizesize of buffer
#define USBD_EP_CONFIG_IN_OUT (   usbd_transfer_t__transfer,
  u16_t__in_size,
  u16_t__out_size 
)    {.IN_enabled = true, .OUT_enabled = true, .transfer_type = usbd_transfer_t__transfer, .IN_buffer_size = u16_t__in_size, .OUT_buffer_size = u16_t__out_size}
Parameters
usbd_transfer_t__transfertransfer type
u16_t__in_sizesize of IN buffer
u16_t__out_sizesize of OUT buffer
#define USBD_EP_CONFIG_OUT (   usbd_transfer_t__transfer,
  u16_t__size 
)    {.IN_enabled = false, .OUT_enabled = true, .transfer_type = usbd_transfer_t__transfer, .IN_buffer_size = 0, .OUT_buffer_size = u16_t__size}
Parameters
usbd_transfer_t__transfertransfer type
u16_t__sizesize of buffer