Skip to content

Commit 2f621c3

Browse files
committed
include: usb: introduce UDC_ROUND_UP macro
Move the common rounding pattern to the UDC_ROUND_UP macro. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
1 parent b539372 commit 2f621c3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

include/zephyr/drivers/usb/udc_buf.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
/** Buffer granularity required by the UDC driver */
6060
#define UDC_BUF_GRANULARITY Z_UDC_BUF_GRANULARITY
6161

62+
/** Round up to the granularity required by the UDC driver */
63+
#define UDC_ROUND_UP(size) ROUND_UP(size, Z_UDC_BUF_GRANULARITY)
64+
6265
/**
6366
* @brief Define a UDC driver-compliant static buffer
6467
*
@@ -70,7 +73,7 @@
7073
*/
7174
#define UDC_STATIC_BUF_DEFINE(name, size) \
7275
static uint8_t Z_UDC_BUF_SECTION __aligned(UDC_BUF_ALIGN) \
73-
name[ROUND_UP(size, UDC_BUF_GRANULARITY)];
76+
name[UDC_ROUND_UP(size)];
7477

7578
/**
7679
* @brief Verify that the buffer is aligned as required by the UDC driver
@@ -148,14 +151,14 @@ extern const struct net_buf_data_cb net_buf_dma_cb;
148151
BUILD_ASSERT((UDC_BUF_GRANULARITY) % (UDC_BUF_ALIGN) == 0, \
149152
"Code assumes granurality is multiple of alignment"); \
150153
static uint8_t Z_UDC_BUF_SECTION __aligned(UDC_BUF_ALIGN) \
151-
net_buf_data_##pname[count][ROUND_UP(size, UDC_BUF_GRANULARITY)];\
154+
net_buf_data_##pname[count][UDC_ROUND_UP(size)]; \
152155
static const struct net_buf_pool_fixed net_buf_fixed_##pname = { \
153156
.data_pool = (uint8_t *)net_buf_data_##pname, \
154157
}; \
155158
static const struct net_buf_data_alloc net_buf_fixed_alloc_##pname = { \
156159
.cb = &net_buf_fixed_cb, \
157160
.alloc_data = (void *)&net_buf_fixed_##pname, \
158-
.max_alloc_size = ROUND_UP(size, UDC_BUF_GRANULARITY), \
161+
.max_alloc_size = UDC_ROUND_UP(size), \
159162
}; \
160163
static STRUCT_SECTION_ITERABLE(net_buf_pool, pname) = \
161164
NET_BUF_POOL_INITIALIZER(pname, &net_buf_fixed_alloc_##pname, \

0 commit comments

Comments
 (0)