Zephyr API Documentation
4.2.0-rc3
A Scalable Open Source RTOS
4.2.0-rc3
Toggle main menu visibility
Main Page
Related Pages
Topics
Data Structures
Data Structures
Data Structure Index
Data Fields
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerations
Enumerator
Files
File List
Globals
All
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Variables
$
a
b
c
d
f
g
h
i
k
l
m
n
o
p
r
s
t
u
x
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Macros
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Zephyr API Documentation
Introduction
Deprecated List
Topics
Data Structures
Files
File List
doc
kernel
lib
modules
subsys
zephyr
acpi
app_memory
arch
audio
bluetooth
canbus
console
crypto
data
debug
devicetree
dfu
display
drivers
adc
bluetooth
can
clock_control
comparator
console
dac
dma
edac
eeprom
ethernet
firmware
flash
gnss
gpio
haptics
i2c
i3c
ieee802154
interrupt_controller
led
led_strip
mfd
mic_privacy
mipi_dsi
misc
mm
modem
mspi
pcie
pinctrl
pm_cpu_ops
power
psi5
pwm
regulator
retained_mem
rtc
sensor
sent
serial
sip_svc
spi
stepper
timer
uart
usb
emul_bc12.h
udc.h
udc_buf.h
uhc.h
usb_bc12.h
usb_dc.h
usb_c
video
virtio
virtualization
adc.h
auxdisplay.h
bbram.h
bluetooth.h
cache.h
can.h
cellular.h
charger.h
clock_control.h
comparator.h
coredump.h
counter.h
dac.h
dai.h
disk.h
display.h
dma.h
edac.h
eeprom.h
emul.h
emul_bbram.h
emul_fuel_gauge.h
emul_sensor.h
emul_stub_device.h
entropy.h
espi.h
espi_emul.h
espi_saf.h
flash.h
fpga.h
fuel_gauge.h
gnss.h
gpio.h
haptics.h
hwinfo.h
hwspinlock.h
i2c.h
i2c_emul.h
i2s.h
i3c.h
ipm.h
led.h
led_strip.h
loopback_disk.h
lora.h
mbox.h
mdio.h
mipi_dbi.h
mipi_dsi.h
mspi.h
mspi_emul.h
peci.h
pinctrl.h
pm_cpu_ops.h
ps2.h
ptp_clock.h
pwm.h
regulator.h
reset.h
retained_mem.h
rtc.h
sdhc.h
sensor.h
sensor_attribute_types.h
sensor_clock.h
sensor_data_types.h
smbus.h
spi.h
spi_emul.h
stepper.h
swdp.h
syscon.h
tee.h
uart.h
uart_emul.h
uart_pipe.h
video-controls.h
video.h
virtio.h
w1.h
watchdog.h
dsp
dt-bindings
fs
input
internal
ipc
kernel
linker
llext
logging
lorawan
math
mem_mgmt
mgmt
misc
modbus
modem
multi_heap
net
platform
pm
pmci
portability
posix
psa
random
retention
rtio
sd
sensing
settings
shell
sip_svc
stats
storage
sys
task_wdt
timing
toolchain
tracing
usb
usb_c
xen
zbus
zvfs
bindesc.h
cache.h
device.h
devicetree.h
fatal.h
fatal_types.h
init.h
irq.h
irq_multilevel.h
irq_nextlevel.h
irq_offload.h
kernel.h
kernel_includes.h
kernel_structs.h
kernel_version.h
net_buf.h
service.h
shared_irq.h
smf.h
spinlock.h
sw_isr_table.h
sys_clock.h
syscall.h
toolchain.h
types.h
Globals
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
Loading...
Searching...
No Matches
udc_buf.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024 Nordic Semiconductor ASA
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
11
12
#ifndef ZEPHYR_INCLUDE_UDC_BUF_H
13
#define ZEPHYR_INCLUDE_UDC_BUF_H
14
15
#include <
zephyr/kernel.h
>
16
#include <
zephyr/net_buf.h
>
17
18
#if defined(CONFIG_DCACHE) && !defined(CONFIG_UDC_BUF_FORCE_NOCACHE)
19
/*
20
* Here we try to get DMA-safe buffers, but we lack a consistent source of
21
* information about data cache properties, such as line cache size, and a
22
* consistent source of information about what part of memory is DMA'able.
23
* For now, we simply assume that all available memory is DMA'able and use
24
* Kconfig option DCACHE_LINE_SIZE for alignment and granularity.
25
*/
26
#define Z_UDC_BUF_ALIGN CONFIG_DCACHE_LINE_SIZE
27
#define Z_UDC_BUF_GRANULARITY CONFIG_DCACHE_LINE_SIZE
28
#else
29
/*
30
* Default alignment and granularity to pointer size if the platform does not
31
* have a data cache or buffers are placed in nocache memory region.
32
*/
33
#define Z_UDC_BUF_ALIGN sizeof(void *)
34
#define Z_UDC_BUF_GRANULARITY sizeof(void *)
35
#endif
36
37
38
#if defined(CONFIG_UDC_BUF_FORCE_NOCACHE)
39
/*
40
* The usb transfer buffer needs to be in __nocache section
41
*/
42
#define Z_UDC_BUF_SECTION __nocache
43
#else
44
#define Z_UDC_BUF_SECTION
45
#endif
46
55
57
#define UDC_BUF_ALIGN Z_UDC_BUF_ALIGN
58
60
#define UDC_BUF_GRANULARITY Z_UDC_BUF_GRANULARITY
61
71
#define UDC_STATIC_BUF_DEFINE(name, size) \
72
static uint8_t Z_UDC_BUF_SECTION __aligned(UDC_BUF_ALIGN) \
73
name[ROUND_UP(size, UDC_BUF_GRANULARITY)];
71
#define UDC_STATIC_BUF_DEFINE(name, size) \
…
74
82
#define IS_UDC_ALIGNED(buf) IS_ALIGNED(buf, UDC_BUF_ALIGN)
83
87
#define UDC_HEAP_DEFINE(name, bytes, in_section) \
88
uint8_t in_section __aligned(UDC_BUF_ALIGN) \
89
kheap_##name[MAX(bytes, Z_HEAP_MIN_SIZE)]; \
90
STRUCT_SECTION_ITERABLE(k_heap, name) = { \
91
.heap = { \
92
.init_mem = kheap_##name, \
93
.init_bytes = MAX(bytes, Z_HEAP_MIN_SIZE), \
94
}, \
95
}
96
97
#define UDC_K_HEAP_DEFINE(name, size) \
98
COND_CODE_1(CONFIG_UDC_BUF_FORCE_NOCACHE, \
99
(UDC_HEAP_DEFINE(name, size, __nocache)), \
100
(UDC_HEAP_DEFINE(name, size, __noinit)))
101
102
extern
const
struct
net_buf_data_cb net_buf_dma_cb;
104
119
#define UDC_BUF_POOL_VAR_DEFINE(pname, count, size, ud_size, fdestroy) \
120
_NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
121
UDC_K_HEAP_DEFINE(net_buf_mem_pool_##pname, size); \
122
static const struct net_buf_data_alloc net_buf_data_alloc_##pname = { \
123
.cb = &net_buf_dma_cb, \
124
.alloc_data = &net_buf_mem_pool_##pname, \
125
.max_alloc_size = 0, \
126
}; \
127
static STRUCT_SECTION_ITERABLE(net_buf_pool, pname) = \
128
NET_BUF_POOL_INITIALIZER(pname, &net_buf_data_alloc_##pname, \
129
_net_buf_##pname, count, ud_size, \
130
fdestroy)
119
#define UDC_BUF_POOL_VAR_DEFINE(pname, count, size, ud_size, fdestroy) \
…
131
146
#define UDC_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy) \
147
_NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
148
BUILD_ASSERT((UDC_BUF_GRANULARITY) % (UDC_BUF_ALIGN) == 0, \
149
"Code assumes granurality is multiple of alignment"); \
150
static uint8_t Z_UDC_BUF_SECTION __aligned(UDC_BUF_ALIGN) \
151
net_buf_data_##pname[count][ROUND_UP(size, UDC_BUF_GRANULARITY)];\
152
static const struct net_buf_pool_fixed net_buf_fixed_##pname = { \
153
.data_pool = (uint8_t *)net_buf_data_##pname, \
154
}; \
155
static const struct net_buf_data_alloc net_buf_fixed_alloc_##pname = { \
156
.cb = &net_buf_fixed_cb, \
157
.alloc_data = (void *)&net_buf_fixed_##pname, \
158
.max_alloc_size = ROUND_UP(size, UDC_BUF_GRANULARITY), \
159
}; \
160
static STRUCT_SECTION_ITERABLE(net_buf_pool, pname) = \
161
NET_BUF_POOL_INITIALIZER(pname, &net_buf_fixed_alloc_##pname, \
162
_net_buf_##pname, count, ud_size, \
163
fdestroy)
146
#define UDC_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy) \
…
164
168
169
#endif
/* ZEPHYR_INCLUDE_UDC_BUF_H */
kernel.h
Public kernel APIs.
net_buf.h
Buffer management.
zephyr
drivers
usb
udc_buf.h
Generated on
for Zephyr API Documentation by
1.14.0