9
9
* @brief Buffers for USB device support
10
10
*/
11
11
12
- #ifndef ZEPHYR_INCLUDE_UDC_BUF_H
13
- #define ZEPHYR_INCLUDE_UDC_BUF_H
12
+ #ifndef ZEPHYR_INCLUDE_USB_BUF_H
13
+ #define ZEPHYR_INCLUDE_USB_BUF_H
14
14
15
15
#include <zephyr/kernel.h>
16
16
#include <zephyr/net_buf.h>
17
17
18
- #if defined(CONFIG_DCACHE ) && !defined(CONFIG_UDC_BUF_FORCE_NOCACHE )
18
+ #if defined(CONFIG_DCACHE ) && !defined(CONFIG_USB_BUF_FORCE_NOCACHE )
19
19
/*
20
20
* Here we try to get DMA-safe buffers, but we lack a consistent source of
21
21
* information about data cache properties, such as line cache size, and a
22
22
* consistent source of information about what part of memory is DMA'able.
23
23
* For now, we simply assume that all available memory is DMA'able and use
24
24
* Kconfig option DCACHE_LINE_SIZE for alignment and granularity.
25
25
*/
26
- #define Z_UDC_BUF_ALIGN CONFIG_DCACHE_LINE_SIZE
27
- #define Z_UDC_BUF_GRANULARITY CONFIG_DCACHE_LINE_SIZE
26
+ #define Z_USB_BUF_ALIGN CONFIG_DCACHE_LINE_SIZE
27
+ #define Z_USB_BUF_GRANULARITY CONFIG_DCACHE_LINE_SIZE
28
28
#else
29
29
/*
30
30
* Default alignment and granularity to pointer size if the platform does not
31
31
* have a data cache or buffers are placed in nocache memory region.
32
32
*/
33
- #define Z_UDC_BUF_ALIGN sizeof(void *)
34
- #define Z_UDC_BUF_GRANULARITY sizeof(void *)
33
+ #define Z_USB_BUF_ALIGN sizeof(void *)
34
+ #define Z_USB_BUF_GRANULARITY sizeof(void *)
35
35
#endif
36
36
37
37
38
- #if defined(CONFIG_UDC_BUF_FORCE_NOCACHE )
38
+ #if defined(CONFIG_USB_BUF_FORCE_NOCACHE )
39
39
/*
40
40
* The usb transfer buffer needs to be in __nocache section
41
41
*/
42
- #define Z_UDC_BUF_SECTION __nocache
42
+ #define Z_USB_BUF_SECTION __nocache
43
43
#else
44
- #define Z_UDC_BUF_SECTION
44
+ #define Z_USB_BUF_SECTION
45
45
#endif
46
46
47
47
/**
48
- * @brief Buffer macros and definitions used in USB device support
49
- * @defgroup udc_buf Buffer macros and definitions used in USB device support
48
+ * @brief USB buffer macros and definitions
49
+ * @defgroup usb_buf USB buffer macros and definitions
50
50
* @ingroup usb
51
51
* @since 4.0
52
- * @version 0.1.0
52
+ * @version 0.1.1
53
53
* @{
54
54
*/
55
55
56
56
/** Buffer alignment required by the UDC driver */
57
- #define UDC_BUF_ALIGN Z_UDC_BUF_ALIGN
57
+ #define USB_BUF_ALIGN Z_USB_BUF_ALIGN
58
58
59
59
/** Buffer granularity required by the UDC driver */
60
- #define UDC_BUF_GRANULARITY Z_UDC_BUF_GRANULARITY
60
+ #define USB_BUF_GRANULARITY Z_USB_BUF_GRANULARITY
61
61
62
62
/** Round up to the granularity required by the UDC driver */
63
- #define UDC_ROUND_UP (size ) ROUND_UP(size, Z_UDC_BUF_GRANULARITY )
63
+ #define USB_BUF_ROUND_UP (size ) ROUND_UP(size, Z_USB_BUF_GRANULARITY )
64
64
65
65
/**
66
66
* @brief Define a UDC driver-compliant static buffer
71
71
* @param name Buffer name
72
72
* @param size Buffer size
73
73
*/
74
- #define UDC_STATIC_BUF_DEFINE (name , size ) \
75
- static uint8_t Z_UDC_BUF_SECTION __aligned(UDC_BUF_ALIGN ) \
76
- name[UDC_ROUND_UP (size)];
74
+ #define USB_STATIC_BUF_DEFINE (name , size ) \
75
+ static uint8_t Z_USB_BUF_SECTION __aligned(USB_BUF_ALIGN ) \
76
+ name[USB_BUF_ROUND_UP (size)];
77
77
78
78
/**
79
79
* @brief Verify that the buffer is aligned as required by the UDC driver
82
82
*
83
83
* @param buf Buffer pointer
84
84
*/
85
- #define IS_UDC_ALIGNED (buf ) IS_ALIGNED(buf, UDC_BUF_ALIGN )
85
+ #define IS_USB_BUF_ALIGNED (buf ) IS_ALIGNED(buf, USB_BUF_ALIGN )
86
86
87
87
/**
88
88
* @cond INTERNAL_HIDDEN
89
89
*/
90
- #define UDC_HEAP_DEFINE (name , bytes , in_section ) \
91
- uint8_t in_section __aligned(UDC_BUF_ALIGN ) \
90
+ #define USB_BUF_HEAP_DEFINE (name , bytes , in_section ) \
91
+ uint8_t in_section __aligned(USB_BUF_ALIGN ) \
92
92
kheap_##name[MAX(bytes, Z_HEAP_MIN_SIZE)]; \
93
93
STRUCT_SECTION_ITERABLE(k_heap, name) = { \
94
94
.heap = { \
97
97
}, \
98
98
}
99
99
100
- #define UDC_K_HEAP_DEFINE (name , size ) \
101
- COND_CODE_1(CONFIG_UDC_BUF_FORCE_NOCACHE , \
102
- (UDC_HEAP_DEFINE (name, size, __nocache)), \
103
- (UDC_HEAP_DEFINE (name, size, __noinit)))
100
+ #define USB_BUF_K_HEAP_DEFINE (name , size ) \
101
+ COND_CODE_1(CONFIG_USB_BUF_FORCE_NOCACHE , \
102
+ (USB_BUF_HEAP_DEFINE (name, size, __nocache)), \
103
+ (USB_BUF_HEAP_DEFINE (name, size, __noinit)))
104
104
105
105
extern const struct net_buf_data_cb net_buf_dma_cb ;
106
106
/** @endcond */
@@ -119,9 +119,9 @@ extern const struct net_buf_data_cb net_buf_dma_cb;
119
119
* @param ud_size User data space to reserve per buffer.
120
120
* @param fdestroy Optional destroy callback when buffer is freed.
121
121
*/
122
- #define UDC_BUF_POOL_VAR_DEFINE (pname , count , size , ud_size , fdestroy ) \
122
+ #define USB_BUF_POOL_VAR_DEFINE (pname , count , size , ud_size , fdestroy ) \
123
123
_NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
124
- UDC_K_HEAP_DEFINE (net_buf_mem_pool_##pname, size); \
124
+ USB_BUF_K_HEAP_DEFINE (net_buf_mem_pool_##pname, size); \
125
125
static const struct net_buf_data_alloc net_buf_data_alloc_##pname = { \
126
126
.cb = &net_buf_dma_cb, \
127
127
.alloc_data = &net_buf_mem_pool_##pname, \
@@ -146,25 +146,68 @@ extern const struct net_buf_data_cb net_buf_dma_cb;
146
146
* @param ud_size User data space to reserve per buffer.
147
147
* @param fdestroy Optional destroy callback when buffer is freed.
148
148
*/
149
- #define UDC_BUF_POOL_DEFINE (pname , count , size , ud_size , fdestroy ) \
149
+ #define USB_BUF_POOL_DEFINE (pname , count , size , ud_size , fdestroy ) \
150
150
_NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
151
- BUILD_ASSERT((UDC_BUF_GRANULARITY ) % (UDC_BUF_ALIGN ) == 0, \
151
+ BUILD_ASSERT((USB_BUF_GRANULARITY ) % (USB_BUF_ALIGN ) == 0, \
152
152
"Code assumes granurality is multiple of alignment"); \
153
- static uint8_t Z_UDC_BUF_SECTION __aligned(UDC_BUF_ALIGN ) \
154
- net_buf_data_##pname[count][UDC_ROUND_UP (size)]; \
153
+ static uint8_t Z_USB_BUF_SECTION __aligned(USB_BUF_ALIGN ) \
154
+ net_buf_data_##pname[count][USB_BUF_ROUND_UP (size)]; \
155
155
static const struct net_buf_pool_fixed net_buf_fixed_##pname = { \
156
156
.data_pool = (uint8_t *)net_buf_data_##pname, \
157
157
}; \
158
158
static const struct net_buf_data_alloc net_buf_fixed_alloc_##pname = { \
159
159
.cb = &net_buf_fixed_cb, \
160
160
.alloc_data = (void *)&net_buf_fixed_##pname, \
161
- .max_alloc_size = UDC_ROUND_UP (size), \
161
+ .max_alloc_size = USB_BUF_ROUND_UP (size), \
162
162
}; \
163
163
static STRUCT_SECTION_ITERABLE(net_buf_pool, pname) = \
164
164
NET_BUF_POOL_INITIALIZER(pname, &net_buf_fixed_alloc_##pname, \
165
165
_net_buf_##pname, count, ud_size, \
166
166
fdestroy)
167
167
168
+ /**
169
+ * @brief Buffer alignment required by the UDC driver
170
+ * @see USB_BUF_ALIGN
171
+ */
172
+ #define UDC_BUF_ALIGN USB_BUF_ALIGN
173
+
174
+ /**
175
+ * @brief Buffer granularity required by the UDC driver
176
+ * @see USB_BUF_GRANULARITY
177
+ */
178
+ #define UDC_BUF_GRANULARITY USB_BUF_GRANULARITY
179
+
180
+ /**
181
+ * @brief Round up to the granularity required by the UDC driver
182
+ * @see USB_BUF_ROUND_UP
183
+ */
184
+ #define UDC_ROUND_UP (size ) USB_BUF_ROUND_UP(size)
185
+
186
+ /**
187
+ * @brief Define a UDC driver-compliant static buffer
188
+ * @see USB_STATIC_BUF_DEFINE
189
+ */
190
+ #define UDC_STATIC_BUF_DEFINE (name , size ) USB_STATIC_BUF_DEFINE(name, size)
191
+
192
+ /**
193
+ * @brief Verify that the buffer is aligned as required by the UDC driver
194
+ * @see IS_UDC_ALIGNED
195
+ */
196
+ #define IS_UDC_ALIGNED (buf ) IS_USB_BUF_ALIGNED(buf)
197
+
198
+ /**
199
+ * @brief Define a new pool for UDC buffers based on fixed-size data
200
+ * @see USB_BUF_POOL_VAR_DEFINE
201
+ */
202
+ #define UDC_BUF_POOL_VAR_DEFINE (pname , count , size , ud_size , fdestroy ) \
203
+ USB_BUF_POOL_VAR_DEFINE(pname, count, size, ud_size, fdestroy)
204
+
205
+ /**
206
+ * @brief Define a new pool for UDC buffers based on fixed-size data
207
+ * @see USB_BUF_POOL_DEFINE
208
+ */
209
+ #define UDC_BUF_POOL_DEFINE (pname , count , size , ud_size , fdestroy ) \
210
+ USB_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy)
168
211
/**
169
212
* @}
170
213
*/
0 commit comments