1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/dose: make use of periph_uart_collision feature

This commit is contained in:
Benjamin Valentin 2021-07-26 14:42:53 +02:00
parent a51fb298dc
commit 0c5631bd52
2 changed files with 35 additions and 2 deletions

View File

@ -1,5 +1,6 @@
FEATURES_REQUIRED += periph_gpio_irq
FEATURES_REQUIRED += periph_uart
FEATURES_OPTIONAL += periph_uart_collision
FEATURES_OPTIONAL += periph_uart_rxstart_irq
USEMODULE += eui_provider

View File

@ -201,9 +201,9 @@ static dose_signal_t state_transit_send(dose_t *ctx, dose_signal_t signal)
/* Don't trace any END octets ... the timeout or the END signal
* will bring us back to the BLOCKED state after _send has emitted
* its last octet. */
#ifndef MODULE_PERIPH_UART_COLLISION
xtimer_set(&ctx->timeout, ctx->timeout_base);
#endif
return DOSE_SIGNAL_NONE;
}
@ -398,6 +398,10 @@ static int send_octet(dose_t *ctx, uint8_t c)
{
uart_write(ctx->uart, (uint8_t *) &c, sizeof(c));
#ifdef MODULE_PERIPH_UART_COLLISION
return uart_collision_detected(ctx->uart);
#endif
/* Wait for a state transition */
uint8_t new_state = wait_for_state(ctx, DOSE_STATE_ANY);
if (new_state != DOSE_STATE_SEND) {
@ -432,6 +436,28 @@ static int send_data_octet(dose_t *ctx, uint8_t c)
return rc;
}
static inline void _send_start(dose_t *ctx)
{
#ifdef MODULE_PERIPH_UART_COLLISION
uart_collision_detect_enable(ctx->uart);
#else
(void)ctx;
#endif
}
static inline void _send_done(dose_t *ctx, bool collision)
{
#ifdef MODULE_PERIPH_UART_COLLISION
uart_collision_detect_disable(ctx->uart);
if (collision) {
state(ctx, DOSE_SIGNAL_XTIMER);
}
#else
(void)ctx;
(void)collision;
#endif
}
static int _send(netdev_t *dev, const iolist_t *iolist)
{
dose_t *ctx = container_of(dev, dose_t, netdev);
@ -459,6 +485,8 @@ send:
state(ctx, DOSE_SIGNAL_SEND);
} while (wait_for_state(ctx, DOSE_STATE_ANY) != DOSE_STATE_SEND);
_send_start(ctx);
/* Send packet buffer */
for (const iolist_t *iol = iolist; iol; iol = iol->iol_next) {
size_t n = iol->iol_len;
@ -491,6 +519,8 @@ send:
goto collision;
}
_send_done(ctx, false);
/* We probably sent the whole packet?! */
dev->event_callback(dev, NETDEV_EVENT_TX_COMPLETE);
@ -500,11 +530,13 @@ send:
return pktlen;
collision:
_send_done(ctx, true);
DEBUG("dose _send(): collision!\n");
if (--retries < 0) {
dev->event_callback(dev, NETDEV_EVENT_TX_MEDIUM_BUSY);
return -EBUSY;
}
goto send;
}