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
9#pragma once
10
23
24#include <stdint.h>
25#include <stdlib.h>
26#include "net/ethernet.h"
27#include "net/ethernet/hdr.h"
28#include "usb/descriptor.h"
29#include "usb/usbus.h"
30#include "usb/usbus/control.h"
31#include "macros/math.h"
32#include "net/netdev.h"
33#include "mutex.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
46#ifndef CONFIG_USBUS_CDC_ECM_CONFIG_SPEED
47#define CONFIG_USBUS_CDC_ECM_CONFIG_SPEED 1000000
48#endif
49
53#ifndef CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_DOWNSTREAM
54#define CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_DOWNSTREAM CONFIG_USBUS_CDC_ECM_CONFIG_SPEED
55#endif
56
60#ifndef CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_UPSTREAM
61#define CONFIG_USBUS_CDC_ECM_CONFIG_SPEED_UPSTREAM CONFIG_USBUS_CDC_ECM_CONFIG_SPEED
62#endif
63
71#define USBUS_CDCECM_EP_CTRL_SIZE 16
72
78#ifndef MODULE_PERIPH_USBDEV_HS
79#define USBUS_CDCECM_EP_DATA_SIZE 64
80#else
81#define USBUS_CDCECM_EP_DATA_SIZE 512
82#endif
83
87#define USBUS_ETHERNET_FRAME_BUF MATH_ALIGN(ETHERNET_FRAME_LEN, USBUS_CDCECM_EP_DATA_SIZE)
88
92#define USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF 2
93
97#define USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF 1
98
108
152
160
161#ifdef __cplusplus
162}
163#endif
164
USBUS control endpoint module.
Definitions for USB protocol messages.
Definitions low-level network driver interface.
Definitions for Ethernet.
struct netdev netdev_t
Forward declaration for netdev struct.
Definition netdev.h:288
#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:31
struct event event_t
event structure forward declaration
Definition event.h:135
struct usbus_interface_alt usbus_interface_alt_t
USBUS interface alternative setting.
struct usbus_string usbus_string_t
USBUS string type.
struct usbus_urb usbus_urb_t
USBUS USB request/response block.
struct usbus_endpoint usbus_endpoint_t
USBUS endpoint context.
struct usbus_descr_gen usbus_descr_gen_t
USBUS descriptor generator.
struct usbus_interface usbus_interface_t
USBUS interface.
struct usbus_handler usbus_handler_t
USBUS event handler forward declaration.
Definition usbus.h:223
struct usbus usbus_t
USBUS context forward declaration.
Definition usbus.h:218
#define USBUS_CDCECM_EP_CTRL_SIZE
CDC ECM interrupt endpoint size.
Definition ecm.h:71
#define USBUS_CDCECM_EP_DATA_SIZE
CDC ECM bulk data endpoint size.
Definition ecm.h:79
usbus_cdcecm_notif_t
notification state, used to track which information must be send to the host
Definition ecm.h:103
#define USBUS_ETHERNET_FRAME_BUF
Full ethernet frame rounded up to a whole number of transfers.
Definition ecm.h:87
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:104
@ USBUS_CDCECM_NOTIF_LINK_UP
Link status is notified.
Definition ecm.h:105
@ USBUS_CDCECM_NOTIF_SPEED
Link speed is notified.
Definition ecm.h:106
Math helper macros.
Mutex for thread synchronization.
Ethernet header definitions.
Mutex structure.
Definition mutex.h:39
USBUS CDC ECM device interface context.
Definition ecm.h:112
usbus_cdcecm_notif_t notif
Startup message notification tracker.
Definition ecm.h:130
usbdev_ep_buf_t control_in[USBUS_CDCECM_EP_CTRL_SIZE]
Host out device in control buffer.
Definition ecm.h:146
usbdev_ep_buf_t data_in[USBUS_CDCECM_EP_DATA_SIZE]
Host in device out data buffer.
Definition ecm.h:141
usbus_interface_t iface_data
Data interface.
Definition ecm.h:114
usbdev_ep_buf_t data_out[USBUS_ETHERNET_FRAME_BUF]
Buffer for received frames from the host.
Definition ecm.h:136
usbus_endpoint_t * ep_ctrl
Control endpoint.
Definition ecm.h:119
netdev_t netdev
Netdev context struct.
Definition ecm.h:123
usbus_descr_gen_t ecm_descr
ECM descriptor generator.
Definition ecm.h:120
event_t tx_xmit
Transmit ready event.
Definition ecm.h:122
usbus_interface_t iface_ctrl
Control interface.
Definition ecm.h:115
unsigned active_iface
Current active data interface.
Definition ecm.h:131
size_t tx_len
Length of the current tx frame.
Definition ecm.h:129
usbus_handler_t handler_ctrl
Control interface handler.
Definition ecm.h:113
usbus_endpoint_t * ep_out
Data endpoint out.
Definition ecm.h:118
char mac_host[13]
host side's MAC address as string
Definition ecm.h:125
mutex_t out_lock
mutex used for locking netif/USBUS send
Definition ecm.h:128
usbus_endpoint_t * ep_in
Data endpoint in.
Definition ecm.h:117
usbus_urb_t out_urb
Host out device in reception URB.
Definition ecm.h:150
event_t rx_flush
Receive flush event.
Definition ecm.h:121
uint8_t mac_netdev[ETHERNET_ADDR_LEN]
this device's MAC address
Definition ecm.h:124
usbus_interface_alt_t iface_data_alt
Data alternative (active) interface.
Definition ecm.h:116
usbus_t * usbus
Ptr to the USBUS context.
Definition ecm.h:127
usbus_string_t mac_str
String context for the host side mac address.
Definition ecm.h:126
USBUS context struct.
Definition usbus.h:447
USBUS basic interface.