*
*/
-#include "lwipopts.h"
+#include "lwip/opt.h"
#include "lwip/memp.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
+#include "lwip/raw.h"
#include "lwip/tcp.h"
#include "lwip/api.h"
#include "lwip/api_msg.h"
static const u16_t memp_sizes[MEMP_MAX] = {
sizeof(struct pbuf),
+ sizeof(struct raw_pcb),
sizeof(struct udp_pcb),
sizeof(struct tcp_pcb),
sizeof(struct tcp_pcb_listen),
static const u16_t memp_num[MEMP_MAX] = {
MEMP_NUM_PBUF,
+ MEMP_NUM_RAW_PCB,
MEMP_NUM_UDP_PCB,
MEMP_NUM_TCP_PCB,
MEMP_NUM_TCP_PCB_LISTEN,
};
static u8_t memp_memory[(MEMP_NUM_PBUF *
- MEM_ALIGN_SIZE(sizeof(struct pbuf) +
- sizeof(struct memp)) +
- MEMP_NUM_UDP_PCB *
- MEM_ALIGN_SIZE(sizeof(struct udp_pcb) +
- sizeof(struct memp)) +
- MEMP_NUM_TCP_PCB *
- MEM_ALIGN_SIZE(sizeof(struct tcp_pcb) +
- sizeof(struct memp)) +
- MEMP_NUM_TCP_PCB_LISTEN *
- MEM_ALIGN_SIZE(sizeof(struct tcp_pcb_listen) +
- sizeof(struct memp)) +
- MEMP_NUM_TCP_SEG *
- MEM_ALIGN_SIZE(sizeof(struct tcp_seg) +
- sizeof(struct memp)) +
- MEMP_NUM_NETBUF *
- MEM_ALIGN_SIZE(sizeof(struct netbuf) +
- sizeof(struct memp)) +
- MEMP_NUM_NETCONN *
- MEM_ALIGN_SIZE(sizeof(struct netconn) +
- sizeof(struct memp)) +
- MEMP_NUM_API_MSG *
- MEM_ALIGN_SIZE(sizeof(struct api_msg) +
- sizeof(struct memp)) +
- MEMP_NUM_TCPIP_MSG *
- MEM_ALIGN_SIZE(sizeof(struct tcpip_msg) +
- sizeof(struct memp)) +
- MEMP_NUM_SYS_TIMEOUT *
- MEM_ALIGN_SIZE(sizeof(struct sys_timeout) +
- sizeof(struct memp)))];
+ MEM_ALIGN_SIZE(sizeof(struct pbuf) +
+ sizeof(struct memp)) +
+ MEMP_NUM_RAW_PCB *
+ MEM_ALIGN_SIZE(sizeof(struct raw_pcb) +
+ sizeof(struct memp)) +
+ MEMP_NUM_UDP_PCB *
+ MEM_ALIGN_SIZE(sizeof(struct udp_pcb) +
+ sizeof(struct memp)) +
+ MEMP_NUM_TCP_PCB *
+ MEM_ALIGN_SIZE(sizeof(struct tcp_pcb) +
+ sizeof(struct memp)) +
+ MEMP_NUM_TCP_PCB_LISTEN *
+ MEM_ALIGN_SIZE(sizeof(struct tcp_pcb_listen) +
+ sizeof(struct memp)) +
+ MEMP_NUM_TCP_SEG *
+ MEM_ALIGN_SIZE(sizeof(struct tcp_seg) +
+ sizeof(struct memp)) +
+ MEMP_NUM_NETBUF *
+ MEM_ALIGN_SIZE(sizeof(struct netbuf) +
+ sizeof(struct memp)) +
+ MEMP_NUM_NETCONN *
+ MEM_ALIGN_SIZE(sizeof(struct netconn) +
+ sizeof(struct memp)) +
+ MEMP_NUM_API_MSG *
+ MEM_ALIGN_SIZE(sizeof(struct api_msg) +
+ sizeof(struct memp)) +
+ MEMP_NUM_TCPIP_MSG *
+ MEM_ALIGN_SIZE(sizeof(struct tcpip_msg) +
+ sizeof(struct memp)) +
+ MEMP_NUM_SYS_TIMEOUT *
+ MEM_ALIGN_SIZE(sizeof(struct sys_timeout) +
+ sizeof(struct memp)))];
-/*-----------------------------------------------------------------------------------*/
+
+#if !SYS_LIGHTWEIGHT_PROT
static sys_sem_t mutex;
-/*-----------------------------------------------------------------------------------*/
-#ifdef LWIP_DEBUG
+#endif
+
+#ifndef LWIP_NOASSERT
static int
memp_sanity(void)
{
for(m = memp_tab[i]; m != NULL; m = m->next) {
c = 1;
for(n = memp_tab[i]; n != NULL; n = n->next) {
- if(n == m) {
- --c;
+ if (n == m) {
+ --c;
}
- if(c < 0) return 0; /* LW was: abort(); */
+ if (c < 0) return 0; /* LW was: abort(); */
}
}
}
return 1;
}
#endif /* LWIP_DEBUG */
-/*-----------------------------------------------------------------------------------*/
+
void
memp_init(void)
{
u16_t i, j;
u16_t size;
-#ifdef MEMP_STATS
+#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;
memp = (struct memp *)&memp_memory[0];
for(i = 0; i < MEMP_MAX; ++i) {
size = MEM_ALIGN_SIZE(memp_sizes[i] + sizeof(struct memp));
- if(memp_num[i] > 0) {
+ if (memp_num[i] > 0) {
memp_tab[i] = memp;
m = memp;
for(j = 0; j < memp_num[i]; ++j) {
- m->next = (struct memp *)MEM_ALIGN((u8_t *)m + size);
- memp = m;
- m = m->next;
+ m->next = (struct memp *)MEM_ALIGN((u8_t *)m + size);
+ memp = m;
+ m = m->next;
}
memp->next = NULL;
memp = m;
}
}
+#if !SYS_LIGHTWEIGHT_PROT
mutex = sys_sem_new(1);
+#endif
}
-/*-----------------------------------------------------------------------------------*/
+
void *
memp_malloc(memp_t type)
{
struct memp *memp;
void *mem;
+#if SYS_LIGHTWEIGHT_PROT
+ SYS_ARCH_DECL_PROTECT(old_level);
+#endif
- ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX);
+ LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX);
+
+#if SYS_LIGHTWEIGHT_PROT
+ SYS_ARCH_PROTECT(old_level);
+#else /* SYS_LIGHTWEIGHT_PROT */
+ sys_sem_wait(mutex);
+#endif /* SYS_LIGHTWEIGHT_PROT */
memp = memp_tab[type];
- if(memp != NULL) {
+ if (memp != NULL) {
memp_tab[type] = memp->next;
memp->next = NULL;
-#ifdef MEMP_STATS
+#if MEMP_STATS
++lwip_stats.memp[type].used;
- if(lwip_stats.memp[type].used > lwip_stats.memp[type].max) {
+ if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) {
lwip_stats.memp[type].max = lwip_stats.memp[type].used;
}
#endif /* MEMP_STATS */
- ASSERT("memp_malloc: memp properly aligned",
- ((u32_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0);
+#if SYS_LIGHTWEIGHT_PROT
+ SYS_ARCH_UNPROTECT(old_level);
+#else /* SYS_LIGHTWEIGHT_PROT */
+ sys_sem_signal(mutex);
+#endif /* SYS_LIGHTWEIGHT_PROT */
+ LWIP_ASSERT("memp_malloc: memp properly aligned",
+ ((u32_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0);
mem = MEM_ALIGN((u8_t *)memp + sizeof(struct memp));
/* initialize memp memory with zeroes */
- memset(mem, 0, memp_sizes[type]);
+ memset(mem, 0, memp_sizes[type]);
return mem;
} else {
- DEBUGF(MEMP_DEBUG, ("memp_malloc: out of memory in pool %d\n", type));
-#ifdef MEMP_STATS
+ LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %d\n", type));
+#if MEMP_STATS
++lwip_stats.memp[type].err;
#endif /* MEMP_STATS */
- return NULL;
- }
-}
-/*-----------------------------------------------------------------------------------*/
-void *
-memp_mallocp(memp_t type)
-{
- void *mem;
- sys_sem_wait(mutex);
- mem = memp_malloc(type);
+#if SYS_LIGHTWEIGHT_PROT
+ SYS_ARCH_UNPROTECT(old_level);
+#else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_signal(mutex);
- return mem;
-}
-/*-----------------------------------------------------------------------------------*/
-#if 0
-void *
-memp_realloc(memp_t fromtype, memp_t totype, void *mem)
-{
- void *rmem;
- u16_t size;
-
- if(mem == NULL) {
+#endif /* SYS_LIGHTWEIGHT_PROT */
return NULL;
}
-
- rmem = memp_malloc(totype);
- if(rmem != NULL) {
- size = memp_sizes[totype];
- if(memp_sizes[fromtype] < size) {
- size = memp_sizes[fromtype];
- }
- bcopy(mem, rmem, size);
- memp_free(fromtype, mem);
- }
- return rmem;
}
-#endif /* 0 */
-/*-----------------------------------------------------------------------------------*/
+
void
memp_free(memp_t type, void *mem)
{
struct memp *memp;
+#if SYS_LIGHTWEIGHT_PROT
+ SYS_ARCH_DECL_PROTECT(old_level);
+#endif /* SYS_LIGHTWEIGHT_PROT */
- if(mem == NULL) {
+ if (mem == NULL) {
return;
}
memp = (struct memp *)((u8_t *)mem - sizeof(struct memp));
-#ifdef MEMP_STATS
+#if SYS_LIGHTWEIGHT_PROT
+ SYS_ARCH_PROTECT(old_level);
+#else /* SYS_LIGHTWEIGHT_PROT */
+ sys_sem_wait(mutex);
+#endif /* SYS_LIGHTWEIGHT_PROT */
+
+#if MEMP_STATS
lwip_stats.memp[type].used--;
#endif /* MEMP_STATS */
memp->next = memp_tab[type];
memp_tab[type] = memp;
- ASSERT("memp sanity", memp_sanity());
+ LWIP_ASSERT("memp sanity", memp_sanity());
- return;
-}
-/*-----------------------------------------------------------------------------------*/
-void
-memp_freep(memp_t type, void *mem)
-{
- sys_sem_wait(mutex);
- memp_free(type, mem);
+#if SYS_LIGHTWEIGHT_PROT
+ SYS_ARCH_UNPROTECT(old_level);
+#else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_signal(mutex);
+#endif /* SYS_LIGHTWEIGHT_PROT */
}
-/*-----------------------------------------------------------------------------------*/
+