-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: counter: add Maxim DS3231 support #17631
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
Conversation
|
All checks are passing now. Review history of this comment for details about previous failed status. |
dbkinder
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh. OK for now. I'll add checking for overviews for the API docs to the bin list :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc build is failing because there's no visible option for CONFIG_APP_SET_ALIGNED_CLOCK defined in the Kconfig tree?
dbkinder
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for doc changes, thanks.
|
@anangl could you please take a look at the proposed API extension mechanism? |
|
Added to dev-review in hopes of getting feedback on this specifically, and device-specific APIs in general. TSC mention and posting on devel didn't produce much/anything. Base question: can this make it into 2.0.0? |
4cd6079 to
53e153e
Compare
153bdc8 to
0f25c1c
Compare
|
This has been rebased and updated with proper locking and usermode support for the extended sync functions and the underlying counter API. I would like to see something like the Please provide feedback, particularly @jdascenzio @henrikbrixandersen @sslupsky who have expressed interest in RTC. I would like to get this in to 2.3, rather than attempt to beat @nordic-krch 's record of 367 days from PR open to merge. |
|
|
||
| /* Flags recording requests for ISW monitoring. */ | ||
| u8_t isw_mon_req; | ||
| #define ISW_MON_REQ_Alarm 0x01 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is unusual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean mixed case? I suppose, though it's standard for some roles (e.g. CMSIS-style bitfield values), and is also present internally Zephyr's time_utils.h where the units suffix is (correctly) in lower case.
If it really bothers people I'll uglify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to define a macro in middle of a struct.
|
@henrikbrixandersen and @jdascenzio could you please review, especially in the context of the work for #23526 |
The DS3231 is an I2C real-time clock with internal temperature compensated oscillator, maintaining civil time to 1 s precision with nominal 2 ppm accuracy from 0-40 Cel. The basic functionality is exposed as a counter that is always running at 1 Hz. Much more functionality is exposed as driver-specific API, including the ability to translate between the time scale of the DS3231 and the time scale of the Zephyr uptime clock. This allows correlation of events in the system clock to UTC, TAI, or whatever time scale is used to maintain the DS3231. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Cloned from counter_basic_api with modifications based on DS3231 limitations: * Only one device tested per board; * Counter cannot be stopped or started; * Alarms are serviced by worker thread, so are not invoked from ISR and require that test thread yield to allow processing (no k_busy_wait()); * Multiple Alarms test is disabled as documented in test. Additional tests were added for DS3231-specific API. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
|
Rebased and all public symbols renamed from |
| * @param user_data the corresponding parameter from | ||
| * maxim_ds3231_alarm::user_data. | ||
| */ | ||
| typedef void (*maxim_ds3231_alarm_callback_handler_t)(struct device *dev, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxim_ds3231_alarm_callback_handler_t is to long, please use shorter names, here ds3231_alarm_cb_handler is fine.
Overall just ds3231/DS3231 instead of maxim_ds3231/MAXIM_DS3231 would be sufficient.
Why not generally abbreviate callback with cb if the prefix give the only feasible interpretation like ds3231_notify_cb?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I started with ds3231_ as the prefix, and that has prior art in tree for (e.g.) ccs811_, Zephyr has not carefully managed namespaces and I don't want to assume that there will never be conflicts between device model numbers across vendors. Standardizing on the compatible name makes sense. The negative impact is small, only affecting those who are using the custom API.
This proposed policy is something we should discuss more widely. So: #24978
callback is unambiguous while cb is only clear in context with interpretation. IMO the biggest problem with long-but-clear names is a consequence of 8-space indentation with a 78 character line limit. I have no reason to believe the shorter version ever directly improves comprehension, and some reason to believe it makes it worse (increased cognitive load from requiring an interpretation at all).
I'm seeing 44 foo_callback_t typedefs, and 96 foo_cb_t typedefs, in Zephyr today.
Not to say I won't change it if people insist, but that's why I picked the names that I did.
henrikbrixandersen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have mainly reviewed the DS3231 specific API extensions. Looks good!
I think we should get this merged. Once we have more RTC drivers in-tree, we can look at extending the counter API in a generic fashion or even defining a new, RTC specific API.
| pwm.rst | ||
| ps2.rst | ||
| peci.rst | ||
| rtc.rst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include this? Or rather wait until we have an API to document?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for the driver-specific extensions ends up here. It does state that it's a placeholder.
| tests: | ||
| sample.basic.maxim_ds3231: | ||
| build_only: true | ||
| platform_whitelist: efr32mg_sltb004a frdm_k64f nrf51_pca10028 nucleo_l476rg particle_xenon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to provide a generic DS3231 shield definition utilising standard connectors such as Arduino instead of the many, board specific overlays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ChronoDot isn't physically compatible with Arduino headers, and at least two boards that are supported don't have them either. So I'm reluctant to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should get this merged. Once we have more RTC drivers in-tree, we can look at extending the counter API in a generic fashion or even defining a new, RTC specific API.
There are a few drivers in the tree already. Many of the existing SOC's have RTC devices on-chip. Zephyr is using them for the system timer (as opposed to a counter). So, in this regard, I think it is quite important to advance the discussion of an RTC api before it becomes a terrible mess to fix in the future.
|
@nordic-krch would you mind approving this if you have no objections? |
|
@jfischer-phytec-iot @sslupsky @nordic-krch please approve if you are fine with this PR as-is. |
|
Merging this since it's been open for far too long. If you have additional comments please voice them to @pabigot and they can go in as bug fixes during the 2.3 stabilization period. |
|
This is a nice starting point thank you but also requires external chip. I have created a feature request here: #35333 :-) |
This PR provides support for the Maxim DS3231 TCXO RTC, a high-precision real-time clock peripheral with support for battery backup.
This is implemented as a counter, but the DS3231 has significant functionality enhancements beyond a general RTC API. Also, as an I2C peripheral it has limitations that are incompatible with assumptions about how a counter can function. Most users of its advanced functionality will interact with it through device specific API provided in a driver-specific header following the approach summarized in #17072. Consequently the interface file is placed in the (existing)
include/drivers/rtcdirectory, and the extension functions are named based on it being a specialization of a (no longer existing)rtcdriver class.There is a question of where to collect the documentation. Because it's device specific, it really should be its own page at API Reference : Peripherals : RTC : DS3231. For now I've just put it under (newly created) RTC.
As more infrastructure is added to support management of civil time tracking in Zephyr some of the functionality in this driver may need to be generalized. For example, the
rtc_ds3231_syncpointstructure should probably be generalized and placed in the recently created<sys/timeutil.h>header long with functions that support generic conversion from a synchronization point and local time to RTC and back.