Use enum pbuf_flag as pbuf_type.

Renumber PBUF_FLAG_*.
This commit is contained in:
marcbou 2007-08-17 02:09:43 +00:00
parent 18636a4df5
commit 0471aaec52
3 changed files with 37 additions and 44 deletions

View File

@ -109,7 +109,7 @@
* is the first pbuf of a pbuf chain. * is the first pbuf of a pbuf chain.
*/ */
struct pbuf * struct pbuf *
pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag) pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)
{ {
struct pbuf *p, *q, *r; struct pbuf *p, *q, *r;
u16_t offset; u16_t offset;
@ -138,7 +138,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
return NULL; return NULL;
} }
switch (flag) { switch (type) {
case PBUF_POOL: case PBUF_POOL:
/* allocate head of pbuf chain into p */ /* allocate head of pbuf chain into p */
p = memp_malloc(MEMP_PBUF_POOL); p = memp_malloc(MEMP_PBUF_POOL);
@ -146,8 +146,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
if (p == NULL) { if (p == NULL) {
return NULL; return NULL;
} }
p->type = PBUF_TYPE_POOL; p->type = type;
p->flgs = 0;
p->next = NULL; p->next = NULL;
/* make the payload pointer point 'offset' bytes into pbuf data memory */ /* make the payload pointer point 'offset' bytes into pbuf data memory */
@ -180,7 +179,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
/* bail out unsuccesfully */ /* bail out unsuccesfully */
return NULL; return NULL;
} }
q->type = PBUF_TYPE_POOL; q->type = type;
q->flgs = 0; q->flgs = 0;
q->next = NULL; q->next = NULL;
/* make previous pbuf point to this pbuf */ /* make previous pbuf point to this pbuf */
@ -216,8 +215,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset)); p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
p->len = p->tot_len = length; p->len = p->tot_len = length;
p->next = NULL; p->next = NULL;
p->type = PBUF_TYPE_RAM; p->type = type;
p->flgs = 0;
LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned", LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0); ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
@ -230,22 +228,23 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
p = memp_malloc(MEMP_PBUF); p = memp_malloc(MEMP_PBUF);
if (p == NULL) { if (p == NULL) {
LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 2, ("pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n", LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 2, ("pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n",
(flag == PBUF_ROM) ? "ROM" : "REF")); (type == PBUF_ROM) ? "ROM" : "REF"));
return NULL; return NULL;
} }
/* caller must set this field properly, afterwards */ /* caller must set this field properly, afterwards */
p->payload = NULL; p->payload = NULL;
p->len = p->tot_len = length; p->len = p->tot_len = length;
p->next = NULL; p->next = NULL;
p->type = ((flag == PBUF_ROM) ? PBUF_TYPE_ROM : PBUF_TYPE_REF); p->type = type;
p->flgs = 0;
break; break;
default: default:
LWIP_ASSERT("pbuf_alloc: erroneous flag", 0); LWIP_ASSERT("pbuf_alloc: erroneous type", 0);
return NULL; return NULL;
} }
/* set reference count */ /* set reference count */
p->ref = 1; p->ref = 1;
/* set flgs */
p->flgs = 0;
LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 3, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p)); LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 3, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p));
return p; return p;
} }
@ -273,10 +272,10 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
u16_t rem_len; /* remaining length */ u16_t rem_len; /* remaining length */
s32_t grow; s32_t grow;
LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_TYPE_POOL || LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_POOL ||
p->type == PBUF_TYPE_ROM || p->type == PBUF_ROM ||
p->type == PBUF_TYPE_RAM || p->type == PBUF_RAM ||
p->type == PBUF_TYPE_REF); p->type == PBUF_REF);
/* desired length larger than current length? */ /* desired length larger than current length? */
if (new_len >= p->tot_len) { if (new_len >= p->tot_len) {
@ -306,7 +305,7 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
/* shrink allocated memory for PBUF_RAM */ /* shrink allocated memory for PBUF_RAM */
/* (other types merely adjust their length fields */ /* (other types merely adjust their length fields */
if ((q->type == PBUF_TYPE_RAM) && (rem_len != q->len)) { if ((q->type == PBUF_RAM) && (rem_len != q->len)) {
/* reallocate and adjust the length of the pbuf that will be split */ /* reallocate and adjust the length of the pbuf that will be split */
mem_realloc(q, (u8_t *)q->payload - (u8_t *)q + rem_len); mem_realloc(q, (u8_t *)q->payload - (u8_t *)q + rem_len);
} }
@ -365,8 +364,8 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
/* Can't assert these as some callers speculatively call /* Can't assert these as some callers speculatively call
pbuf_header() to see if it's OK. Will return 1 below instead. */ pbuf_header() to see if it's OK. Will return 1 below instead. */
/* Check that we've got the correct type of pbuf to work with */ /* Check that we've got the correct type of pbuf to work with */
LWIP_ASSERT("p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_POOL", LWIP_ASSERT("p->type == PBUF_RAM || p->type == PBUF_POOL",
p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_POOL); p->type == PBUF_RAM || p->type == PBUF_POOL);
/* Check that we aren't going to move off the beginning of the pbuf */ /* Check that we aren't going to move off the beginning of the pbuf */
LWIP_ASSERT("p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF", LWIP_ASSERT("p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF",
(u8_t *)p->payload - increment_magnitude >= (u8_t *)p + SIZEOF_STRUCT_PBUF); (u8_t *)p->payload - increment_magnitude >= (u8_t *)p + SIZEOF_STRUCT_PBUF);
@ -378,7 +377,7 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
payload = p->payload; payload = p->payload;
/* pbuf types containing payloads? */ /* pbuf types containing payloads? */
if (type == PBUF_TYPE_RAM || type == PBUF_TYPE_POOL) { if (type == PBUF_RAM || type == PBUF_POOL) {
/* set new payload pointer */ /* set new payload pointer */
p->payload = (u8_t *)p->payload - header_size_increment; p->payload = (u8_t *)p->payload - header_size_increment;
/* boundary check fails? */ /* boundary check fails? */
@ -392,7 +391,7 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
return 1; return 1;
} }
/* pbuf types refering to external payloads? */ /* pbuf types refering to external payloads? */
} else if (type == PBUF_TYPE_REF || type == PBUF_TYPE_ROM) { } else if (type == PBUF_REF || type == PBUF_ROM) {
/* hide a header in the payload? */ /* hide a header in the payload? */
if ((header_size_increment < 0) && (increment_magnitude <= p->len)) { if ((header_size_increment < 0) && (increment_magnitude <= p->len)) {
/* increase payload pointer */ /* increase payload pointer */
@ -405,7 +404,7 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
} }
else { else {
/* Unknown type */ /* Unknown type */
LWIP_ASSERT("bad pbuf flag type", 0); LWIP_ASSERT("bad pbuf type", 0);
return 1; return 1;
} }
/* modify pbuf length fields */ /* modify pbuf length fields */
@ -469,8 +468,8 @@ pbuf_free(struct pbuf *p)
PERF_START; PERF_START;
LWIP_ASSERT("pbuf_free: sane type", LWIP_ASSERT("pbuf_free: sane type",
p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_ROM || p->type == PBUF_RAM || p->type == PBUF_ROM ||
p->type == PBUF_TYPE_REF || p->type == PBUF_TYPE_POOL); p->type == PBUF_REF || p->type == PBUF_POOL);
count = 0; count = 0;
/* de-allocate all consecutive pbufs from the head of the chain that /* de-allocate all consecutive pbufs from the head of the chain that
@ -494,12 +493,12 @@ pbuf_free(struct pbuf *p)
LWIP_DEBUGF( PBUF_DEBUG | 2, ("pbuf_free: deallocating %p\n", (void *)p)); LWIP_DEBUGF( PBUF_DEBUG | 2, ("pbuf_free: deallocating %p\n", (void *)p));
type = p->type; type = p->type;
/* is this a pbuf from the pool? */ /* is this a pbuf from the pool? */
if (type == PBUF_TYPE_POOL) { if (type == PBUF_POOL) {
memp_free(MEMP_PBUF_POOL, p); memp_free(MEMP_PBUF_POOL, p);
/* is this a ROM or RAM referencing pbuf? */ /* is this a ROM or RAM referencing pbuf? */
} else if (type == PBUF_TYPE_ROM || type == PBUF_TYPE_REF) { } else if (type == PBUF_ROM || type == PBUF_REF) {
memp_free(MEMP_PBUF, p); memp_free(MEMP_PBUF, p);
/* type == PBUF_TYPE_RAM */ /* type == PBUF_RAM */
} else { } else {
mem_free(p); mem_free(p);
} }

View File

@ -51,23 +51,17 @@ typedef enum {
} pbuf_layer; } pbuf_layer;
typedef enum { typedef enum {
PBUF_RAM, PBUF_RAM, /* pbuf data is stored in RAM */
PBUF_ROM, PBUF_ROM, /* pbuf data is stored in ROM */
PBUF_REF, PBUF_REF, /* pbuf comes from the pbuf pool */
PBUF_POOL PBUF_POOL /* pbuf payload refers to RAM */
} pbuf_flag; } pbuf_type;
/* Definitions for the pbuf flag field. These are NOT the flags that
* are passed to pbuf_alloc(). */
#define PBUF_TYPE_RAM 0x00U /* pbuf data is stored in RAM */
#define PBUF_TYPE_ROM 0x01U /* pbuf data is stored in ROM */
#define PBUF_TYPE_POOL 0x02U /* pbuf comes from the pbuf pool */
#define PBUF_TYPE_REF 0x04U /* pbuf payload refers to RAM */
/** indicates this packet's data should be immediately passed to the application */ /** indicates this packet's data should be immediately passed to the application */
#define PBUF_FLAG_PUSH 0x40U #define PBUF_FLAG_PUSH 0x01U
/** indicates this packet was broadcast on the link */ /** indicates this packet was broadcast on the link */
#define PBUF_FLAG_LINK_BROADCAST 0x80U #define PBUF_FLAG_LINK_BROADCAST 0x02U
struct pbuf { struct pbuf {
/** next pbuf in singly linked pbuf chain */ /** next pbuf in singly linked pbuf chain */
@ -88,8 +82,8 @@ struct pbuf {
/** length of this buffer */ /** length of this buffer */
u16_t len; u16_t len;
/** type of pbuf, see PBUF_TYPE_ */ /** pbuf_type as u8_t instead of enum to save space */
u8_t type; u8_t /*pbuf_type*/ type;
/** misc flags */ /** misc flags */
u8_t flgs; u8_t flgs;
@ -106,7 +100,7 @@ struct pbuf {
/* Initializes the pbuf module. This call is empty for now, but may not be in future. */ /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
#define pbuf_init() #define pbuf_init()
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag); struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_type type);
void pbuf_realloc(struct pbuf *p, u16_t size); void pbuf_realloc(struct pbuf *p, u16_t size);
u8_t pbuf_header(struct pbuf *p, s16_t header_size); u8_t pbuf_header(struct pbuf *p, s16_t header_size);
void pbuf_ref(struct pbuf *p); void pbuf_ref(struct pbuf *p);

View File

@ -936,7 +936,7 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
p = q; p = q;
while (p) { while (p) {
LWIP_ASSERT("no packet queues allowed!", (p->len != p->tot_len) || (p->next == 0)); LWIP_ASSERT("no packet queues allowed!", (p->len != p->tot_len) || (p->next == 0));
if(p->type != PBUF_TYPE_ROM) { if(p->type != PBUF_ROM) {
copy_needed = 1; copy_needed = 1;
break; break;
} }