3

我目前在 Freescale K60 项目上使用lwIP来帮助我们的以太网 TCP 实施,并在 lwipopts.h 中设置了以下选项。

#define MEM_SIZE                (12*1024)

/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
   sends a lot of data out of ROM (or other static memory), this
   should be set high. */
#define MEMP_NUM_PBUF           10
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
   per active UDP "connection". */
#define MEMP_NUM_UDP_PCB        6
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
   connections. */
#define MEMP_NUM_TCP_PCB        10
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
   connections. */
#define MEMP_NUM_TCP_PCB_LISTEN 6
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
   segments. */
#define MEMP_NUM_TCP_SEG        12
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. */
#define MEMP_NUM_SYS_TIMEOUT    10

/* ---------- Pbuf options ---------- */
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
#define PBUF_POOL_SIZE          10

/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
#define PBUF_POOL_BUFSIZE       1518

我遇到了一个问题,即从 PC 客户端到设备的前 9 条消息已成功读取并传递到应用程序级别,但在第 10 次尝试时失败了,我们不再通过以太网连接收到任何消息。

在追查这个之后,我发现在 pbuf.c 内部,PBUF_POOL_IS_EMPTY()由于调用

(struct pbuf *)memp_malloc(MEMP_PBUF_POOL); returning NULL.

进一步检查表明,memp_tab发布后的值如下

-memp_tab[0] 0x1FFF4160 </br>
-memp_tab[1] 0x1FFF421C </br>
-memp_tab[2] 0x1FFF423C </br>
-memp_tab[3] 0x1FFF4364 </br>
-memp_tab[4] 0x1FFF4478 </br>
-memp_tab[5] 0x1FFF450C </br>
-memp_tab[6] 0x1FFF467C </br>
-memp_tab[7] 0x1FFF46D4 </br>
-memp_tab[8] 0x1FFF4744 </br> 
-memp_tab[9] 0x00000000 </br>

的价值memp_tab[9]是一个担忧。

在我看来,这一切就像我们的内存在使用后没有被重新分配,尽管我们包含了 memp_malloc 调用。有什么方法可以在使用后重新分配这个内存,在调用中这将允许我们使用函数超过声明的用途。

4

0 回答 0