Skip to content

Commit

Permalink
Merge pull request #16823 from jia200x/pr/submac/fix_rx_continuous
Browse files Browse the repository at this point in the history
ieee802154/submac: fix leftovers of #16746
  • Loading branch information
benpicco committed Sep 7, 2021
2 parents eaeea8a + 201c2e7 commit 86f4206
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
10 changes: 10 additions & 0 deletions sys/net/link_layer/ieee802154/submac.c
Expand Up @@ -153,11 +153,21 @@ static ieee802154_fsm_state_t _fsm_state_rx(ieee802154_submac_t *submac, ieee802
}
else {
ieee802154_radio_read(&submac->dev, NULL, 0, NULL);

/* If the radio doesn't support RX Continuous, go to RX */
if (!ieee802154_radio_has_rx_continuous(&submac->dev)) {
_req_set_trx_state_wait_busy(&submac->dev, IEEE802154_TRX_STATE_RX_ON);
}

/* Keep on current state */
return IEEE802154_FSM_STATE_RX;
}
case IEEE802154_FSM_EV_CRC_ERROR:
ieee802154_radio_read(&submac->dev, NULL, 0, NULL);
/* If the radio doesn't support RX Continuous, go to RX */
if (!ieee802154_radio_has_rx_continuous(&submac->dev)) {
_req_set_trx_state_wait_busy(&submac->dev, IEEE802154_TRX_STATE_RX_ON);
}
/* Keep on current state */
return IEEE802154_FSM_STATE_RX;

Expand Down
32 changes: 24 additions & 8 deletions tests/ieee802154_submac/main.c
Expand Up @@ -41,6 +41,20 @@
#define RADIO_DEFAULT_ID (0U)

netdev_ieee802154_submac_t netdev_submac;
mutex_t lock;

struct send_ctx {
event_t ev;
iolist_t pkt;
};

static void _send_handler(event_t *ev)
{
struct send_ctx *ctx = (struct send_ctx*) ev;
netdev_t *dev = &netdev_submac.dev.netdev;

dev->driver->send(dev, &ctx->pkt);
}

void _ack_timeout(void *arg);

Expand Down Expand Up @@ -201,6 +215,7 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
default:
assert(false);
}
mutex_unlock(&lock);
}
}

Expand Down Expand Up @@ -235,6 +250,8 @@ static int _init(void)
{
netdev_t *dev = &netdev_submac.dev.netdev;

mutex_init(&lock);
mutex_lock(&lock);
dev->event_callback = _event_cb;
struct _reg_container reg = {0};
netdev_ieee802154_submac_init(&netdev_submac);
Expand All @@ -247,14 +264,13 @@ static int _init(void)
uint8_t payload[] =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ornare lacinia mi elementum interdum ligula.";

static iolist_t iol_hdr;

static int send(uint8_t *dst, size_t dst_len,
size_t len)
{
uint8_t flags;
uint8_t mhr[IEEE802154_MAX_HDR_LEN];
int mhr_len;
struct send_ctx ctx = {0};

le_uint16_t src_pan, dst_pan;
iolist_t iol_data = {
Expand All @@ -278,13 +294,13 @@ static int send(uint8_t *dst, size_t dst_len,
return 1;
}

iol_hdr.iol_next = &iol_data;
iol_hdr.iol_base = mhr;
iol_hdr.iol_len = mhr_len;

netdev_t *dev = &netdev_submac.dev.netdev;
ctx.ev.handler = _send_handler;
ctx.pkt.iol_next = &iol_data;
ctx.pkt.iol_base = mhr;
ctx.pkt.iol_len = mhr_len;

dev->driver->send(dev, &iol_hdr);
event_post(EVENT_PRIO_HIGHEST, &ctx.ev);
mutex_lock(&lock);
return 0;
}

Expand Down

0 comments on commit 86f4206

Please sign in to comment.