我跟踪测试发现在下面函数中获取p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);再也获取不到空间了。而#define MEM_SIZE (20*1024) 已经很大了。整个程序已经用了62K没有更多空间咯。
low_level_input(struct netif *netif)
{
struct pbuf *p, *q;
u16_t len;
int l =0;
FrameTypeDef frame;
u8 *buffer;
p = NULL;
frame = ETH_RxPkt_ChainMode();
/* Obtain the size of the packet and put it into the "len"
variable. */
if(frame.length != ETH_ERROR)
{
len = frame.length;
buffer = (u8 *)frame.buffer;
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL)
{
for (q = p; q != NULL; q = q->next)
{
memcpy((u8_t*)q->payload, (u8_t*)&buffer[l], q->len);
l = l + q->len;
}
}
else
{
USART_Blocking_SendByte(USART2,0xAA);
USART_Blocking_SendByte(USART2,len);
}
}
else
{
p = NULL;
USART_Blocking_SendByte(USART2,0xBB);
}
/* Set Own bit of the Rx descriptor Status: gives the buffer back to ETHERNET DMA */
frame.descriptor->Status = ETH_DMARxDesc_OWN;
/* When Rx Buffer unavailable flag is set: clear it and resume reception */
if ((ETH->DMASR & ETH_DMASR_RBUS) != (u32)RESET)
{
/* Clear RBUS ETHERNET DMA flag */
ETH->DMASR = ETH_DMASR_RBUS;
/* Resume DMA reception */
ETH->DMARPDR = 0;
}
return p;
}
|