hal_nordic: nrfs: dvfs: Update SystemCoreClock on frequency change

Update SystemCoreClock to match current core frequency. This MDK
variable is used by nrfx_coredep_delay_us which performs busy
waiting and is used by k_busy_wait.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2024-12-12 14:37:55 +01:00 committed by Benjamin Cabé
parent d8f0787ab5
commit 6c754e636f

View file

@ -139,9 +139,19 @@ static void dvfs_service_handler_scaling_background_job(enum dvfs_frequency_sett
}
}
/* Update MDK variable which is used by nrfx_coredep_delay_us (k_busy_wait). */
static void dvfs_service_update_core_clock(enum dvfs_frequency_setting oppoint_freq)
{
extern uint32_t SystemCoreClock;
SystemCoreClock = oppoint_freq == DVFS_FREQ_HIGH ? 320000000 :
oppoint_freq == DVFS_FREQ_MEDLOW ? 128000000 : 64000000;
}
/* Perform scaling finnish procedure. */
static void dvfs_service_handler_scaling_finish(enum dvfs_frequency_setting oppoint_freq)
{
LOG_DBG("Scaling finnish oppoint freq %d", oppoint_freq);
ld_dvfs_scaling_finish(dvfs_service_handler_is_downscaling(oppoint_freq));
if (!dvfs_service_handler_is_downscaling(oppoint_freq)) {
@ -153,6 +163,7 @@ static void dvfs_service_handler_scaling_finish(enum dvfs_frequency_setting oppo
}
dvfs_service_handler_clear_state_bit(DVFS_SERV_HDL_FREQ_CHANGE_REQ_PENDING_BIT_POS);
current_freq_setting = oppoint_freq;
dvfs_service_update_core_clock(oppoint_freq);
LOG_DBG("Current LD freq setting: %d", current_freq_setting);
if (dvfs_frequency_change_applied_clb) {
dvfs_frequency_change_applied_clb(current_freq_setting);
@ -215,6 +226,7 @@ static void nrfs_dvfs_evt_handler(nrfs_dvfs_evt_t const *p_evt, void *context)
dvfs_service_handler_clear_state_bit(DVFS_SERV_HDL_FREQ_CHANGE_REQ_PENDING_BIT_POS);
LOG_DBG("DVFS handler EVT_OPPOINT_REQ_CONFIRMED %d", (uint32_t)p_evt->freq);
if (dvfs_service_handler_get_requested_oppoint() == p_evt->freq) {
dvfs_service_update_core_clock(p_evt->freq);
if (dvfs_frequency_change_applied_clb) {
dvfs_frequency_change_applied_clb(p_evt->freq);
}