/**
* Should allocate a pbuf and transfer
the bytes of the incoming
* packet from the interface into the
pbuf.
*
* @param netif the lwip network
interface structure for this ethernetif
* @return a pbuf filled with the
received packet (including MAC header)
* NULL on memory error
*/
static struct pbuf *
low_level_input(struct netif *netif)
{
static xSemaphoreHandle xRxSemaphore =
NULL;
struct pbuf *p, *q;
u16_t len;
int l =0;
FrameTypeDef frame;
u8 *buffer;
p = NULL;
if( xRxSemaphore ==NULL)
{
vSemaphoreCreateBinary(xRxSemaphore);
}
/* access to emac is guarded using a
semphore */
if (xSemaphoreTake(xRxSemaphore,
netifGUARD_BLOCK_TIME))
{
frame = ETH_RxPkt_ChainMode();
/* Obtain the size of the packet and
put it into the "len"
variable. */
len = frame.length;
if (len)
{
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;
}
/* 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;
}
}
}
}
xSemaphoreGive(xRxSemaphore);
return p;
}
/**
* This function should be
called when a packet is ready to be read
* from the interface. It
uses the function low_level_input() that
* should handle the actual
reception of bytes from the network
* interface. Then the type
of the received packet is determined and
* the appropriate input
function is called.
*
* @param netif the lwip
network interface structure for this ethernetif
*/
static void
ethernetif_input( void * pvParameters )
{
struct ethernetif
*ethernetif;
struct eth_hdr *ethhdr;
struct pbuf *p;
// for(
;; )
{
do
{
ethernetif
= s_pxNetIf->state;
/*
move received packet into a new pbuf */
p
= low_level_input( s_pxNetIf );
if(
p == NULL )
{
/*
No packet could be read. Wait a for an interrupt to
tell us
there
is more data available. */
vEMACWaitForInput();
}
}
while( p == NULL );
/*
points to packet payload, which starts with an
Ethernet header */
ethhdr
= p->payload;
#if
LINK_STATS
lwip_stats.link.recv++;
#endif
/* LINK_STATS */
ethhdr
= p->payload;
switch
(htons(ethhdr->type))
{
/*
IP packet? */
case
256:
case
ETHTYPE_IP:
/* full packet send to tcpip_thread to process */
if
(s_pxNetIf->input(p, s_pxNetIf) != ERR_OK)
{
LWIP_DEBUGF(NETIF_DEBUG,
("ethernetif_input: IP input error\n"));
pbuf_free(p);
p
= NULL;
}
break;
case ETHTYPE_ARP:
/* pass p to ARP module */
ethernet_input(p, s_pxNetIf);
break;
default:
pbuf_free(p);
p = NULL;
break;
}
}
}
Could
you please help me to try ur approach(I also think
that might be the problem)? I could not uinderstand
from which variable DMARxFRAME_infos
is?
Thank you very
veryy much.
Cheers,
Anna