diff --git a/sys/can/device.c b/sys/can/device.c index 8d12aa05d8f58a4e50dfc804faf0cc309f93ac15..8f81a2a85ca3376d7021c3c7f13ceb129f8e713a 100644 --- a/sys/can/device.c +++ b/sys/can/device.c @@ -159,7 +159,10 @@ static int power_down(candev_dev_t *candev_dev) #endif canopt_state_t state = CANOPT_STATE_SLEEP; int res = dev->driver->set(dev, CANOPT_STATE, &state, sizeof(state)); - dev->state = CAN_STATE_SLEEPING; + + if (dev->state != CAN_STATE_BUS_OFF) { + dev->state = CAN_STATE_SLEEPING; + } #ifdef MODULE_CAN_PM xtimer_remove(&candev_dev->pm_timer); @@ -211,6 +214,9 @@ static void *_can_device_thread(void *args) candev_dev->pid = thread_getpid(); +#ifdef MODULE_CAN_TRX + can_trx_init(candev_dev->trx); +#endif #ifdef MODULE_CAN_PM if (candev_dev->rx_inactivity_timeout == 0) { candev_dev->rx_inactivity_timeout = CAN_DEVICE_PM_DEFAULT_RX_TIMEOUT; @@ -222,9 +228,6 @@ static void *_can_device_thread(void *args) candev_dev->pm_timer.arg = candev_dev; pm_reset(candev_dev, candev_dev->rx_inactivity_timeout); #endif -#ifdef MODULE_CAN_TRX - can_trx_init(candev_dev->trx); -#endif int res; can_pkt_t *pkt; @@ -240,7 +243,7 @@ static void *_can_device_thread(void *args) candev_dev->ifnum = can_dll_register_candev(candev_dev); dev->driver->init(dev); - dev->state = CAN_STATE_ERROR_ACTIVE; + power_up(candev_dev); while (1) { msg_receive(&msg);