• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 typedef struct my_custom_pbuf
2 {
3    struct pbuf_custom p;
4    void* dma_descriptor;
5 } my_custom_pbuf_t;
6 
7 LWIP_MEMPOOL_DECLARE(RX_POOL, 10, sizeof(my_custom_pbuf_t), "Zero-copy RX PBUF pool");
8 
my_pbuf_free_custom(void * p)9 void 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!
16   // (invalidate is faster than flushing, and noone needs the correct data in the buffer)
17   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 
eth_rx_irq()25 void 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 }
46