Skip to content
Permalink
Browse files

usb: move the request handler buffer to the USB device code

In order to unify the legacy and composite code, move the class and
vendor request handler buffer into the USB device code, just like in
composite mode. The option is renamed from USB_COMPOSITE_BUFFER_SIZE
into USB_REQUEST_BUFFER_SIZE and also replaces the USB_DFU_MAX_XFER_SIZE
and USB_HID_MAX_PAYLOAD_SIZE options.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information...
aurel32 authored and nashif committed Nov 2, 2018
1 parent 67de7ec commit 819e749ccd845f47285e9ac3cc5fd49f4555ea51
@@ -71,18 +71,13 @@ config USB_DW_USB_2_0
default y

if USB_DEVICE_HID
config USB_HID_MAX_PAYLOAD_SIZE
config USB_REQUEST_BUFFER_SIZE
default 128
endif

config USB_COMPOSITE_BUFFER_SIZE
default 128

if USB_DFU_CLASS

config USB_DFU_MAX_XFER_SIZE
config USB_REQUEST_BUFFER_SIZE
default 4096

endif

config USB_DEVICE_STACK
@@ -159,19 +159,6 @@ struct usb_interface_cfg_data {
* handler.
*/
usb_request_handler custom_handler;
/**
* This data area, allocated by the application, is used to store
* Class specific command data and must be large enough to store the
* largest payload associated with the largest supported Class'
* command set. This data area may be used for USB IN or OUT
* communications.
*/
u8_t *payload_data;
/**
* This data area, allocated by the application, is used to store
* Vendor specific payload.
*/
u8_t *vendor_data;
};

/**
@@ -3,6 +3,7 @@ CONFIG_USB_DEVICE_PID=0x101
CONFIG_GPIO=y
CONFIG_USB=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_REQUEST_BUFFER_SIZE=300
CONFIG_UART_INTERRUPT_DRIVEN=y

CONFIG_TEST_RANDOM_GENERATOR=y
@@ -24,9 +24,6 @@ LOG_MODULE_REGISTER(wpanusb);
/* Max packet size for endpoints */
#define WPANUSB_BULK_EP_MPS 64

/* Max wpanusb command data size */
#define WPANUSB_CLASS_MAX_DATA_SIZE 100

#define WPANUSB_ENDP_BULK_IN 0x81

static struct ieee802154_radio_api *radio_api;
@@ -37,8 +34,6 @@ static struct k_fifo tx_queue;
/* IEEE802.15.4 frame + 1 byte len + 1 byte LQI */
u8_t tx_buf[IEEE802154_MTU + 1 + 1];

u8_t interface_data[WPANUSB_CLASS_MAX_DATA_SIZE];

/**
* Stack for the tx thread.
*/
@@ -359,16 +354,11 @@ static void tx_thread(void)
}
}

/* TODO: FIXME: correct buffer size */
static u8_t buffer[300];

static struct usb_cfg_data wpanusb_config = {
.usb_device_description = (u8_t *)&wpanusb_desc,
.cb_usb_status = wpanusb_status_cb,
.interface = {
.vendor_handler = wpanusb_vendor_handler,
.vendor_data = buffer,
.payload_data = interface_data,
.class_handler = NULL,
.custom_handler = NULL,
},
@@ -24,8 +24,6 @@ LOG_MODULE_REGISTER(webusb);

/* Max packet size for Bulk endpoints */
#define CDC_BULK_EP_MPS 64
/* Max CDC ACM class request max data size */
#define CDC_CLASS_REQ_MAX_DATA_SIZE 8
/* Number of interfaces */
#define WEBUSB_NUM_ITF 0x01
/* Number of Endpoints in the custom interface */
@@ -35,8 +33,6 @@ LOG_MODULE_REGISTER(webusb);

static struct webusb_req_handlers *req_handlers;

u8_t interface_data[CDC_CLASS_REQ_MAX_DATA_SIZE];

u8_t rx_buf[64];

/* Structure representing the global USB description */
@@ -312,8 +308,6 @@ USBD_CFG_DATA_DEFINE(webusb) struct usb_cfg_data webusb_config = {
.class_handler = NULL,
.custom_handler = webusb_custom_handle_req,
.vendor_handler = webusb_vendor_handle_req,
.vendor_data = interface_data,
.payload_data = interface_data,
},
.num_endpoints = ARRAY_SIZE(webusb_ep_data),
.endpoint = webusb_ep_data
@@ -57,9 +57,8 @@ config USB_COMPOSITE_DEVICE
help
Enable composite USB device driver.

config USB_COMPOSITE_BUFFER_SIZE
int "Set buffer size for Class Handler"
depends on USB_COMPOSITE_DEVICE
config USB_REQUEST_BUFFER_SIZE
int "Set buffer size for Class and Vendor request handlers"
default 256 if USB_DEVICE_NETWORK_RNDIS
default 64

@@ -141,11 +141,6 @@ config USB_DFU_WAIT_DELAY_MS
help
A thread can wait for a prescribed time (in ms) for DFU to begin

config USB_DFU_MAX_XFER_SIZE
int
depends on USB_DFU_CLASS
default 64

config USB_DFU_DETACH_TIMEOUT
int
depends on USB_DFU_CLASS
@@ -23,10 +23,6 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(usb_bluetooth);

#if !defined(CONFIG_USB_COMPOSITE_DEVICE)
static u8_t interface_data[64];
#endif

static K_FIFO_DEFINE(rx_queue);
static K_FIFO_DEFINE(tx_queue);

@@ -300,7 +296,6 @@ USBD_CFG_DATA_DEFINE(hci) struct usb_cfg_data bluetooth_config = {
.class_handler = bluetooth_class_handler,
.custom_handler = NULL,
.vendor_handler = NULL,
.payload_data = NULL,
},
.num_endpoints = ARRAY_SIZE(bluetooth_ep_data),
.endpoint = bluetooth_ep_data,
@@ -319,7 +314,6 @@ static int bluetooth_init(struct device *dev)
}

