Skip to content

Conversation

@pabigot
Copy link
Contributor

@pabigot pabigot commented Jul 17, 2019

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/rtc directory, and the extension functions are named based on it being a specialization of a (no longer existing) rtc driver 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_syncpoint structure 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.

@zephyrbot
Copy link

zephyrbot commented Jul 17, 2019

All checks are passing now.

Review history of this comment for details about previous failed status.
Note that some checks might have not completed yet.

Copy link
Contributor

@dbkinder dbkinder left a 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 :)

Copy link
Contributor

@dbkinder dbkinder left a 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?

Copy link
Contributor

@dbkinder dbkinder left a 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.

@carlescufi carlescufi requested a review from anangl July 25, 2019 15:35
@carlescufi
Copy link
Member

@anangl could you please take a look at the proposed API extension mechanism?

@pabigot pabigot added the dev-review To be discussed in dev-review meeting label Jul 31, 2019
@pabigot
Copy link
Contributor Author

pabigot commented Jul 31, 2019

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?

@galak galak added the TSC Topics that need TSC discussion label Aug 1, 2019
@pabigot pabigot added the DNM This PR should not be merged (Do Not Merge) label Apr 20, 2020
@pabigot pabigot force-pushed the pr/20190717a branch 2 times, most recently from 4cd6079 to 53e153e Compare April 24, 2020 13:43
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Apr 24, 2020
@pabigot pabigot force-pushed the pr/20190717a branch 3 times, most recently from 153bdc8 to 0f25c1c Compare April 24, 2020 21:16
@pabigot pabigot removed the DNM This PR should not be merged (Do Not Merge) label Apr 24, 2020
@pabigot pabigot added this to the v2.3.0 milestone Apr 25, 2020
@pabigot
Copy link
Contributor Author

pabigot commented Apr 25, 2020

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 rtc_ds3231_{req,get}_syncpoint() API in whatever we use for RTC extensions.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is unusual.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@carlescufi
Copy link
Member

@henrikbrixandersen and @jdascenzio could you please review, especially in the context of the work for #23526

pabigot added 2 commits April 30, 2020 08:53
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>
@pabigot
Copy link
Contributor Author

pabigot commented Apr 30, 2020

Rebased and all public symbols renamed from rtc_ds3231_ to maxim_ds3231_ in anticipation of possible dedicated RTC API.

* @param user_data the corresponding parameter from
* maxim_ds3231_alarm::user_data.
*/
typedef void (*maxim_ds3231_alarm_callback_handler_t)(struct device *dev,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

@henrikbrixandersen henrikbrixandersen left a 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
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@carlescufi
Copy link
Member

@nordic-krch would you mind approving this if you have no objections?

@carlescufi
Copy link
Member

@jfischer-phytec-iot @sslupsky @nordic-krch please approve if you are fine with this PR as-is.

@carlescufi
Copy link
Member

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.

@carlescufi carlescufi merged commit e697656 into zephyrproject-rtos:master May 7, 2020
@pabigot pabigot deleted the pr/20190717a branch May 13, 2020 18:51
@cederom
Copy link

cederom commented May 20, 2021

This is a nice starting point thank you but also requires external chip. I have created a feature request here: #35333 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: API Changes to public APIs area: Counter area: Devicetree Binding PR modifies or adds a Device Tree binding area: Devicetree area: Documentation area: Drivers area: Samples Samples area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.