• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ LWIP_MEM_ALIGN函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中LWIP_MEM_ALIGN函数的典型用法代码示例。如果您正苦于以下问题:C++ LWIP_MEM_ALIGN函数的具体用法?C++ LWIP_MEM_ALIGN怎么用?C++ LWIP_MEM_ALIGN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了LWIP_MEM_ALIGN函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: memp_overflow_init

/**
 * Initialize the restricted areas of all memp elements in every pool.
 */
static void
memp_overflow_init(void)
{
  u16_t i, j;
  struct memp *p;
  u8_t *m;

#if !MEMP_SEPARATE_POOLS
  p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
#endif /* !MEMP_SEPARATE_POOLS */
  for (i = 0; i < MEMP_MAX; ++i) {
#if MEMP_SEPARATE_POOLS
    p = (struct memp *)(memp_bases[i]);
#endif /* MEMP_SEPARATE_POOLS */
    for (j = 0; j < memp_num[i]; ++j) {
#if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0
      m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED;
      memset(m, 0xcd, MEMP_SANITY_REGION_BEFORE_ALIGNED);
#endif
#if MEMP_SANITY_REGION_AFTER_ALIGNED > 0
      m = (u8_t*)p + MEMP_SIZE + memp_sizes[i];
      memset(m, 0xcd, MEMP_SANITY_REGION_AFTER_ALIGNED);
#endif
      p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
    }
  }
}
开发者ID:michas2,项目名称:l4re-snapshot,代码行数:30,代码来源:memp.c


示例2: mem_init

/**
 * Zero the heap and initialize start, end and lowest-free
 */
void
mem_init(void)
{
  struct mem *mem;

  LWIP_ASSERT("Sanity check alignment",
    (SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT-1)) == 0);

  /* align the heap */
  ram = LWIP_MEM_ALIGN(ram_heap);
  /* initialize the start of the heap */
  mem = (struct mem *)ram;
  mem->next = MEM_SIZE_ALIGNED;
  mem->prev = 0;
  mem->used = 0;
  /* initialize the end of the heap */
  ram_end = (struct mem *)&ram[MEM_SIZE_ALIGNED];
  ram_end->used = 1;
  ram_end->next = MEM_SIZE_ALIGNED;
  ram_end->prev = MEM_SIZE_ALIGNED;

  mem_sem = sys_sem_new(1);

  /* initialize the lowest-free pointer to the start of the heap */
  lfree = (struct mem *)ram;

  MEM_STATS_AVAIL(avail, MEM_SIZE_ALIGNED);
}
开发者ID:InSoonPark,项目名称:asf,代码行数:31,代码来源:mem.c


示例3: memp_init

/**
 * Initialize this module.
 *
 * Carves out memp_memory into linked lists for each pool-type.
 */
void
memp_init(void)
{
  struct memp *memp;
  u16_t i, j;

#if MEMP_STATS
  for (i = 0; i < MEMP_MAX; ++i) {
    lwip_stats.memp[i].used = lwip_stats.memp[i].max =
      lwip_stats.memp[i].err = 0;
    lwip_stats.memp[i].avail = memp_num[i];
  }
#endif /* MEMP_STATS */

  memp = LWIP_MEM_ALIGN(memp_memory);
  /* for every pool: */
  for (i = 0; i < MEMP_MAX; ++i) {
    memp_tab[i] = NULL;
    /* create a linked list of memp elements */
    for (j = 0; j < memp_num[i]; ++j) {
      memp->next = memp_tab[i];
      memp_tab[i] = memp;
      memp = (struct memp *)((u8_t *)memp + MEMP_SIZE + memp_sizes[i]);
    }
  }
#if MEMP_OVERFLOW_CHECK
  memp_overflow_init();
  /* check everything a first time to see if it worked */
  memp_overflow_check_all();
#endif /* MEMP_OVERFLOW_CHECK */
}
开发者ID:BlueSkyGjj,项目名称:nRF52,代码行数:36,代码来源:memp.c


示例4: memp_init

/**
 * Initialize this module.
 * 
 * Carves out memp_memory into linked lists for each pool-type.
 */
