drivers: usb_dc_nrfx: Use static memory for out endpoints

Change switches to using static memory for out endpoints. Using
heap is not necessary, because number of out endpoints is defined
in DTS.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
This commit is contained in:
Marek Pieta 2020-12-23 13:15:04 +01:00 committed by Carles Cufí
commit 5dbca81f1a

View file

@ -185,11 +185,6 @@ struct usbd_event {
K_HEAP_DEFINE(fifo_elem_pool,
FIFO_ELEM_MAX_SZ * CONFIG_USB_NRFX_EVT_QUEUE_SIZE);
/**
* @brief Endpoint buffer pool
* Used for allocating buffers for the endpoints' data transfer
* Max pool size possible: 3072 Bytes (16 EP * 64B + 2 ISO * 1024B)
*/
/** Number of IN Endpoints configured (including control) */
#define CFG_EPIN_CNT (DT_INST_PROP(0, num_in_endpoints) + \
@ -212,34 +207,20 @@ K_HEAP_DEFINE(fifo_elem_pool,
#define EP_BUF_MAX_SZ 64UL
#define ISO_EP_BUF_MAX_SZ 1024UL
/** Minimum endpoint buffer size (minimum block size) */
#define EP_BUF_POOL_BLOCK_MIN_SZ EP_BUF_MAX_SZ
/** Maximum endpoint buffer size (maximum block size) */
#if (CFG_EP_ISOIN_CNT || CFG_EP_ISOOUT_CNT)
#define EP_BUF_POOL_BLOCK_MAX_SZ ISO_EP_BUF_MAX_SZ
#else
#define EP_BUF_POOL_BLOCK_MAX_SZ EP_BUF_MAX_SZ
#endif
/**
* @brief Output endpoint buffers
* Used as buffers for the endpoints' data transfer
* Max buffers size possible: 1536 Bytes (8 EP * 64B + 1 ISO * 1024B)
*/
static uint8_t ep_out_bufs[CFG_EPOUT_CNT][EP_BUF_MAX_SZ]
__aligned(sizeof(uint32_t));
static uint8_t ep_isoout_bufs[CFG_EP_ISOOUT_CNT][ISO_EP_BUF_MAX_SZ]
__aligned(sizeof(uint32_t));
/** Total endpoints configured */
#define CFG_EP_CNT (CFG_EPIN_CNT + CFG_EP_ISOIN_CNT + \
CFG_EPOUT_CNT + CFG_EP_ISOOUT_CNT)
/** Total buffer size for all endpoints */
#define EP_BUF_TOTAL ((CFG_EPOUT_CNT * EP_BUF_MAX_SZ) + \
(CFG_EP_ISOOUT_CNT * ISO_EP_BUF_MAX_SZ))
/** Total number of maximum sized buffers needed */
#define EP_BUF_POOL_BLOCK_COUNT ((EP_BUF_TOTAL / EP_BUF_POOL_BLOCK_MAX_SZ) + \
((EP_BUF_TOTAL % EP_BUF_POOL_BLOCK_MAX_SZ) ? 1 : 0))
/** 4 Byte Buffer alignment required by hardware */
#define EP_BUF_POOL_ALIGNMENT sizeof(unsigned int)
K_HEAP_DEFINE(ep_buf_pool,
EP_BUF_POOL_BLOCK_MAX_SZ * EP_BUF_POOL_BLOCK_COUNT);
/**
* @brief USBD control structure
*
@ -644,13 +625,7 @@ static int eps_ctx_init(void)
__ASSERT_NO_MSG(ep_ctx);
if (!ep_ctx->buf.block.data) {
ep_ctx->buf.block.data =
k_heap_alloc(&ep_buf_pool,
EP_BUF_MAX_SZ, K_NO_WAIT);
if (ep_ctx->buf.block.data == NULL) {
LOG_ERR("Buffer alloc failed for EP 0x%02x", i);
return -ENOMEM;
}
ep_ctx->buf.block.data = ep_out_bufs[i];
}
ep_ctx_reset(ep_ctx);
@ -663,17 +638,13 @@ static int eps_ctx_init(void)
}
if (CFG_EP_ISOOUT_CNT) {
BUILD_ASSERT(CFG_EP_ISOOUT_CNT <= 1);
ep_ctx = out_endpoint_ctx(NRF_USBD_EPOUT(8));
__ASSERT_NO_MSG(ep_ctx);
if (!ep_ctx->buf.block.data) {
ep_ctx->buf.block.data = k_heap_alloc(&ep_buf_pool,
ISO_EP_BUF_MAX_SZ,
K_NO_WAIT);
if (ep_ctx->buf.block.data == NULL) {
LOG_ERR("EP buffer alloc failed for ISOOUT");
return -ENOMEM;
}
ep_ctx->buf.block.data = ep_isoout_bufs[0];
}
ep_ctx_reset(ep_ctx);
@ -696,7 +667,6 @@ static void eps_ctx_uninit(void)
for (i = 0U; i < CFG_EPOUT_CNT; i++) {
ep_ctx = out_endpoint_ctx(i);
__ASSERT_NO_MSG(ep_ctx);
k_heap_free(&ep_buf_pool, ep_ctx->buf.block.data);
memset(ep_ctx, 0, sizeof(*ep_ctx));
}
@ -709,7 +679,6 @@ static void eps_ctx_uninit(void)
if (CFG_EP_ISOOUT_CNT) {
ep_ctx = out_endpoint_ctx(NRF_USBD_EPOUT(8));
__ASSERT_NO_MSG(ep_ctx);
k_heap_free(&ep_buf_pool, ep_ctx->buf.block.data);
memset(ep_ctx, 0, sizeof(*ep_ctx));
}
}