blob: 600b13a0f3fd7ba230b724c113a57e673dddde4b [file] [log] [blame]
rihab koukif0d19c32020-07-15 15:00:08 +01001typedef struct my_custom_pbuf
2{
3 struct pbuf_custom p;
4 void* dma_descriptor;
5} my_custom_pbuf_t;
6
7LWIP_MEMPOOL_DECLARE(RX_POOL, 10, sizeof(my_custom_pbuf_t), "Zero-copy RX PBUF pool");
8
9void my_pbuf_free_custom(void* p)
10{
11 SYS_ARCH_DECL_PROTECT(old_level);
12
13 my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p;
14
15 // invalidate data cache here - lwIP and/or application may have written into buffer!
ImeneHammia7710d52025-03-28 14:30:02 +010016 // (invalidate is faster than flushing, and no one needs the correct data in the buffer)
rihab koukif0d19c32020-07-15 15:00:08 +010017 invalidate_cpu_cache(p->payload, p->tot_len);
18
19 SYS_ARCH_PROTECT(old_level);
20 free_rx_dma_descriptor(my_pbuf->dma_descriptor);
21 LWIP_MEMPOOL_FREE(RX_POOL, my_pbuf);
22 SYS_ARCH_UNPROTECT(old_level);
23}
24
25void eth_rx_irq()
26{
27 dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet();
28 my_custom_pbuf_t* my_pbuf = (my_custom_pbuf_t*)LWIP_MEMPOOL_ALLOC(RX_POOL);
29
30 my_pbuf->p.custom_free_function = my_pbuf_free_custom;
31 my_pbuf->dma_descriptor = dma_desc;
32
33 invalidate_cpu_cache(dma_desc->rx_data, dma_desc->rx_length);
34
35 struct pbuf* p = pbuf_alloced_custom(PBUF_RAW,
36 dma_desc->rx_length,
37 PBUF_REF,
38 &my_pbuf->p,
39 dma_desc->rx_data,
40 dma_desc->max_buffer_size);
41
42 if(netif->input(p, netif) != ERR_OK) {
43 pbuf_free(p);
44 }
45}