uip_pbuf.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "uip_pbuf.h"
  2. #include "rtdef.h"
  3. typedef rt_uint32_t mem_ptr_t;
  4. #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + RT_ALIGN_SIZE - 1) & ~(mem_ptr_t)(RT_ALIGN_SIZE-1)))
  5. #define LWIP_MEM_ALIGN_SIZE(size) (((size) + RT_ALIGN_SIZE - 1) & ~(RT_ALIGN_SIZE-1))
  6. #define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
  7. u8_t
  8. pbuf_free(struct pbuf *p)
  9. {
  10. //struct pbuf *q;
  11. if (p == RT_NULL) return 0;
  12. rt_free(p);
  13. //rt_free(&p->len);
  14. return 1;
  15. }
  16. struct pbuf *
  17. pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
  18. {
  19. struct pbuf *p;
  20. u16_t offset = 0;
  21. offset += 16;
  22. /* If pbuf is to be allocated in RAM, allocate memory for it. */
  23. p = (struct pbuf*)rt_malloc(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + LWIP_MEM_ALIGN_SIZE(length));
  24. if (p == RT_NULL) return RT_NULL;
  25. /* Set up internal structure of the pbuf. */
  26. p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
  27. p->len = length;
  28. return p;
  29. }
  30. u8_t
  31. pbuf_header(struct pbuf *p, s16_t header_size_increment) //
  32. {
  33. //extrat link header
  34. uint8_t *ptr;
  35. ptr = p->payload;
  36. ptr -= header_size_increment;
  37. p->payload = ptr;
  38. p->len += header_size_increment;
  39. return 0;
  40. }