Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,35 @@
#include <zephyr/kernel.h>
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
#include <nrf_sys_event.h>
#include <hal/nrf_egu.h>

static bool hfclk_is_running;
/**
* The implementation uses EGU to de-escalate execution context from ZLI to a regular interrupt
* to ensure that Zephyr APIs can be used safely.
*
* Both the nrf_802154_clock_hfclk_start() and nrf_802154_clock_hfclk_stop() can potentially be
* called from ZLI and non-ZLI contexts and consecutive calls are not guaranteed to be alternating.
*
* For example, it is possible that _stop() may be called multiple times in succession and the
* same thing applies to _start(). What is known however is that the last call always takes
* the precedence.
*/

#define NTF_INT NRFX_CONCAT_2(NRF_EGU_INT_TRIGGERED, NRF_802154_SL_EGU_CLOCK_CHANNEL_NO)
#define NTF_TASK NRFX_CONCAT_2(NRF_EGU_TASK_TRIGGER, NRF_802154_SL_EGU_CLOCK_CHANNEL_NO)
#define NTF_EVENT NRFX_CONCAT_2(NRF_EGU_EVENT_TRIGGERED, NRF_802154_SL_EGU_CLOCK_CHANNEL_NO)

Check notice on line 32 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:32 -#define NTF_INT NRFX_CONCAT_2(NRF_EGU_INT_TRIGGERED, NRF_802154_SL_EGU_CLOCK_CHANNEL_NO) -#define NTF_TASK NRFX_CONCAT_2(NRF_EGU_TASK_TRIGGER, NRF_802154_SL_EGU_CLOCK_CHANNEL_NO) +#define NTF_INT NRFX_CONCAT_2(NRF_EGU_INT_TRIGGERED, NRF_802154_SL_EGU_CLOCK_CHANNEL_NO) +#define NTF_TASK NRFX_CONCAT_2(NRF_EGU_TASK_TRIGGER, NRF_802154_SL_EGU_CLOCK_CHANNEL_NO)

#define CLOCK_NONE 0u
#define CLOCK_REQUEST 1u
#define CLOCK_RELEASE 2u

static bool hfclk_is_running = false;

Check failure on line 38 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

INITIALISED_STATIC

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:38 do not initialise statics to false
static bool enabled = false;

Check failure on line 39 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

INITIALISED_STATIC

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:39 do not initialise statics to false
static atomic_t request = CLOCK_NONE;

/* Forward declarations. */
static void hfclk_start(void);
static void hfclk_stop(void);

void nrf_802154_clock_init(void)
{
Expand All @@ -23,11 +50,13 @@

nrf_802154_clock_hfclk_latency_set(clock_latency_us);
#endif

nrf_egu_int_enable(NRF_802154_EGU_INSTANCE, NTF_INT);
}

void nrf_802154_clock_deinit(void)
{
/* Intentionally empty. */
nrf_egu_int_disable(NRF_802154_EGU_INSTANCE, NTF_INT);
}

bool nrf_802154_clock_hfclk_is_running(void)
Expand All @@ -47,8 +76,44 @@
nrf_802154_clock_hfclk_ready();
}

#if defined(CONFIG_CLOCK_CONTROL_NRF)
void nrf_802154_sl_clock_swi_irq_handler(void)
{
if (nrf_egu_event_check(NRF_802154_EGU_INSTANCE, NTF_EVENT))

Check warning on line 81 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BRACES

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:81 braces {} are required around if/while/for/else

Check failure on line 81 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

OPEN_BRACE

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:81 that open brace { should be on the previous line

Check warning on line 81 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:81 please, no spaces at the start of a line
{

Check warning on line 82 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:82 please, no spaces at the start of a line
nrf_egu_event_clear(NRF_802154_EGU_INSTANCE, NTF_EVENT);

Check warning on line 83 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:83 please, no spaces at the start of a line

Check failure on line 83 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:83 code indent should use tabs where possible

atomic_val_t previous = atomic_set(&request, CLOCK_NONE);

switch (previous) {

Check failure on line 87 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SWITCH_CASE_INDENT_LEVEL

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:87 switch and case should be at the same indent
case CLOCK_REQUEST:

Check notice on line 88 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:88 - if (nrf_egu_event_check(NRF_802154_EGU_INSTANCE, NTF_EVENT)) - { - nrf_egu_event_clear(NRF_802154_EGU_INSTANCE, NTF_EVENT); - - atomic_val_t previous = atomic_set(&request, CLOCK_NONE); - - switch (previous) { + if (nrf_egu_event_check(NRF_802154_EGU_INSTANCE, NTF_EVENT)) { + nrf_egu_event_clear(NRF_802154_EGU_INSTANCE, NTF_EVENT); + + atomic_val_t previous = atomic_set(&request, CLOCK_NONE); + + switch (previous) {
hfclk_start();
break;

case CLOCK_RELEASE:
hfclk_stop();
break;

default:
__ASSERT_NO_MSG(false);
break;
}
}

Check warning on line 100 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:100 please, no spaces at the start of a line
}

Check notice on line 101 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:101 - } - } + } + }

void nrf_802154_clock_hfclk_start(void)
{
atomic_set(&request, CLOCK_REQUEST);
nrf_egu_task_trigger(NRF_802154_EGU_INSTANCE, NTF_TASK);
}

void nrf_802154_clock_hfclk_stop(void)
{
atomic_set(&request, CLOCK_RELEASE);
nrf_egu_task_trigger(NRF_802154_EGU_INSTANCE, NTF_TASK);
}

#if defined(CONFIG_CLOCK_CONTROL_NRF)
static void hfclk_start(void)
{
struct onoff_manager *mgr =
z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
Expand All @@ -57,56 +122,88 @@

sys_notify_init_callback(&hfclk_cli.notify, hfclk_on_callback);

/*
* todo: replace constlat request with PM policy API when
* controlling the event latency becomes possible.
*/
if (IS_ENABLED(CONFIG_NRF_802154_CONSTLAT_CONTROL)) {
nrf_sys_event_request_global_constlat();
if (!enabled) {
unsigned int key = irq_lock();

/*
* todo: replace constlat request with PM policy API when

Check warning on line 129 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BLOCK_COMMENT_STYLE

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:129 Block comments should align the * on each line
* controlling the event latency becomes possible.
*/
if (IS_ENABLED(CONFIG_NRF_802154_CONSTLAT_CONTROL)) {

Check notice on line 132 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:132 - * todo: replace constlat request with PM policy API when - * controlling the event latency becomes possible. - */ + * todo: replace constlat request with PM policy API when + * controlling the event latency becomes possible. + */
nrf_sys_event_request_global_constlat();
}

int ret = onoff_request(mgr, &hfclk_cli);
__ASSERT_NO_MSG(ret >= 0);

Check warning on line 137 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LINE_SPACING

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:137 Missing a blank line after declarations
(void)ret;

irq_unlock(key);
}

int ret = onoff_request(mgr, &hfclk_cli);
__ASSERT_NO_MSG(ret >= 0);
(void)ret;
enabled = true;
}

void nrf_802154_clock_hfclk_stop(void)
static void hfclk_stop(void)
{
struct onoff_manager *mgr =
z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);

Check notice on line 150 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:150 - struct onoff_manager *mgr = - z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF); + struct onoff_manager *mgr = z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
__ASSERT_NO_MSG(mgr != NULL);

int ret = onoff_cancel_or_release(mgr, &hfclk_cli);
__ASSERT_NO_MSG(ret >= 0);
(void)ret;
if (enabled) {
unsigned int key = irq_lock();

int ret = onoff_cancel_or_release(mgr, &hfclk_cli);
__ASSERT_NO_MSG(ret >= 0);

Check warning on line 157 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LINE_SPACING

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:157 Missing a blank line after declarations
(void)ret;

if (IS_ENABLED(CONFIG_NRF_802154_CONSTLAT_CONTROL)) {
nrf_sys_event_release_global_constlat();
}

hfclk_is_running = false;

if (IS_ENABLED(CONFIG_NRF_802154_CONSTLAT_CONTROL)) {
nrf_sys_event_release_global_constlat();
irq_unlock(key);
}

hfclk_is_running = false;
enabled = false;
}

#elif DT_NODE_HAS_STATUS(DT_NODELABEL(hfxo), okay) && \
DT_NODE_HAS_COMPAT(DT_NODELABEL(hfxo), nordic_nrf54h_hfxo)

void nrf_802154_clock_hfclk_start(void)
static void hfclk_start(void)
{
sys_notify_init_callback(&hfclk_cli.notify, hfclk_on_callback);
int ret = nrf_clock_control_request(DEVICE_DT_GET(DT_NODELABEL(hfxo)), NULL, &hfclk_cli);
if (!enabled) {
unsigned int key = irq_lock();

sys_notify_init_callback(&hfclk_cli.notify, hfclk_on_callback);
int ret = nrf_clock_control_request(DEVICE_DT_GET(DT_NODELABEL(hfxo)), NULL, &hfclk_cli);

Check warning on line 181 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:181 line length of 105 exceeds 100 columns

Check notice on line 182 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:182 - int ret = nrf_clock_control_request(DEVICE_DT_GET(DT_NODELABEL(hfxo)), NULL, &hfclk_cli); + int ret = nrf_clock_control_request(DEVICE_DT_GET(DT_NODELABEL(hfxo)), NULL, + &hfclk_cli);
__ASSERT_NO_MSG(ret >= 0);
(void)ret;

irq_unlock(key);
}

__ASSERT_NO_MSG(ret >= 0);
(void)ret;
enabled = true;
}

void nrf_802154_clock_hfclk_stop(void)
static void hfclk_stop(void)
{
int ret = nrf_clock_control_cancel_or_release(DEVICE_DT_GET(DT_NODELABEL(hfxo)),
NULL, &hfclk_cli);
if (enabled) {
unsigned int key = irq_lock();

int ret = nrf_clock_control_cancel_or_release(DEVICE_DT_GET(DT_NODELABEL(hfxo)),
NULL, &hfclk_cli);

Check notice on line 199 in modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_clock_zephyr.c:199 - NULL, &hfclk_cli); + NULL, &hfclk_cli);
__ASSERT_NO_MSG(ret >= 0);
(void)ret;

irq_unlock(key);
}

__ASSERT_NO_MSG(ret >= 0);
(void)ret;
enabled = false;
}

#endif
Loading