Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ZeroCopyRx.c
00001 typedef struct my_custom_pbuf 00002 { 00003 struct pbuf_custom p; 00004 void* dma_descriptor; 00005 } my_custom_pbuf_t; 00006 00007 LWIP_MEMPOOL_DECLARE(RX_POOL, 10, sizeof(my_custom_pbuf_t), "Zero-copy RX PBUF pool"); 00008 00009 void my_pbuf_free_custom(void* p) 00010 { 00011 SYS_ARCH_DECL_PROTECT(old_level); 00012 00013 my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p; 00014 00015 // invalidate data cache here - lwIP and/or application may have written into buffer! 00016 // (invalidate is faster than flushing, and noone needs the correct data in the buffer) 00017 invalidate_cpu_cache(p->payload, p->tot_len); 00018 00019 SYS_ARCH_PROTECT(old_level); 00020 free_rx_dma_descriptor(my_pbuf->dma_descriptor); 00021 LWIP_MEMPOOL_FREE(RX_POOL, my_pbuf); 00022 SYS_ARCH_UNPROTECT(old_level); 00023 } 00024 00025 void eth_rx_irq() 00026 { 00027 dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet(); 00028 my_custom_pbuf_t* my_pbuf = (my_custom_pbuf_t*)LWIP_MEMPOOL_ALLOC(RX_POOL); 00029 00030 my_pbuf->p.custom_free_function = my_pbuf_free_custom; 00031 my_pbuf->dma_descriptor = dma_desc; 00032 00033 invalidate_cpu_cache(dma_desc->rx_data, dma_desc->rx_length); 00034 00035 struct pbuf* p = pbuf_alloced_custom(PBUF_RAW, 00036 dma_desc->rx_length, 00037 PBUF_REF, 00038 &my_pbuf->p, 00039 dma_desc->rx_data, 00040 dma_desc->max_buffer_size); 00041 00042 if(netif->input(p, netif) != ERR_OK) { 00043 pbuf_free(p); 00044 } 00045 }
Generated on Tue Jul 12 2022 13:55:05 by
