void my_pbuf_free_custom(void* p) { SYS_ARCH_DECL_PROTECT(old_level); 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 noone 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); struct pbuf* p = pbuf_alloced_custom(PBUF_RAW, dma_desc->rx_length, PBUF_REF, &my_pbuf->p, dma_desc->rx_data, dma_desc->max_buffer_size); if(netif->input(p, netif) != ERR_OK) { pbuf_free(p); } }
static void sync_buf_pre_cpu(struct cach_buf *buf, enum hwmem_access access, struct hwmem_region *region) { bool write = access & HWMEM_ACCESS_WRITE; bool read = access & HWMEM_ACCESS_READ; if (!write && !read) return; if (buf->cache_settings & HWMEM_ALLOC_HINT_CACHED) { struct cach_range region_range; region_2_range(region, buf->size, ®ion_range); if (read || (write && buf->cache_settings & HWMEM_ALLOC_HINT_CACHE_WB)) /* Perform defered invalidates */ invalidate_cpu_cache(buf, ®ion_range); if (read || (write && buf->cache_settings & HWMEM_ALLOC_HINT_CACHE_AOW)) expand_range(&buf->range_in_cpu_cache, ®ion_range); if (write && buf->cache_settings & HWMEM_ALLOC_HINT_CACHE_WB) { struct cach_range dirty_range_addition; if (buf->cache_settings & HWMEM_ALLOC_HINT_CACHE_AOW) dirty_range_addition = region_range; else intersect_range(&buf->range_in_cpu_cache, ®ion_range, &dirty_range_addition); expand_range(&buf->range_dirty_in_cpu_cache, &dirty_range_addition); } } if (buf->cache_settings & HWMEM_ALLOC_HINT_WRITE_COMBINE) { if (write) buf->in_cpu_write_buf = true; } }