You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by "m-gorecki (via GitHub)" <gi...@apache.org> on 2023/05/11 14:28:23 UTC
[GitHub] [mynewt-core] m-gorecki opened a new pull request, #2993: nrf53: Add APIs to change Low Frequency Clock source in the runtime
m-gorecki opened a new pull request, #2993:
URL: https://github.com/apache/mynewt-core/pull/2993
This adds the same API for appcore and netcore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [mynewt-core] andrzej-kaczmarek commented on a diff in pull request #2993: nrf53: Add APIs to change Low Frequency Clock source in the runtime
Posted by "andrzej-kaczmarek (via GitHub)" <gi...@apache.org>.
andrzej-kaczmarek commented on code in PR #2993:
URL: https://github.com/apache/mynewt-core/pull/2993#discussion_r1191739523
##########
hw/mcu/nordic/nrf5340_net/src/nrf5340_net_clock.c:
##########
@@ -75,3 +75,64 @@ nrf5340_net_clock_hfxo_release(void)
return stopped;
}
+
+/**
+ * Request low frequency clock source change.
+ *
+ * @return int 0: clock source was already as requested. 1: clock source
+ * changed.
+ */
+int
+nrf5340_net_set_lf_clock_source(uint32_t clksrc)
+{
+ uint32_t regmsk;
+ uint32_t regval;
+
+ regmsk = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Msk;
+ regval = CLOCK_LFCLKSTAT_STATE_Running << CLOCK_LFCLKSTAT_STATE_Pos;
+
+ regval |= clksrc << CLOCK_LFCLKSTAT_SRC_Pos;
+
+ /* Check if this clock source isn't already running */
+ if ((NRF_CLOCK_NS->LFCLKSTAT & regmsk) == regval) {
+ return 0;
+ }
+
+ /*
+ * Request HFXO if LFSYNTH is going to be set as source. If LFSYNTH is going to be
+ * replaced with other source, release HFXO.
+ */
+ if (clksrc == CLOCK_LFCLKSTAT_SRC_LFSYNT) {
+ if ((NRF_CLOCK_NS->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk) !=
+ (CLOCK_HFCLKSTAT_STATE_Running << CLOCK_HFCLKSTAT_STATE_Pos)) {
+ NRF_CLOCK_NS->EVENTS_HFCLKSTARTED = 0;
+ nrf5340_net_clock_hfxo_request();
+ while (1) {
Review Comment:
```
while (!NRF_CLOCK_NS->EVENTS_HFCLKSTARTED) {
}
```
##########
hw/mcu/nordic/nrf5340_net/src/nrf5340_net_clock.c:
##########
@@ -75,3 +75,64 @@ nrf5340_net_clock_hfxo_release(void)
return stopped;
}
+
+/**
+ * Request low frequency clock source change.
+ *
+ * @return int 0: clock source was already as requested. 1: clock source
+ * changed.
+ */
+int
+nrf5340_net_set_lf_clock_source(uint32_t clksrc)
+{
+ uint32_t regmsk;
+ uint32_t regval;
+
+ regmsk = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Msk;
+ regval = CLOCK_LFCLKSTAT_STATE_Running << CLOCK_LFCLKSTAT_STATE_Pos;
+
+ regval |= clksrc << CLOCK_LFCLKSTAT_SRC_Pos;
+
+ /* Check if this clock source isn't already running */
+ if ((NRF_CLOCK_NS->LFCLKSTAT & regmsk) == regval) {
+ return 0;
+ }
+
+ /*
+ * Request HFXO if LFSYNTH is going to be set as source. If LFSYNTH is going to be
+ * replaced with other source, release HFXO.
+ */
+ if (clksrc == CLOCK_LFCLKSTAT_SRC_LFSYNT) {
+ if ((NRF_CLOCK_NS->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk) !=
+ (CLOCK_HFCLKSTAT_STATE_Running << CLOCK_HFCLKSTAT_STATE_Pos)) {
+ NRF_CLOCK_NS->EVENTS_HFCLKSTARTED = 0;
+ nrf5340_net_clock_hfxo_request();
+ while (1) {
+ if ((NRF_CLOCK_NS->EVENTS_HFCLKSTARTED) != 0) {
+ break;
+ }
+ }
+ } else {
+ nrf5340_net_clock_hfxo_request();
+ }
+ } else if ((NRF_CLOCK_NS->LFCLKSTAT & CLOCK_LFCLKSTAT_SRC_Msk) ==
Review Comment:
`LFCLKSRC` can be used instead of masking
##########
hw/mcu/nordic/nrf5340_net/src/nrf5340_net_clock.c:
##########
@@ -75,3 +75,64 @@ nrf5340_net_clock_hfxo_release(void)
return stopped;
}
+
+/**
+ * Request low frequency clock source change.
+ *
+ * @return int 0: clock source was already as requested. 1: clock source
+ * changed.
+ */
+int
+nrf5340_net_set_lf_clock_source(uint32_t clksrc)
+{
+ uint32_t regmsk;
+ uint32_t regval;
+
+ regmsk = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Msk;
+ regval = CLOCK_LFCLKSTAT_STATE_Running << CLOCK_LFCLKSTAT_STATE_Pos;
+
+ regval |= clksrc << CLOCK_LFCLKSTAT_SRC_Pos;
+
+ /* Check if this clock source isn't already running */
+ if ((NRF_CLOCK_NS->LFCLKSTAT & regmsk) == regval) {
+ return 0;
+ }
+
+ /*
+ * Request HFXO if LFSYNTH is going to be set as source. If LFSYNTH is going to be
+ * replaced with other source, release HFXO.
+ */
+ if (clksrc == CLOCK_LFCLKSTAT_SRC_LFSYNT) {
+ if ((NRF_CLOCK_NS->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk) !=
+ (CLOCK_HFCLKSTAT_STATE_Running << CLOCK_HFCLKSTAT_STATE_Pos)) {
+ NRF_CLOCK_NS->EVENTS_HFCLKSTARTED = 0;
+ nrf5340_net_clock_hfxo_request();
+ while (1) {
+ if ((NRF_CLOCK_NS->EVENTS_HFCLKSTARTED) != 0) {
+ break;
+ }
+ }
+ } else {
+ nrf5340_net_clock_hfxo_request();
+ }
+ } else if ((NRF_CLOCK_NS->LFCLKSTAT & CLOCK_LFCLKSTAT_SRC_Msk) ==
+ CLOCK_LFCLKSTAT_SRC_LFSYNT) {
+ nrf5340_net_clock_hfxo_release();
+ }
+
+ NRF_CLOCK_NS->TASKS_LFCLKSTOP = 1;
+ NRF_CLOCK_NS->EVENTS_LFCLKSTARTED = 0;
+ NRF_CLOCK_NS->LFCLKSRC = clksrc;
+ NRF_CLOCK_NS->TASKS_LFCLKSTART = 1;
Review Comment:
lfclk source can be changes without restarting lfclk:
`The LFCLK source can be configured at any time (for instance, when the LFCLK has already been started). The content of the LFCLKSRC register only takes effect when the LFCLKSTART task is triggered.`
so we can only start lfclk once on system startup, then this API can change source at any time only taking care of hfxo when switching to/from lfsynth
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] nrf53: Add APIs to change Low Frequency Clock source in the runtime [mynewt-core]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #2993:
URL: https://github.com/apache/mynewt-core/pull/2993#issuecomment-6325186907
This pull request had no activity for 12 months and is marked as stale. If it is still valid, please rebase it on current base branch. Stale pull requests are not closed automatically, the label is removed on any update or comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org