ec3c3f153b
This commit introduces a common API for managing nRF53 SoC network CPU Force-OFF state. From the application CPU point of view, the network CPU is a shared resource used by multiple users. The current solution where every user controls the network core state directly leads to dependencies between users and does not scale well. To address this problem there should be a single entity responsible for controlling the network CPU Force-OFF signal. This commit introduces such module. Signed-off-by: Jędrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
69 lines
1.4 KiB
C
69 lines
1.4 KiB
C
/*
|
|
* Copyright (c) 2024 Nordic Semiconductor ASA
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @file Nordic Semiconductor nRF53 processors family management helper for the network CPU.
|
|
*/
|
|
|
|
#include <nrf53_cpunet_mgmt.h>
|
|
|
|
#include <zephyr/kernel.h>
|
|
#include <zephyr/init.h>
|
|
#include <zephyr/sys/__assert.h>
|
|
#include <zephyr/sys/notify.h>
|
|
#include <zephyr/sys/onoff.h>
|
|
|
|
#include <hal/nrf_reset.h>
|
|
|
|
static struct onoff_manager cpunet_mgr;
|
|
|
|
static void onoff_start(struct onoff_manager *mgr, onoff_notify_fn notify)
|
|
{
|
|
nrf_reset_network_force_off(NRF_RESET, false);
|
|
|
|
notify(mgr, 0);
|
|
}
|
|
|
|
static void onoff_stop(struct onoff_manager *mgr, onoff_notify_fn notify)
|
|
{
|
|
nrf_reset_network_force_off(NRF_RESET, true);
|
|
|
|
notify(mgr, 0);
|
|
}
|
|
|
|
static int nrf53_cpunet_mgmt_init(void)
|
|
{
|
|
static const struct onoff_transitions transitions = {
|
|
.start = onoff_start,
|
|
.stop = onoff_stop
|
|
};
|
|
|
|
return onoff_manager_init(&cpunet_mgr, &transitions);
|
|
}
|
|
|
|
SYS_INIT(nrf53_cpunet_mgmt_init, PRE_KERNEL_1, 0);
|
|
|
|
void nrf53_cpunet_enable(bool on)
|
|
{
|
|
int ret;
|
|
int ignored;
|
|
struct onoff_client cli;
|
|
|
|
if (on) {
|
|
sys_notify_init_spinwait(&cli.notify);
|
|
|
|
ret = onoff_request(&cpunet_mgr, &cli);
|
|
__ASSERT_NO_MSG(ret >= 0);
|
|
|
|
/* The transition is synchronous and shall take effect immediately. */
|
|
ret = sys_notify_fetch_result(&cli.notify, &ignored);
|
|
} else {
|
|
ret = onoff_release(&cpunet_mgr);
|
|
}
|
|
|
|
__ASSERT_NO_MSG(ret >= 0);
|
|
}
|