Skip to content

Conversation

jnohlgard
Copy link
Member

This PR splits the xtimer_periodic_wakeup function into one generic part which is reused by xtimer_periodic_wakeup and xtimer_periodic_msg, and one specific part for setting up the callback.

xtimer_periodic_msg is functionally similar to xtimer_set_msg, but the target time is computed in the same way as for xtimer_periodic_wakeup.

xtimer_periodic_msg can be used to create periodic messages. This is especially useful if a thread has an event loop for handling asynchronous events, but some events need to occur periodically on a schedule. Using xtimer_periodic_wakeup in these kinds of applications would cause the asynchronous events to be delayed until the next wakeup, instead of processed immediately.

This is in preparation for some future MAC layer functionality that we are working on.

@jnohlgard jnohlgard added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: timers Area: timer subsystems labels Aug 22, 2017
@jnohlgard jnohlgard added this to the Release 2017.10 milestone Aug 22, 2017
@jnohlgard jnohlgard added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 22, 2017
@jnohlgard
Copy link
Member Author

I removed chronos from the insufficient memory blacklist for the other xtimer_periodic_ test, it was probably just a copy pasta from some other test since these tests are pretty tiny with the current settings.

@kaspar030
Copy link
Contributor

This is in preparation for some future MAC layer functionality that we are working on.

If you're designing the MAC layer around this, keep in mind that messages from ISR's are not reliable, as they get silently discarded if the receiving thread is not waiting (or it's queue is full).

@jnohlgard
Copy link
Member Author

Thanks for the warning. We will be using this for scheduling transceiver wake times for the RX schedule. The thread will use this function to send a message to itself to trigger an event at the beginning of the next receive window. This is necessary in order for still be able to handle TX operations while idling with the RX part turned off.

@haukepetersen
Copy link
Contributor

have you thought about using thread_flags for the periodic wakeup?

@jnohlgard
Copy link
Member Author

@haukepetersen I have not. How do I use them?

@jnohlgard
Copy link
Member Author

I have looked into using thread flags and I think it will be a better solution than a pure msg based event loop. I will do some experiments and possibly add something more to this PR.

@haukepetersen
Copy link
Contributor

perfect.

Copy link
Member Author

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

Need to address the last_wakeup issue

* For very small offsets, spin.
*/
/*
* Note: last_wakeup _must never_ specify a time in the future after
Copy link
Member Author

Choose a reason for hiding this comment

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

accidentally messed up the indentation...

DEBUG("xps, abs: %" PRIu32 "\n", target);
_xtimer_set_absolute(timer, target);
}
} while (0);
*last_wakeup = target;
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a problem for the _msg variant, the last wakeup time will increment before that time has actually passed, leading to the situation described above in the long comment about not returning early.
Calling xtimer_periodic_msg twice without waiting for the first message to send will mess up the timer.

DEBUG("xps, abs: %" PRIu32 "\n", target);
_xtimer_set_absolute(timer, target);
}
} while (0);
Copy link
Member

Choose a reason for hiding this comment

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

why do you need the do { ... } while(0);?

Copy link
Member Author

Choose a reason for hiding this comment

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

So that the break replaces the goto

@jnohlgard jnohlgard force-pushed the pr/xtimer-periodic-msg branch from 75c8d8d to e996db1 Compare September 21, 2017 08:20
@kaspar030 kaspar030 removed this from the Release 2018.04 milestone Apr 11, 2018
@smlng smlng added the State: waiting for other PR State: The PR requires another PR to be merged first label Jan 16, 2019
@smlng
Copy link
Member

smlng commented Jan 16, 2019

requires #7628

@smlng
Copy link
Member

smlng commented Jan 16, 2019

needs rebase

@smlng
Copy link
Member

smlng commented Jan 16, 2019

actually needs rebase and does not need #7628 as similar changes were introduced by #9211

@smlng smlng removed the State: waiting for other PR State: The PR requires another PR to be merged first label Jan 16, 2019
@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: stale State: The issue / PR has no activity for >185 days Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants