Loading...
Searching...
No Matches
ecm.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Koen Zandberg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for
6 * more details.
7 */
8
22#ifndef USB_USBUS_CDC_ECM_H
23#define USB_USBUS_CDC_ECM_H
24
25#include <stdint.h>
26#include <stdlib.h>
27#include "net/ethernet.h"
28#include "net/ethernet/hdr.h"
29#include "usb/descriptor.h"
30#include "usb/usbus.h"
31#include "usb/usbus/control.h"
32#include "macros/math.h"
33#include "net/netdev.h"
34#include "mutex.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
47#ifndef CONFIG_USBUS_CDC_ECM_CONFIG_SPEED
48#define CONFIG_USBUS_CDC_ECM_CONFIG_SPEED 1000000
49#endif
50
54#ifndef CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_DOWNSTREAM
55#define CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_DOWNSTREAM CONFIG_USBUS_CDC_ECM_CONFIG_SPEED
56#endif
57
61#ifndef CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_UPSTREAM
62#define CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_UPSTREAM CONFIG_USBUS_CDC_ECM_CONFIG_SPEED
63#endif
64
72#define USBUS_CDCECM_EP_CTRL_SIZE 16
73
79#ifndef MODULE_PERIPH_USBDEV_HS
80#define USBUS_CDCECM_EP_DATA_SIZE 64
81#else
82#define USBUS_CDCECM_EP_DATA_SIZE 512
83#endif
84
88#define USBUS_ETHERNET_FRAME_BUF MATH_ALIGN(ETHERNET_FRAME_LEN, USBUS_CDCECM_EP_DATA_SIZE)
89
93#define USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF 2
94
98#define USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF 1
99
109
153
161
162#ifdef __cplusplus
163}
164#endif
165
166#endif /* USB_USBUS_CDC_ECM_H */
USBUS control endpoint module.
Definitions for USB protocol messages.
Definitions low-level network driver interface.
Definitions for Ethernet.
#define usbdev_ep_buf_t
Instantiation type for usbdev endpoint buffers.
Definition usbdev.h:126
#define ETHERNET_ADDR_LEN
Length of an Ethernet address.
Definition hdr.h:32
#define USBUS_CDCECM_EP_CTRL_SIZE
CDC ECM interrupt endpoint size.
Definition ecm.h:72
#define USBUS_CDCECM_EP_DATA_SIZE
CDC ECM bulk data endpoint size.
Definition ecm.h:80
usbus_cdcecm_notif_t
notification state, used to track which information must be send to the host
Definition ecm.h:104
#define USBUS_ETHERNET_FRAME_BUF
Full ethernet frame rounded up to a whole number of transfers.
Definition ecm.h:88
void usbus_cdcecm_init(usbus_t *usbus, usbus_cdcecm_device_t *handler)
CDC ECM initialization function.
struct usbus_cdcecm_device usbus_cdcecm_device_t
USBUS CDC ECM device interface context.
@ USBUS_CDCECM_NOTIF_NONE
Nothing notified so far.
Definition ecm.h:105
@ USBUS_CDCECM_NOTIF_LINK_UP
Link status is notified.
Definition ecm.h:106
@ USBUS_CDCECM_NOTIF_SPEED
Link speed is notified.
Definition ecm.h:107
Math helper macros.
Mutex for thread synchronization.
Ethernet header definitions.
event structure
Definition event.h:148
Mutex structure.
Definition mutex.h:146
Structure to hold driver state.
Definition netdev.h:363
USBUS CDC ECM device interface context.
Definition ecm.h:113
usbus_cdcecm_notif_t notif
Startup message notification tracker.
Definition ecm.h:131
usbdev_ep_buf_t control_in[USBUS_CDCECM_EP_CTRL_SIZE]
Host out device in control buffer.
Definition ecm.h:147
usbdev_ep_buf_t data_in[USBUS_CDCECM_EP_DATA_SIZE]
Host in device out data buffer.
Definition ecm.h:142
usbus_interface_t iface_data
Data interface.
Definition ecm.h:115
usbdev_ep_buf_t data_out[USBUS_ETHERNET_FRAME_BUF]
Buffer for received frames from the host.
Definition ecm.h:137
usbus_endpoint_t * ep_ctrl
Control endpoint.
Definition ecm.h:120
netdev_t netdev
Netdev context struct.
Definition ecm.h:124
usbus_descr_gen_t ecm_descr
ECM descriptor generator.
Definition ecm.h:121
event_t tx_xmit
Transmit ready event.
Definition ecm.h:123
usbus_interface_t iface_ctrl
Control interface.
Definition ecm.h:116
unsigned active_iface
Current active data interface.
Definition ecm.h:132
size_t tx_len
Length of the current tx frame.
Definition ecm.h:130
usbus_handler_t handler_ctrl
Control interface handler.
Definition ecm.h:114
usbus_endpoint_t * ep_out
Data endpoint out.
Definition ecm.h:119
char mac_host[13]
host side's MAC address as string
Definition ecm.h:126
mutex_t out_lock
mutex used for locking netif/USBUS send
Definition ecm.h:129
usbus_endpoint_t * ep_in
Data endpoint in.
Definition ecm.h:118
usbus_urb_t out_urb
Host out device in reception URB.
Definition ecm.h:151
event_t rx_flush
Receive flush event.
Definition ecm.h:122
uint8_t mac_netdev[ETHERNET_ADDR_LEN]
this device's MAC address
Definition ecm.h:125
usbus_interface_alt_t iface_data_alt
Data alternative (active) interface.
Definition ecm.h:117
usbus_t * usbus
Ptr to the USBUS context.
Definition ecm.h:128
usbus_string_t mac_str
String context for the host side mac address.
Definition ecm.h:127
USBUS descriptor generator.
Definition usbus.h:298
USBUS endpoint context.
Definition usbus.h:308
USBUS handler struct.
Definition usbus.h:436
USBUS interface alternative setting.
Definition usbus.h:341
USBUS interface.
Definition usbus.h:353
USBUS string type.
Definition usbus.h:210
USBUS USB request/response block.
Definition usbus.h:328
USBUS context struct.
Definition usbus.h:448
USBUS basic interface.