Skip to content

Commit

Permalink
CAN: move timer to context
Browse files Browse the repository at this point in the history
  • Loading branch information
garethpotter committed Aug 11, 2024
1 parent 7b547a7 commit 2f3df3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/thingset/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;

Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2f3df3f

Please sign in to comment.