void
memp_init(void)
{
  struct memp *memp;
  u16_t i, j;

  for (i = 0; i < MEMP_MAX; ++i) {
    MEMP_STATS_AVAIL(used, i, 0);
    MEMP_STATS_AVAIL(max, i, 0);
    MEMP_STATS_AVAIL(err, i, 0);
    MEMP_STATS_AVAIL(avail, i, memp_num[i]);
  }

  memp = LWIP_MEM_ALIGN(memp_memory);
  /* for every pool: */
  for (i = 0; i < MEMP_MAX; ++i) {
    memp_tab[i] = NULL;
    /* create a linked list of memp elements */
    for (j = 0; j < memp_num[i]; ++j) {
      memp->next = memp_tab[i];
      memp_tab[i] = memp;
      memp = (struct memp *)((u8_t *)memp + MEMP_SIZE + memp_sizes[i]
#if MEMP_OVERFLOW_CHECK
        + MEMP_SANITY_REGION_AFTER_ALIGNED
#endif
      );
    }
  }
#if MEMP_OVERFLOW_CHECK
  memp_overflow_init();
  /* check everything a first time to see if it worked */
  memp_overflow_check_all();
#endif /* MEMP_OVERFLOW_CHECK */
}
开发者ID:7h0ma5,项目名称:kiss-avraprs,代码行数:39,代码来源:memp.c


示例5: mem_free

/**
 * Free memory previously allocated by mem_malloc. Loads the pool number
 * and calls memp_free with that pool number to put the element back into
 * its pool
 *
 * @param rmem the memory element to free
 */
void
mem_free(void *rmem) {
	struct memp_malloc_helper *hmem = (struct memp_malloc_helper *)rmem;

	LWIP_ASSERT("rmem != NULL", (rmem != NULL));
	LWIP_ASSERT("rmem == MEM_ALIGN(rmem)", (rmem == LWIP_MEM_ALIGN(rmem)));

	/* get the original struct memp_malloc_helper */
	hmem--;

	LWIP_ASSERT("hmem != NULL", (hmem != NULL));
	LWIP_ASSERT("hmem == MEM_ALIGN(hmem)", (hmem == LWIP_MEM_ALIGN(hmem)));
	LWIP_ASSERT("hmem->poolnr < MEMP_MAX", (hmem->poolnr < MEMP_MAX));

	/* and put it in the pool we saved earlier */
	memp_free(hmem->poolnr, hmem);
}
开发者ID:Itachihi,项目名称:esp8266_car,代码行数:24,代码来源:mem.c


示例6: mem_free

/**
 * Free memory previously allocated by mem_malloc. Loads the pool number
 * and calls memp_free with that pool number to put the element back into
 * its pool
 *
 * @param rmem the memory element to free
 */
void
mem_free(void *rmem)
{
  struct memp_malloc_helper *hmem;

  LWIP_ASSERT("rmem != NULL", (rmem != NULL));
  LWIP_ASSERT("rmem == MEM_ALIGN(rmem)", (rmem == LWIP_MEM_ALIGN(rmem)));

  /* get the original struct memp_malloc_helper */
  hmem = (struct memp_malloc_helper*)(void*)((u8_t*)rmem - LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper)));

  LWIP_ASSERT("hmem != NULL", (hmem != NULL));
  LWIP_ASSERT("hmem == MEM_ALIGN(hmem)", (hmem == LWIP_MEM_ALIGN(hmem)));
  LWIP_ASSERT("hmem->poolnr < MEMP_MAX", (hmem->poolnr < MEMP_MAX));

  /* and put it in the pool we saved earlier */
    fprintf(stderr,"mem_free ###################\n");
  memp_free(hmem->poolnr, hmem);
}
开发者ID:networkextension,项目名称:A.BIG.T,代码行数:26,代码来源:mem.c


示例7: mem_free

/** Put memory back on the heap
 *
 * @param rmem is the pointer as returned by a previous call to mem_malloc()
 */
