usb: device_next: Respect granularity in UDC buf pool define
Round up buffer size used in UDC_BUF_POOL_DEFINE() to respect the required buffer granularity. The issue was observed with UAC2 explicit feedback data, but the problem applies to any UDC_BUF_POOL_DEFINE() use. In order for every buffer returned by UDC_BUF_POOL_DEFINE() to be both aligned and to have required granurality, it is required to allocate the buffers for ROUND_UP(size, LCM(UDC_BUF_GRANULARITY, UDC_BUF_ALIGN)). Because we do not have Least Common Multiple nor Greatest Common Divisor compile time macros, assume that granularity is multiple of alignment. Validate the assumption with a build time assert. When we get a target where this assumption fails we would have to come up with a solution to compute LCM and/or GCD at compile time. Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
This commit is contained in:
parent
debc744665
commit
0f41950564
1 changed files with 4 additions and 2 deletions
|
|
@ -132,15 +132,17 @@ extern const struct net_buf_data_cb net_buf_dma_cb;
|
|||
*/
|
||||
#define UDC_BUF_POOL_DEFINE(pname, count, size, ud_size, fdestroy) \
|
||||
_NET_BUF_ARRAY_DEFINE(pname, count, ud_size); \
|
||||
BUILD_ASSERT((UDC_BUF_GRANULARITY) % (UDC_BUF_ALIGN) == 0, \
|
||||
"Code assumes granurality is multiple of alignment"); \
|
||||
static uint8_t __nocache __aligned(UDC_BUF_ALIGN) \
|
||||
net_buf_data_##pname[count][size]; \
|
||||
net_buf_data_##pname[count][ROUND_UP(size, UDC_BUF_GRANULARITY)];\
|
||||
static const struct net_buf_pool_fixed net_buf_fixed_##pname = { \
|
||||
.data_pool = (uint8_t *)net_buf_data_##pname, \
|
||||
}; \
|
||||
static const struct net_buf_data_alloc net_buf_fixed_alloc_##pname = { \
|
||||
.cb = &net_buf_fixed_cb, \
|
||||
.alloc_data = (void *)&net_buf_fixed_##pname, \
|
||||
.max_alloc_size = size, \
|
||||
.max_alloc_size = ROUND_UP(size, UDC_BUF_GRANULARITY), \
|
||||
}; \
|
||||
static STRUCT_SECTION_ITERABLE(net_buf_pool, pname) = \
|
||||
NET_BUF_POOL_INITIALIZER(pname, &net_buf_fixed_alloc_##pname, \
|
||||
|
|
|
|||
Loading…
Reference in a new issue