Open FFBoard
Open source force feedback firmware
ncm.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2021, Ha Thach (tinyusb.org)
5 * Copyright (c) 2024, Hardy Griech
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_NCM_H_
29#define _TUSB_NCM_H_
30
31#include "common/tusb_common.h"
32
33// NTB buffers size for reception side, must be >> MTU to avoid TCP retransmission (driver issue ?)
34// Linux use 2048 as minimal size
35#ifndef CFG_TUD_NCM_OUT_NTB_MAX_SIZE
36 #define CFG_TUD_NCM_OUT_NTB_MAX_SIZE 3200
37#endif
38
39// NTB buffers size for reception side, must be > MTU
40// Linux use 2048 as minimal size
41#ifndef CFG_TUD_NCM_IN_NTB_MAX_SIZE
42 #define CFG_TUD_NCM_IN_NTB_MAX_SIZE 3200
43#endif
44
45// Number of NTB buffers for reception side
46// Depending on the configuration, this parameter could be increased with the cost of additional RAM requirements
47// On Full-Speed (RP2040) :
48// 1 - good performance
49// 2 - up to 30% more performance with iperf with small packets
50// >2 - no performance gain
51// On High-Speed (STM32F7) :
52// No performance gain
53#ifndef CFG_TUD_NCM_OUT_NTB_N
54 #define CFG_TUD_NCM_OUT_NTB_N 1
55#endif
56
57// Number of NTB buffers for transmission side
58// Depending on the configuration, this parameter could be increased with the cost of additional RAM requirements
59// On Full-Speed (RP2040) :
60// 1 - good performance but SystemView shows lost events (on load test)
61// 2 - up to 50% more performance with iperf with small packets, "tud_network_can_xmit: request blocked"
62// happens from time to time with SystemView
63// 3 - "tud_network_can_xmit: request blocked" never happens
64// >3 - no performance gain
65// On High-Speed (STM32F7) :
66// No performance gain
67#ifndef CFG_TUD_NCM_IN_NTB_N
68 #define CFG_TUD_NCM_IN_NTB_N 1
69#endif
70
71// How many datagrams it is allowed to put into an NTB for transmission side
72#ifndef CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB
73 #define CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB 8
74#endif
75
76// This tells the host how many datagrams it is allowed to put into an NTB
77#ifndef CFG_TUD_NCM_OUT_MAX_DATAGRAMS_PER_NTB
78 #define CFG_TUD_NCM_OUT_MAX_DATAGRAMS_PER_NTB 6
79#endif
80
81// Table 6.2 Class-Specific Request Codes for Network Control Model subclass
82typedef enum
83{
101
102#define NTH16_SIGNATURE 0x484D434E
103#define NDP16_SIGNATURE_NCM0 0x304D434E
104#define NDP16_SIGNATURE_NCM1 0x314D434E
105
106typedef struct TU_ATTR_PACKED {
120
121typedef struct TU_ATTR_PACKED {
122 uint32_t dwSignature;
128
129typedef struct TU_ATTR_PACKED {
133
134typedef struct TU_ATTR_PACKED {
135 uint32_t dwSignature;
138 //ndp16_datagram_t datagram[];
140
141typedef union TU_ATTR_PACKED {
142 struct {
145 ndp16_datagram_t ndp_datagram[CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB + 1];
146 };
147 uint8_t data[CFG_TUD_NCM_IN_NTB_MAX_SIZE];
149
150typedef union TU_ATTR_PACKED {
151 struct {
152 nth16_t nth;
153 // only the header is at a guaranteed position
154 };
155 uint8_t data[CFG_TUD_NCM_OUT_NTB_MAX_SIZE];
157
160 uint32_t downlink, uplink;
161};
162
163#endif
struct TU_ATTR_PACKED ndp16_datagram_t
union TU_ATTR_PACKED recv_ntb_t
struct TU_ATTR_PACKED ntb_parameters_t
union TU_ATTR_PACKED xmit_ntb_t
struct TU_ATTR_PACKED ndp16_t
ncm_request_code_t
Definition: ncm.h:83
@ NCM_SET_CRC_MODE
Definition: ncm.h:99
@ NCM_SET_NTB_INPUT_SIZE
Definition: ncm.h:95
@ NCM_SET_NTB_FORMAT
Definition: ncm.h:93
@ NCM_GET_MAX_DATAGRAM_SIZE
Definition: ncm.h:96
@ NCM_SET_ETHERNET_PACKET_FILTER
Definition: ncm.h:87
@ NCM_GET_NTB_FORMAT
Definition: ncm.h:92
@ NCM_SET_ETHERNET_MULTICAST_FILTERS
Definition: ncm.h:84
@ NCM_GET_NTB_INPUT_SIZE
Definition: ncm.h:94
@ NCM_SET_MAX_DATAGRAM_SIZE
Definition: ncm.h:97
@ NCM_GET_NTB_PARAMETERS
Definition: ncm.h:89
@ NCM_SET_NET_ADDRESS
Definition: ncm.h:91
@ NCM_GET_CRC_MODE
Definition: ncm.h:98
@ NCM_SET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER
Definition: ncm.h:85
@ NCM_GET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER
Definition: ncm.h:86
@ NCM_GET_NET_ADDRESS
Definition: ncm.h:90
@ NCM_GET_ETHERNET_STATISTIC
Definition: ncm.h:88
struct TU_ATTR_PACKED nth16_t
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
uint16_t wDatagramIndex
Definition: ncm.h:130
uint16_t wNdbInAlignment
Definition: ncm.h:112
uint16_t wNextNdpIndex
Definition: ncm.h:137
nth16_t nth
Definition: ncm.h:143
uint16_t bmNtbFormatsSupported
Definition: ncm.h:108
uint16_t wDatagramLength
Definition: ncm.h:131
uint32_t dwSignature
Definition: ncm.h:122
uint16_t wSequence
Definition: ncm.h:124
uint8_t data[CFG_TUD_NCM_IN_NTB_MAX_SIZE]
Definition: ncm.h:147
uint16_t wBlockLength
Definition: ncm.h:125
uint16_t wLength
Definition: audio.h:840
uint16_t wNdbOutDivisor
Definition: ncm.h:115
volatile uint16_t
Definition: hcd_rusb2.c:58
uint32_t dwNtbOutMaxSize
Definition: ncm.h:114
uint16_t wNtbOutMaxDatagrams
Definition: ncm.h:118
uint16_t wReserved
Definition: ncm.h:113
uint16_t wNdpIndex
Definition: ncm.h:126
uint16_t wHeaderLength
Definition: ncm.h:123
ndp16_datagram_t ndp_datagram[CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB+1]
Definition: ncm.h:145
uint16_t wNdbOutAlignment
Definition: ncm.h:117
ndp16_t ndp
Definition: ncm.h:144
uint16_t wNdbOutPayloadRemainder
Definition: ncm.h:116
uint32_t dwNtbInMaxSize
Definition: ncm.h:109
uint16_t wNdbInDivisor
Definition: ncm.h:110
uint16_t wNdbInPayloadRemainder
Definition: ncm.h:111
uint32_t uplink
Definition: ncm.h:160
tusb_control_request_t header
Definition: ncm.h:159
uint32_t downlink
Definition: ncm.h:160