void
mem_free(void *rmem)
{
  LWIP_ASSERT("rmem != NULL", (rmem != NULL));
  LWIP_ASSERT("rmem == MEM_ALIGN(rmem)", (rmem == LWIP_MEM_ALIGN(rmem)));
#if LWIP_STATS && MEM_STATS
  rmem = (u8_t*)rmem - MEM_LIBC_STATSHELPER_SIZE;
  MEM_STATS_DEC_USED(used, *(mem_size_t*)rmem);
#endif
  mem_clib_free(rmem);
}
开发者ID:SolarTeamEindhoven,项目名称:mbed,代码行数:15,代码来源:lwip_mem.c


示例8: memp_initialize_pbuf_list

void memp_initialize_pbuf_list(void)
{
    assert(memp_memory != NULL);
    struct memp *memp;
    uintptr_t uimemp;
    u16_t k, i, j;
    for (i = 0; i < MEMP_MAX; ++i) {
        MEMP_STATS_AVAIL(used, i, 0);
        MEMP_STATS_AVAIL(max, i, 0);
        MEMP_STATS_AVAIL(err, i, 0);
        MEMP_STATS_AVAIL(avail, i, memp_num[i]);
    }
    memp = LWIP_MEM_ALIGN(memp_memory);
/*    printf("memp_init: total types of pools %d\n", MEMP_MAX );
    printf("memp_init: total types of pools %d, memp_mem %p\n",
            MEMP_MAX, memp_memory);
    printf("memp_init: total types of pools %d, memp %p\n", MEMP_MAX, memp);
*/
    memp->next = NULL;
    /* for every pool: */
    for (k = 0; k < MEMP_MAX; ++k) {
        i = memp_sorted[k];
        memp_tab[i] = NULL;


        // Align memp to element size
        uimemp = (uintptr_t) memp;
        if (uimemp % memp_sizes[i] > 0) {
            uimemp += memp_sizes[i] - (uimemp % memp_sizes[i]);
        }
        memp = (struct memp *) uimemp;

        /* create a linked list of memp elements */
        for (j = 0; j < memp_num[i]; ++j) {
            memp->next = NULL;
            memp->next = memp_tab[i];
            memp_tab[i] = memp;
            memp = (struct memp *) ((u8_t *) memp + memp_sizes[i]);
        }
    }
    // Set how many free pbuf_pools are there
//    printf("memp_num[PBUF_POOL] %" PRIu16 "\n", memp_num[MEMP_MAX - 1]);
    pbuf_pool_counter = 0;
#if MEMP_OVERFLOW_CHECK
    memp_overflow_init();
    /* check everything a first time to see if it worked */
    memp_overflow_check_all();
#endif                          /* MEMP_OVERFLOW_CHECK */

//    mem_barrelfish_register_buf(RX_BUFFER_ID, memp_memory_size);
}
开发者ID:Karamax,项目名称:arrakis,代码行数:51,代码来源:memp.c


示例9: pbuf_alloced_custom

/** Initialize a custom pbuf (already allocated).
 *
 * @param layer flag to define header size
 * @param length size of the pbuf's payload
 * @param type type of the pbuf (only used to treat the pbuf accordingly, as
 *        this function allocates no memory)
 * @param p pointer to the custom pbuf to initialize (already allocated)
 * @param payload_mem pointer to the buffer that is used for payload and headers,
 *        must be at least big enough to hold 'length' plus the header size,
 *        may be NULL if set later
 * @param payload_mem_len the size of the 'payload_mem' buffer, must be at least
 *        big enough to hold 'length' plus the header size
 */
