Skip to content

Commit

Permalink
Legacy selftest fixes (#346)
Browse files Browse the repository at this point in the history
* make sure to VCORE_init() and VCORE_set_voltage() no matter what hw version.

* added "PRESS RESET" to selftest endscreen. pulled out magic numbers to #defines

* oops, cleanup

* update 402 power target

* 403+support

---------

Co-authored-by: Benjamin Wilson <[email protected]>
  • Loading branch information
skot and Benjamin Wilson authored Sep 23, 2024
1 parent 7b5e3ef commit 8b22bb2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
69 changes: 44 additions & 25 deletions main/self_test/self_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "string.h"
#include "TPS546.h"

#define POWER_CONSUMPTION_TARGET_SUB_402 12 //watts
#define POWER_CONSUMPTION_TARGET_402 5 //watts
#define POWER_CONSUMPTION_TARGET_GAMMA 11 //watts
#define POWER_CONSUMPTION_MARGIN 3 //+/- watts

static const char * TAG = "self_test";

static void display_msg(char * msg, GlobalState * GLOBAL_STATE) {
Expand All @@ -33,6 +38,24 @@ static void display_msg(char * msg, GlobalState * GLOBAL_STATE) {
}
}

static void display_end_screen(GlobalState * GLOBAL_STATE) {

switch (GLOBAL_STATE->device_model) {
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
case DEVICE_GAMMA:
if (OLED_status()) {
OLED_clearLine(2);
OLED_writeString(0, 2, " PASS");
OLED_clearLine(3);
OLED_writeString(0, 3, "PRESS RESET");
}
break;
default:
}
}

static bool fan_sense_pass(GlobalState * GLOBAL_STATE)
{
uint16_t fan_speed = 0;
Expand Down Expand Up @@ -147,35 +170,30 @@ void self_test(void * pvParameters)
default:
}

uint8_t result = VCORE_init(GLOBAL_STATE);
VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, GLOBAL_STATE);

// VCore regulator testing
switch (GLOBAL_STATE->device_model) {
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
if(GLOBAL_STATE->board_version != 402){
if(!DS4432U_test()){
ESP_LOGE(TAG, "DS4432 test failed!");
display_msg("DS4432U:FAIL", GLOBAL_STATE);
return;
}
}else{

uint8_t result = VCORE_init(GLOBAL_STATE);
VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, GLOBAL_STATE);

if(result != 0){
if (GLOBAL_STATE->board_version >= 402 && GLOBAL_STATE->board_version <= 499){
if (result != 0) {
ESP_LOGE(TAG, "TPS546 test failed!");
display_msg("TPS546:FAIL", GLOBAL_STATE);
return;
}
} else {
if(!DS4432U_test()) {
ESP_LOGE(TAG, "DS4432 test failed!");
display_msg("DS4432U:FAIL", GLOBAL_STATE);
return;
}
}
break;
case DEVICE_GAMMA:

uint8_t result = VCORE_init(GLOBAL_STATE);
VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, GLOBAL_STATE);

if(result != 0){
if (result != 0) {
ESP_LOGE(TAG, "TPS546 test failed!");
display_msg("TPS546:FAIL", GLOBAL_STATE);
return;
Expand Down Expand Up @@ -273,23 +291,23 @@ void self_test(void * pvParameters)
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
if(GLOBAL_STATE->board_version != 402){
if (!INA260_power_consumption_pass(12, 3)) {
ESP_LOGE(TAG, "INA260 Power Draw Failed");
if(GLOBAL_STATE->board_version >= 402 && GLOBAL_STATE->board_version <= 499){
if (!TPS546_power_consumption_pass(POWER_CONSUMPTION_TARGET_402, POWER_CONSUMPTION_MARGIN)) {
ESP_LOGE(TAG, "TPS546 Power Draw Failed, target %.2f", (float)POWER_CONSUMPTION_TARGET_402);
display_msg("POWER: FAIL", GLOBAL_STATE);
return;
}
} else {
if (!TPS546_power_consumption_pass(8, 3)) {
ESP_LOGE(TAG, "TPS546 Power Draw Failed, target %f", 8.0);
if (!INA260_power_consumption_pass(POWER_CONSUMPTION_TARGET_SUB_402, POWER_CONSUMPTION_MARGIN)) {
ESP_LOGE(TAG, "INA260 Power Draw Failed, target %.2f", (float)POWER_CONSUMPTION_TARGET_SUB_402);
display_msg("POWER: FAIL", GLOBAL_STATE);
return;
}
}
break;
case DEVICE_GAMMA:
if (!TPS546_power_consumption_pass(11, 3)) {
ESP_LOGE(TAG, "TPS546 Power Draw Failed, target %f", 11.0);
if (!TPS546_power_consumption_pass(POWER_CONSUMPTION_TARGET_GAMMA, POWER_CONSUMPTION_MARGIN)) {
ESP_LOGE(TAG, "TPS546 Power Draw Failed, target %.2f", (float)POWER_CONSUMPTION_TARGET_GAMMA);
display_msg("POWER: FAIL", GLOBAL_STATE);
return;
}
Expand All @@ -303,6 +321,7 @@ void self_test(void * pvParameters)
}


display_msg(" PASS", GLOBAL_STATE);
ESP_LOGI(TAG, "SELF TESTS PASS -- Press RESET to continue");
display_end_screen(GLOBAL_STATE);
nvs_config_set_u16(NVS_CONFIG_SELF_TEST, 0);
}
8 changes: 4 additions & 4 deletions main/tasks/power_management_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
if (GLOBAL_STATE->board_version != 402) {
if (GLOBAL_STATE->board_version < 402 || GLOBAL_STATE->board_version > 499) {
// Configure GPIO12 as input(barrel jack) 1 is plugged in
gpio_config_t barrel_jack_conf = {
.pin_bit_mask = (1ULL << GPIO_NUM_12),
Expand Down Expand Up @@ -128,7 +128,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
if (GLOBAL_STATE->board_version == 402) {
if (GLOBAL_STATE->board_version >= 402 && GLOBAL_STATE->board_version <= 499) {
power_management->voltage = TPS546_get_vin() * 1000;
power_management->current = TPS546_get_iout() * 1000;
// calculate regulator power (in milliwatts)
Expand Down Expand Up @@ -177,7 +177,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
case DEVICE_ULTRA:
case DEVICE_SUPRA:

if (GLOBAL_STATE->board_version == 402) {
if (GLOBAL_STATE->board_version >= 402 && GLOBAL_STATE->board_version <= 499) {
power_management->chip_temp_avg = GLOBAL_STATE->ASIC_initalized ? EMC2101_get_external_temp() : -1;
power_management->vr_temp = (float)TPS546_get_temperature();
} else {
Expand All @@ -196,7 +196,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
ESP_LOGE(TAG, "OVERHEAT! VR: %fC ASIC %fC", power_management->vr_temp, power_management->chip_temp_avg );

EMC2101_set_fan_speed(1);
if (GLOBAL_STATE->board_version == 402) {
if (GLOBAL_STATE->board_version >= 402 && GLOBAL_STATE->board_version <= 499) {
// Turn off core voltage
VCORE_set_voltage(0.0, GLOBAL_STATE);
} else if (power_management->HAS_POWER_EN) {
Expand Down
4 changes: 2 additions & 2 deletions main/vcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ uint8_t VCORE_init(GlobalState * global_state) {
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
if (global_state->board_version == 402) {
if (global_state->board_version >= 402 && global_state->board_version <= 499) {
result = TPS546_init();
}
break;
Expand Down Expand Up @@ -75,7 +75,7 @@ bool VCORE_set_voltage(float core_voltage, GlobalState * global_state)
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
if (global_state->board_version == 402) {
if (global_state->board_version >= 402 && global_state->board_version <= 499) {
ESP_LOGI(TAG, "Set ASIC voltage = %.3fV", core_voltage);
TPS546_set_vout(core_voltage * (float)global_state->voltage_domain);
} else {
Expand Down

0 comments on commit 8b22bb2

Please sign in to comment.