Skip to content

Commit 48c66c2

Browse files
committed
wip: soft off bringup ironside
Temp changes added grtc channel disable to avoid wakeups when going to soft off Signed-off-by: Łukasz Stępnicki <[email protected]>
1 parent 477aa35 commit 48c66c2

File tree

8 files changed

+138
-7
lines changed

8 files changed

+138
-7
lines changed

drivers/timer/nrf_grtc_timer.c

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ uint64_t z_nrf_grtc_timer_startup_value_get(void)
364364
return grtc_start_value;
365365
}
366366

367-
#if defined(CONFIG_POWEROFF) && defined(CONFIG_NRF_GRTC_START_SYSCOUNTER)
367+
#if defined(CONFIG_POWEROFF)
368+
#if defined(CONFIG_NRF_GRTC_START_SYSCOUNTER)
368369
int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
369370
{
370371
nrfx_err_t err_code;
@@ -426,6 +427,91 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
426427
k_spin_unlock(&lock, key);
427428
return 0;
428429
}
430+
#else
431+
int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
432+
{
433+
//nrfx_err_t err_code;
434+
//static uint8_t systemoff_channel;
435+
//uint64_t now = counter();
436+
//nrfx_grtc_sleep_config_t sleep_cfg;
437+
/* Minimum time that ensures valid execution of system-off procedure. */
438+
//uint32_t minimum_latency_us;
439+
uint32_t chan;
440+
//int ret;
441+
442+
// nrfx_grtc_sleep_configuration_get(&sleep_cfg);
443+
// minimum_latency_us =
444+
// (sleep_cfg.waketime + sleep_cfg.timeout) * USEC_PER_SEC / LFCLK_FREQUENCY_HZ +
445+
// CONFIG_NRF_GRTC_SYSCOUNTER_SLEEP_MINIMUM_LATENCY;
446+
// sleep_cfg.auto_mode = false;
447+
// nrfx_grtc_sleep_configure(&sleep_cfg);
448+
449+
// if (minimum_latency_us > wake_time_us) {
450+
// return -EINVAL;
451+
// }
452+
453+
//k_spinlock_key_t key = k_spin_lock(&lock);
454+
455+
// err_code = nrfx_grtc_channel_alloc(&systemoff_channel);
456+
// if (err_code != NRFX_SUCCESS) {
457+
// k_spin_unlock(&lock, key);
458+
// return -ENOMEM;
459+
// }
460+
//(void)nrfx_grtc_syscounter_cc_int_disable(systemoff_channel);
461+
// ret = compare_set(systemoff_channel,
462+
// now + wake_time_us * sys_clock_hw_cycles_per_sec() / USEC_PER_SEC, NULL,
463+
// NULL);
464+
// if (ret < 0) {
465+
// k_spin_unlock(&lock, key);
466+
// return ret;
467+
// }
468+
// for (uint32_t grtc_chan_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK;
469+
for (uint32_t grtc_chan_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK;
470+
grtc_chan_mask > 0; grtc_chan_mask &= ~BIT(chan)) {
471+
/* Clear all GRTC channels except the systemoff_channel. */
472+
chan = u32_count_trailing_zeros(grtc_chan_mask);
473+
// if (chan != systemoff_channel) {
474+
nrfx_grtc_syscounter_cc_disable(chan);
475+
//}
476+
}
477+
#if 0
478+
#if defined(CONFIG_SOC_NRF54H20_CPUAPP)
479+
for (uint32_t grtc_chan_mask = 0x70;
480+
grtc_chan_mask > 0; grtc_chan_mask &= ~BIT(chan)) {
481+
/* Clear all GRTC channels except the systemoff_channel. */
482+
chan = u32_count_trailing_zeros(grtc_chan_mask);
483+
// if (chan != systemoff_channel) {
484+
nrfx_grtc_syscounter_cc_disable(chan);
485+
// }
486+
}
487+
#endif
488+
#if defined(CONFIG_SOC_NRF54H20_CPURAD)
489+
//for (uint32_t grtc_chan_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK;
490+
for (uint32_t grtc_chan_mask = 0xFF80;
491+
grtc_chan_mask > 0; grtc_chan_mask &= ~BIT(chan)) {
492+
/* Clear all GRTC channels except the systemoff_channel. */
493+
chan = u32_count_trailing_zeros(grtc_chan_mask);
494+
//if (chan != systemoff_channel) {
495+
nrfx_grtc_syscounter_cc_disable(chan);
496+
//}
497+
}
498+
#endif
499+
#endif
500+
// /* Make sure that wake_time_us was not triggered yet. */
501+
// if (nrfx_grtc_syscounter_compare_event_check(systemoff_channel)) {
502+
// k_spin_unlock(&lock, key);
503+
// return -EINVAL;
504+
// }
505+
506+
// /* This mechanism ensures that stored CC value is latched. */
507+
//uint32_t wait_time =
508+
// nrfy_grtc_timeout_get(NRF_GRTC) * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / 32768 +
509+
// MAX_CC_LATCH_WAIT_TIME_US;
510+
k_busy_wait(1000);
511+
// k_spin_unlock(&lock, key);
512+
return 0;
513+
}
514+
#endif /* CONFIG_NRF_GRTC_START_SYSCOUNTER */
429515
#endif /* CONFIG_POWEROFF */
430516

431517
uint32_t sys_clock_cycle_get_32(void)

