Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static struct pbuf *lpc_low_level_input(struct netif *netif)
- {
- struct lpc_enetdata *lpc_enetif = netif->state;
- struct pbuf *p = NULL, *q;
- u32_t idx, length;
- u8_t *src;
- #ifdef LOCK_RX_THREAD
- #if NO_SYS == 0
- /* Get exclusive access */
- sys_mutex_lock(&lpc_enetif->TXLockMutex);
- #endif
- #endif
- /* Monitor RX overrun status. This should never happen unless
- (possibly) the internal bus is behing held up by something.
- Unless your system is running at a very low clock speed or
- there are possibilities that the internal buses may be held
- up for a long time, this can probably safely be removed. */
- if (LPC_EMAC->IntStatus & EMAC_INT_RX_OVERRUN) {
- LINK_STATS_INC(link.err);
- LINK_STATS_INC(link.drop);
- /* Temporarily disable RX */
- LPC_EMAC->MAC1 &= ~EMAC_MAC1_REC_EN;
- /* Reset the RX side */
- LPC_EMAC->MAC1 |= EMAC_MAC1_RES_RX;
- LPC_EMAC->IntClear = EMAC_INT_RX_OVERRUN;
- /* De-allocate all queued RX pbufs */
- for (idx = 0; idx < LPC_NUM_BUFF_RXDESCS; idx++) {
- if (lpc_enetif->rxb[idx] != NULL) {
- pbuf_free(lpc_enetif->rxb[idx]);
- lpc_enetif->rxb[idx] = NULL;
- }
- }
- /* Start RX side again */
- lpc_rx_setup(lpc_enetif);
- /* Re-enable RX */
- LPC_EMAC->MAC1 |= EMAC_MAC1_REC_EN;
- #ifdef LOCK_RX_THREAD
- #if NO_SYS == 0
- sys_mutex_unlock(&lpc_enetif->TXLockMutex);
- #endif
- #endif
- return NULL;
- }
- /* Determine if a frame has been received */
- length = 0;
- idx = LPC_EMAC->RxConsumeIndex;
- if (LPC_EMAC->RxProduceIndex != idx) {
- /* Handle errors */
- if (lpc_enetif->prxs[idx].statusinfo & (EMAC_RINFO_CRC_ERR |
- EMAC_RINFO_SYM_ERR | EMAC_RINFO_ALIGN_ERR | EMAC_RINFO_LEN_ERR)) {
- #if LINK_STATS
- if (lpc_enetif->prxs[idx].statusinfo & (EMAC_RINFO_CRC_ERR |
- EMAC_RINFO_SYM_ERR | EMAC_RINFO_ALIGN_ERR))
- LINK_STATS_INC(link.chkerr);
- if (lpc_enetif->prxs[idx].statusinfo & EMAC_RINFO_LEN_ERR)
- LINK_STATS_INC(link.lenerr);
- #endif
- /* Drop the frame */
- LINK_STATS_INC(link.drop);
- /* Re-queue the pbuf for receive */
- lpc_enetif->rx_free_descs++;
- p = lpc_enetif->rxb[idx];
- lpc_enetif->rxb[idx] = NULL;
- lpc_rxqueue_pbuf(lpc_enetif, p);
- LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
- ("lpc_low_level_input: Packet dropped with errors (0x%x)\n",
- lpc_enetif->prxs[idx].statusinfo));
- p = NULL; /* UPDATE: Add this line to return NULL on failure */
- } else {
- /* A packet is waiting, get length */
- length = (lpc_enetif->prxs[idx].statusinfo & 0x7FF) + 1;
- /* Zero-copy */
- p = lpc_enetif->rxb[idx];
- p->len = (u16_t) length;
- /* Free pbuf from desriptor */
- lpc_enetif->rxb[idx] = NULL;
- lpc_enetif->rx_free_descs++;
- LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
- ("lpc_low_level_input: Packet received: %p, size %d (index=%d)\n",
- p, length, idx));
- /* Save size */
- p->tot_len = (u16_t) length;
- LINK_STATS_INC(link.recv);
- /* Queue new buffer(s) */
- lpc_rx_queue(lpc_enetif->netif);
- }
- }
- #ifdef LOCK_RX_THREAD
- #if NO_SYS == 0
- sys_mutex_unlock(&lpc_enetif->TXLockMutex);
- #endif
- #endif
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement