SterlingPeet / fprime-arduino

A platform support library allowing fprime to be run on a limited number of Arduino compatible devices.
1 stars 2 forks source link

ArduinoTime #3

Open SterlingPeet opened 2 years ago

SterlingPeet commented 2 years ago

I am planning to refactor the ArduinoTime component to be less awkwardly broken of a LinuxTime implementation. It turns out this is not as simple as I may have hoped. There are some concerns:

@LeStarch Thoughts?

LeStarch commented 2 years ago

From the library perspective, we should have something that works out-of-the-box based on arduino framework calls. I like the module approach because that forces into a known box: seconds, mircoseconds [0, 1000000). I didn't quite follow what was meant by: "and noticed that some seconds had more than 1 second worth of microseconds in them. This idiosyncrasy can be corrected on the ground, but I don't like providing a component that does this." and thus this may not be the best opinion.

Likely for your project you'll need better timing. There are two options:

  1. New component
  2. HW conditional implementation file

I prefer option 1 in this case as the implementations will likely be so vastly different that it really makes sense to be a separate component.

SterlingPeet commented 2 years ago

OK, so the problem I ran into is that time progresses between the millis() and micros() calls. The original component that I forked from your Teensy example had a bug that never bounded the micros() call, so it incremented until the 32 bit number rolled over rather than rolling over at the second boundary.

While investigating the unbounded microsecond bug, I discovered that my fix resulted in different bugs, where a time like "165 seconds and 12 microseconds", could happen twice. Once at the beginning of the second, and again at the end of the second.

Switching the order of the calls resulted in the opposite error, where very low microsecond values couldn't occur, and the microsecond values above 1 million did occur.

The question about providing a reference time component with only Arduino library references is this: Should we provide a component that is known to be broken in this way, or should we try to do something different?

LeStarch commented 2 years ago

I'd prefer a "working" solution but I am not sure how easy it is to do better. Perhaps a good-enough solution would be to just provide millisecond resolution for the stock example?

U32 mills = millis();
time = Fw::Time(millis/1000, (millis % 1000) * 1000);

We could use a counter member variable, and count microseconds roll-over but this gets complicated.