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
Marian Buschsieweke committed Jul 22, 2022
1 parent cedfa84 commit 47f807f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cpu/stm32/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ifneq (,$(filter stm32_eth,$(USEMODULE)))
FEATURES_REQUIRED += periph_eth
USEMODULE += iolist
USEMODULE += netdev_eth
USEMODULE += netdev_legacy_api
USEMODULE += netdev_new_api
USEMODULE += ztimer
USEMODULE += ztimer_msec

Expand Down
32 changes: 22 additions & 10 deletions cpu/stm32/periph/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ static ztimer_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 @@ -300,6 +297,14 @@ static int stm32_eth_get(netdev_t *dev, netopt_t opt,
}
res = sizeof(netopt_enable_t);
break;
case NETOPT_TX_END_IRQ:
assert(max_len == sizeof(netopt_enable_t));
{
const netopt_enable_t yes = NETOPT_ENABLE;
memcpy(value, &yes, sizeof(yes));
}
res = sizeof(netopt_enable_t);
break;
default:
res = netdev_eth_get(dev, opt, value, max_len);
break;
Expand Down Expand Up @@ -495,17 +500,23 @@ static int stm32_eth_send(netdev_t *netdev, const struct iolist *iolist)

/* start TX */
ETH->DMATPDR = 0;
/* await completion */
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");
}

return 0;
}


static int stm32_eth_confirm_send(netdev_t *netdev, void *info)
{
(void)info;
(void)netdev;
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 @@ -530,16 +541,16 @@ 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;
}
}

netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE);
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 +717,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 47f807f

Please sign in to comment.