Skip to content

Commit

Permalink
fixup! fixup! drivers/slipdev: implement sleep states
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 26, 2022
1 parent 8a06156 commit f087314
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions drivers/slipdev/slipdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ static void _slip_rx_cb(void *arg, uint8_t byte)
}
}

static void _poweron(slipdev_t *dev)
{
if ((dev->state != SLIPDEV_STATE_STANDBY) ||
(dev->state != SLIPDEV_STATE_SLEEP)) {
return;
}

dev->state = 0;
uart_init(dev->config.uart, dev->config.baudrate, _slip_rx_cb, dev);
}

static inline void _poweroff(slipdev_t *dev, uint8_t state)
{
uart_poweroff(dev->config.uart);
dev->state = state;
}

static int _init(netdev_t *netdev)
{
slipdev_t *dev = (slipdev_t *)netdev;
Expand Down Expand Up @@ -147,6 +164,26 @@ unsigned slipdev_unstuff_readbyte(uint8_t *buf, uint8_t byte, bool *escaped)
return res;
}

static int _check_state(slipdev_t *dev)
{
/* power states not supported when multiplexing stdio */
if (IS_USED(MODULE_SLIPDEV_STDIO)) {
return 0;
}

/* discard data when interface is in SLEEP mode */
if (dev->state == SLIPDEV_STATE_SLEEP) {
return -ENETDOWN;
}

/* sending data wakes the interface from STANDBY */
if (dev->state == SLIPDEV_STATE_STANDBY) {
_poweron(dev);
}

return 0;
}

static int _send(netdev_t *netdev, const iolist_t *iolist)
{
slipdev_t *dev = (slipdev_t *)netdev;
Expand Down Expand Up @@ -225,45 +262,7 @@ static void _isr(netdev_t *netdev)
}
}

#if IS_USED(MODULE_SLIPDEV_STDIO)
static int _check_state(slipdev_t *dev)
{
(void)dev;
return 0;
}
#else
static void _poweron(slipdev_t *dev)
{
if ((dev->state != SLIPDEV_STATE_STANDBY) ||
(dev->state != SLIPDEV_STATE_SLEEP)) {
return;
}

dev->state = 0;
uart_init(dev->config.uart, dev->config.baudrate, _slip_rx_cb, dev);
}

static void _poweroff(slipdev_t *dev, uint8_t state)
{
uart_poweroff(dev->config.uart);
dev->state = state;
}

static int _check_state(slipdev_t *dev)
{
/* discard data when interface is in SLEEP mode */
if (dev->state == SLIPDEV_STATE_SLEEP) {
return -ENETDOWN;
}

/* sending data wakes the interface from STANDBY */
if (dev->state == SLIPDEV_STATE_STANDBY) {
_poweron(dev);
}

return 0;
}

#if !IS_USED(MODULE_SLIPDEV_STDIO)
static int _set_state(slipdev_t *dev, netopt_state_t state)
{
if (IS_USED(MODULE_SLIPDEV_STDIO)) {
Expand Down

0 comments on commit f087314

Please sign in to comment.