struct pbuf*
pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p,
		void *payload_mem, u16_t payload_mem_len)
{
	u16_t offset;
	LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloced_custom(length=%"U16_F")\n", length));

	/* determine header offset */
	offset = 0;
	switch (l)
	{
		case PBUF_TRANSPORT:
		/* add room for transport (often TCP) layer header */
		offset += PBUF_TRANSPORT_HLEN;
		/* FALLTHROUGH */
		case PBUF_IP:
		/* add room for IP layer header */
		offset += PBUF_IP_HLEN;
		/* FALLTHROUGH */
		case PBUF_LINK:
		/* add room for link layer header */
		offset += PBUF_LINK_HLEN;
		break;
		case PBUF_RAW:
		break;
		default:
		LWIP_ASSERT("pbuf_alloced_custom: bad pbuf layer", 0);
		return NULL;
	}

	if (LWIP_MEM_ALIGN_SIZE(offset) + length < payload_mem_len)
	{
		LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_LEVEL_WARNING, ("pbuf_alloced_custom(length=%"U16_F") buffer too short\n", length));
		return NULL;
	}

	p->pbuf.next = NULL;
	if (payload_mem != NULL)
	{
		p->pbuf.payload = LWIP_MEM_ALIGN((void *)((u8_t *)payload_mem + offset));
	}
	else
	{
		p->pbuf.payload = NULL;
	}
	p->pbuf.flags = PBUF_FLAG_IS_CUSTOM;
	p->pbuf.len = p->pbuf.tot_len = length;
	p->pbuf.type = type;
	p->pbuf.ref = 1;
	return &p->pbuf;
}
开发者ID:Intelligent-Productions,项目名称:UDP_SPI_project,代码行数:64,代码来源:pbuf.c


示例10: memp_overflow_check_all

/**
 * Do an overflow check for all elements in every pool.
 *
 * @see memp_overflow_check_element for a description of the check
 */
static void ICACHE_FLASH_ATTR
memp_overflow_check_all(void)
{
  u16_t i, j;
  struct memp *p;

  p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
  for (i = 0; i < MEMP_MAX; ++i) {
    p = p;
    for (j = 0; j < memp_num[i]; ++j) {
      memp_overflow_check_element_overflow(p, i);
      p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
    }
  }
  p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
  for (i = 0; i < MEMP_MAX; ++i) {
    p = p;
    for (j = 0; j < memp_num[i]; ++j) {
      memp_overflow_check_element_underflow(p, i);
      p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
    }
  }
}
开发者ID:AbuShaqra,项目名称:nodemcu-firmware,代码行数:28,代码来源:memp.c


示例11: pbuf_alloc

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;
}
开发者ID:634351070,项目名称:rt-thread,代码行数:15,代码来源:uip_pbuf.c


示例12: memp_overflow_check_all

/**
 * Do an overflow check for all elements in every pool.
 *
 * @see memp_overflow_check_element for a description of the check
 */
static void
memp_overflow_check_all(void)
{
  u16_t i, j;
  struct memp *p;

#if !MEMP_SEPARATE_POOLS
  p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
#endif /* !MEMP_SEPARATE_POOLS */

  for (i = 0; i < MEMP_MAX; ++i) {
#if MEMP_SEPARATE_POOLS
    p = (struct memp*)memp_bases[i];
#endif /* MEMP_SEPARATE_POOLS */
    p = p;
    for (j = 0; j < memp_num[i]; ++j) {
      memp_overflow_check_element_overflow(p, i);
      p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
    }
  }

#if !MEMP_SEPARATE_POOLS
  p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
#endif /* !MEMP_SEPARATE_POOLS */

  for (i = 0; i < MEMP_MAX; ++i) {
#if MEMP_SEPARATE_POOLS
    p = (struct memp*)memp_bases[i];
#endif /* MEMP_SEPARATE_POOLS */
    p = p;
    for (j = 0; j < memp_num[i]; ++j) {
      memp_overflow_check_element_underflow(p, i);
      p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
    }
  }
}
开发者ID:119,项目名称:bcm-wiced-sdk,代码行数:41,代码来源:memp.c


示例13: memp_overflow_check_all

/**
 * Do an overflow check for all elements in every pool.
 *
 * @see memp_overflow_check_element for a description of the check
 */
static void
memp_overflow_check_all(void)
{
  u16_t i, j;
  struct memp *p;

  p = LWIP_MEM_ALIGN(memp_memory);
  for (i = 0; i < MEMP_MAX; ++i) {
    p = p;
    for (j = 0; j < memp_num[i]; ++j) {
      memp_overflow_check_element(p, memp_sizes[i]);
      p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i]);
    }
  }
}
开发者ID:BlueSkyGjj,项目名称:nRF52,代码行数:20,代码来源:memp.c


示例14: memp_initialize_pbuf_list

