Skip to content

Commit

Permalink
cpu/stm32/periph/eth: update to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
maribu committed Jan 22, 2021
1 parent 9eb12b3 commit 4e0e8c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 14 additions & 8 deletions cpu/stm32/periph/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ static xtimer_t _link_status_timer;

#define MIN(a, b) (((a) <= (b)) ? (a) : (b))

/* Synchronization between IRQ and thread context */
mutex_t stm32_eth_tx_completed = MUTEX_INIT_LOCKED;

/* Descriptors */
static edma_desc_t rx_desc[ETH_RX_DESCRIPTOR_COUNT];
static edma_desc_t tx_desc[ETH_TX_DESCRIPTOR_COUNT];
Expand Down Expand Up @@ -508,13 +505,20 @@ static int stm32_eth_send(netdev_t *netdev, const struct iolist *iolist)
if (IS_ACTIVE(ENABLE_DEBUG_VERBOSE)) {
DEBUG("[stm32_eth] Started to send %u B via DMA\n", bytes_to_send);
}
mutex_lock(&stm32_eth_tx_completed);
if (IS_ACTIVE(ENABLE_DEBUG_VERBOSE)) {
DEBUG("[stm32_eth] TX completed\n");
}

DEBUG("[stm32_eth] Started to send %u B via DMA\n", bytes_to_send);
return 0;
}


static int stm32_eth_confirm_send(netdev_t *netdev, void *info)
{
(void)info;
DEBUG("[stm32_eth] TX completed\n");

/* Error check */
_debug_tx_descriptor_info(__LINE__);
int tx_bytes = 0;
int error = 0;
while (1) {
uint32_t status = tx_curr->status;
Expand All @@ -539,6 +543,7 @@ static int stm32_eth_send(netdev_t *netdev, const struct iolist *iolist)
_reset_eth_dma();
}
tx_curr = tx_curr->desc_next;
tx_bytes += tx_curr->control;
if (status & TX_DESC_STAT_LS) {
break;
}
Expand All @@ -548,7 +553,7 @@ static int stm32_eth_send(netdev_t *netdev, const struct iolist *iolist)
if (error) {
return error;
}
return (int)bytes_to_send;
return tx_bytes;
}

static int get_rx_frame_size(void)
Expand Down Expand Up @@ -706,6 +711,7 @@ static void stm32_eth_isr(netdev_t *netdev)

static const netdev_driver_t netdev_driver_stm32f4eth = {
.send = stm32_eth_send,
.confirm_send = stm32_eth_confirm_send,
.recv = stm32_eth_recv,
.init = stm32_eth_init,
.isr = stm32_eth_isr,
Expand Down
4 changes: 2 additions & 2 deletions cpu/stm32/periph/eth_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ void isr_eth(void)

if (IS_USED(MODULE_STM32_ETH)) {
extern netdev_t *stm32_eth_netdev;
extern mutex_t stm32_eth_tx_completed;
unsigned tmp = ETH->DMASR;

if ((tmp & ETH_DMASR_TS)) {
ETH->DMASR = ETH_DMASR_NIS | ETH_DMASR_TS;
DEBUG("isr_eth: TX completed\n");
mutex_unlock(&stm32_eth_tx_completed);
stm32_eth_netdev->event_callback(stm32_eth_netdev,
NETDEV_EVENT_TX_COMPLETE);
}

if ((tmp & ETH_DMASR_RS)) {
Expand Down

0 comments on commit 4e0e8c3

Please sign in to comment.