Skip to content

Commit 4f8c7a6

Browse files
piotrkoziarrlubos
authored andcommitted
[nrf fromlist] modules: hal_nordic: implement hfclk start/stop for cases when clock_control is not available.
Upstream PR: zephyrproject-rtos/zephyr#73156 Clock_control is currently not supported on nRF54H20. This commit adds new way of handling the hfclk targeted for nRF54H20. This solution shall be replaced once the clock_control is supported for nRF54H20. Signed-off-by: Piotr Koziar <piotr.koziar@nordicsemi.no>
1 parent 61b8c9b commit 4f8c7a6

File tree

1 file changed

+39
-41
lines changed

1 file changed

+39
-41
lines changed

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <nrf_802154_config.h>
78
#include <platform/nrf_802154_clock.h>
89

910
#include <stddef.h>
1011

1112
#include <compiler_abstraction.h>
13+
#include <zephyr/kernel.h>
14+
#if defined(CONFIG_CLOCK_CONTROL_NRF)
1215
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
1316
#include <zephyr/drivers/clock_control.h>
17+
#elif !defined(NRF54H_SERIES)
18+
#error No implementation to start or stop HFCLK due to missing clock_control.
19+
#endif
1420

1521
static bool hfclk_is_running;
16-
static bool lfclk_is_running;
17-
static struct onoff_client hfclk_cli;
18-
static struct onoff_client lfclk_cli;
1922

2023
void nrf_802154_clock_init(void)
2124
{
@@ -27,6 +30,15 @@ void nrf_802154_clock_deinit(void)
2730
/* Intentionally empty. */
2831
}
2932

33+
bool nrf_802154_clock_hfclk_is_running(void)
34+
{
35+
return hfclk_is_running;
36+
}
37+
38+
#if defined(CONFIG_CLOCK_CONTROL_NRF)
39+
40+
static struct onoff_client hfclk_cli;
41+
3042
static void hfclk_on_callback(struct onoff_manager *mgr,
3143
struct onoff_client *cli,
3244
uint32_t state,
@@ -63,53 +75,39 @@ void nrf_802154_clock_hfclk_stop(void)
6375
hfclk_is_running = false;
6476
}
6577

66-
bool nrf_802154_clock_hfclk_is_running(void)
67-
{
68-
return hfclk_is_running;
69-
}
78+
#elif defined(NRF54H_SERIES)
7079

71-
static void lfclk_on_callback(struct onoff_manager *mgr,
72-
struct onoff_client *cli,
73-
uint32_t state,
74-
int res)
75-
{
76-
lfclk_is_running = true;
77-
nrf_802154_clock_lfclk_ready();
78-
}
80+
#define NRF_LRCCONF_RADIO_PD NRF_LRCCONF010
81+
#define MAX_HFXO_RAMP_UP_TIME_US 1000
7982

80-
void nrf_802154_clock_lfclk_start(void)
83+
static void hfclk_started_timer_handler(struct k_timer *dummy)
8184
{
82-
int ret;
83-
struct onoff_manager *mgr =
84-
z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_LF);
85-
86-
__ASSERT_NO_MSG(mgr != NULL);
87-
88-
sys_notify_init_callback(&lfclk_cli.notify, lfclk_on_callback);
89-
90-
ret = onoff_request(mgr, &lfclk_cli);
91-
__ASSERT_NO_MSG(ret >= 0);
85+
hfclk_is_running = true;
86+
nrf_802154_clock_hfclk_ready();
9287
}
9388

94-
void nrf_802154_clock_lfclk_stop(void)
95-
{
96-
int ret;
97-
struct onoff_manager *mgr =
98-
z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_LF);
89+
K_TIMER_DEFINE(hfclk_started_timer, hfclk_started_timer_handler, NULL);
9990

100-
__ASSERT_NO_MSG(mgr != NULL);
91+
void nrf_802154_clock_hfclk_start(void)
92+
{
93+
/* Use register directly, there is no support for that task in nrf_lrcconf_task_trigger.
94+
* This code might cause troubles if there are other HFXO users in this CPU.
95+
*/
96+
NRF_LRCCONF_RADIO_PD->EVENTS_HFXOSTARTED = 0x0;
97+
NRF_LRCCONF_RADIO_PD->TASKS_REQHFXO = 0x1;
10198

102-
ret = onoff_cancel_or_release(mgr, &lfclk_cli);
103-
__ASSERT_NO_MSG(ret >= 0);
104-
lfclk_is_running = false;
99+
k_timer_start(&hfclk_started_timer, K_USEC(MAX_HFXO_RAMP_UP_TIME_US), K_NO_WAIT);
105100
}
106101

107-
bool nrf_802154_clock_lfclk_is_running(void)
102+
void nrf_802154_clock_hfclk_stop(void)
108103
{
109-
return lfclk_is_running;
110-
}
104+
/* Use register directly, there is no support for that task in nrf_lrcconf_task_trigger.
105+
* This code might cause troubles if there are other HFXO users in this CPU.
106+
*/
107+
NRF_LRCCONF_RADIO_PD->TASKS_STOPREQHFXO = 0x1;
108+
NRF_LRCCONF_RADIO_PD->EVENTS_HFXOSTARTED = 0x0;
111109

112-
__WEAK void nrf_802154_clock_lfclk_ready(void)
113-
{
114-
/* Intentionally empty. */
110+
hfclk_is_running = false;
115111
}
112+
113+
#endif

0 commit comments

Comments
 (0)