1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/can: migrate to ztimer

This commit is contained in:
Alexandre Abadie 2021-12-09 12:27:54 +01:00
parent 622fca0235
commit ce373902ee
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
7 changed files with 59 additions and 55 deletions

View File

@ -399,14 +399,16 @@ ifneq (,$(filter can,$(USEMODULE)))
endif
ifneq (,$(filter can_isotp,$(USEMODULE)))
USEMODULE += xtimer
USEMODULE += ztimer
USEMODULE += ztimer_usec
USEMODULE += gnrc_pktbuf
endif
ifneq (,$(filter conn_can,$(USEMODULE)))
USEMODULE += can
USEMODULE += can_mbox
USEMODULE += xtimer
USEMODULE += ztimer
USEMODULE += ztimer_usec
endif
ifneq (,$(filter entropy_source_%,$(USEMODULE)))

View File

@ -32,15 +32,15 @@
#define ENABLE_DEBUG 0
#include "debug.h"
#include "xtimer.h"
#include "ztimer.h"
#define _TIMEOUT_TX_MSG_TYPE (0x8000)
#define _TIMEOUT_RX_MSG_TYPE (0x8001)
#define _CLOSE_CONN_MSG_TYPE (0x8002)
#define _TIMEOUT_MSG_VALUE (0xABCDEFAB)
#ifndef CONN_CAN_ISOTP_TIMEOUT_TX_CONF
#define CONN_CAN_ISOTP_TIMEOUT_TX_CONF (10 * US_PER_SEC)
#ifndef CONN_CAN_ISOTP_TIMEOUT_TX_CONF_US
#define CONN_CAN_ISOTP_TIMEOUT_TX_CONF_US (10 * US_PER_SEC)
#endif
static inline int try_put_msg(conn_can_isotp_t *conn, msg_t *msg)
@ -169,10 +169,10 @@ int conn_can_isotp_send(conn_can_isotp_t *conn, const void *buf, size_t size, in
return isotp_send(&conn->isotp, buf, size, flags);
}
else {
xtimer_t timer;
ztimer_t timer;
timer.callback = _tx_conf_timeout;
timer.arg = conn;
xtimer_set(&timer, CONN_CAN_ISOTP_TIMEOUT_TX_CONF);
ztimer_set(ZTIMER_USEC, &timer, CONN_CAN_ISOTP_TIMEOUT_TX_CONF_US);
ret = isotp_send(&conn->isotp, buf, size, flags);
@ -192,7 +192,7 @@ int conn_can_isotp_send(conn_can_isotp_t *conn, const void *buf, size_t size, in
break;
}
#endif
xtimer_remove(&timer);
ztimer_remove(ZTIMER_USEC, &timer);
return ret;
case _TIMEOUT_TX_MSG_TYPE:
return -ETIMEDOUT;
@ -246,11 +246,11 @@ int conn_can_isotp_recv(conn_can_isotp_t *conn, void *buf, size_t size, uint32_t
}
#endif
xtimer_t timer;
ztimer_t timer;
if (timeout != 0) {
timer.callback = _rx_timeout;
timer.arg = conn;
xtimer_set(&timer, timeout);
ztimer_set(ZTIMER_USEC, &timer, timeout);
}
msg_t msg;
@ -270,7 +270,7 @@ int conn_can_isotp_recv(conn_can_isotp_t *conn, void *buf, size_t size, uint32_t
}
#endif
if (timeout != 0) {
xtimer_remove(&timer);
ztimer_remove(ZTIMER_USEC, &timer);
}
if (snip->size <= size) {
memcpy(buf, snip->data, snip->size);
@ -296,7 +296,7 @@ int conn_can_isotp_recv(conn_can_isotp_t *conn, void *buf, size_t size, uint32_t
if ((msg.content.ptr == conn) || (msg.content.ptr == conn->master)) {
#endif
if (timeout != 0) {
xtimer_remove(&timer);
ztimer_remove(ZTIMER_USEC, &timer);
}
return -ECONNABORTED;
#ifdef MODULE_CONN_CAN_ISOTP_MULTI
@ -306,7 +306,7 @@ int conn_can_isotp_recv(conn_can_isotp_t *conn, void *buf, size_t size, uint32_t
default:
DEBUG("conn_can_isotp_recv: unexpected msg %x\n", msg.type);
if (timeout != 0) {
xtimer_remove(&timer);
ztimer_remove(ZTIMER_USEC, &timer);
}
ret = -EINTR;
return ret;
@ -383,11 +383,11 @@ int conn_can_isotp_select(conn_can_isotp_slave_t **conn, conn_can_isotp_t *maste
int ret;
xtimer_t timer;
ztimer_t timer;
if (timeout != 0) {
timer.callback = _rx_timeout;
timer.arg = master;
xtimer_set(&timer, timeout);
ztimer_set(ZTIMER_USEC, &timer, timeout);
}
msg_t msg;
@ -396,7 +396,7 @@ int conn_can_isotp_select(conn_can_isotp_slave_t **conn, conn_can_isotp_t *maste
mbox_get(&master->mbox, &msg);
if (timeout != 0) {
xtimer_remove(&timer);
ztimer_remove(ZTIMER_USEC, &timer);
}
switch (msg.type) {
case CAN_MSG_RX_INDICATION:

View File

@ -28,15 +28,15 @@
#define ENABLE_DEBUG 0
#include "debug.h"
#include "xtimer.h"
#include "ztimer.h"
#define _TIMEOUT_TX_MSG_TYPE (0x8000)
#define _TIMEOUT_RX_MSG_TYPE (0x8001)
#define _CLOSE_CONN_MSG_TYPE (0x8002)
#define _TIMEOUT_MSG_VALUE (0xABCDEFAB)
#ifndef CONN_CAN_RAW_TIMEOUT_TX_CONF
#define CONN_CAN_RAW_TIMEOUT_TX_CONF (1 * US_PER_SEC)
#ifndef CONN_CAN_ISOTP_TIMEOUT_TX_CONF_US
#define CONN_CAN_ISOTP_TIMEOUT_TX_CONF_US (1 * US_PER_SEC)
#endif
int conn_can_raw_create(conn_can_raw_t *conn, struct can_filter *filter, size_t count,
@ -146,14 +146,14 @@ int conn_can_raw_send(conn_can_raw_t *conn, const struct can_frame *frame, int f
}
}
else {
xtimer_t timer;
ztimer_t timer;
timer.callback = _tx_conf_timeout;
timer.arg = conn;
xtimer_set(&timer, CONN_CAN_RAW_TIMEOUT_TX_CONF);
ztimer_set(ZTIMER_USEC, &timer, CONN_CAN_ISOTP_TIMEOUT_TX_CONF_US);
handle = raw_can_send_mbox(conn->ifnum, frame, &conn->mbox);
if (handle < 0) {
xtimer_remove(&timer);
ztimer_remove(ZTIMER_USEC, &timer);
return handle;
}
@ -161,7 +161,7 @@ int conn_can_raw_send(conn_can_raw_t *conn, const struct can_frame *frame, int f
int timeout = 5;
while (1) {
mbox_get(&conn->mbox, &msg);
xtimer_remove(&timer);
ztimer_remove(ZTIMER_USEC, &timer);
switch (msg.type) {
case CAN_MSG_TX_ERROR:
return -EIO;
@ -186,7 +186,7 @@ int conn_can_raw_send(conn_can_raw_t *conn, const struct can_frame *frame, int f
if (!timeout--) {
return -EINTR;
}
xtimer_set(&timer, CONN_CAN_RAW_TIMEOUT_TX_CONF);
ztimer_set(ZTIMER_USEC, &timer, CONN_CAN_ISOTP_TIMEOUT_TX_CONF_US);
break;
}
}
@ -216,12 +216,12 @@ int conn_can_raw_recv(conn_can_raw_t *conn, struct can_frame *frame, uint32_t ti
assert(frame != NULL);
xtimer_t timer;
ztimer_t timer;
if (timeout != 0) {
timer.callback = _rx_timeout;
timer.arg = conn;
xtimer_set(&timer, timeout);
ztimer_set(ZTIMER_USEC, &timer, timeout);
}
int ret;
@ -230,7 +230,7 @@ int conn_can_raw_recv(conn_can_raw_t *conn, struct can_frame *frame, uint32_t ti
mbox_get(&conn->mbox, &msg);
if (timeout != 0) {
xtimer_remove(&timer);
ztimer_remove(ZTIMER_USEC, &timer);
}
switch (msg.type) {
case CAN_MSG_RX_INDICATION:

View File

@ -22,6 +22,7 @@
#include <errno.h>
#include "thread.h"
#include "ztimer.h"
#include "can/device.h"
#include "can/common.h"
#include "can/pkt.h"
@ -146,7 +147,7 @@ static int power_down(candev_dev_t *candev_dev)
}
#ifdef MODULE_CAN_PM
xtimer_remove(&candev_dev->pm_timer);
ztimer_remove(ZTIMER_USEC, &candev_dev->pm_timer);
candev_dev->last_pm_update = 0;
#endif
@ -171,15 +172,15 @@ static void pm_reset(candev_dev_t *candev_dev, uint32_t value)
if (value == 0) {
candev_dev->last_pm_value = 0;
xtimer_remove(&candev_dev->pm_timer);
ztimer_remove(ZTIMER_USEC, &candev_dev->pm_timer);
return;
}
if (candev_dev->last_pm_update == 0 ||
value > (candev_dev->last_pm_value - (xtimer_now_usec() - candev_dev->last_pm_update))) {
value > (candev_dev->last_pm_value - (ztimer_now(ZTIMER_USEC) - candev_dev->last_pm_update))) {
candev_dev->last_pm_value = value;
candev_dev->last_pm_update = xtimer_now_usec();
xtimer_set(&candev_dev->pm_timer, value);
candev_dev->last_pm_update = ztimer_now(ZTIMER_USEC);
ztimer_set(ZTIMER_USEC, &candev_dev->pm_timer, value);
}
}
#endif

View File

@ -29,6 +29,7 @@
#include "thread.h"
#include "mutex.h"
#include "timex.h"
#include "ztimer.h"
#include "utlist.h"
#define ENABLE_DEBUG 0
@ -196,7 +197,7 @@ static int _isotp_rcv_fc(struct isotp *isotp, struct can_frame *frame, int ae)
return 0;
}
xtimer_remove(&isotp->tx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->tx_timer);
if (frame->can_dlc < ae + FC_CONTENT_SZ) {
/* Invalid length */
@ -230,7 +231,7 @@ static int _isotp_rcv_fc(struct isotp *isotp, struct can_frame *frame, int ae)
isotp->tx_wft = 0;
isotp->tx.bs = 0;
isotp->tx.state = ISOTP_SENDING_NEXT_CF;
xtimer_set(&isotp->tx_timer, isotp->tx_gap);
ztimer_set(ZTIMER_USEC, &isotp->tx_timer, isotp->tx_gap);
break;
case ISOTP_FC_WT:
@ -240,7 +241,7 @@ static int _isotp_rcv_fc(struct isotp *isotp, struct can_frame *frame, int ae)
return 1;
}
/* BS and STmin shall be ignored */
xtimer_set(&isotp->tx_timer, CAN_ISOTP_TIMEOUT_N_Bs);
ztimer_set(ZTIMER_USEC, &isotp->tx_timer, CAN_ISOTP_TIMEOUT_N_Bs);
break;
case ISOTP_FC_OVFLW:
@ -257,7 +258,7 @@ static int _isotp_rcv_fc(struct isotp *isotp, struct can_frame *frame, int ae)
static int _isotp_rcv_sf(struct isotp *isotp, struct can_frame *frame, int ae)
{
xtimer_remove(&isotp->rx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->rx_timer);
isotp->rx.state = ISOTP_IDLE;
int len = (frame->data[ae] & 0x0F);
@ -341,7 +342,7 @@ static int _isotp_rcv_cf(struct isotp *isotp, struct can_frame *frame, int ae)
return 1;
}
xtimer_remove(&isotp->rx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->rx_timer);
if ((frame->data[ae] & 0x0F) != isotp->rx.sn) {
DEBUG("_isotp_rcv_cf: wrong seq number %d, expected %d\n", frame->data[ae] & 0x0F, isotp->rx.sn);
@ -380,7 +381,7 @@ static int _isotp_rcv_cf(struct isotp *isotp, struct can_frame *frame, int ae)
DEBUG("_isotp_rcv_cf: rxfc.bs=%" PRIx8 " rx.bs=%" PRIx8 "\n", isotp->rxfc.bs, isotp->rx.bs);
if (!isotp->rxfc.bs || (++isotp->rx.bs < isotp->rxfc.bs)) {
xtimer_set(&isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Cr);
ztimer_set(ZTIMER_USEC, &isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Cr);
return 0;
}
@ -456,7 +457,7 @@ static int _isotp_send_fc(struct isotp *isotp, int ae, uint8_t status)
DEBUG("\n");
}
xtimer_set(&isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Ar);
ztimer_set(ZTIMER_USEC, &isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Ar);
isotp->rx.tx_handle = raw_can_send(isotp->entry.ifnum, &fc, isotp_pid);
if (isotp->rx.tx_handle >= 0) {
@ -464,7 +465,7 @@ static int _isotp_send_fc(struct isotp *isotp, int ae, uint8_t status)
}
else {
isotp->rx.state = ISOTP_IDLE;
xtimer_remove(&isotp->rx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->rx_timer);
return isotp->rx.tx_handle;
}
}
@ -555,7 +556,7 @@ static void _isotp_tx_timeout_task(struct isotp *isotp)
static void _isotp_tx_tx_conf(struct isotp *isotp)
{
xtimer_remove(&isotp->tx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->tx_timer);
isotp->tx.tx_handle = 0;
DEBUG("_isotp_tx_tx_conf: state=%d\n", isotp->tx.state);
@ -568,7 +569,7 @@ static void _isotp_tx_tx_conf(struct isotp *isotp)
case ISOTP_SENDING_FF:
isotp->tx.state = ISOTP_WAIT_FC;
xtimer_set(&isotp->tx_timer, CAN_ISOTP_TIMEOUT_N_Bs);
ztimer_set(ZTIMER_USEC, &isotp->tx_timer, CAN_ISOTP_TIMEOUT_N_Bs);
break;
case ISOTP_SENDING_CF:
@ -582,12 +583,12 @@ static void _isotp_tx_tx_conf(struct isotp *isotp)
if (isotp->txfc.bs && (isotp->tx.bs >= isotp->txfc.bs)) {
/* wait for FC */
isotp->tx.state = ISOTP_WAIT_FC;
xtimer_set(&isotp->tx_timer, CAN_ISOTP_TIMEOUT_N_Bs);
ztimer_set(ZTIMER_USEC, &isotp->tx_timer, CAN_ISOTP_TIMEOUT_N_Bs);
break;
}
isotp->tx.state = ISOTP_SENDING_NEXT_CF;
xtimer_set(&isotp->tx_timer, isotp->tx_gap);
ztimer_set(ZTIMER_USEC, &isotp->tx_timer, isotp->tx_gap);
break;
}
}
@ -611,7 +612,7 @@ static void _isotp_rx_timeout_task(struct isotp *isotp)
static void _isotp_rx_tx_conf(struct isotp *isotp)
{
xtimer_remove(&isotp->rx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->rx_timer);
isotp->rx.tx_handle = 0;
DEBUG("_isotp_rx_tx_conf: state=%d\n", isotp->rx.state);
@ -619,18 +620,18 @@ static void _isotp_rx_tx_conf(struct isotp *isotp)
switch (isotp->rx.state) {
case ISOTP_SENDING_FC:
isotp->rx.state = ISOTP_WAIT_CF;
xtimer_set(&isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Cr);
ztimer_set(ZTIMER_USEC, &isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Cr);
break;
}
}
static int _isotp_tx_send(struct isotp *isotp, struct can_frame *frame)
{
xtimer_set(&isotp->tx_timer, CAN_ISOTP_TIMEOUT_N_As);
ztimer_set(ZTIMER_USEC, &isotp->tx_timer, CAN_ISOTP_TIMEOUT_N_As);
isotp->tx.tx_handle = raw_can_send(isotp->entry.ifnum, frame, isotp_pid);
DEBUG("isotp_send: FF/SF/CF sent handle=%d\n", isotp->tx.tx_handle);
if (isotp->tx.tx_handle < 0) {
xtimer_remove(&isotp->tx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->tx_timer);
isotp->tx.state = ISOTP_IDLE;
return _isotp_dispatch_tx(isotp, isotp->tx.tx_handle);
}
@ -868,7 +869,7 @@ int isotp_release(struct isotp *isotp)
.can_mask = 0xFFFFFFFF,
};
raw_can_unsubscribe_rx(isotp->entry.ifnum, &filter, isotp_pid, isotp);
xtimer_remove(&isotp->rx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->rx_timer);
if (isotp->rx.snip) {
DEBUG("isotp_release: freeing rx buf\n");
@ -878,7 +879,7 @@ int isotp_release(struct isotp *isotp)
isotp->rx.state = ISOTP_IDLE;
isotp->entry.target.pid = KERNEL_PID_UNDEF;
xtimer_remove(&isotp->tx_timer);
ztimer_remove(ZTIMER_USEC, &isotp->tx_timer);
mutex_lock(&lock);
LL_DELETE(isotp_list, isotp);

View File

@ -28,7 +28,7 @@ extern "C" {
#include "sched.h"
#ifdef MODULE_CAN_PM
#include "xtimer.h"
#include "ztimer.h"
#endif
#ifdef MODULE_CAN_TRX
#include "can/can_trx.h"
@ -79,7 +79,7 @@ typedef struct candev_dev {
uint32_t tx_wakeup_timeout; /**< Min timeout loaded when a frame is sent */
uint32_t last_pm_update; /**< time when the pm was updated */
uint32_t last_pm_value; /**< last pm timer value set */
xtimer_t pm_timer; /**< timer for power management */
ztimer_t pm_timer; /**< timer for power management */
#endif
} candev_dev_t;

View File

@ -28,7 +28,7 @@ extern "C" {
#include "can/can.h"
#include "can/common.h"
#include "thread.h"
#include "xtimer.h"
#include "ztimer.h"
#include "net/gnrc/pktbuf.h"
#ifndef CAN_ISOTP_BS
@ -110,8 +110,8 @@ struct isotp {
struct isotp_fc_options txfc; /**< tx flow control options (defined remotely) */
struct tpcon tx; /**< transmit state */
struct tpcon rx; /**< receive state */
xtimer_t tx_timer; /**< timer for tx operations */
xtimer_t rx_timer; /**< timer for rx operations */
ztimer_t tx_timer; /**< timer for tx operations */
ztimer_t rx_timer; /**< timer for rx operations */
can_reg_entry_t entry; /**< entry containing ifnum and upper layer msg system */
uint32_t tx_gap; /**< transmit gap from fc (in us) */
uint8_t tx_wft; /**< transmit wait counter */