mikroSDK Reference Manual
net_device.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2020 Peter Lawrence
5 * Copyright (c) 2019 Ha Thach (tinyusb.org)
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 * This file is part of the TinyUSB stack.
26 */
27
28#ifndef _TUSB_NET_DEVICE_H_
29#define _TUSB_NET_DEVICE_H_
30
31#include "class/cdc/cdc.h"
32
33#if CFG_TUD_ECM_RNDIS && CFG_TUD_NCM
34#error "Cannot enable both ECM_RNDIS and NCM network drivers"
35#endif
36
37#include "ncm.h"
38
39/* declared here, NOT in usb_descriptors.c, so that the driver can intelligently ZLP as needed */
40#define CFG_TUD_NET_ENDPOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
41
42/* Maximum Transmission Unit (in bytes) of the network, including Ethernet header */
43#ifndef CFG_TUD_NET_MTU
44#define CFG_TUD_NET_MTU 1514
45#endif
46
47#ifndef CFG_TUD_NCM_IN_NTB_MAX_SIZE
48#define CFG_TUD_NCM_IN_NTB_MAX_SIZE 3200
49#endif
50
51#ifndef CFG_TUD_NCM_OUT_NTB_MAX_SIZE
52#define CFG_TUD_NCM_OUT_NTB_MAX_SIZE 3200
53#endif
54
55#ifndef CFG_TUD_NCM_MAX_DATAGRAMS_PER_NTB
56#define CFG_TUD_NCM_MAX_DATAGRAMS_PER_NTB 8
57#endif
58
59#ifndef CFG_TUD_NCM_ALIGNMENT
60#define CFG_TUD_NCM_ALIGNMENT 4
61#endif
62
63#ifdef __cplusplus
64 extern "C" {
65#endif
66
67//--------------------------------------------------------------------+
68// Application API
69//--------------------------------------------------------------------+
70
71// indicate to network driver that client has finished with the packet provided to network_recv_cb()
72void tud_network_recv_renew(void);
73
74// poll network driver for its ability to accept another packet to transmit
75bool tud_network_can_xmit(uint16_t size);
76
77// if network_can_xmit() returns true, network_xmit() can be called once
78void tud_network_xmit(void *ref, uint16_t arg);
79
80//--------------------------------------------------------------------+
81// Application Callbacks (WEAK is optional)
82//--------------------------------------------------------------------+
83
84// client must provide this: return false if the packet buffer was not accepted
85bool tud_network_recv_cb(const uint8_t *src, uint16_t size);
86
87// client must provide this: copy from network stack packet pointer to dst
88uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg);
89
90//------------- ECM/RNDIS -------------//
91
92// client must provide this: initialize any network state back to the beginning
93void tud_network_init_cb(void);
94
95// client must provide this: 48-bit MAC address
96// TODO removed later since it is not part of tinyusb stack
97extern uint8_t tud_network_mac_address[6];
98
99//------------- NCM -------------//
100
101// callback to client providing optional indication of internal state of network driver
102void tud_network_link_state_cb(bool state);
103
104//--------------------------------------------------------------------+
105// INTERNAL USBD-CLASS DRIVER API
106//--------------------------------------------------------------------+
107void netd_init (void);
108void netd_reset (uint8_t rhport);
109uint16_t netd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
110bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
111bool netd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
112void netd_report (uint8_t *buf, uint16_t len);
113
114#ifdef __cplusplus
115 }
116#endif
117
118#endif /* _TUSB_NET_DEVICE_H_ */
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647