Skip to content

Conversation

@nordic-krch
Copy link
Contributor

@nordic-krch nordic-krch commented Jul 3, 2019

Clock_control has been re-implemented to support new clock control API and calibration algorithm which optionally uses temperature sensor and skips calibration on no temperature change.

  • Added new API implementation
  • Added calibration algorithm (calibration support extracted to separate file)
  • Added test suite
  • Updated usage of clock _control API in nordic drivers, removed hacky usage of subsys parameter.

Fixes #12114

@nordic-krch nordic-krch requested review from anangl and cvinayak July 3, 2019 08:28
@zephyrbot zephyrbot added area: Sensors Sensors area: Counter area: Timer Timer area: Bluetooth area: API Changes to public APIs area: Tests Issues related to a particular existing or missing test EXT Has change or related to ext/ (obsolete) labels Jul 3, 2019
@zephyrbot
Copy link

zephyrbot commented Jul 3, 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.

@aescolar aescolar self-requested a review July 3, 2019 08:33
@nordic-krch nordic-krch force-pushed the clock_control_calibration branch 2 times, most recently from 9026473 to e320b09 Compare July 3, 2019 08:56
@aescolar aescolar requested a review from ioannisg July 3, 2019 09:19
@nordic-krch nordic-krch force-pushed the clock_control_calibration branch 3 times, most recently from 604cbae to 8de2f92 Compare July 3, 2019 11:22
Copy link
Member

@anangl anangl left a comment

Choose a reason for hiding this comment

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

Just some initial comments. I'll need some more time to dive into nrf_power_clock.c.

Copy link
Member

Choose a reason for hiding this comment

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

missing CONFIG_ before TEMP_NRF5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

  • static missing
  • you should use K_WORK_DEFINE for this initialization
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to involve floats here? The sensor's resolution is 0.25 °C, so multiplying by 4 should be sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to work in 0,25 degree units. Also modified kconfig option to use same units which allows to chose fractional temperature diff that will trigger calibration.

Copy link
Member

Choose a reason for hiding this comment

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

k_work_submit(&temp_measure_work);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

NULL, just for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

0 -> NULL, for consistency, same below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

static missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

NRF_POWER_HAS_POFCON is defined in <nrf_power.h>, which may not have been included yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now nrf_power.h is always included.

Copy link
Member

Choose a reason for hiding this comment

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

I guess it would be better to place this initial | after NRF_CLOCK_INT_LF_STARTED_MASK above and use (0) as the "else" part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

Why is it defined as atomic_t when atomic API is not used for this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to s32_t

@aescolar
Copy link
Member

aescolar commented Jul 3, 2019

@nordic-krch In https://github.com/aescolar/zephyr/tree/clock_control_calibration_fix you have this branch with a couple of updates for simulation and rebased on top of #17301 . With it the nrf52_bsim works nicely

@nordic-krch nordic-krch force-pushed the clock_control_calibration branch from 8de2f92 to 4dc534d Compare July 4, 2019 06:11
@nordic-krch
Copy link
Contributor Author

It's been out for 3 months. There are 3 approvals. @carlescufi @ioannisg can we merge this then unless someone plans to review it soon?

@aescolar aescolar removed the request for review from thoh-ot October 3, 2019 09:36
@aescolar
Copy link
Member

aescolar commented Oct 3, 2019

For the record, I have no issue with this PR. The only file changed I own is perfectly fine. But as this is a Nordic only change, I do not believe I should approve it. I presume BT and USB maintainers would have a similar feeling as the BT and USB code changes are minor and circumstantial.

@ioannisg ioannisg requested a review from pabigot October 3, 2019 09:56
@ioannisg
Copy link
Member

ioannisg commented Oct 3, 2019

It's been out for 3 months. There are 3 approvals. @carlescufi @ioannisg can we merge this then unless someone plans to review it soon?

I would appreciate if @pabigot could re-review once more (and approve if possible). I guess we can merge this afterwards ;)

Copy link
Contributor

@pabigot pabigot left a comment

Choose a reason for hiding this comment

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

My comments appear to have been addressed. I haven't tested this or done an in-depth functional review so don't feel comfortable "approving" it, but I don't see any reason it should be kept out.

@martintv
Copy link
Contributor

martintv commented Oct 3, 2019

