add transition to power management

This commit is contained in:
WantClue 2024-09-06 10:37:04 +02:00
parent d925d615ce
commit 1c66c20561

View File

@ -119,7 +119,9 @@ void POWER_MANAGEMENT_task(void * pvParameters)
}
vTaskDelay(4000 / portTICK_PERIOD_MS);
uint16_t last_core_voltage = 0.0;
uint16_t last_asic_frequency = power_management->frequency_value;
while (1) {
switch (GLOBAL_STATE->device_model) {
@ -269,6 +271,27 @@ void POWER_MANAGEMENT_task(void * pvParameters)
}
}
// New voltage and frequency adjustment code
uint16_t core_voltage = nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE);
uint16_t asic_frequency = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY);
if (core_voltage != last_core_voltage) {
ESP_LOGI(TAG, "setting new vcore voltage to %umV", core_voltage);
VCORE_set_voltage((double) core_voltage / 1000.0, GLOBAL_STATE);
last_core_voltage = core_voltage;
}
if (asic_frequency != last_asic_frequency) {
ESP_LOGI(TAG, "New ASIC frequency requested: %uMHz (current: %uMHz)", asic_frequency, last_asic_frequency);
if (do_frequency_transition((float)asic_frequency)) {
power_management->frequency_value = (float)asic_frequency;
ESP_LOGI(TAG, "Successfully transitioned to new ASIC frequency: %uMHz", asic_frequency);
} else {
ESP_LOGE(TAG, "Failed to transition to new ASIC frequency: %uMHz", asic_frequency);
}
last_asic_frequency = asic_frequency;
}
vTaskDelay(POLL_RATE / portTICK_PERIOD_MS);
}
}