Userspace alternative to gpstime kernel module
This code can be used when models run in userspace and without GPS hardware. It removes the dependency on the special device file /dev/gpstime. GPS time is obtained in userspace from the system clock. Enable at compile time by defining USE_GPSCLOCK. When building a model, add userspacegps=1 to the CDS parameters.
Merge request reports
Activity
@christopher.wipf Thanks for the MR.
I like the idea, it would be good to allow things to run w/o custom kernel drivers when possible. There are a few things I would like changed to help with future maintenance/support and packaging.
-
We can do all of this at run time, so I don't think we need to do this via a configuration time check. This will make it easier for support as we will have less packages and variants to work with.
a. The code can try to open /dev/gpstime, and if that fails call the gpsclock calls.
-
For readability and maintenance down the line I would like to reduce the number of ifdefs. Typically consolidate them at the front of a file, including small static inline functions/macros that are used later in the code to make the code paths read the same.
-
You found some bits of dead/unused code that we should just drop.
I took the liberty of implementing these as a MR against this MR, and it has been submitted for your review.
Thanks.
Edited by Jonathan Hanks-
added 2 commits
@rolf.bork Can you sign off on the RCG side of the changes. I'm ready to merge this if it looks good to you.
Specifically:
- timing changes in controllerAppUser.c, controllerIopUser.c, there are supporting changes to feCodeGen.pl, Parameters.pm, and createUserMakefile.pm
mentioned in commit 5b9c93d2
- src/drv/gpsclock.c 0 → 100644
18 } 19 20 int gpsclock_offset(long *offset) { 21 // TAI-UTC offset in seconds as of 1972 22 const long INITIAL_TAI_OFFSET = 10; 23 // GPS-TAI offset in seconds 24 const long GPS_TAI_OFFSET = -19; 25 26 char *savetz; 27 time_t now, gpszero, posixutc, rightutc; 28 struct tm now_tm, gpszero_tm = {.tm_year=80, .tm_mon=0, .tm_mday=6, .tm_hour=0, .tm_min=0, .tm_sec=0, .tm_wday=-1, .tm_yday=-1, .tm_isdst=-1}; 29 30 // save TZ 31 savetz = getenv("TZ"); 32 if (savetz) { 33 setenv("GPSCLOCK_TZ_ORIG", savetz, 1); @christopher.wipf I didn't mean why is it saved and restored, I meant why is it saved to an environment variable, rather than just in the savetz variable (
GPSCLOCK_TZ_ORIG
)? Seems like writing it to the environment is an unnecessary step.Edited by Jameson Rollins