kernel/init.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ void __weak z_early_rand_get(uint8_t *buf, size_t length)
755755
buf += rc;
756756
}
757757
}
758-
758+
#include <hal/nrf_gpio.h>
759759
/**
760760
*
761761
* @brief Initialize kernel
@@ -770,15 +770,25 @@ __boot_func
770770
FUNC_NO_STACK_PROTECTOR
771771
FUNC_NORETURN void z_cstart(void)
772772
{
773+
//nrf_gpio_port_pin_output_set(NRF_P9_S_BASE, 3);
774+
//nrf_gpio_port_dir_output_set(NRF_P9_S, 0xf);
775+
//nrf_gpio_pin_write(289, 1);
776+
//nrf_gpio_pin_write(288, 1);
777+
//nrf_gpio_pin_write(290, 1);
773778
/* gcov hook needed to get the coverage report.*/
774779
gcov_static_init();
780+
//nrf_gpio_port_dir_output_set(NRF_P9_S_BASE, 0);
775781

776782
/* initialize early init calls */
777783
z_sys_init_run_level(INIT_LEVEL_EARLY);
778784

785+
//nrf_gpio_port_dir_output_set(NRF_P9_S_BASE, 1);
786+
779787
/* perform any architecture-specific initialization */
780788
arch_kernel_init();
781789

790+
//nrf_gpio_port_dir_output_set(NRF_P9_S_BASE, 0);
791+
782792
LOG_CORE_INIT();
783793

784794
#if defined(CONFIG_MULTITHREADING)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
&uart135 {
2+
status = "disabled";
23
zephyr,pm-device-runtime-auto;
34
};
5+
6+
&can120 {
7+
//status = "disabled";
8+
};
9+
10+
&usbhs {
11+
//status = "disabled";
12+
};

samples/boards/nordic/system_off/prj.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ CONFIG_NRF_REGTOOL_VERBOSITY=2
77
CONFIG_CRC=y
88
CONFIG_POWEROFF=y
99
CONFIG_HWINFO=y
10+
CONFIG_SERIAL=y
11+
CONFIG_CONSOLE=y
12+
CONFIG_UART_CONSOLE=y
13+
CONFIG_RESET_ON_FATAL_ERROR=y

samples/boards/nordic/system_off/remote/prj.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ CONFIG_UART_ASYNC_API=y
66
CONFIG_SERIAL=n
77
CONFIG_CONSOLE=n
88
CONFIG_UART_CONSOLE=n
9-
CONFIG_NRF_REGTOOL_VERBOSITY=2
9+
CONFIG_RESET_ON_FATAL_ERROR=y

samples/boards/nordic/system_off/remote/src/main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@
99
#include <zephyr/pm/device_runtime.h>
1010
#include <zephyr/sys/poweroff.h>
1111
#include <hal/nrf_memconf.h>
12+
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
1213

1314
int main(void)
1415
{
16+
17+
1518
if (IS_ENABLED(CONFIG_CONSOLE)) {
1619
printf("%s system off demo. Ready for system off.\n", CONFIG_BOARD);
1720
}
1821

22+
23+
24+
//k_sleep(K_FOREVER);
25+
//k_msleep(10000);
26+
27+
z_nrf_grtc_wakeup_prepare(1000);
28+
1929
if (0) {
2030
/*nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, RAMBLOCK_RET_MASK, false);*/
2131
/*nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 1, RAMBLOCK_RET_MASK, false);*/
2232
k_sleep(K_FOREVER);
2333
} else {
24-
/*nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, RAMBLOCK_RET_MASK, false);*/
25-
/*nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 1, RAMBLOCK_RET_MASK, false);*/
34+
nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, RAMBLOCK_RET_MASK, false);
35+
nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 1, RAMBLOCK_RET_MASK, false);
2636

2737
sys_poweroff();
2838
}

samples/boards/nordic/system_off/src/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ int print_reset_cause(uint32_t reset_cause)
6161
return 0;
6262
}
6363

64+
#include "ppr_prl.h"
65+
6466
int main(void)
6567
{
68+
//k_msleep(3000);
69+
//ppr_prl_configure(4096, 16000);
70+
//ppr_prl_start();
71+
//k_sleep(K_FOREVER);
6672
int rc;
6773
uint32_t reset_cause;
6874
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
@@ -109,7 +115,8 @@ int main(void)
109115
} else {
110116
printf("Retained data not supported\n");
111117
}
112-
118+
k_sleep(K_MSEC(4000));
119+
//ppr_prl_start();
113120
#if defined(CONFIG_GRTC_WAKEUP_ENABLE)
114121
int err = z_nrf_grtc_wakeup_prepare(DEEP_SLEEP_TIME_S * USEC_PER_SEC);
115122

@@ -168,7 +175,7 @@ int main(void)
168175
retained_update();
169176
}
170177

171-
k_sleep(K_MSEC(4000));
178+
172179
if (do_poweroff) {
173180
#if CONFIG_SOC_NRF54H20_CPUAPP
174181
/* Local RAM0 (TCM) is currently not used so retention can be disabled. */

soc/nordic/nrf54h/power.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <hal/nrf_resetinfo.h>
1212
#include <hal/nrf_memconf.h>
1313
#include <zephyr/cache.h>
14+
#include <zephyr/sys/reboot.h>
1415
#include <power.h>
1516
#include <soc_lrcconf.h>
1617
#include "soc.h"
@@ -87,8 +88,12 @@ void nrf_poweroff(void)
8788
__set_BASEPRI(0);
8889
__ISB();
8990
__DSB();
91+
__NOP();
92+
__NOP();
9093
__WFI();
9194

95+
sys_reboot(SYS_REBOOT_COLD);
96+
9297
CODE_UNREACHABLE;
9398
}
9499

0 commit comments

Comments
 (0)