void memp_initialize_pbuf_list(void)
{

    assert(memp_memory != NULL);
    struct memp *memp;
    u16_t i, j;
    for (i = 0; i < MEMP_MAX; ++i) {
        MEMP_STATS_AVAIL(used, i, 0);
        MEMP_STATS_AVAIL(max, i, 0);
        MEMP_STATS_AVAIL(err, i, 0);
        MEMP_STATS_AVAIL(avail, i, memp_num[i]);
    }
    memp = LWIP_MEM_ALIGN(memp_memory);
/*    printf("memp_init: total types of pools %d\n", MEMP_MAX );
    printf("memp_init: total types of pools %d, memp_mem %p\n",
            MEMP_MAX, memp_memory);
    printf("memp_init: total types of pools %d, memp %p\n", MEMP_MAX, memp);
*/
    memp->next = NULL;
    /* for every pool: */
    for (i = 0; i < MEMP_MAX; ++i) {
        memp_tab[i] = NULL;
/*      printf("memp_init: %" PRIu16 "(%s) size %" PRIu16 " num %" PRIu16 "\n",
               i, memp_desc[i], memp_sizes[i], memp_num[i]);
*/
        /* create a linked list of memp elements */
        for (j = 0; j < memp_num[i]; ++j) {
            memp->next = NULL;
            memp->next = memp_tab[i];
            memp_tab[i] = memp;
            memp = (struct memp *) ((u8_t *) memp + MEMP_SIZE + memp_sizes[i]
#if MEMP_OVERFLOW_CHECK
                                    + MEMP_SANITY_REGION_AFTER_ALIGNED
#endif
              );
        }
    }
    // Set how many free pbuf_pools are there
//    printf("memp_num[PBUF_POOL] %" PRIu16 "\n", memp_num[MEMP_MAX - 1]);
    pbuf_pool_counter = 0;
#if MEMP_OVERFLOW_CHECK
    memp_overflow_init();
    /* check everything a first time to see if it worked */
    memp_overflow_check_all();
#endif                          /* MEMP_OVERFLOW_CHECK */

//    mem_barrelfish_register_buf(RX_BUFFER_ID, memp_memory_size);
}
开发者ID:CoryXie,项目名称:BarrelfishOS,代码行数:48,代码来源:memp.c


示例15: mem_malloc

/**
 * Allocate a block of memory with a minimum of 'size' bytes.
 *
 * @param size is the minimum size of the requested block in bytes.
 * @return pointer to allocated memory or NULL if no free memory was found.
 *
 * Note that the returned value must always be aligned (as defined by MEM_ALIGNMENT).
 */
void *
mem_malloc(mem_size_t size)
{
  void* ret = mem_clib_malloc(size + MEM_LIBC_STATSHELPER_SIZE);
  if (ret == NULL) {
    MEM_STATS_INC(err);
  } else {
    LWIP_ASSERT("malloc() must return aligned memory", LWIP_MEM_ALIGN(ret) == ret);
#if LWIP_STATS && MEM_STATS
    *(mem_size_t*)ret = size;
    ret = (u8_t*)ret + MEM_LIBC_STATSHELPER_SIZE;
    MEM_STATS_INC_USED(used, size);
#endif
  }
  return ret;
}
开发者ID:SolarTeamEindhoven,项目名称:mbed,代码行数:24,代码来源:lwip_mem.c


示例16: memp_overflow_check_all

/**
 * Do an overflow check for all elements in every pool.
 *
 * @see memp_overflow_check_element for a description of the check
 */
static void
memp_overflow_check_all(void)
{
  u16_t i, j;
  struct memp *p;
  SYS_ARCH_DECL_PROTECT(old_level);
  SYS_ARCH_PROTECT(old_level);

  for (i = 0; i < MEMP_MAX; ++i) {
    p = (struct memp*)LWIP_MEM_ALIGN(memp_pools[i]->base);
    for (j = 0; j < memp_pools[i]->num; ++j) {
      memp_overflow_check_element_overflow(p, memp_pools[i]);
      memp_overflow_check_element_underflow(p, memp_pools[i]);
      p = LWIP_ALIGNMENT_CAST(struct memp*, ((u8_t*)p + MEMP_SIZE + memp_pools[i]->size + MEMP_SANITY_REGION_AFTER_ALIGNED));
    }
  }
  SYS_ARCH_UNPROTECT(old_level);
}
开发者ID:NXPmicro,项目名称:mbed,代码行数:23,代码来源:lwip_memp.c


