-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing osxtime_t? #10
Comments
Thinking on this some more, I realized I was assuming a 16μs tick, as that's what the Arduino HAL uses, but other values are also allowed by BasicMAC, so that should be kept in mind here. However, the source documents an allowed range of 15.5μs - 100μs, so the above conclusions wrt to how long an interval an As for the available times, I realized that one other advantage of passing an Lines 952 to 954 in 982b514
So in that sense, we won't lose any precision by simply skipping the conversion to I also considered not to store available times in 16-bit seconds, but just storing the upper 16 bits of the I also wondered if some kind of hybrid approach could work, where short times are more precise than longer times, but that can only be made to work with intervals relative to a base value, and probably requires updating the base value (and thus all available times) more often, which might end up being contraproductive. Then, for something completely different but related: I noticed |
I decided to just see how it would look like with not using xtime for avail times, without changing the "store seconds" approach used now and came up with https://github.com/LacunaSpace/basicmac/commits/no-xtime In addition to some small cleanups, there's two main changes:
I haven't done long-term testing of that branch yet (just finished it), I'll be doing that next. |
Thanks for raising this -- really it's two issues, although they are interrelated. Definition of terms Some history Extended time availability
Changing As a side note, while unsigned overflow is well defined in C, a cast from unsigned to signed, e.g. from A while ago I started an effort to get rid of global state in LMiC. As part of that, I also created a clean version of the runtime without global state that also fixed the signed overflow issues and included macros for creating time deltas and doing time stamp comparisons. I'll dig that up and throw it onto GitHub, maybe that can serve as some inspiration. In any case, I think we should separate the two issues, reducing/removing the use of xticks in the stack, and the signed overflow UB issue. What do you think? |
Here's my no-global runtime concept I mentioned earlier: https://github.com/mkuyper/rtic/blob/master/rtic.h |
Agreed, probably best to open another issue for the signed vs unsigned issue. I'll do that next and then respond there as well.
Arduino does something like that internally (extending a 16-bit micro-second timer to 32-bits) to produce a 32-bit Btw, you say 272 years, but I get 142 years for an 48-bit timer?
This is what I implemented in https://github.com/LacunaSpace/basicmac/commits/no-xtime, what would you think of that? |
In the Lacuna version / Arduino HAL, we're running into some hal timer-related problem that I'd like to pick your brain on.
The problem is caused because we didn't implement the 64-bit
hal_getxticks()
, because we don't have an easily accessible 64-bit counter (and I was a bit lazy). We could just implement it by extending the 32-bit timer we have (which we already do a bit to extends 32-bit micros to 32-bit 16-us-ticks), but I've seen that this xticks handling actually adds complexity, probably code size and IIRC wasn't implemented perfectly everywhere (i.e. truncating back to 32-bits in some places, voiding the advantages of using a 64-bit timer elsewhere).So, I'm pondering to just remove the hal_xtimer() / osxtime_t (nearly) completely instead and just simplify things. The main question is, when is it actually used / needed? I haven't checked thoroughly before, but doing so now I find it is used for:
Dutycycle available times.
For these, 2³¹ ticks x 16μs = 9.5 hours should be sufficient (at 0.1% DC, this allows up to 34s of airtime for a single packet, which is over 500 bytes at SF12BW125 IIUC). Even more, the current code uses
osxtime_t
inupdateTx
andnextTx
, but truncates toostime_t
in thenextTx
return value anyway, so if the avail time would be > 9.5h in the future, I expect things to break with the current code already. Also, the actual available times are stored as 16-bit seconds anyway (from a baseosxtime_t
), so we could keep that and with some special care support up to 2¹⁶ seconds (18 hours) of (un)avail time as well (but maybe it's not even needed).One advantage of storing the base timestamp as
osxtime_t
currently, is that the availability times will remain valid even when there is no activity for > 9.5 hours (i.e. no activitity that causessetAvail
to update the base timestamp), but this can probably also be handled by just updating the base timestamp once every 2³¹ or so ticks (maybe using a dedicated "overflow" task?).Tracking the wall time using
MCMD_TIME_ANS
/LMIC.gpsEpochOff
.This code uses the wall time from the
MCMD_TIME_ANS
returned by the network to store an offset, which allows translating the result ofhal_xticks()
to wall time later. This can still work with a 32-bit ticks, but then the translation is only valid for 19 hours, after which the calculated wall time loops back. This can be solved by using a longer external timer, or maybe by Given there is no documented API for this (other than directLMIC.gpsEpochOff
access), maybe we can come up with some alternative (such as agetWallTime(ostime_t)
function or so that works for timestamps within 9.5 hours around the current time as long as you call it at least once every 9.5h, or maybe the offset can be updated automatically internally whenever the timer overflow, using the same overflow task suggested above)?"Extended" scheduled callbacks (i.e. callbacks after 9.5 hours or more). It seems these are not used by BasicMac itself, only maybe by user code.
If we want to keep this (which I guess could make sense when you do all scheduling of tasks in your application using the BasicMac scheduler), then we can still implement this even without having to keep
hal_xticks()
. This would require changing the API slightly (i.e. by specifying a relative callback, rather than an absolute time, which should be acceptable since these callbacks are approximate anyway) and then the implementation can be slightly changed by just counting off multiples of 2³¹ ticks instead of comparing againsthal_xticks()
on every intermediate callback (if implemented properly, this should be doable without stacking timing errors, so total accuracy is similar to the current implementation).From your experience with the code, does the above seem plausible? Or am I missing something?
Summarizing, I think the availability time tracking can be internally improved to not require 64-bit timestamps without any user-visible changes, so I'll probably have a go at that.
Then, it might be useful for BasicMac to still offer an 64-bit timer, but maybe it can be made optional (and then the Arduino core could just not provide it, or we could add it anyway later, but people can disable it to save code space). If the 64-bit timer is enabled, the GPS offset and an absolute "extended" callbacks can be offered as is now. If the 64-bit timer is omitted, either these can just be omitted entirely (initially), or have limited / relative implementations as suggested above (implemented later maybe).
The text was updated successfully, but these errors were encountered: