Skip to content
Snippets Groups Projects
Unverified Commit 836fe3db authored by Kaspar Schleiser's avatar Kaspar Schleiser Committed by GitHub
Browse files

Merge pull request #9890 from bergzand/pr/ethos/sync

ethos: Only accept frame if previous frame is read
parents a98edd33 c4608ca0
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,7 @@ void ethos_setup(ethos_t *dev, const ethos_params_t *params)
dev->framesize = 0;
dev->frametype = 0;
dev->last_framesize = 0;
dev->accept_new = true;
tsrb_init(&dev->inbuf, (char*)params->buf, params->bufsize);
mutex_init(&dev->out_mutex);
......@@ -82,6 +83,7 @@ static void _reset_state(ethos_t *dev)
dev->state = WAIT_FRAMESTART;
dev->frametype = 0;
dev->framesize = 0;
dev->accept_new = true;
}
static void _handle_char(ethos_t *dev, char c)
......@@ -90,9 +92,12 @@ static void _handle_char(ethos_t *dev, char c)
case ETHOS_FRAME_TYPE_DATA:
case ETHOS_FRAME_TYPE_HELLO:
case ETHOS_FRAME_TYPE_HELLO_REPLY:
if (tsrb_add_one(&dev->inbuf, c) == 0) {
dev->framesize++;
} else {
if (dev->accept_new) {
if (tsrb_add_one(&dev->inbuf, c) == 0) {
dev->framesize++;
}
}
else {
//puts("lost frame");
dev->inbuf.reads = 0;
dev->inbuf.writes = 0;
......@@ -112,6 +117,7 @@ static void _end_of_frame(ethos_t *dev)
switch(dev->frametype) {
case ETHOS_FRAME_TYPE_DATA:
if (dev->framesize) {
assert(dev->last_framesize == 0);
dev->last_framesize = dev->framesize;
dev->netdev.event_callback((netdev_t*) dev, NETDEV_EVENT_ISR);
}
......@@ -137,6 +143,9 @@ static void ethos_isr(void *arg, uint8_t c)
case WAIT_FRAMESTART:
if (c == ETHOS_FRAME_DELIMITER) {
_reset_state(dev);
if (dev->last_framesize) {
dev->accept_new = false;
}
dev->state = IN_FRAME;
}
break;
......@@ -304,13 +313,14 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void* info)
}
len = dev->last_framesize;
dev->last_framesize = 0;
if ((tsrb_get(&dev->inbuf, buf, len) != (int)len)) {
DEBUG("ethos _recv(): inbuf doesn't contain enough bytes.\n");
dev->last_framesize = 0;
return -1;
}
dev->last_framesize = 0;
return (int)len;
}
else {
......
......@@ -21,6 +21,8 @@
#ifndef ETHOS_H
#define ETHOS_H
#include <stdbool.h>
#include "kernel_types.h"
#include "periph/uart.h"
#include "net/netdev.h"
......@@ -78,6 +80,7 @@ typedef struct {
unsigned frametype; /**< type of currently incoming frame */
size_t last_framesize; /**< size of last completed frame */
mutex_t out_mutex; /**< mutex used for locking concurrent sends */
bool accept_new; /**< incoming frame can be stored or not */
} ethos_t;
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment