make a better usage of vcore module

This commit is contained in:
Georges Palauqui 2024-06-07 14:36:15 +02:00
parent 27376e5b75
commit bc365e6301
No known key found for this signature in database
GPG Key ID: 1E45F544CE4D04A5
5 changed files with 44 additions and 24 deletions

View File

@ -13,6 +13,7 @@
#include "freertos/task.h"
#include "global_state.h"
#include "nvs_config.h"
#include "vcore.h"
#include <fcntl.h>
#include <string.h>
#include <sys/param.h>
@ -368,7 +369,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddNumberToObject(root, "freeHeap", esp_get_free_heap_size());
cJSON_AddNumberToObject(root, "coreVoltage", nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE));
cJSON_AddNumberToObject(root, "coreVoltageActual", ADC_get_vcore());
cJSON_AddNumberToObject(root, "coreVoltageActual", VCORE_get_voltage_mv(GLOBAL_STATE));
cJSON_AddNumberToObject(root, "frequency", nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY));
cJSON_AddStringToObject(root, "ssid", ssid);
cJSON_AddStringToObject(root, "hostname", hostname);

View File

@ -33,9 +33,9 @@ static bool power_consumption_pass()
return false;
}
static bool core_voltage_pass()
static bool core_voltage_pass(GlobalState * global_state)
{
uint16_t core_voltage = ADC_get_vcore();
uint16_t core_voltage = VCORE_get_voltage_mv(global_state);
ESP_LOGI(TAG, "Voltage: %u", core_voltage);
if (core_voltage > 1100 && core_voltage < 1300) {
@ -67,8 +67,8 @@ void self_test(void * pvParameters)
ESP_ERROR_CHECK(i2c_master_init());
ESP_LOGI(TAG, "I2C initialized successfully");
ADC_init();
VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, *GLOBAL_STATE);
VCORE_init(GLOBAL_STATE);
VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, GLOBAL_STATE);
EMC2101_init(nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1));
EMC2101_set_fan_speed(1);
@ -179,7 +179,7 @@ void self_test(void * pvParameters)
free(GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs);
free(GLOBAL_STATE->valid_jobs);
if (!core_voltage_pass()) {
if (!core_voltage_pass(GLOBAL_STATE)) {
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "POWER: FAIL");

View File

@ -82,12 +82,17 @@ static void _init_system(GlobalState * global_state, SystemModule * module)
ESP_ERROR_CHECK(i2c_master_init());
ESP_LOGI(TAG, "I2C initialized successfully");
ADC_init();
VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, *global_state);
EMC2101_init(nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1));
VCORE_init(global_state);
VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, global_state);
switch (global_state->device_model) {
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
EMC2101_init(nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1));
break;
default:
}
vTaskDelay(500 / portTICK_PERIOD_MS);
@ -174,11 +179,12 @@ static void _update_system_info(GlobalState * GLOBAL_STATE)
}
}
static void _update_esp32_info(SystemModule * module)
static void _update_esp32_info(GlobalState * GLOBAL_STATE)
{
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;
uint32_t free_heap_size = esp_get_free_heap_size();
uint16_t vcore = ADC_get_vcore();
uint16_t vcore = VCORE_get_voltage_mv(GLOBAL_STATE);
if (OLED_status()) {
@ -405,7 +411,7 @@ void SYSTEM_task(void * pvParameters)
_update_system_info(GLOBAL_STATE);
break;
case 2:
_update_esp32_info(module);
_update_esp32_info(GLOBAL_STATE);
break;
}

View File

@ -3,6 +3,7 @@
#include "esp_log.h"
#include "vcore.h"
#include "adc.h"
#include "DS4432U.h"
// DS4432U Transfer function constants for Bitaxe board
@ -16,6 +17,10 @@
static const char *TAG = "vcore.c";
void VCORE_init(GlobalState * global_state) {
ADC_init();
}
/**
* @brief ds4432_tps40305_bitaxe_voltage_to_reg takes a voltage and returns a register setting for the DS4432U to get that voltage on the TPS40305
* careful with this one!!
@ -44,19 +49,25 @@ static uint8_t ds4432_tps40305_bitaxe_voltage_to_reg(float vout)
return reg;
}
bool VCORE_set_voltage(float core_voltage, GlobalState global_state)
bool VCORE_set_voltage(float core_voltage, GlobalState * global_state)
{
uint8_t reg_setting;
if ((global_state.device_model == DEVICE_MAX) ||
(global_state.device_model == DEVICE_ULTRA) ||
(global_state.device_model == DEVICE_SUPRA)) {
reg_setting = ds4432_tps40305_bitaxe_voltage_to_reg(core_voltage);
ESP_LOGI(TAG, "Set ASIC voltage = %.3fV [0x%02X]", core_voltage, reg_setting);
DS4432U_set_current_code(0, reg_setting); /// eek!
switch (global_state->device_model) {
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
reg_setting = ds4432_tps40305_bitaxe_voltage_to_reg(core_voltage);
ESP_LOGI(TAG, "Set ASIC voltage = %.3fV [0x%02X]", core_voltage, reg_setting);
DS4432U_set_current_code(0, reg_setting); /// eek!
break;
// case DEVICE_HEX:
default:
}
// can make other fancy 'else if' based on other device_model or specific version that have different HW to set VCore value
// for example DEVICE_HEX will have a different way to set VCore using TPS546...
return true;
}
uint16_t VCORE_get_voltage_mv(GlobalState * global_state) {
return ADC_get_vcore();
}

View File

@ -3,6 +3,8 @@
#include "global_state.h"
bool VCORE_set_voltage(float core_voltage, GlobalState global_state);
void VCORE_init(GlobalState * global_state);
bool VCORE_set_voltage(float core_voltage, GlobalState * global_state);
uint16_t VCORE_get_voltage_mv(GlobalState * global_state);
#endif /* VCORE_H_ */