Skip to content

Commit

Permalink
Improved when to run self test and fail messages
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-wilson committed Mar 18, 2024
1 parent 75d5643 commit 493dbcc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 75 deletions.
10 changes: 10 additions & 0 deletions main/DS4432U.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ static esp_err_t register_write_byte(uint8_t reg_addr, uint8_t data)
return ret;
}

bool DS4432U_test(void)
{
uint8_t data[3];

/* Read the DS4432U+ WHO_AM_I register, on power up the register should have the value 0x00 */
esp_err_t register_result = register_read(DS4432U_OUT0_REG, data, 1);
ESP_LOGI(TAG, "DS4432U+ OUT1 = 0x%02X", data[0]);
return register_result == ESP_OK;
}

void DS4432U_read(void)
{
uint8_t data[3];
Expand Down
2 changes: 1 addition & 1 deletion main/DS4432U.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
esp_err_t i2c_master_init(void);
esp_err_t i2c_master_delete(void);
void DS4432U_read(void);

bool DS4432U_test(void);
bool DS4432U_set_vcore(float);

#endif /* DS4432U_H_ */
6 changes: 4 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ void app_main(void)
GLOBAL_STATE.ASIC_functions = ASIC_functions;
}

bool is_max = strcmp(GLOBAL_STATE.asic_model, "BM1397") == 0;
uint64_t best_diff = nvs_config_get_u64(NVS_CONFIG_BEST_DIFF, 0);
uint16_t should_self_test = nvs_config_get_u16(NVS_CONFIG_SELF_TEST, 1);
if (should_self_test == 1) {
if (should_self_test == 1 && !is_max && best_diff < 1) {
self_test((void *) &GLOBAL_STATE);
vTaskDelay(60 * 60 * 1000 / portTICK_PERIOD_MS);
}

xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void *) &GLOBAL_STATE, 3, NULL);
Expand Down Expand Up @@ -151,4 +154,3 @@ void MINER_set_wifi_status(wifi_status_t status, uint16_t retry_count)
return;
}
}

109 changes: 37 additions & 72 deletions main/self_test/self_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ static bool core_voltage_pass()

void self_test(void * pvParameters)
{
bool ASIC_PASS = false;
bool POWER_PASS = false;

GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;

Expand Down Expand Up @@ -86,20 +85,17 @@ void self_test(void * pvParameters)
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "SELF TEST...");
OLED_writeString(0, 0, module->oled_buf);
}

memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "ASIC:");
OLED_writeString(0, 1, module->oled_buf);

memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "POWER:");
OLED_writeString(0, 2, module->oled_buf);

memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "FAN:");
OLED_writeString(0, 3, module->oled_buf);
if(!DS4432U_test()){
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "DS4432U:FAIL");
OLED_writeString(0, 2, module->oled_buf);
}
}


SERIAL_init();
uint8_t chips_detected = (GLOBAL_STATE->ASIC_functions.init_fn)(GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value);
ESP_LOGI(TAG, "%u chips detected", chips_detected);
Expand Down Expand Up @@ -168,79 +164,48 @@ void self_test(void * pvParameters)
// ESP_LOGI(TAG, "Nonce %lu Nonce difficulty %.32f.", asic_result->nonce, nonce_diff);

// if (asic_result->nonce == 4054974794) {
if (chips_detected > 0) {
ESP_LOGI(TAG, "SELF TEST PASS");
ASIC_PASS = true;
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "ASIC: PASS");
OLED_writeString(0, 1, module->oled_buf);
}
} else {
ESP_LOGE(TAG, "SELF TEST FAIL, INCORRECT NONCE DIFF");
if (chips_detected < 1) {
ESP_LOGE(TAG, "SELF TEST FAIL, NO CHIPS DETECTED");
// ESP_LOGE(TAG, "SELF TEST FAIL, INCORRECT NONCE DIFF");
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "ASIC: FAIL");
OLED_writeString(0, 1, module->oled_buf);
snprintf(module->oled_buf, 20, "ASIC:FAIL NO CHIPS");
OLED_writeString(0, 2, module->oled_buf);
}
return;
}
// } else {
// ESP_LOGE(TAG, "SELF TEST FAIL, NO NONCE DIFF");
// if (OLED_status()) {
// memset(module->oled_buf, 0, 20);
// snprintf(module->oled_buf, 20, "ASIC: FAIL");
// OLED_writeString(0, 1, module->oled_buf);
// }
// }

free(GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs);
free(GLOBAL_STATE->valid_jobs);


if (INA260_installed()) {
if (power_consumption_pass() && core_voltage_pass()) {
POWER_PASS = true;
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "POWER: PASS");
OLED_writeString(0, 2, module->oled_buf);
}
} else {
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "POWER: FAIL");
OLED_writeString(0, 2, module->oled_buf);
}
if (!core_voltage_pass()) {
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "POWER: FAIL");
OLED_writeString(0, 2, module->oled_buf);
}
} else {
if (core_voltage_pass()) {
POWER_PASS = true;
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "POWER: PASS");
OLED_writeString(0, 2, module->oled_buf);
}
} else {
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "POWER: FAIL");
OLED_writeString(0, 2, module->oled_buf);
}
return;
}

if (INA260_installed() && !power_consumption_pass()) {
if (OLED_status()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "POWER: FAIL");
OLED_writeString(0, 2, module->oled_buf);
}
return;
}

if (fan_sense_pass()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "FAN: PASS");
OLED_writeString(0, 3, module->oled_buf);
} else {
if (!fan_sense_pass()) {
memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, "FAN: WARN");
OLED_writeString(0, 3, module->oled_buf);
OLED_writeString(0, 1, module->oled_buf);
}

if (POWER_PASS && ASIC_PASS) {
nvs_config_set_u16(NVS_CONFIG_SELF_TEST, 0);
}
vTaskDelay(60 * 60 * 1000 / portTICK_PERIOD_MS);

memset(module->oled_buf, 0, 20);
snprintf(module->oled_buf, 20, " PASS");
OLED_writeString(0, 2, module->oled_buf);
nvs_config_set_u16(NVS_CONFIG_SELF_TEST, 0);

}

0 comments on commit 493dbcc

Please sign in to comment.