diff --git a/include/thingset/can.h b/include/thingset/can.h index 5eb3c83..c58046b 100644 --- a/include/thingset/can.h +++ b/include/thingset/can.h @@ -271,6 +271,7 @@ struct thingset_can #ifdef CONFIG_THINGSET_CAN_CONTROL_REPORTING int64_t next_control_report_time; #endif + struct k_timer timeout_timer; uint8_t node_addr; /** bus or bridge number */ uint8_t route; diff --git a/src/can.c b/src/can.c index 05357a6..7fddef8 100644 --- a/src/can.c +++ b/src/can.c @@ -561,8 +561,7 @@ static void thingset_can_reqresp_sent_callback(int result, void *arg) static void thingset_can_timeout_timer_expired(struct k_timer *timer) { - ARG_UNUSED(timer); - + struct thingset_can *ts_can = CONTAINER_OF(timer, struct thingset_can, timeout_timer); k_event_set(&ts_can->events, EVENT_ADDRESS_CLAIM_TIMED_OUT); } @@ -577,7 +576,6 @@ int thingset_can_init_inst(struct thingset_can *ts_can, const struct device *can struct can_frame tx_frame = { .flags = CAN_FRAME_IDE, }; - struct k_timer timeout_timer; int filter_id; int err; @@ -593,7 +591,7 @@ int thingset_can_init_inst(struct thingset_can *ts_can, const struct device *can #endif k_sem_init(&ts_can->request_response.sem, 1, 1); k_sem_init(&ts_can->report_tx_sem, 0, 1); - k_timer_init(&timeout_timer, thingset_can_timeout_timer_expired, + k_timer_init(&ts_can->timeout_timer, thingset_can_timeout_timer_expired, thingset_can_timeout_timer_stopped); #ifdef CONFIG_THINGSET_SUBSET_LIVE_METRICS @@ -613,7 +611,7 @@ int thingset_can_init_inst(struct thingset_can *ts_can, const struct device *can } k_event_init(&ts_can->events); - k_timer_start(&timeout_timer, timeout, K_NO_WAIT); + k_timer_start(&ts_can->timeout_timer, timeout, K_NO_WAIT); #ifdef CONFIG_CAN_FD_MODE can_mode_t supported_modes; @@ -715,7 +713,7 @@ int thingset_can_init_inst(struct thingset_can *ts_can, const struct device *can if (err_cnt_after.tx_err_cnt <= err_cnt_before.tx_err_cnt) { /* address claiming is finished */ k_event_post(&ts_can->events, EVENT_ADDRESS_CLAIMING_FINISHED); - k_timer_stop(&timeout_timer); + k_timer_stop(&ts_can->timeout_timer); LOG_INF("Using CAN node address 0x%.2X on %s", ts_can->node_addr, ts_can->dev->name); break;