/** * \brief Test EMAC read/write interfaces. * * \param test Current test case. */ static void run_emac_read_write_test(const struct test_case *test) { uint32_t ul_frm_size; uint8_t uc_rc = 0; uint32_t ul_retry_time = 0; /* Write the arp frame first */ emac_dev_write(&gs_emac_dev, gs_arp_frame, sizeof(gs_arp_frame), NULL); while ( ul_retry_time < EMAC_UINT_TEST_MAX_RETRY_TIME ) { /* Read the frame in the emac buffer */ if (EMAC_OK != emac_dev_read(&gs_emac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_frm_size)) { continue; } /* Is arp frame sent? */ if (strncmp((const char *)gs_uc_eth_buffer, (const char *)gs_uc_mac_address, sizeof(gs_uc_mac_address))) { uc_rc = 1; break; } ul_retry_time++; } test_assert_true(test, uc_rc == 1, "Test EMAC: emac write error!"); }
/** * \brief 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) { struct pbuf *p = NULL, *q = NULL; u16_t s_len; uint8_t pc_buf[NET_RW_BUFF_SIZE]; int8_t *bufptr = (int8_t *)&pc_buf[0]; uint32_t ul_frmlen; uint8_t uc_rc; /* Obtain the size of the packet and put it into the "len" * variable. */ uc_rc = emac_dev_read(&gs_emac_dev, pc_buf, sizeof(pc_buf), &ul_frmlen); if (uc_rc != EMAC_OK) { return NULL; } s_len = ul_frmlen; #if ETH_PAD_SIZE s_len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc(PBUF_RAW, s_len, PBUF_POOL); if (p != NULL) { #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif /* Iterate over the pbuf chain until we have read the entire * packet into the pbuf. */ for (q = p; q != NULL; q = q->next) { /* Read enough bytes to fill this pbuf in the chain. The * available data in the pbuf is given by the q->len * variable. */ /* read data into(q->payload, q->len); */ memcpy(q->payload, bufptr, q->len); bufptr += q->len; } /* Acknowledge that packet has been read(); */ #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* Reclaim the padding word */ #endif LINK_STATS_INC(link.recv); } else { /* Drop packet(); */ LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); } return p; }