The following code is an example for zero-copy RX ethernet driver:
typedef struct my_custom_pbuf
{
void* dma_descriptor;
} my_custom_pbuf_t;
void my_pbuf_free_custom(void* p)
{
my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p;
invalidate_cpu_cache(p->payload, p->tot_len);
free_rx_dma_descriptor(my_pbuf->dma_descriptor);
}
void eth_rx_irq()
{
dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet();
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);
}
}