summaryrefslogtreecommitdiff
path: root/components/net/uip/rt-thread/uip_pbuf.c
blob: ea12e84e62c581845975e41b2733c20ca9a1a5db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "uip_pbuf.h"
#include "rtdef.h"

typedef rt_uint32_t	mem_ptr_t;
#define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + RT_ALIGN_SIZE - 1) & ~(mem_ptr_t)(RT_ALIGN_SIZE-1)))
#define LWIP_MEM_ALIGN_SIZE(size) (((size) + RT_ALIGN_SIZE - 1) & ~(RT_ALIGN_SIZE-1))
#define SIZEOF_STRUCT_PBUF        LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))

u8_t
pbuf_free(struct pbuf *p)
{

  //struct pbuf *q;
  
  if (p == RT_NULL) return 0;
  rt_free(p);
  //rt_free(&p->len);
  
  return 1;
}

struct pbuf *
pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
{
  struct pbuf *p;
  u16_t offset = 0;
  offset += 16;
  
    /* If pbuf is to be allocated in RAM, allocate memory for it. */
  p = (struct pbuf*)rt_malloc(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + LWIP_MEM_ALIGN_SIZE(length));
  if (p == RT_NULL)  return RT_NULL; 
    /* Set up internal structure of the pbuf. */
  p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
  p->len = length;   
  return p;
}

u8_t
pbuf_header(struct pbuf *p, s16_t header_size_increment) //
{
 //extrat link header
    uint8_t *ptr;
    
    ptr = p->payload;
    ptr -= header_size_increment;
    p->payload = ptr;
    p->len += header_size_increment;
 
    return 0;
}