#include <pbuf.h> #include <debug.h> void pbuf_pool_create(pbuf_pool_t *pool, uint32_t pbuf_count, void *pbuf_memory, uint32_t pbuf_payload_capacity, void *pbuf_payload_memory) { assert(pool); assert(pbuf_count); assert(pbuf_memory); assert(pbuf_payload_capacity); assert(pbuf_payload_memory); pool->pbuf_memory = (pbuf_t*)pbuf_memory; pool->pbuf_count = pbuf_count; pool->payload_capacity = pbuf_payload_capacity; pool->payload_memory = (uint8_t*)pbuf_payload_memory; pool->free_callback = NULL; pbuf_pool_reset(pool); } void pbuf_pool_reset(pbuf_pool_t *pool) { assert(pool); //initialize pbuf structures uint8_t *payload = pool->payload_memory; pbuf_t *p = pool->free_list = pool->pbuf_memory; for(uint32_t i = 0; i < pool->pbuf_count - 1; i++) { p->payload_memory = payload; payload += pool->payload_capacity; p->pool = pool; p->next = p + 1; p++; } p->payload_memory = payload; p->pool = pool; p->next = 0; pool->pbufs_available = pool->pbuf_count; } void pbuf_dump_pool(pbuf_pool_t *pool) { debug_printf("\r\nPool %x, %u pbufs available\r\n", pool, pool->pbufs_available); pbuf_t *p = pool->free_list; while(p) { debug_printf("\r\n%x", p); p = p->next; } debug_printf("\r\nEnd of dump\r\n"); }