mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2026-01-01 01:41:18 +01:00
USBUS/cdc_ecm: Adapt to xmit API
This commit is contained in:
parent
1a0bc3d8bc
commit
5455c40c7a
@ -106,12 +106,26 @@ typedef struct usbus_cdcecm_device {
|
||||
char mac_host[13]; /**< host side's MAC address as string */
|
||||
usbus_string_t mac_str; /**< String context for the host side mac address */
|
||||
usbus_t *usbus; /**< Ptr to the USBUS context */
|
||||
mutex_t out_lock; /**< mutex used for locking netif/USBUS send */
|
||||
size_t tx_len; /**< Length of the current tx frame */
|
||||
uint8_t in_buf[ETHERNET_FRAME_LEN]; /**< Buffer for the received frames */
|
||||
mutex_t out_lock; /**< mutex used for locking netif/USBUS send */
|
||||
size_t tx_len; /**< Length of the current tx frame */
|
||||
size_t len; /**< Length of the current rx frame */
|
||||
usbus_cdcecm_notif_t notif; /**< Startup message notification tracker */
|
||||
unsigned active_iface; /**< Current active data interface */
|
||||
usbus_cdcecm_notif_t notif; /**< Startup message notification tracker */
|
||||
unsigned active_iface; /**< Current active data interface */
|
||||
|
||||
/**
|
||||
* @brief Buffer for received frames
|
||||
*/
|
||||
usbdev_ep_buf_t data_out[ETHERNET_FRAME_LEN];
|
||||
|
||||
/**
|
||||
* @brief Host in device out data buffer
|
||||
*/
|
||||
usbdev_ep_buf_t data_in[USBUS_CDCECM_EP_DATA_SIZE];
|
||||
|
||||
/**
|
||||
* @brief Host out device in control buffer
|
||||
*/
|
||||
usbdev_ep_buf_t control_in[USBUS_CDCECM_EP_CTRL_SIZE];
|
||||
} usbus_cdcecm_device_t;
|
||||
|
||||
/**
|
||||
|
||||
@ -115,7 +115,7 @@ static void _notify_link_speed(usbus_cdcecm_device_t *cdcecm)
|
||||
{
|
||||
DEBUG("CDC ECM: sending link speed indication\n");
|
||||
usb_desc_cdcecm_speed_t *notification =
|
||||
(usb_desc_cdcecm_speed_t *)cdcecm->ep_ctrl->ep->buf;
|
||||
(usb_desc_cdcecm_speed_t *)cdcecm->control_in;
|
||||
notification->setup.type = USB_SETUP_REQUEST_DEVICE2HOST |
|
||||
USB_SETUP_REQUEST_TYPE_CLASS |
|
||||
USB_SETUP_REQUEST_RECIPIENT_INTERFACE;
|
||||
@ -126,7 +126,7 @@ static void _notify_link_speed(usbus_cdcecm_device_t *cdcecm)
|
||||
|
||||
notification->down = CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_DOWNSTREAM;
|
||||
notification->up = CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_UPSTREAM;
|
||||
usbdev_ep_ready(cdcecm->ep_ctrl->ep,
|
||||
usbdev_ep_xmit(cdcecm->ep_ctrl->ep, cdcecm->control_in,
|
||||
sizeof(usb_desc_cdcecm_speed_t));
|
||||
cdcecm->notif = USBUS_CDCECM_NOTIF_SPEED;
|
||||
}
|
||||
@ -134,7 +134,7 @@ static void _notify_link_speed(usbus_cdcecm_device_t *cdcecm)
|
||||
static void _notify_link_up(usbus_cdcecm_device_t *cdcecm)
|
||||
{
|
||||
DEBUG("CDC ECM: sending link up indication\n");
|
||||
usb_setup_t *notification = (usb_setup_t *)cdcecm->ep_ctrl->ep->buf;
|
||||
usb_setup_t *notification = (usb_setup_t *)cdcecm->control_in;
|
||||
notification->type = USB_SETUP_REQUEST_DEVICE2HOST |
|
||||
USB_SETUP_REQUEST_TYPE_CLASS |
|
||||
USB_SETUP_REQUEST_RECIPIENT_INTERFACE;
|
||||
@ -142,7 +142,7 @@ static void _notify_link_up(usbus_cdcecm_device_t *cdcecm)
|
||||
notification->value = 1;
|
||||
notification->index = cdcecm->iface_ctrl.idx;
|
||||
notification->length = 0;
|
||||
usbdev_ep_ready(cdcecm->ep_ctrl->ep, sizeof(usb_setup_t));
|
||||
usbdev_ep_xmit(cdcecm->ep_ctrl->ep, cdcecm->control_in, sizeof(usb_setup_t));
|
||||
cdcecm->notif = USBUS_CDCECM_NOTIF_LINK_UP;
|
||||
}
|
||||
|
||||
@ -251,7 +251,8 @@ static int _control_handler(usbus_t *usbus, usbus_handler_t *handler,
|
||||
setup->value);
|
||||
cdcecm->active_iface = (uint8_t)setup->value;
|
||||
if (cdcecm->active_iface == 1) {
|
||||
usbdev_ep_ready(cdcecm->ep_out->ep, 0);
|
||||
usbdev_ep_xmit(cdcecm->ep_out->ep, cdcecm->data_out,
|
||||
USBUS_CDCECM_EP_DATA_SIZE);
|
||||
_notify_link_up(cdcecm);
|
||||
}
|
||||
break;
|
||||
@ -290,36 +291,15 @@ static void _handle_tx_xmit(event_t *ev)
|
||||
mutex_unlock(&cdcecm->out_lock);
|
||||
}
|
||||
/* Data prepared by netdev_send, signal ready to usbus */
|
||||
usbdev_ep_ready(cdcecm->ep_in->ep, cdcecm->tx_len);
|
||||
}
|
||||
|
||||
static void _handle_rx_flush(usbus_cdcecm_device_t *cdcecm)
|
||||
{
|
||||
cdcecm->len = 0;
|
||||
usbdev_ep_xmit(cdcecm->ep_in->ep, cdcecm->data_in, cdcecm->tx_len);
|
||||
}
|
||||
|
||||
static void _handle_rx_flush_ev(event_t *ev)
|
||||
{
|
||||
usbus_cdcecm_device_t *cdcecm = container_of(ev, usbus_cdcecm_device_t,
|
||||
rx_flush);
|
||||
|
||||
usbdev_ep_ready(cdcecm->ep_out->ep, 0);
|
||||
_handle_rx_flush(cdcecm);
|
||||
}
|
||||
|
||||
static void _store_frame_chunk(usbus_cdcecm_device_t *cdcecm, size_t len)
|
||||
{
|
||||
uint8_t *buf = cdcecm->ep_out->ep->buf;
|
||||
|
||||
/* Truncate if it exceeds the expected MTU size. */
|
||||
/* TODO: Should be converted to an endpoint halt after #17090 is merged */
|
||||
if (cdcecm->len + len < ETHERNET_FRAME_LEN) {
|
||||
memcpy(cdcecm->in_buf + cdcecm->len, buf, len);
|
||||
cdcecm->len += len;
|
||||
}
|
||||
if (len < USBUS_CDCECM_EP_DATA_SIZE) {
|
||||
netdev_trigger_event_isr(&cdcecm->netdev);
|
||||
}
|
||||
cdcecm->len = 0; /* Flush packet */
|
||||
usbdev_ep_xmit(cdcecm->ep_out->ep, cdcecm->data_out, USBUS_CDCECM_EP_DATA_SIZE);
|
||||
}
|
||||
|
||||
static void _transfer_handler(usbus_t *usbus, usbus_handler_t *handler,
|
||||
@ -335,9 +315,14 @@ static void _transfer_handler(usbus_t *usbus, usbus_handler_t *handler,
|
||||
}
|
||||
size_t len = 0;
|
||||
usbdev_ep_get(ep, USBOPT_EP_AVAILABLE, &len, sizeof(size_t));
|
||||
_store_frame_chunk(cdcecm, len);
|
||||
cdcecm->len += len;
|
||||
if (len == USBUS_CDCECM_EP_DATA_SIZE) {
|
||||
usbdev_ep_ready(ep, 0);
|
||||
/* ready next chunk */
|
||||
usbdev_ep_xmit(ep, cdcecm->data_out + cdcecm->len,
|
||||
USBUS_CDCECM_EP_DATA_SIZE);
|
||||
}
|
||||
else {
|
||||
netdev_trigger_event_isr(&cdcecm->netdev);
|
||||
}
|
||||
}
|
||||
else if (ep == cdcecm->ep_in->ep) {
|
||||
@ -354,9 +339,9 @@ static void _handle_reset(usbus_t *usbus, usbus_handler_t *handler)
|
||||
usbus_cdcecm_device_t *cdcecm = (usbus_cdcecm_device_t *)handler;
|
||||
|
||||
DEBUG("CDC ECM: Reset\n");
|
||||
_handle_rx_flush(cdcecm);
|
||||
_handle_in_complete(usbus, handler);
|
||||
cdcecm->notif = USBUS_CDCECM_NOTIF_NONE;
|
||||
cdcecm->len = 0; /* Flush received data */
|
||||
cdcecm->active_iface = 0;
|
||||
mutex_unlock(&cdcecm->out_lock);
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
|
||||
{
|
||||
assert(iolist);
|
||||
usbus_cdcecm_device_t *cdcecm = _netdev_to_cdcecm(netdev);
|
||||
uint8_t *buf = cdcecm->ep_in->ep->buf;
|
||||
uint8_t *buf = cdcecm->data_in;
|
||||
const iolist_t *iolist_start = iolist;
|
||||
size_t len = iolist_size(iolist);
|
||||
/* interface with alternative function ID 1 is the interface containing the
|
||||
@ -142,7 +142,7 @@ static int _recv(netdev_t *netdev, void *buf, size_t max_len, void *info)
|
||||
return pktlen;
|
||||
}
|
||||
if (pktlen <= max_len) {
|
||||
memcpy(buf, cdcecm->in_buf, pktlen);
|
||||
memcpy(buf, cdcecm->data_out, pktlen);
|
||||
}
|
||||
_signal_rx_flush(cdcecm);
|
||||
return (pktlen <= max_len) ? (int)pktlen : -ENOBUFS;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user