I haven't looked much at the code, this switch to zephyr is all new to me, so I am still confused. So so this is more a question than a suggestion. After this PR we will still use the Calibration timer in the NRF_CLOCK peripheral right? how easy would it be to switch to using some other source for the periodic timer to drive the calibration state machine in zephyr world? we always wanted to do that in SoftDevice, but never did. The calibration timer in in NRF_CLOCK has some big awkward weaknesses, since some register can not be written withing the same 32khz clock cycle as some things happens. Another reason to stop using the calibration timer, is that we want to remove it from the chip, to save silicon, if sw could do without it.

@nordic-krch
Copy link
Contributor Author

@martintv i don't see any obstacles. In the next step we can replace calibration timer with k_timer.

@nordic-krch
Copy link
Contributor Author

@ioannisg see @pabigot comment. What then blocks as from merging it?

@ioannisg
Copy link
Member

ioannisg commented Oct 4, 2019

@ioannisg see @pabigot comment. What then blocks as from merging it?

Your description is still blocking this PR @nordic-krch.
#17301 is not reviewed/merged. Please, advice

@nordic-krch
Copy link
Contributor Author

@ioannisg i've updated description as this is no longer true. I don't use functionality which #17301 attempted to add.

@ioannisg
Copy link
Member

ioannisg commented Oct 4, 2019

@ioannisg i've updated description as this is no longer true. I don't use functionality which #17301 attempted to add.

OK, great, now this PR is not blocked-by-definition ;)
Could you rebase and run CI (PR hasn't been rebased for ~10 days, AFAICS)

The incomming new NRF clock driver requires extra nrf HAL and drivers functions, which are only supported in the HW models after version 1.8 Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
@nordic-krch nordic-krch force-pushed the clock_control_calibration branch from 1735cec to 364818b Compare October 4, 2019 10:29
@nordic-krch
Copy link
Contributor Author

@ioannisg, done.

Copy link
Member

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

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

I tested the following:

  • central_hr on nRF51 DK
  • peripheral (complete with bonding and reconnection) on nRF51 DK
  • central_hr on BBC micro:bit
  • peripheral_hr on BBC micro:bit
@joerchan
Copy link
Contributor

joerchan commented Oct 4, 2019

There is by default a lot of info lines being printed. Can we change the settings so that that doesn't happen?

[00:10:10.496,673] <inf> clock_control: CLOCK_16M: callback [00:10:10.496,704] <inf> clock_control: CLOCK_16M: node 0x0000000 

Tested connections using 2 nrf52840. and 500 PPM, works fine.

@carlescufi
Copy link
Member

There is by default a lot of info lines being printed. Can we change the settings so that that doesn't happen?

[00:10:10.496,673] <inf> clock_control: CLOCK_16M: callback [00:10:10.496,704] <inf> clock_control: CLOCK_16M: node 0x0000000 

Tested connections using 2 nrf52840. and 500 PPM, works fine.

I saw that as well, I assumed this was my config but now that @joerchan also brings it up I think this is worth cleaning up. @nordic-krch could you please disable those by default?

Reimplementation of clock control driver for nrf platform. It includes latest API changes: asynchronous starting and getting clock status. Additionally, it implements calibration algorithm which optionally skips calibration based on no temperature change. Internal temperature sensor is used for that. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added test suite for clock control driver. It covers latest API update for starting clock asynchronously and getting status. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added test for LF clock calibration when RC source is used. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Align to use clock_control_get_status for blocking clock start. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Align drivers to use new clock control API. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Test for bbc_microbit was failing due to RAM usage. Reduced main stack size and turned off temperature algorithm to fit. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
@nordic-krch nordic-krch force-pushed the clock_control_calibration branch from 364818b to 7b6754d Compare October 4, 2019 12:33
@nordic-krch
Copy link
Contributor Author

@carlescufi @joerchan removed those log calls.

@carlescufi I've reduced irq locking time. Additionally, i did measurement to check longest locking time in clock driver vs other lockings (used peripheral_hr sample for that). Clock locking is up to 1.4us while there are many many more longer lockings (up to 2.5ms which seems very odd). In general locking in clock is one of the shortest.

@carlescufi
Copy link
Member

@carlescufi @joerchan removed those log calls.

@carlescufi I've reduced irq locking time. Additionally, i did measurement to check longest locking time in clock driver vs other lockings (used peripheral_hr sample for that). Clock locking is up to 1.4us while there are many many more longer lockings (up to 2.5ms which seems very odd). In general locking in clock is one of the shortest.

Thank you @nordic-krch. I will merge this as soon as CI passes.

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: Bluetooth area: Boards area: Counter area: Sensors Sensors area: Tests Issues related to a particular existing or missing test area: Timer Timer Blocked Blocked by another PR or issue EXT Has change or related to ext/ (obsolete)

10 participants