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:
parent
49e992ac8c
commit
5dbca81f1a
1 changed files with 13 additions and 44 deletions
|
@ -185,11 +185,6 @@ struct usbd_event {
|
||||||
K_HEAP_DEFINE(fifo_elem_pool,
|
K_HEAP_DEFINE(fifo_elem_pool,
|
||||||
FIFO_ELEM_MAX_SZ * CONFIG_USB_NRFX_EVT_QUEUE_SIZE);
|
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) */
|
/** Number of IN Endpoints configured (including control) */
|
||||||
#define CFG_EPIN_CNT (DT_INST_PROP(0, num_in_endpoints) + \
|
#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 EP_BUF_MAX_SZ 64UL
|
||||||
#define ISO_EP_BUF_MAX_SZ 1024UL
|
#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
|
* @brief Output endpoint buffers
|
||||||
|
* Used as buffers for the endpoints' data transfer
|
||||||
/** Maximum endpoint buffer size (maximum block size) */
|
* Max buffers size possible: 1536 Bytes (8 EP * 64B + 1 ISO * 1024B)
|
||||||
#if (CFG_EP_ISOIN_CNT || CFG_EP_ISOOUT_CNT)
|
*/
|
||||||
#define EP_BUF_POOL_BLOCK_MAX_SZ ISO_EP_BUF_MAX_SZ
|
static uint8_t ep_out_bufs[CFG_EPOUT_CNT][EP_BUF_MAX_SZ]
|
||||||
#else
|
__aligned(sizeof(uint32_t));
|
||||||
#define EP_BUF_POOL_BLOCK_MAX_SZ EP_BUF_MAX_SZ
|
static uint8_t ep_isoout_bufs[CFG_EP_ISOOUT_CNT][ISO_EP_BUF_MAX_SZ]
|
||||||
#endif
|
__aligned(sizeof(uint32_t));
|
||||||
|
|
||||||
/** Total endpoints configured */
|
/** Total endpoints configured */
|
||||||
#define CFG_EP_CNT (CFG_EPIN_CNT + CFG_EP_ISOIN_CNT + \
|
#define CFG_EP_CNT (CFG_EPIN_CNT + CFG_EP_ISOIN_CNT + \
|
||||||
CFG_EPOUT_CNT + CFG_EP_ISOOUT_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
|
* @brief USBD control structure
|
||||||
*
|
*
|
||||||
|
@ -644,13 +625,7 @@ static int eps_ctx_init(void)
|
||||||
__ASSERT_NO_MSG(ep_ctx);
|
__ASSERT_NO_MSG(ep_ctx);
|
||||||
|
|
||||||
if (!ep_ctx->buf.block.data) {
|
if (!ep_ctx->buf.block.data) {
|
||||||
ep_ctx->buf.block.data =
|
ep_ctx->buf.block.data = ep_out_bufs[i];
|
||||||
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_reset(ep_ctx);
|
ep_ctx_reset(ep_ctx);
|
||||||
|
@ -663,17 +638,13 @@ static int eps_ctx_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CFG_EP_ISOOUT_CNT) {
|
if (CFG_EP_ISOOUT_CNT) {
|
||||||
|
BUILD_ASSERT(CFG_EP_ISOOUT_CNT <= 1);
|
||||||
|
|
||||||
ep_ctx = out_endpoint_ctx(NRF_USBD_EPOUT(8));
|
ep_ctx = out_endpoint_ctx(NRF_USBD_EPOUT(8));
|
||||||
__ASSERT_NO_MSG(ep_ctx);
|
__ASSERT_NO_MSG(ep_ctx);
|
||||||
|
|
||||||
if (!ep_ctx->buf.block.data) {
|
if (!ep_ctx->buf.block.data) {
|
||||||
ep_ctx->buf.block.data = k_heap_alloc(&ep_buf_pool,
|
ep_ctx->buf.block.data = ep_isoout_bufs[0];
|
||||||
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_reset(ep_ctx);
|
ep_ctx_reset(ep_ctx);
|
||||||
|
@ -696,7 +667,6 @@ static void eps_ctx_uninit(void)
|
||||||
for (i = 0U; i < CFG_EPOUT_CNT; i++) {
|
for (i = 0U; i < CFG_EPOUT_CNT; i++) {
|
||||||
ep_ctx = out_endpoint_ctx(i);
|
ep_ctx = out_endpoint_ctx(i);
|
||||||
__ASSERT_NO_MSG(ep_ctx);
|
__ASSERT_NO_MSG(ep_ctx);
|
||||||
k_heap_free(&ep_buf_pool, ep_ctx->buf.block.data);
|
|
||||||
memset(ep_ctx, 0, sizeof(*ep_ctx));
|
memset(ep_ctx, 0, sizeof(*ep_ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,7 +679,6 @@ static void eps_ctx_uninit(void)
|
||||||
if (CFG_EP_ISOOUT_CNT) {
|
if (CFG_EP_ISOOUT_CNT) {
|
||||||
ep_ctx = out_endpoint_ctx(NRF_USBD_EPOUT(8));
|
ep_ctx = out_endpoint_ctx(NRF_USBD_EPOUT(8));
|
||||||
__ASSERT_NO_MSG(ep_ctx);
|
__ASSERT_NO_MSG(ep_ctx);
|
||||||
k_heap_free(&ep_buf_pool, ep_ctx->buf.block.data);
|
|
||||||
memset(ep_ctx, 0, sizeof(*ep_ctx));
|
memset(ep_ctx, 0, sizeof(*ep_ctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue