Advertisement
Guest User

Untitled

a guest
Feb 7th, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.08 KB | None | 0 0
  1. static struct pbuf *lpc_low_level_input(struct netif *netif)
  2. {
  3.     struct lpc_enetdata *lpc_enetif = netif->state;
  4.     struct pbuf *p = NULL, *q;
  5.     u32_t idx, length;
  6.     u8_t *src;
  7.  
  8. #ifdef LOCK_RX_THREAD
  9. #if NO_SYS == 0
  10.     /* Get exclusive access */
  11.     sys_mutex_lock(&lpc_enetif->TXLockMutex);
  12. #endif
  13. #endif
  14.  
  15.     /* Monitor RX overrun status. This should never happen unless
  16.        (possibly) the internal bus is behing held up by something.
  17.        Unless your system is running at a very low clock speed or
  18.        there are possibilities that the internal buses may be held
  19.        up for a long time, this can probably safely be removed. */
  20.     if (LPC_EMAC->IntStatus & EMAC_INT_RX_OVERRUN) {
  21.         LINK_STATS_INC(link.err);
  22.         LINK_STATS_INC(link.drop);
  23.  
  24.         /* Temporarily disable RX */
  25.         LPC_EMAC->MAC1 &= ~EMAC_MAC1_REC_EN;
  26.  
  27.         /* Reset the RX side */
  28.         LPC_EMAC->MAC1 |= EMAC_MAC1_RES_RX;
  29.         LPC_EMAC->IntClear = EMAC_INT_RX_OVERRUN;
  30.  
  31.         /* De-allocate all queued RX pbufs */
  32.         for (idx = 0; idx < LPC_NUM_BUFF_RXDESCS; idx++) {
  33.             if (lpc_enetif->rxb[idx] != NULL) {
  34.                 pbuf_free(lpc_enetif->rxb[idx]);
  35.                 lpc_enetif->rxb[idx] = NULL;
  36.             }
  37.         }
  38.  
  39.         /* Start RX side again */
  40.         lpc_rx_setup(lpc_enetif);
  41.  
  42.         /* Re-enable RX */
  43.         LPC_EMAC->MAC1 |= EMAC_MAC1_REC_EN;
  44.  
  45. #ifdef LOCK_RX_THREAD
  46. #if NO_SYS == 0
  47.         sys_mutex_unlock(&lpc_enetif->TXLockMutex);
  48. #endif
  49. #endif
  50.  
  51.         return NULL;
  52.     }
  53.  
  54.     /* Determine if a frame has been received */
  55.     length = 0;
  56.     idx = LPC_EMAC->RxConsumeIndex;
  57.     if (LPC_EMAC->RxProduceIndex != idx) {
  58.         /* Handle errors */
  59.         if (lpc_enetif->prxs[idx].statusinfo & (EMAC_RINFO_CRC_ERR |
  60.             EMAC_RINFO_SYM_ERR | EMAC_RINFO_ALIGN_ERR | EMAC_RINFO_LEN_ERR)) {
  61. #if LINK_STATS
  62.             if (lpc_enetif->prxs[idx].statusinfo & (EMAC_RINFO_CRC_ERR |
  63.                 EMAC_RINFO_SYM_ERR | EMAC_RINFO_ALIGN_ERR))
  64.                 LINK_STATS_INC(link.chkerr);
  65.             if (lpc_enetif->prxs[idx].statusinfo & EMAC_RINFO_LEN_ERR)
  66.                 LINK_STATS_INC(link.lenerr);
  67. #endif
  68.  
  69.             /* Drop the frame */
  70.             LINK_STATS_INC(link.drop);
  71.  
  72.             /* Re-queue the pbuf for receive */
  73.             lpc_enetif->rx_free_descs++;
  74.             p = lpc_enetif->rxb[idx];
  75.             lpc_enetif->rxb[idx] = NULL;
  76.             lpc_rxqueue_pbuf(lpc_enetif, p);
  77.  
  78.             LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
  79.                 ("lpc_low_level_input: Packet dropped with errors (0x%x)\n",
  80.                 lpc_enetif->prxs[idx].statusinfo));
  81.                 p = NULL; /* UPDATE: Add this line to return NULL on failure */
  82.         } else {
  83.             /* A packet is waiting, get length */
  84.             length = (lpc_enetif->prxs[idx].statusinfo & 0x7FF) + 1;
  85.  
  86.             /* Zero-copy */
  87.             p = lpc_enetif->rxb[idx];
  88.             p->len = (u16_t) length;
  89.        
  90.             /* Free pbuf from desriptor */
  91.             lpc_enetif->rxb[idx] = NULL;
  92.             lpc_enetif->rx_free_descs++;
  93.            
  94.             LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
  95.                 ("lpc_low_level_input: Packet received: %p, size %d (index=%d)\n",
  96.                 p, length, idx));
  97.  
  98.             /* Save size */
  99.             p->tot_len = (u16_t) length;
  100.             LINK_STATS_INC(link.recv);
  101.  
  102.             /* Queue new buffer(s) */
  103.             lpc_rx_queue(lpc_enetif->netif);
  104.         }
  105.     }
  106.  
  107. #ifdef LOCK_RX_THREAD
  108. #if NO_SYS == 0
  109.     sys_mutex_unlock(&lpc_enetif->TXLockMutex);
  110. #endif
  111. #endif
  112.  
  113.     return p;  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement