Skip to content
Merged
2 changes: 0 additions & 2 deletions boards/common/esp8266/include/board_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ extern "C" {
* @name XTimer configuration
* @{
*/
#define XTIMER_OVERHEAD (0U)

#if defined(MODULE_ESP_SW_TIMER)
#define XTIMER_BACKOFF (100U)
#define XTIMER_ISR_BACKOFF (100U)
Expand Down
1 change: 0 additions & 1 deletion boards/common/iotlab/include/board_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ extern "C" {
* @{
*/
#define XTIMER_WIDTH (16U)
#define XTIMER_OVERHEAD (6U)
/** @} */

/**
Expand Down
6 changes: 0 additions & 6 deletions boards/common/nucleo/include/board_nucleo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,17 @@ extern "C" {
#define XTIMER_WIDTH (16)
#endif

#if defined(CPU_MODEL_STM32F334R8)
#define XTIMER_OVERHEAD (5)
#endif

#if defined(CPU_FAM_STM32F1)
#define XTIMER_WIDTH (16)
#define XTIMER_BACKOFF (19)
#endif

#if defined(CPU_FAM_STM32L1)
#define XTIMER_BACKOFF (11)
#define XTIMER_OVERHEAD (6)
#endif

#if defined(CPU_FAM_STM32F4) || defined(CPU_MODEL_STM32F303ZE)
#define XTIMER_BACKOFF (8)
#define XTIMER_OVERHEAD (6)
#endif
/** @} */

Expand Down
1 change: 0 additions & 1 deletion boards/frdm-kw41z/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ extern "C"
#define XTIMER_WIDTH (16)
#define XTIMER_BACKOFF (5)
#define XTIMER_ISR_BACKOFF (5)
#define XTIMER_OVERHEAD (4)
#define XTIMER_HZ (32768ul)
#endif
/** @} */
Expand Down
1 change: 0 additions & 1 deletion boards/hamilton/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extern "C" {
*/
#define XTIMER_DEV TIMER_DEV(1)
#define XTIMER_CHAN (0)
#define XTIMER_OVERHEAD (0)
/** @} */

/**
Expand Down
7 changes: 0 additions & 7 deletions boards/msba2/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ extern "C" {
#define LED1_TOGGLE (FIO3PIN ^= LED1_MASK)
/** @} */

/**
* @name xtimer tuning values
* @{
*/
#define XTIMER_OVERHEAD 7
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions boards/mulle/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@
#define XTIMER_WIDTH (16)
#define XTIMER_BACKOFF (4)
#define XTIMER_ISR_BACKOFF (4)
#define XTIMER_OVERHEAD (3)
#define XTIMER_HZ (32768ul)
#else
/* PIT xtimer configuration */
#define XTIMER_DEV (TIMER_PIT_DEV(0))
#define XTIMER_CHAN (0)
#define XTIMER_BACKOFF (40)
#define XTIMER_ISR_BACKOFF (40)
#define XTIMER_OVERHEAD (30)
#endif
/** @} */

Expand Down
1 change: 0 additions & 1 deletion boards/phynode-kw41z/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ extern "C"
#define XTIMER_WIDTH (16)
#define XTIMER_BACKOFF (5)
#define XTIMER_ISR_BACKOFF (5)
#define XTIMER_OVERHEAD (4)
#define XTIMER_HZ (32768ul)
#endif
/** @} */
Expand Down
1 change: 0 additions & 1 deletion boards/stm32f4discovery/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ extern "C" {
* @name xtimer configuration
* @{
*/
#define XTIMER_OVERHEAD (6)
#define XTIMER_BACKOFF (10)
/** @} */

Expand Down
1 change: 0 additions & 1 deletion boards/teensy31/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ extern "C" {
#define XTIMER_CHAN (0)
#define XTIMER_BACKOFF (40)
#define XTIMER_ISR_BACKOFF (40)
#define XTIMER_OVERHEAD (30)
/** @} */

/**
Expand Down
1 change: 0 additions & 1 deletion boards/usb-kw41z/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ extern "C"
#define XTIMER_WIDTH (16)
#define XTIMER_BACKOFF (5)
#define XTIMER_ISR_BACKOFF (5)
#define XTIMER_OVERHEAD (4)
#define XTIMER_HZ (32768ul)
#endif
/** @} */
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp32/esp_xtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void ets_timer_arm_us(ETSTimer *timer, uint32_t tmout, bool repeat)

xtimer_set(&e2xt->xtimer, tmout);

e2xt->ets_timer->timer_expire = e2xt->xtimer.target;
e2xt->ets_timer->timer_expire = e2xt->xtimer.start_time + e2xt->xtimer.offset;
e2xt->ets_timer->timer_period = repeat ? tmout : 0;
}

Expand Down
2 changes: 0 additions & 2 deletions cpu/native/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ extern "C" {
/**
* @brief xtimer configuration
*/
#define XTIMER_OVERHEAD 14

/* timer_set_absolute() has a high margin for possible underflow if set with
* value not far in the future. To prevent this, we set high backoff values
* here.
Expand Down
2 changes: 1 addition & 1 deletion drivers/dose/dose.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ static const netdev_driver_t netdev_driver_dose = {

void dose_setup(dose_t *ctx, const dose_params_t *params)
{
static const xtimer_ticks32_t min_timeout = {.ticks32 = XTIMER_BACKOFF + XTIMER_OVERHEAD};
static const xtimer_ticks32_t min_timeout = {.ticks32 = XTIMER_BACKOFF};

ctx->netdev.driver = &netdev_driver_dose;

Expand Down
52 changes: 52 additions & 0 deletions pkg/ndn-riot/patches/0001-update-xtimer_member_names.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
From 22f5984e32bec116e3449ebad1b29b2a18f4d93e Mon Sep 17 00:00:00 2001
From: Michel Rottleuthner <michel.rottleuthner@haw-hamburg.de>
Date: Thu, 9 Jan 2020 11:16:38 +0100
Subject: [PATCH] update xtimer_t member names

---
app.c | 2 +-
l2.c | 2 +-
pit.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/app.c b/app.c
index 8d37bd9..da9fc3c 100644
--- a/app.c
+++ b/app.c
@@ -380,7 +380,7 @@ int ndn_app_schedule(ndn_app_t* handle, ndn_app_sched_cb_t cb, void* context,
if (entry == NULL) return -1;

// initialize the timer
- entry->timer.target = entry->timer.long_target = 0;
+ entry->timer.offset = entry->timer.long_offset = 0;

// initialize the msg struct
entry->timer_msg.type = MSG_XTIMER;
diff --git a/l2.c b/l2.c
index 77d6be4..b64b9df 100644
--- a/l2.c
+++ b/l2.c
@@ -155,7 +155,7 @@ ndn_shared_block_t* ndn_l2_frag_receive(kernel_pid_t iface,
entry->id = id;

// initialize timer
- entry->timer.target = entry->timer.long_target = 0;
+ entry->timer.offset = entry->timer.long_offset = 0;
entry->timer_msg.type = NDN_L2_FRAG_MSG_TYPE_TIMEOUT;
entry->timer_msg.content.ptr = (char*)(&entry->timer_msg);

diff --git a/pit.c b/pit.c
index 644cf08..944a07c 100644
--- a/pit.c
+++ b/pit.c
@@ -155,7 +155,7 @@ int ndn_pit_add(kernel_pid_t face_id, int face_type, ndn_shared_block_t* si,
*pit_entry = entry;

/* initialize the timer */
- entry->timer.target = entry->timer.long_target = 0;
+ entry->timer.offset = entry->timer.long_offset = 0;

/* initialize the msg struct */
entry->timer_msg.type = NDN_PIT_MSG_TYPE_TIMEOUT;
--
2.24.1
24 changes: 24 additions & 0 deletions pkg/nimble/patches/0001-xtimer_member_names.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From 6b1223df6884bcfd00f4ecc8918b790baf041021 Mon Sep 17 00:00:00 2001
From: Michel Rottleuthner <michel.rottleuthner@haw-hamburg.de>
Date: Wed, 8 Jan 2020 19:50:48 +0100
Subject: [PATCH] update xtimer_t member names

---
porting/npl/riot/include/nimble/nimble_npl_os.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/porting/npl/riot/include/nimble/nimble_npl_os.h b/porting/npl/riot/include/nimble/nimble_npl_os.h
index 67eb74e1..61c1ea8a 100644
--- a/porting/npl/riot/include/nimble/nimble_npl_os.h
+++ b/porting/npl/riot/include/nimble/nimble_npl_os.h
@@ -209,7 +209,7 @@ ble_npl_callout_stop(struct ble_npl_callout *co)
static inline bool
ble_npl_callout_is_active(struct ble_npl_callout *c)
{
- return (c->timer.target || c->timer.long_target);
+ return (c->timer.offset || c->timer.long_offset);
}

static inline ble_npl_time_t
--
2.24.1
5 changes: 4 additions & 1 deletion pkg/semtech-loramac/contrib/semtech_loramac_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ extern kernel_pid_t semtech_loramac_pid;

void TimerInit(TimerEvent_t *obj, void (*cb)(void))
{
obj->dev.target = 0;
obj->dev.start_time = 0;
obj->dev.long_start_time = 0;
obj->dev.offset = 0;
obj->dev.long_offset = 0;
obj->running = 0;
obj->cb = cb;
}
Expand Down
6 changes: 4 additions & 2 deletions sys/evtimer/evtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ static void _update_timer(evtimer_t *evtimer)
static uint32_t _get_offset(xtimer_t *timer)
{
uint64_t now_us = xtimer_now_usec64();
uint64_t target_us = _xtimer_usec_from_ticks64(
((uint64_t)timer->long_target) << 32 | timer->target);
uint64_t start_us = _xtimer_usec_from_ticks64(
((uint64_t)timer->long_start_time << 32) | timer->start_time);
uint64_t target_us = start_us + _xtimer_usec_from_ticks64(
((uint64_t)timer->long_offset) << 32 | timer->offset);

if (target_us <= now_us) {
return 0;
Expand Down
64 changes: 4 additions & 60 deletions sys/include/xtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ typedef void (*xtimer_callback_t)(void*);
*/
typedef struct xtimer {
struct xtimer *next; /**< reference to next timer in timer lists */
uint32_t target; /**< lower 32bit absolute target time */
uint32_t long_target; /**< upper 32bit absolute target time */
uint32_t offset; /**< lower 32bit offset time */
uint32_t long_offset; /**< upper 32bit offset time */
uint32_t start_time; /**< lower 32bit absolute start time */
uint32_t long_start_time; /**< upper 32bit absolute start time */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah! I initially started ztimer to reduce the size of xtimer_t. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is not optimal, but I think we can live with it for now.
Actually it could be possible to just have a reference to the long_start_time, always assume a 0 start_time and adapt the offsets accordingly... but that will create other problems with the extension again^^
For comparison of xtimer/ztimer benches this should be good for ztimer though ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For comparison of xtimer/ztimer benches this should be good for ztimer though ;)

yup. 😄 sizeof(xtimer) is 28 with this PR vs. 16 in ztimer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichelRottleuthner good suggestion. Might be able to consider as a next PR :) Adding long_start_time is kinda quick, after-thought to merge this PR for this release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, I'm totally fine with leaving that for a future PR

xtimer_callback_t callback; /**< callback function to call when timer
expires */
void *arg; /**< argument to pass to callback function */
Expand Down Expand Up @@ -218,8 +220,6 @@ static inline void xtimer_periodic_wakeup(xtimer_ticks32_t *last_wakeup, uint32_
* expired.
*
* @param[in] timer timer struct to work with.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use
* @param[in] offset microseconds from now
* @param[in] pid pid of the thread that will be woken up
*/
Expand All @@ -232,8 +232,6 @@ static inline void xtimer_set_wakeup(xtimer_t *timer, uint32_t offset, kernel_pi
* expired.
*
* @param[in] timer timer struct to work with.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use
* @param[in] offset microseconds from now
* @param[in] pid pid of the thread that will be woken up
*/
Expand All @@ -252,8 +250,6 @@ static inline void xtimer_set_wakeup64(xtimer_t *timer, uint64_t offset, kernel_
* know *exactly* what that means.
*
* @param[in] timer the timer structure to use.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use
* @param[in] offset time in microseconds from now specifying that timer's
* callback's execution time
*/
Expand All @@ -273,8 +269,6 @@ static inline void xtimer_set(xtimer_t *timer, uint32_t offset);
* know *exactly* what that means.
*
* @param[in] timer the timer structure to use.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use
* @param[in] offset_us time in microseconds from now specifying that timer's
* callback's execution time
*/
Expand Down Expand Up @@ -426,8 +420,6 @@ void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
* needs to point to valid memory until the message has been delivered.
*
* @param[in] timer timer struct to work with.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use.
* @param[in] offset microseconds from now
* @param[in] msg ptr to msg that will be sent
* @param[in] target_pid pid the message will be sent to
Expand All @@ -444,8 +436,6 @@ static inline void xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg,
* needs to point to valid memory until the message has been delivered.
*
* @param[in] timer timer struct to work with.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use.
* @param[in] offset microseconds from now
* @param[in] msg ptr to msg that will be sent
* @param[in] target_pid pid the message will be sent to
Expand Down Expand Up @@ -487,29 +477,6 @@ static inline int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout);
#define XTIMER_BACKOFF 30
#endif

/**
* @brief xtimer overhead value, in hardware ticks
*
* This value specifies the time a timer will be late if uncorrected, e.g.,
* the system-specific xtimer execution time from timer ISR to executing
* a timer's callback's first instruction.
*
* E.g., with XTIMER_OVERHEAD == 0
* start=xtimer_now();
* xtimer_set(&timer, X);
* (in callback:)
* overhead=xtimer_now()-start-X;
*
* xtimer automatically subtracts XTIMER_OVERHEAD from a timer's target time,
* but when the timer triggers, xtimer will spin-lock until a timer's target
* time is reached, so timers will never trigger early.
*
* This is supposed to be defined per-device in e.g., periph_conf.h.
*/
#ifndef XTIMER_OVERHEAD
#define XTIMER_OVERHEAD 20
#endif

#ifndef XTIMER_ISR_BACKOFF
/**
* @brief xtimer IRQ backoff time, in hardware ticks
Expand All @@ -522,29 +489,6 @@ static inline int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout);
#define XTIMER_ISR_BACKOFF 20
#endif

#ifndef XTIMER_PERIODIC_SPIN
/**
* @brief xtimer_periodic_wakeup spin cutoff
*
* If the difference between target time and now is less than this value, then
* xtimer_periodic_wakeup will use xtimer_spin instead of setting a timer.
*/
#define XTIMER_PERIODIC_SPIN (XTIMER_BACKOFF * 2)
#endif

#ifndef XTIMER_PERIODIC_RELATIVE
/**
* @brief xtimer_periodic_wakeup relative target cutoff
*
* If the difference between target time and now is less than this value, then
* xtimer_periodic_wakeup will set a relative target time in the future instead
* of the true target.
*
* This is done to prevent target time underflows.
*/
#define XTIMER_PERIODIC_RELATIVE (512)
#endif

/*
* Default xtimer configuration
*/
Expand Down
Loading