#ifndef CONFIG_USB_COMPOSITE_DEVICE
bluetooth_config.interface.payload_data = interface_data;
bluetooth_config.usb_device_description =
usb_get_device_descriptor();
/* Initialize the USB driver with the right configuration */
@@ -67,9 +67,6 @@ LOG_MODULE_REGISTER(usb_cdc_acm);
/* Size of the internal buffer used for storing received data */
#define CDC_ACM_BUFFER_SIZE (CONFIG_CDC_ACM_BULK_EP_MPS)

/* Max CDC ACM class request max data size */
#define CDC_CLASS_REQ_MAX_DATA_SIZE 8

/* Serial state notification timeout */
#define CDC_CONTROL_SERIAL_STATE_TIMEOUT_US 100000

@@ -189,9 +186,6 @@ struct cdc_acm_dev_data_t {
struct ring_buf *rx_ringbuf;
struct ring_buf *tx_ringbuf;
/* Interface data buffer */
#ifndef CONFIG_USB_COMPOSITE_DEVICE
u8_t interface_data[CDC_CLASS_REQ_MAX_DATA_SIZE];
#endif
/* CDC ACM line coding properties. LE order */
struct cdc_acm_line_coding line_coding;
/* CDC ACM line state bitmap, DTE side */
@@ -531,7 +525,6 @@ static int cdc_acm_init(struct device *dev)
#ifndef CONFIG_USB_COMPOSITE_DEVICE
struct usb_cfg_data *cfg = (void *)dev->config->config_info;

cfg->interface.payload_data = dev_data->interface_data;
cfg->usb_device_description = usb_get_device_descriptor();

/* Initialize the USB driver with the right configuration */
@@ -1001,7 +994,6 @@ static const struct uart_driver_api cdc_acm_driver_api = {
.interface = { \
.class_handler = cdc_acm_class_handle_req, \
.custom_handler = NULL, \
.payload_data = NULL, \
}, \
.num_endpoints = ARRAY_SIZE(cdc_acm_ep_data_##x), \
.endpoint = cdc_acm_ep_data_##x, \
@@ -36,12 +36,6 @@ config HID_INTERRUPT_EP_MPS
help
USB HID Device interrupt endpoint size

config USB_HID_MAX_PAYLOAD_SIZE
int
default 64
help
Max allowed payload size over USB HID Class

config USB_HID_POLL_INTERVAL_MS
int "Polling interval"
default 9
@@ -640,16 +640,11 @@ static void hid_interface_config(struct usb_desc_header *head,
.interface = { \
.class_handler = hid_class_handle_req, \
.custom_handler = hid_custom_handle_req, \
.payload_data = NULL, \
}, \
.num_endpoints = ARRAY_SIZE(hid_ep_data_##x), \
.endpoint = hid_ep_data_##x, \
};

#if !defined(CONFIG_USB_COMPOSITE_DEVICE)
static u8_t interface_data[CONFIG_USB_HID_MAX_PAYLOAD_SIZE];
#endif

int usb_hid_init(const struct device *dev)
{
struct usb_cfg_data *cfg = (void *)dev->config->config_info;
@@ -665,7 +660,6 @@ int usb_hid_init(const struct device *dev)
#ifndef CONFIG_USB_COMPOSITE_DEVICE
int ret;

cfg->interface.payload_data = interface_data;
cfg->usb_device_description = usb_get_device_descriptor();

/* Initialize the USB driver with the right configuration */
@@ -23,10 +23,6 @@ LOG_MODULE_REGISTER(usb_loopback);
#define LOOPBACK_OUT_EP_IDX 0
#define LOOPBACK_IN_EP_IDX 1

#if !defined(CONFIG_USB_COMPOSITE_DEVICE)
static u8_t interface_data[64];
#endif

static u8_t loopback_buf[1024];

/* usb.rst config structure start */
@@ -179,8 +175,6 @@ USBD_CFG_DATA_DEFINE(loopback) struct usb_cfg_data loopback_config = {
.class_handler = NULL,
.custom_handler = NULL,
.vendor_handler = loopback_vendor_handler,
.vendor_data = loopback_buf,
.payload_data = NULL,
},
.num_endpoints = ARRAY_SIZE(ep_cfg),
.endpoint = ep_cfg,
@@ -192,7 +186,6 @@ static int loopback_init(struct device *dev)
#ifndef CONFIG_USB_COMPOSITE_DEVICE
int ret;

loopback_config.interface.payload_data = interface_data;
loopback_config.usb_device_description = usb_get_device_descriptor();

/* usb.rst configure USB controller start */
@@ -862,7 +862,6 @@ USBD_CFG_DATA_DEFINE(msd) struct usb_cfg_data mass_storage_config = {
.interface = {
.class_handler = mass_storage_class_handle_req,
.custom_handler = NULL,
.payload_data = NULL,
},
.num_endpoints = ARRAY_SIZE(mass_ep_data),
.endpoint = mass_ep_data
@@ -901,10 +900,6 @@ static void mass_thread_main(int arg1, int unused)
}
}

#ifndef CONFIG_USB_COMPOSITE_DEVICE
static u8_t interface_data[64];
#endif

/**
* @brief Initialize USB mass storage setup
*
@@ -957,7 +952,6 @@ static int mass_storage_init(struct device *dev)
#ifndef CONFIG_USB_COMPOSITE_DEVICE
int ret;

mass_storage_config.interface.payload_data = interface_data;
mass_storage_config.usb_device_description =
usb_get_device_descriptor();
/* Initialize the USB driver with the right configuration */
@@ -437,7 +437,6 @@ USBD_CFG_DATA_DEFINE(netusb) struct usb_cfg_data netusb_config = {
.class_handler = ecm_class_handler,
.custom_handler = NULL,
.vendor_handler = NULL,
.payload_data = NULL,
},
.num_endpoints = ARRAY_SIZE(ecm_ep_data),
.endpoint = ecm_ep_data,
@@ -286,7 +286,6 @@ USBD_CFG_DATA_DEFINE(netusb) struct usb_cfg_data netusb_config = {
.class_handler = NULL,
.custom_handler = NULL,
.vendor_handler = NULL,
.payload_data = NULL,
},
.num_endpoints = ARRAY_SIZE(eem_ep_data),
.endpoint = eem_ep_data,
@@ -1173,7 +1173,6 @@ USBD_CFG_DATA_DEFINE(netusb) struct usb_cfg_data netusb_config = {
.class_handler = rndis_class_handler,
.custom_handler = NULL,
.vendor_handler = NULL,
.payload_data = NULL,
},
.num_endpoints = ARRAY_SIZE(rndis_ep_data),
.endpoint = rndis_ep_data,
@@ -26,11 +26,6 @@ static struct __netusb {
const struct netusb_function *func;
} netusb;

#if !defined(CONFIG_USB_COMPOSITE_DEVICE)
/* TODO: FIXME: correct buffer size */
static u8_t interface_data[300];
#endif

static int netusb_send(struct device *dev, struct net_pkt *pkt)
{
int ret;
@@ -154,7 +149,6 @@ static void netusb_init(struct net_if *iface)

LOG_DBG("Registering function %u", i);

cfg->interface.payload_data = interface_data;
cfg->usb_device_description = usb_get_device_descriptor();

ret = usb_set_config(cfg);
@@ -58,12 +58,7 @@ LOG_MODULE_REGISTER(usb_dfu);

#define NUMOF_ALTERNATE_SETTINGS 2

#ifdef CONFIG_USB_COMPOSITE_DEVICE
#define USB_DFU_MAX_XFER_SIZE (MIN(CONFIG_USB_COMPOSITE_BUFFER_SIZE, \
CONFIG_USB_DFU_MAX_XFER_SIZE))
#else
#define USB_DFU_MAX_XFER_SIZE CONFIG_USB_DFU_MAX_XFER_SIZE
#endif
#define USB_DFU_MAX_XFER_SIZE CONFIG_USB_REQUEST_BUFFER_SIZE

#define FIRMWARE_IMAGE_0_LABEL "image-1"
#define FIRMWARE_IMAGE_1_LABEL "image-0"
@@ -711,7 +706,6 @@ USBD_CFG_DATA_DEFINE(dfu) struct usb_cfg_data dfu_config = {
.interface = {
.class_handler = dfu_class_handle_req,
.custom_handler = dfu_custom_handle_req,
.payload_data = dfu_data.buffer,
},
.num_endpoints = 0,
};
@@ -728,7 +722,6 @@ USBD_CFG_DATA_DEFINE(dfu_mode) struct usb_cfg_data dfu_mode_config = {
.interface = {
.class_handler = dfu_class_handle_req,
.custom_handler = dfu_custom_handle_req,
.payload_data = dfu_data.buffer,
},
.num_endpoints = 0,
};

0 comments on commit 819e749

Please sign in to comment.
You can’t perform that action at this time.