MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / efm_eth_rx

Function efm_eth_rx

bsp/efm32/drv_ethernet.c:712–825  ·  view source on GitHub ↗

/ * @brief * Packet receiving function * * @details * * @note * * @param[in] dev * Pointer to device descriptor * * @return * Pointer to packet buffer ******************************************************************************/

Source from the content-addressed store, hash-verified

710* Pointer to packet buffer
711******************************************************************************/
712struct pbuf *efm_eth_rx(rt_device_t dev)
713{
714 rt_uint8_t buf_ins[5], buf_read[6];
715 rt_uint8_t data, reg_eie;
716 rt_uint16_t len_rx, sta_rx;
717 struct pbuf* p;
718
719 /* Lock device */
720 rt_sem_take(&ethLock, RT_WAITING_FOREVER);
721
722 /* Disable interrupts */
723 data = EIE_INTIE;
724 efm_eth_sendCmd(ENC28J60_BIT_FIELD_CLR, EIE, &data);
725
726 p = RT_NULL;
727 reg_eie = 0;
728 if (efm_eth_readReg(EPKTCNT))
729 {
730 /* Set read pointer to the start of RX packet */
731 efm_eth_writeReg(ERDPTL, ethNxtPkt & 0xFF);
732 efm_eth_writeReg(ERDPTH, ethNxtPkt >> 8);
733
734 /* Send read buffer command */
735 efm_eth_sendCmd(ENC28J60_READ_BUF_MEM, EFM32_NO_DATA, EFM32_NO_POINTER);
736 /* Build instruction buffer */
737 buf_ins[0] = 0x00;
738 *(rt_uint8_t **)(&buf_ins[1]) = buf_read;
739 /* Read packet header */
740 if (spi->read(spi, EFM32_NO_DATA, buf_ins, sizeof(buf_read)) == 0)
741 {
742 eth_debug("ETH: RX header failed!\n");
743 }
744
745 ethNxtPkt = buf_read[0] | (buf_read[1] << 8);
746 len_rx = buf_read[2] | (buf_read[3] << 8);
747 sta_rx = buf_read[4] | (buf_read[5] << 8);
748 eth_debug("ETH: RX header ethNxtPkt %x, len_rx %x, sta_rx %x\n",
749 ethNxtPkt, len_rx, sta_rx);
750 /* Check if OK */
751 if (sta_rx & 0x80)
752 {
753 /* Allocate pbuf */
754 p = pbuf_alloc(PBUF_LINK, len_rx - 4, PBUF_RAM);
755 if (p != RT_NULL)
756 {
757 struct pbuf* q;
758
759 for (q = p; q != RT_NULL; q= q->next)
760 {
761 /* Build instruction buffer */
762 buf_ins[0] = 0x00;
763 *(rt_uint8_t **)(&buf_ins[1]) = q->payload;
764 /* Read packet header */
765 if (spi->read(spi, EFM32_NO_DATA, buf_ins, q->len) == 0)
766 {
767 eth_debug("ETH: RX payload failed!\n");
768 }
769#ifdef EFM32_ETHERNET_DEBUG

Callers

nothing calls this directly

Calls 8

rt_sem_takeFunction · 0.85
efm_eth_sendCmdFunction · 0.85
efm_eth_readRegFunction · 0.85
efm_eth_writeRegFunction · 0.85
efm_eth_csFunction · 0.85
rt_sem_releaseFunction · 0.85
pbuf_allocFunction · 0.50
readMethod · 0.45

Tested by

no test coverage detected