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 "net/netdev.h"
33 #include "mutex.h"
34 
35 #ifdef __cplusplus
36 extern "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 #define USBUS_CDCECM_EP_DATA_SIZE 64
79 
84 typedef enum {
89 
93 typedef struct usbus_cdcecm_device {
106  char mac_host[13];
110  size_t tx_len;
112  size_t len;
114  unsigned active_iface;
116 
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif /* USB_USBUS_CDC_ECM_H */
130 
usbus.h
USBUS basic interface.
usbus_cdcecm_device::notif
usbus_cdcecm_notif_t notif
Startup message notification tracker.
Definition: ecm.h:113
usbus_cdcecm_device_t
struct usbus_cdcecm_device usbus_cdcecm_device_t
USBUS CDC ECM device interface context.
control.h
USBUS control endpoint module.
usbus_cdcecm_device::iface_data
usbus_interface_t iface_data
Data interface.
Definition: ecm.h:95
usbus_cdcecm_device::usbus
usbus_t * usbus
Ptr to the USBUS context.
Definition: ecm.h:108
usbus_interface_alt
USBUS interface alternative setting.
Definition: usbus.h:291
usbus_cdcecm_device::active_iface
unsigned active_iface
Current active data interface.
Definition: ecm.h:114
usbus_cdcecm_device::mac_host
char mac_host[13]
host side's MAC address as string
Definition: ecm.h:106
event
event structure
Definition: event.h:142
ethernet.h
Definitions for Ethernet.
usbus_cdcecm_device::iface_ctrl
usbus_interface_t iface_ctrl
Control interface.
Definition: ecm.h:96
usbus_cdcecm_device::netdev
netdev_t netdev
Netdev context struct.
Definition: ecm.h:104
hdr.h
Ethernet header definitions.
netdev.h
Definitions low-level network driver interface.
ETHERNET_ADDR_LEN
#define ETHERNET_ADDR_LEN
Length of an Ethernet address.
Definition: hdr.h:33
USBUS_CDCECM_NOTIF_LINK_UP
@ USBUS_CDCECM_NOTIF_LINK_UP
Link status is notified.
Definition: ecm.h:86
usbus_cdcecm_init
void usbus_cdcecm_init(usbus_t *usbus, usbus_cdcecm_device_t *handler)
CDC ECM initialization function.
usbus_cdcecm_device::len
size_t len
Length of the current rx frame.
Definition: ecm.h:112
usbus_cdcecm_notif_t
usbus_cdcecm_notif_t
notification state, used to track which information must be send to the host
Definition: ecm.h:84
usbus_handler
USBUS handler struct.
Definition: usbus.h:385
usbus_cdcecm_device::tx_xmit
event_t tx_xmit
Transmit ready event.
Definition: ecm.h:103
usbus_cdcecm_device::out_lock
mutex_t out_lock
mutex used for locking netif/USBUS send
Definition: ecm.h:109
usbus_cdcecm_device::tx_len
size_t tx_len
Length of the current tx frame.
Definition: ecm.h:110
netdev
Structure to hold driver state.
Definition: netdev.h:302
usbus_cdcecm_device::ep_ctrl
usbus_endpoint_t * ep_ctrl
Control endpoint.
Definition: ecm.h:100
usbus_cdcecm_device
USBUS CDC ECM device interface context.
Definition: ecm.h:93
USBUS_CDCECM_NOTIF_NONE
@ USBUS_CDCECM_NOTIF_NONE
Nothing notified so far.
Definition: ecm.h:85
usbus_descr_gen
USBUS descriptor generator.
Definition: usbus.h:263
usbus_cdcecm_device::rx_flush
event_t rx_flush
Receive flush event.
Definition: ecm.h:102
mutex.h
Mutex for thread synchronization.
usbus_cdcecm_device::mac_netdev
uint8_t mac_netdev[ETHERNET_ADDR_LEN]
this device's MAC address
Definition: ecm.h:105
usbus_cdcecm_device::ecm_descr
usbus_descr_gen_t ecm_descr
ECM descriptor generator.
Definition: ecm.h:101
usbus_string
USBUS string type.
Definition: usbus.h:175
usbus_interface
USBUS interface.
Definition: usbus.h:302
usbus_cdcecm_device::ep_in
usbus_endpoint_t * ep_in
Data endpoint in.
Definition: ecm.h:98
usbus_cdcecm_device::in_buf
uint8_t in_buf[ETHERNET_FRAME_LEN]
Buffer for the received frames.
Definition: ecm.h:111
ETHERNET_FRAME_LEN
#define ETHERNET_FRAME_LEN
maximum number of bytes in an ethernet frame (without FCS)
Definition: ethernet.h:41
usbus_cdcecm_device::mac_str
usbus_string_t mac_str
String context for the host side mac address.
Definition: ecm.h:107
usbus_cdcecm_device::iface_data_alt
usbus_interface_alt_t iface_data_alt
Data alternative (active) interface.
Definition: ecm.h:97
usbus_cdcecm_device::ep_out
usbus_endpoint_t * ep_out
Data endpoint out.
Definition: ecm.h:99
usbus_endpoint
USBUS endpoint context.
Definition: usbus.h:273
USBUS_CDCECM_NOTIF_SPEED
@ USBUS_CDCECM_NOTIF_SPEED
Link speed is notified.
Definition: ecm.h:87
usbus_cdcecm_device::handler_ctrl
usbus_handler_t handler_ctrl
Control interface handler.
Definition: ecm.h:94
mutex_t
Mutex structure.
Definition: mutex.h:120
descriptor.h
Definitions for USB protocol messages.
usbus
USBUS context struct.
Definition: usbus.h:397