示例17: mem_init

/**
 * Zero the heap and initialize start, end and lowest-free
 */
void
mem_init(LWIP_MEM_CFG *mem_cfg)
{
  struct mem *mem;
  BOOL en = mem_cfg->enable;
  UINT8 *start = mem_cfg->start;
  UINT32 length = LWIP_MEM_ALIGN_SIZE(mem_cfg->length);
  
  LWIP_ASSERT("Sanity check alignment",
    (SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT-1)) == 0);

  if(en == TRUE)
  {
    ram_heap = (UINT8 *)start;
    MEM_SIZE_ALIGNED = (length - (2*SIZEOF_STRUCT_MEM) - MEM_ALIGNMENT);
  }
  else
  {
    ram_heap = (UINT8 *)MALLOC(MEM_SIZE);
    MEM_SIZE_ALIGNED = (MEM_SIZE - (2*SIZEOF_STRUCT_MEM) - MEM_ALIGNMENT);
  }
  
  /* align the heap */
  ram = LWIP_MEM_ALIGN(ram_heap);
  /* initialize the start of the heap */
  mem = (struct mem *)ram;
  mem->next = MEM_SIZE_ALIGNED;
  mem->prev = 0;
  mem->used = 0;
  /* initialize the end of the heap */
  ram_end = (struct mem *)&ram[MEM_SIZE_ALIGNED];
  ram_end->used = 1;
  ram_end->next = MEM_SIZE_ALIGNED;
  ram_end->prev = MEM_SIZE_ALIGNED;

  mem_sem = sys_sem_new(1);

  /* initialize the lowest-free pointer to the start of the heap */
  lfree = (struct mem *)ram;

#if MEM_STATS
  lwip_stats.mem.avail = MEM_SIZE_ALIGNED;
#endif /* MEM_STATS */
}
开发者ID:alkap007,项目名称:ali3606,代码行数:47,代码来源:mem.c


示例18: memp_init_pool

void
memp_init_pool(const struct memp_desc *desc)
{
  int i;
  struct memp *memp;
  
  *desc->tab = NULL;
  memp = (struct memp*)LWIP_MEM_ALIGN(desc->base);
  /* create a linked list of memp elements */
  for (i = 0; i < desc->num; ++i) {
    memp->next = *desc->tab;
    *desc->tab = memp;
    memp = (struct memp *)(void *)((u8_t *)memp + MEMP_SIZE + desc->size
#if MEMP_OVERFLOW_CHECK
      + MEMP_SANITY_REGION_AFTER_ALIGNED
#endif
    );
  }  

#if MEMP_OVERFLOW_CHECK
  memp_overflow_init(desc);
#endif /* MEMP_OVERFLOW_CHECK */
}
开发者ID:bb2048er,项目名称:lwip,代码行数:23,代码来源:memp.c


示例19: memp_overflow_init

/**
 * Initialize the restricted areas of all memp elements in every pool.
 */
static void ICACHE_FLASH_ATTR
memp_overflow_init(void)
{
  u16_t i, j;
  struct memp *p;
  u8_t *m;

  p = (struct memp *)LWIP_MEM_ALIGN(memp_memory);
  for (i = 0; i < MEMP_MAX; ++i) {
    p = p;
    for (j = 0; j < memp_num[i]; ++j) {
#if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0
      m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED;
      memset(m, 0xcd, MEMP_SANITY_REGION_BEFORE_ALIGNED);
#endif
#if MEMP_SANITY_REGION_AFTER_ALIGNED > 0
      m = (u8_t*)p + MEMP_SIZE + memp_sizes[i];
      memset(m, 0xcd, MEMP_SANITY_REGION_AFTER_ALIGNED);
#endif
      p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
    }
  }
}
开发者ID:AbuShaqra,项目名称:nodemcu-firmware,代码行数:26,代码来源:memp.c


