Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/{dose, slipdev, sam0_eth}: generate RX event for queued packets #18201

Merged
merged 3 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cpu/sam0_common/periph/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ int sam0_eth_receive_blocking(char *data, unsigned max_len)
return _try_receive(data, max_len, 1);
}

bool sam0_eth_has_queued_pkt(void)
{
return _try_receive(NULL, 0, 0) > 0;
}

int sam0_eth_init(void)
{
/* Enable clocks */
Expand Down
7 changes: 7 additions & 0 deletions cpu/sam0_common/sam0_eth/eth-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern void sam0_eth_poweron(void);
extern void sam0_eth_poweroff(void);
extern int sam0_eth_send(const struct iolist *iolist);
extern int sam0_eth_receive_blocking(char *data, unsigned max_len);
extern bool sam0_eth_has_queued_pkt(void);
extern void sam0_eth_set_mac(const eui48_t *mac);
extern void sam0_eth_get_mac(char *out);
extern void sam0_clear_rx_buffers(void);
Expand Down Expand Up @@ -68,6 +69,12 @@ static int _sam0_eth_recv(netdev_t *netdev, void *buf, size_t len, void *info)
(void)info;
(void)netdev;
unsigned ret = sam0_eth_receive_blocking((char *)buf, len);

/* frame received, check if another frame is queued */
if (buf && sam0_eth_has_queued_pkt()) {
netdev_trigger_event_isr(netdev);
}

return ret;
}

Expand Down
13 changes: 11 additions & 2 deletions drivers/dose/dose.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ static void _isr(netdev_t *netdev)

static int _recv(netdev_t *dev, void *buf, size_t len, void *info)
{
int res;
dose_t *ctx = container_of(dev, dose_t, netdev);

(void)info;
Expand All @@ -446,10 +447,18 @@ static int _recv(netdev_t *dev, void *buf, size_t len, void *info)
}

if (crb_consume_chunk(&ctx->rb, buf, len)) {
return len;
res = len;
} else {
return -1;
res = -1;
}

size_t dummy;
if (crb_get_chunk_size(&ctx->rb, &dummy)) {
DEBUG("dose: %u byte pkt in rx queue\n", (unsigned)dummy);
netdev_trigger_event_isr(&ctx->netdev);
}

return res;
}

static uint8_t wait_for_state(dose_t *ctx, uint8_t state)
Expand Down
2 changes: 2 additions & 0 deletions drivers/include/slipdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ typedef struct {
* @see [Device state definitions](@ref drivers_slipdev_states)
*/
uint8_t state;
uint8_t rx_queued; /**< pkt queued in inbuf */
uint8_t rx_done; /**< pkt processed */
} slipdev_t;

/**
Expand Down
6 changes: 6 additions & 0 deletions drivers/slipdev/slipdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static void _slip_rx_cb(void *arg, uint8_t byte)
check_end:
if (byte == SLIPDEV_END) {
if (dev->state == SLIPDEV_STATE_NET) {
dev->rx_queued++;
netdev_trigger_event_isr(&dev->netdev);
}
dev->state = SLIPDEV_STATE_NONE;
Expand Down Expand Up @@ -207,6 +208,11 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
return -ENOBUFS;
}
} while (byte != SLIPDEV_END);

if (++dev->rx_done != dev->rx_queued) {
DEBUG("slipdev: pkt still in queue");
netdev_trigger_event_isr(&dev->netdev);
}
}
return res;
}
Expand Down