lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] pbuf_init


From: vrnud
Subject: [lwip-users] pbuf_init
Date: Thu, 9 May 2019 23:37:23 -0700 (MST)

Hello,

below is the code for pbuf_init.
is it ok?

static u8_t pbuf_pool_memory[(PBUF_POOL_SIZE *
LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE + sizeof(struct pbuf)))]; 

#if !SYS_LIGHTWEIGHT_PROT
 static volatile u8_t pbuf_pool_free_lock, pbuf_pool_alloc_lock;
 static sys_sem_t pbuf_pool_free_sem;
#endif
 
static struct pbuf *pbuf_pool = NULL;
static struct pbuf *pbuf_pool_alloc_cache = NULL;
static struct pbuf *pbuf_pool_free_cache = NULL;

void
 pbuf_init(void)
{
   struct pbuf *p, *q = NULL;
   u16_t i;
 
   pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0];
   LWIP_ASSERT("pbuf_init: pool aligned", (long)pbuf_pool % MEM_ALIGNMENT ==
0);
    
 #ifdef PBUF_STATS
   lwip_stats.pbuf.avail = PBUF_POOL_SIZE;
 #endif /* PBUF_STATS */
   
   /* Set up ->next pointers to link the pbufs of the pool together */
   p = pbuf_pool;
   
   for(i = 0; i < PBUF_POOL_SIZE; ++i) {
     p->next = (struct pbuf *)((u8_t *)p + PBUF_POOL_BUFSIZE + sizeof(struct
pbuf));
     p->len = p->tot_len = PBUF_POOL_BUFSIZE;
     p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf)));
     q = p;
     p = p->next;
   }
   
   /* The ->next pointer of last pbuf is NULL to indicate that there
      are no more pbufs in the pool */
   q->next = NULL;
 #if !SYS_LIGHTWEIGHT_PROT  
   pbuf_pool_alloc_lock = 0;
   pbuf_pool_free_lock = 0;
   pbuf_pool_free_sem = sys_sem_new(1);
 #endif  
 }


Regards,
Vrund






--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]