示例20: pbuf_alloc

/**
 * @ingroup pbuf
 * Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
 *
 * The actual memory allocated for the pbuf is determined by the
 * layer at which the pbuf is allocated and the requested size
 * (from the size parameter).
 *
 * @param layer flag to define header size
 * @param length size of the pbuf's payload
 * @param type this parameter decides how and where the pbuf
 * should be allocated as follows:
 *
 * - PBUF_RAM: buffer memory for pbuf is allocated as one large
 *             chunk. This includes protocol headers as well.
 * - PBUF_ROM: no buffer memory is allocated for the pbuf, even for
 *             protocol headers. Additional headers must be prepended
 *             by allocating another pbuf and chain in to the front of
 *             the ROM pbuf. It is assumed that the memory used is really
 *             similar to ROM in that it is immutable and will not be
 *             changed. Memory which is dynamic should generally not
 *             be attached to PBUF_ROM pbufs. Use PBUF_REF instead.
 * - PBUF_REF: no buffer memory is allocated for the pbuf, even for
 *             protocol headers. It is assumed that the pbuf is only
 *             being used in a single thread. If the pbuf gets queued,
 *             then pbuf_take should be called to copy the buffer.
 * - PBUF_POOL: the pbuf is allocated as a pbuf chain, with pbufs from
 *              the pbuf pool that is allocated during pbuf_init().
 *
 * @return the allocated pbuf. If multiple pbufs where allocated, this
 * is the first pbuf of a pbuf chain.
 */
struct pbuf *
pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
{
  struct pbuf *p, *q, *r;
  u16_t offset;
  s32_t rem_len; /* remaining length */
  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F")\n", length));

  /* determine header offset */
  switch (layer) {
  case PBUF_TRANSPORT:
    /* add room for transport (often TCP) layer header */
    offset = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN;
    break;
  case PBUF_IP:
    /* add room for IP layer header */
    offset = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN;
    break;
  case PBUF_LINK:
    /* add room for link layer header */
    offset = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN;
    break;
  case PBUF_RAW_TX:
    /* add room for encapsulating link layer headers (e.g. 802.11) */
    offset = PBUF_LINK_ENCAPSULATION_HLEN;
    break;
  case PBUF_RAW:
    /* no offset (e.g. RX buffers or chain successors) */
    offset = 0;
    break;
  default:
    LWIP_ASSERT("pbuf_alloc: bad pbuf layer", 0);
    return NULL;
  }

  switch (type) {
  case PBUF_POOL:
    /* allocate head of pbuf chain into p */
    p = (struct pbuf *)memp_malloc(MEMP_PBUF_POOL);
    LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc: allocated pbuf %p\n", (void *)p));
    if (p == NULL) {
      PBUF_POOL_IS_EMPTY();
      return NULL;
    }
    p->type = type;
    p->next = NULL;
    p->if_idx = NETIF_NO_INDEX;

    /* make the payload pointer point 'offset' bytes into pbuf data memory */
    p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + (SIZEOF_STRUCT_PBUF + offset)));
    LWIP_ASSERT("pbuf_alloc: pbuf p->payload properly aligned",
            ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
    /* the total length of the pbuf chain is the requested size */
    p->tot_len = length;
    /* set the length of the first pbuf in the chain */
    p->len = LWIP_MIN(length, PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset));
    LWIP_ASSERT("check p->payload + p->len does not overflow pbuf",
                ((u8_t*)p->payload + p->len <=
                 (u8_t*)p + SIZEOF_STRUCT_PBUF + PBUF_POOL_BUFSIZE_ALIGNED));
    LWIP_ASSERT("PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
      (PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset)) > 0 );
    /* set reference count (needed here in case we fail) */
    p->ref = 1;

    /* now allocate the tail of the pbuf chain */

    /* remember first pbuf for linkage in next iteration */
    r = p;
//.........这里部分代码省略.........
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:101,代码来源:pbuf.c



注:本文中的LWIP_MEM_ALIGN函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ LWIP_MEM_ALIGN_SIZE函数代码示例发布时间:2022-05-30
下一篇:
C++ LWIP_DEBUGF函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap