Skip to content

Commit 9fd6b4e

Browse files
Kamil Gawordoki-nordic
authored andcommitted
samples: esb: Clock control for nRF54h20
This adds support for clock control driver for nRF54h20 target in the ESB samples. Jira: NCSDK-28468 Signed-off-by: Kamil Gawor <[email protected]> Co-authored-by: Dominik Kilian <[email protected]>
1 parent 83b34cd commit 9fd6b4e

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

samples/esb/esb_prx/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
CONFIG_NCS_SAMPLES_DEFAULTS=y
77
CONFIG_ESB=y
88
CONFIG_DK_LIBRARY=y
9+
CONFIG_CLOCK_CONTROL=y

samples/esb/esb_prx/src/main.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
*/
66
#include <zephyr/device.h>
77
#include <zephyr/devicetree.h>
8-
#if defined(CONFIG_CLOCK_CONTROL_NRF)
98
#include <zephyr/drivers/clock_control.h>
109
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
11-
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
1210
#if defined(NRF54L15_XXAA)
1311
#include <hal/nrf_clock.h>
1412
#endif /* defined(NRF54L15_XXAA) */
@@ -20,6 +18,9 @@
2018
#include <zephyr/kernel.h>
2119
#include <zephyr/types.h>
2220
#include <dk_buttons_and_leds.h>
21+
#if defined(CONFIG_CLOCK_CONTROL_NRF2)
22+
#include <hal/nrf_lrcconf.h>
23+
#endif
2324

2425
LOG_MODULE_REGISTER(esb_prx, CONFIG_ESB_PRX_APP_LOG_LEVEL);
2526

@@ -104,7 +105,45 @@ int clocks_start(void)
104105
LOG_DBG("HF clock started");
105106
return 0;
106107
}
107-
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
108+
109+
#elif defined(CONFIG_CLOCK_CONTROL_NRF2)
110+
111+
int clocks_start(void)
112+
{
113+
int err;
114+
int res;
115+
const struct device *radio_clk_dev =
116+
DEVICE_DT_GET_OR_NULL(DT_CLOCKS_CTLR(DT_NODELABEL(radio)));
117+
struct onoff_client radio_cli;
118+
119+
/** Keep radio domain powered all the time to reduce latency. */
120+
nrf_lrcconf_poweron_force_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_DOMAIN_1, true);
121+
122+
sys_notify_init_spinwait(&radio_cli.notify);
123+
124+
err = nrf_clock_control_request(radio_clk_dev, NULL, &radio_cli);
125+
126+
do {
127+
err = sys_notify_fetch_result(&radio_cli.notify, &res);
128+
if (!err && res) {
129+
LOG_ERR("Clock could not be started: %d", res);
130+
return res;
131+
}
132+
} while (err == -EAGAIN);
133+
134+
#if defined(NRF54L15_XXAA)
135+
/* MLTPAN-20 */
136+
nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_PLLSTART);
137+
#endif /* defined(NRF54L15_XXAA) */
138+
139+
LOG_DBG("HF clock started");
140+
141+
return 0;
142+
}
143+
144+
#else
145+
BUILD_ASSERT(false, "No Clock Control driver");
146+
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF2) */
108147

109148
int esb_initialize(void)
110149
{
@@ -156,12 +195,10 @@ int main(void)
156195

157196
LOG_INF("Enhanced ShockBurst prx sample");
158197

159-
#if defined(CONFIG_CLOCK_CONTROL_NRF)
160198
err = clocks_start();
161199
if (err) {
162200
return 0;
163201
}
164-
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
165202

166203
err = dk_leds_init();
167204
if (err) {

samples/esb/esb_ptx/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
CONFIG_NCS_SAMPLES_DEFAULTS=y
77
CONFIG_ESB=y
88
CONFIG_DK_LIBRARY=y
9+
CONFIG_CLOCK_CONTROL=y

samples/esb/esb_ptx/src/main.c

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
*
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
6-
#if defined(CONFIG_CLOCK_CONTROL_NRF)
76
#include <zephyr/drivers/clock_control.h>
87
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
9-
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
108
#if defined(NRF54L15_XXAA)
119
#include <hal/nrf_clock.h>
1210
#endif /* defined(NRF54L15_XXAA) */
@@ -20,6 +18,9 @@
2018
#include <zephyr/kernel.h>
2119
#include <zephyr/types.h>
2220
#include <dk_buttons_and_leds.h>
21+
#if defined(CONFIG_CLOCK_CONTROL_NRF2)
22+
#include <hal/nrf_lrcconf.h>
23+
#endif
2324

2425
LOG_MODULE_REGISTER(esb_ptx, CONFIG_ESB_PTX_APP_LOG_LEVEL);
2526

@@ -97,7 +98,44 @@ int clocks_start(void)
9798
LOG_DBG("HF clock started");
9899
return 0;
99100
}
100-
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
101+
102+
#elif defined(CONFIG_CLOCK_CONTROL_NRF2)
103+
104+
int clocks_start(void)
105+
{
106+
int err;
107+
int res;
108+
const struct device *radio_clk_dev =
109+
DEVICE_DT_GET_OR_NULL(DT_CLOCKS_CTLR(DT_NODELABEL(radio)));
110+
struct onoff_client radio_cli;
111+
112+
/** Keep radio domain powered all the time to reduce latency. */
113+
nrf_lrcconf_poweron_force_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_DOMAIN_1, true);
114+
115+
sys_notify_init_spinwait(&radio_cli.notify);
116+
117+
err = nrf_clock_control_request(radio_clk_dev, NULL, &radio_cli);
118+
119+
do {
120+
err = sys_notify_fetch_result(&radio_cli.notify, &res);
121+
if (!err && res) {
122+
LOG_ERR("Clock could not be started: %d", res);
123+
return res;
124+
}
125+
} while (err == -EAGAIN);
126+
127+
#if defined(NRF54L15_XXAA)
128+
/* MLTPAN-20 */
129+
nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_PLLSTART);
130+
#endif /* defined(NRF54L15_XXAA) */
131+
132+
LOG_DBG("HF clock started");
133+
return 0;
134+
}
135+
136+
#else
137+
BUILD_ASSERT(false, "No Clock Control driver");
138+
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF2) */
101139

102140
int esb_initialize(void)
103141
{
@@ -162,12 +200,10 @@ int main(void)
162200

163201
LOG_INF("Enhanced ShockBurst ptx sample");
164202

165-
#if defined(CONFIG_CLOCK_CONTROL_NRF)
166203
err = clocks_start();
167204
if (err) {
168205
return 0;
169206
}
170-
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
171207

172208
err = dk_leds_init();
173209
if (err) {

0 commit comments

Comments
 (0)