Replies: 5 comments 14 replies
-
This seem about right. Since the clock_id can be passed on a short stack, and an empty short stack is a zero aka CLOCK_REALTIME, there's no reason to avoid implementing the full POSIX-y. POSIX is the direction I'll always try to take. Returning a full timespec with a tv_nsec set to 0 is fine. Did you look into timezones? I expect timezone to be a RIA setting one day. Don't want this to get weird, so it deserves some thought now. If the xstack seems daunting, hang tight and watch the upcoming API improvements. |
Beta Was this translation helpful? Give feedback.
-
I agree it isn't necessary for apps to set the system time zone. I'll use this approach in my next revision. I definitely like the second idea. This will allow the use of the timestamps for stuff like measuring time duration even when the RTC isn't set. |
Beta Was this translation helpful? Give feedback.
-
I’ve been working on it again for the last few days. Everything looks good to me except the timezones. I will finalize a version without timezones and show it to you. If it is ok I’d also like to show you what I have with timezones to see what you think. Sent from my iPhoneOn Oct 23, 2023, at 3:22 PM, rumbledethumps ***@***.***> wrote:
The SDK side is complete except maybe the name clock_gettimezone could be up for debate. Leave clock_gettimezone unimplemented on the RIA since the default of returning an error leaves the standard library at UTC and apps can later use the error to know if the RIA version supports timezones.
Everything in the SDK ended up as the thinnest possible implementation, just like all the other standard library calls, so this feels like the correct plan. I think you have everything worked out on the RIA side. Did you want to finish the coding or should I?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Here is the latest version. I think it is ready for a PR but I thought I should create another version for comment before: |
Beta Was this translation helpful? Give feedback.
-
I need another PR with BSD-3 licenses on the new files. Copypasta a header comment, add your name as a new line if you like. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, I'm working on the RTC for the kernel. I am sharing my plan here for comment.
rp6502 0.1+rtc1 release: https://github.com/brentward/rp6502/releases/tag/v0.1%2Brtc1
rp6502-sdk 0.1+rtc1 release: https://github.com/brentward/rp6502-sdk/releases/tag/v0.1%2Brtc1
This change includes a driver for the RTC and implementations of the POSIX clock functions in the SDK.
The purpose of the driver is to add kernel APIs for enabling/setting the RTC and getting the time from the RTC, and to implement the get_fattime() function that FatFs requires to add timestamps to the file system. The driver will not activate the RTC until a time is set and FatFs will use the current default values if the RTC is not set. The driver APIs accept and receive 32-bit timestamps so they can be passed in and out of the kernel with the AXSreg rather than manipulating the stack directly. The time is set on the RTC without including timezone information, so the time defaults to UTC.
The implementation of the POSIX functions ignores the clockid_t parameter, which is part of the prototype. I did this because the implementaion of
time_t __fastcall__ time (time_t* t)
that CC65 uses does not pass aclock_id
parameter intoget_time
(see https://github.com/cc65/cc65/blob/master/libsrc/common/time.s#L28). This causes calls totime()
to fail if the clock_id paramater is validated to matchCLOCK_REALTIME
; this is contrary to the documentation which says it should only succeed if it does matchCLOCK_REALTIME
. Because of this I chose to ignoreclock_id
in all of the POSIX clock prototypes.The API calls and the POSIX functions both use the
_mappederrno()
function to set theerrno
to standard POSIX error codes and set the_oserror
to new error codes specific to the RTC, which will indicate the RTC not being set and invalid datetime formats.I chose to not set a time zone on the RIA so the timestamps returned could be in UTC and a time zone can be set by updating the _tz variable that CC65 uses.
I would appreciate any feedback on the design. In particular I'd like feedback on the choice to ignore the clock_id, how the error responses should behave, how time zones are handled, and any ideas on a system for indicating that the RTC is waiting for a NTP response to set the time.
I've written some utilities that utilize the optimized calls, the POSIX wrappers to the calls, and the C time functions:
https://github.com/brentward/rp6502-rtc/releases/tag/v0.1 (use https://github.com/brentward/rp6502-sdk/releases/tag/v0.1%2Brtc1 for the SDK when building)
RTC Clock Driver
Typedefs
unsigned long time_t
Kernal API calls
API calls are setup to be similar to POSIX calls but are optimized to only require the axsreg rather than using the stack.
$14 clock_gettime_
int clock_gettime_(time_t* timep)
Reads the RTC and writes it as a timestamp to timep.
Parameters:
timep
: Destination for the returned time_t value.Returns: On success 0 is returned. On error -1 is returned and errno and oserror are set to indicate the error.
Errno:
EINVAL
Oserror:
RTC_NOT_SET
$15 clock_settime_
int clock_settime_(const time_t* timep)
Turns on the RTC if not already active and sets time to the timestamp in timep
Parameters:
timep
: Location of the timestamp used to set the RTC.Returns: On success 0 is returned. On error -1 is returned and errno and oserror are set to indicate the error.
ASX regs: timep
Errno:
EINVAL
Oserror:
RTC_INVALID_DATETIME
Kernel events
Typedefs
uint32_t DWORD
get_fattime
DWORD get_fattime (void)
The get_fattime function shall return any valid time even if the system does not support a real time clock. If a zero is returned, the file will not have a valid timestamp. If the RTC is not running it will return the default NORTC values.
Returns: Always returns a valid timestamp packed into DWORD
POSIX wrapper
Wrappers to standard POSIX calls are implemented to enable the ISO C time functions located in time.h.
clock_getres
int __fastcall__ clock_getres (clockid_t clock_id, struct timespec *res)
Determine the realtime clock resolution. As implemented it ignores clock_id. Currently a non 0 response is not possible.
Parameters:
*res
: Destination for the returned timespec value of the clock resolutionReturns: On success 0 is returned.
clock_gettime
int __fastcall__ clock_gettime (clockid_t clock_id, struct timespec *tp)
Get the time from the real time clock.
Parameters:
*tp
: Destination for the returned timespec value of the current time in RTCReturns: On success 0 is returned. On error -1 is returned and errno and oserror are set to indicate the error.
Errno:
EINVAL
Oserror:
RTC_NOT_SET
clock_settime
int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec *tp)
Set the time on the real time clock
Parameters:
*tp
: Source of the timespec containing the current time to set the RTCReturns: On success 0 is returned. On error -1 is returned and errno and oserror are set to indicate the error.
Errno:
EINVAL
Oserror:
RTC_INVALID_DATETIME
Beta Was this translation helpful? Give feedback.
All reactions