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

Function efm_eth_tx

bsp/efm32/drv_ethernet.c:844–915  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

842* Error code
843******************************************************************************/
844rt_err_t efm_eth_tx(rt_device_t dev, struct pbuf* p)
845{
846 rt_uint8_t data;
847 struct pbuf* q;
848
849 /* Lock device */
850 rt_sem_take(&ethLock, RT_WAITING_FOREVER);
851
852 /* Disable interrupts */
853 data = EIE_INTIE;
854 efm_eth_sendCmd(ENC28J60_BIT_FIELD_CLR, EIE, &data);
855
856 /* Set write pointer to the start of TX buffer */
857 efm_eth_writeReg(EWRPTL, TXSTART_INIT & 0xFF);
858 efm_eth_writeReg(EWRPTH, TXSTART_INIT >> 8);
859 /* Set buffer end pointer according to the packet size */
860 efm_eth_writeReg(ETXNDL, (TXSTART_INIT + p->tot_len + 1) & 0xFF);
861 efm_eth_writeReg(ETXNDH, (TXSTART_INIT + p->tot_len + 1) >> 8);
862
863 /* Send write buffer command */
864 data = 0x00; /* Control byte */
865 efm_eth_sendCmd(ENC28J60_WRITE_BUF_MEM, EFM32_NO_DATA, &data);
866 /* Send data */
867 for (q = p; q != NULL; q = q->next)
868 {
869 if (spi->write(spi, EFM32_NO_DATA, q->payload, q->len) == 0)
870 {
871 eth_debug("ETH: TX failed!\n");
872 return -RT_ERROR;
873 }
874#ifdef EFM32_ETHERNET_DEBUG
875 {
876 rt_uint8_t *temp = (rt_uint8_t *)q->payload;
877 rt_uint32_t i;
878
879 eth_debug("ETH: ***** write TX (len %d) *****\n", p->len);
880 for (i = 0; i < q->len; i += 8)
881 {
882 eth_debug("%02x %02x %02x %02x %02x %02x %02x %02x | %c %c %c %c %c %c %c %c\n",
883 temp[i], temp[i + 1], temp[i + 2], temp[i + 3],
884 temp[i + 4], temp[i + 5], temp[i + 6], temp[i + 7],
885 temp[i], temp[i + 1], temp[i + 2], temp[i + 3],
886 temp[i + 4], temp[i + 5], temp[i + 6], temp[i + 7]);
887 }
888 }
889#endif
890 }
891 efm_eth_cs(0);
892 /* Start TX */
893 data = ECON1_TXRTS;
894 efm_eth_sendCmd(ENC28J60_BIT_FIELD_SET, ECON1, &data);
895 /* Errata 12 */
896 if (efm_eth_readReg(EIR) & EIR_TXERIF)
897 {
898 efm_eth_sendCmd(ENC28J60_BIT_FIELD_CLR, ECON1, &data);
899 data = EIR_TXERIF;
900 efm_eth_sendCmd(ENC28J60_BIT_FIELD_CLR, EIR, &data);
901 data = ECON1_TXRTS;

Callers

nothing calls this directly

Calls 8

rt_sem_takeFunction · 0.85
efm_eth_sendCmdFunction · 0.85
efm_eth_writeRegFunction · 0.85
efm_eth_csFunction · 0.85
efm_eth_readRegFunction · 0.85
rt_thread_delayFunction · 0.85
rt_sem_releaseFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected