lwIP 2.2.0
Lightweight IP stack
Loading...
Searching...
No Matches
Zero-copy RX

The following code is an example for zero-copy RX ethernet driver:

typedef struct my_custom_pbuf
{
struct pbuf_custom p;
void* dma_descriptor;
} my_custom_pbuf_t;
LWIP_MEMPOOL_DECLARE(RX_POOL, 10, sizeof(my_custom_pbuf_t), "Zero-copy RX PBUF pool");
void my_pbuf_free_custom(void* p)
{
my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p;
// invalidate data cache here - lwIP and/or application may have written into buffer!
// (invalidate is faster than flushing, and no one needs the correct data in the buffer)
invalidate_cpu_cache(p->payload, p->tot_len);
SYS_ARCH_PROTECT(old_level);
free_rx_dma_descriptor(my_pbuf->dma_descriptor);
LWIP_MEMPOOL_FREE(RX_POOL, my_pbuf);
SYS_ARCH_UNPROTECT(old_level);
}
void eth_rx_irq()
{
dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet();
my_custom_pbuf_t* my_pbuf = (my_custom_pbuf_t*)LWIP_MEMPOOL_ALLOC(RX_POOL);
my_pbuf->p.custom_free_function = my_pbuf_free_custom;
my_pbuf->dma_descriptor = dma_desc;
invalidate_cpu_cache(dma_desc->rx_data, dma_desc->rx_length);
dma_desc->rx_length,
&my_pbuf->p,
dma_desc->rx_data,
dma_desc->max_buffer_size);
if(netif->input(p, netif) != ERR_OK) {
}
}
@ ERR_OK
Definition err.h:55
#define LWIP_MEMPOOL_DECLARE(name, num, size, desc)
Definition memp.h:95
#define LWIP_MEMPOOL_ALLOC(name)
Definition memp.h:122
#define LWIP_MEMPOOL_FREE(name, x)
Definition memp.h:127
struct pbuf * pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p, void *payload_mem, u16_t payload_mem_len)
Definition pbuf.c:363
u8_t pbuf_free(struct pbuf *p)
Definition pbuf.c:727
@ PBUF_REF
Definition pbuf.h:160
@ PBUF_RAW
Definition pbuf.h:111
#define SYS_ARCH_UNPROTECT(lev)
Definition sys.h:509
#define SYS_ARCH_PROTECT(lev)
Definition sys.h:498
#define SYS_ARCH_DECL_PROTECT(lev)
Definition sys.h:486
Definition netif.h:269
netif_input_fn input
Definition netif.h:297
Definition pbuf.h:245
Definition pbuf.h:186