]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
Use enum pbuf_flag as pbuf_type.
authormarcbou <marcbou>
Fri, 17 Aug 2007 02:09:43 +0000 (02:09 +0000)
committermarcbou <marcbou>
Fri, 17 Aug 2007 02:09:43 +0000 (02:09 +0000)
Renumber PBUF_FLAG_*.

src/core/pbuf.c
src/include/lwip/pbuf.h
src/netif/etharp.c

index 20929c0d55f1fd1d5d5b97a6c9becb767c42eaaf..0b88d732a7dd3401d8f89a8ac40acebb6f5394bd 100644 (file)
  * is the first pbuf of a pbuf chain.
  */
 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;
   u16_t offset;
@@ -138,7 +138,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
     return NULL;
   }
 
-  switch (flag) {
+  switch (type) {
   case PBUF_POOL:
     /* allocate head of pbuf chain into p */
       p = memp_malloc(MEMP_PBUF_POOL);
@@ -146,8 +146,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
     if (p == NULL) {
       return NULL;
     }
-    p->type = PBUF_TYPE_POOL;
-    p->flgs = 0;
+    p->type = type;
     p->next = NULL;
 
     /* 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 */
         return NULL;
       }
-      q->type = PBUF_TYPE_POOL;
+      q->type = type;
       q->flgs = 0;
       q->next = NULL;
       /* 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->len = p->tot_len = length;
     p->next = NULL;
-    p->type = PBUF_TYPE_RAM;
-    p->flgs = 0;
+    p->type = type;
 
     LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
            ((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);
     if (p == NULL) {
       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;
     }
     /* caller must set this field properly, afterwards */
     p->payload = NULL;
     p->len = p->tot_len = length;
     p->next = NULL;
-    p->type = ((flag == PBUF_ROM) ? PBUF_TYPE_ROM : PBUF_TYPE_REF);
-    p->flgs = 0;
+    p->type = type;
     break;
   default:
-    LWIP_ASSERT("pbuf_alloc: erroneous flag", 0);
+    LWIP_ASSERT("pbuf_alloc: erroneous type", 0);
     return NULL;
   }
   /* set reference count */
   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));
   return p;
 }
@@ -273,10 +272,10 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
   u16_t rem_len; /* remaining length */
   s32_t grow;
 
-  LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_TYPE_POOL ||
-              p->type == PBUF_TYPE_ROM ||
-              p->type == PBUF_TYPE_RAM ||
-              p->type == PBUF_TYPE_REF);
+  LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_POOL ||
+              p->type == PBUF_ROM ||
+              p->type == PBUF_RAM ||
+              p->type == PBUF_REF);
 
   /* desired length larger than current length? */
   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 */
   /* (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 */
     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
          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 */
-    LWIP_ASSERT("p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_POOL", 
-                p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_POOL);
+    LWIP_ASSERT("p->type == PBUF_RAM || p->type == PBUF_POOL", 
+                p->type == PBUF_RAM || p->type == PBUF_POOL);
     /* Check that we aren't going to move off the beginning of the pbuf */
     LWIP_ASSERT("p->payload - increment_magnitude >= 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;
 
   /* pbuf types containing payloads? */
-  if (type == PBUF_TYPE_RAM || type == PBUF_TYPE_POOL) {
+  if (type == PBUF_RAM || type == PBUF_POOL) {
     /* set new payload pointer */
     p->payload = (u8_t *)p->payload - header_size_increment;
     /* boundary check fails? */
@@ -392,7 +391,7 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
       return 1;
     }
   /* 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? */
     if ((header_size_increment < 0) && (increment_magnitude <= p->len)) {
       /* increase payload pointer */
@@ -405,7 +404,7 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
   }
   else {
     /* Unknown type */
-    LWIP_ASSERT("bad pbuf flag type", 0);
+    LWIP_ASSERT("bad pbuf type", 0);
     return 1;
   }
   /* modify pbuf length fields */
@@ -469,8 +468,8 @@ pbuf_free(struct pbuf *p)
   PERF_START;
 
   LWIP_ASSERT("pbuf_free: sane type",
-    p->type == PBUF_TYPE_RAM || p->type == PBUF_TYPE_ROM ||
-    p->type == PBUF_TYPE_REF || p->type == PBUF_TYPE_POOL);
+    p->type == PBUF_RAM || p->type == PBUF_ROM ||
+    p->type == PBUF_REF || p->type == PBUF_POOL);
 
   count = 0;
   /* 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));
       type = p->type;
       /* is this a pbuf from the pool? */
-      if (type == PBUF_TYPE_POOL) {
+      if (type == PBUF_POOL) {
         memp_free(MEMP_PBUF_POOL, p);
       /* 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);
-      /* type == PBUF_TYPE_RAM */
+      /* type == PBUF_RAM */
       } else {
         mem_free(p);
       }
index 8b6ee74230c72dfc1f719116d5e9c318f3615dee..bf0581fbc0bbd7d30579c788527dbe5594c3edfd 100644 (file)
@@ -51,23 +51,17 @@ typedef enum {
 } pbuf_layer;
 
 typedef enum {
-  PBUF_RAM,
-  PBUF_ROM,
-  PBUF_REF,
-  PBUF_POOL
-} pbuf_flag;
-
-/* 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 */
+  PBUF_RAM, /* pbuf data is stored in RAM */
+  PBUF_ROM, /* pbuf data is stored in ROM */
+  PBUF_REF, /* pbuf comes from the pbuf pool */
+  PBUF_POOL /* pbuf payload refers to RAM */
+} pbuf_type;
+
 
 /** 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 */
-#define PBUF_FLAG_LINK_BROADCAST 0x80U
+#define PBUF_FLAG_LINK_BROADCAST 0x02U
 
 struct pbuf {
   /** next pbuf in singly linked pbuf chain */
@@ -88,12 +82,12 @@ struct pbuf {
   /** length of this buffer */
   u16_t len;  
 
-  /** type of pbuf, see PBUF_TYPE_ */
-  u8_t type;
+  /** pbuf_type as u8_t instead of enum to save space */
+  u8_t /*pbuf_type*/ type;
 
   /** misc flags */
   u8_t flgs;
-  
+
   /**
    * the reference count always equals the number of pointers
    * that refer to this pbuf. This can be pointers from an application,
@@ -106,7 +100,7 @@ struct pbuf {
 /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
 #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); 
 u8_t pbuf_header(struct pbuf *p, s16_t header_size);
 void pbuf_ref(struct pbuf *p);
index 7b32ddf0c3c648a49e162fc691511de6c9561bd1..90a75ab8c71511058bd8b30936bb0ae731ea7610 100644 (file)
@@ -936,7 +936,7 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
       p = q;
       while (p) {
         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;
           break;
         }