Skip to content

Commit

Permalink
moved _init_system() out of SYSTEM_Task() to avoid I2c init race cond…
Browse files Browse the repository at this point in the history
…ition.
  • Loading branch information
skot committed Oct 8, 2024
1 parent 1c9633b commit 59fc875
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 198 deletions.
50 changes: 25 additions & 25 deletions main/TPS546.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,26 @@ int TPS546_init(void)
TPS546_write_entire_config();
//}

/* Show temperature */
ESP_LOGI(TAG, "--------------------------------");
ESP_LOGI(TAG, "Temp: %d", TPS546_get_temperature());
// /* Show temperature */
// ESP_LOGI(TAG, "--------------------------------");
// ESP_LOGI(TAG, "Temp: %d", TPS546_get_temperature());

/* Show switching frequency */
TPS546_get_frequency();
TPS546_set_frequency(650);
// /* Show switching frequency */
// TPS546_get_frequency();
// TPS546_set_frequency(650);

/* Show voltage settings */
TPS546_show_voltage_settings();

TPS546_print_status();
//TPS546_print_status();

ESP_LOGI(TAG, "-----------VOLTAGE/CURRENT---------------------");
/* Get voltage input (SLINEAR11) */
TPS546_get_vin();
/* Get output current (SLINEAR11) */
TPS546_get_iout();
/* Get voltage output (ULINEAR16) */
TPS546_get_vout();
// ESP_LOGI(TAG, "-----------VOLTAGE/CURRENT---------------------");
// /* Get voltage input (SLINEAR11) */
// ESP_LOGI(TAG, "READ_VIN: %.2fV", TPS546_get_vin());
// /* Get output current (SLINEAR11) */
// ESP_LOGI(TAG, "READ_IOUT: %.2fA", TPS546_get_iout());
// /* Get voltage output (ULINEAR16) */
// ESP_LOGI(TAG, "READ_VOUT: %.2fV", TPS546_get_vout());

ESP_LOGI(TAG, "-----------TIMING---------------------");
smb_read_word(PMBUS_TON_DELAY, &u16_value);
Expand Down Expand Up @@ -729,56 +729,56 @@ void TPS546_show_voltage_settings(void)
/* VIN_ON SLINEAR11 */
smb_read_word(PMBUS_VIN_ON, &u16_value);
f_value = slinear11_2_float(u16_value);
ESP_LOGI(TAG, "VIN ON set to: %f", f_value);
ESP_LOGI(TAG, "VIN ON set to: %.2f", f_value);

/* VIN_OFF SLINEAR11 */
smb_read_word(PMBUS_VIN_OFF, &u16_value);
f_value = slinear11_2_float(u16_value);
ESP_LOGI(TAG, "VIN OFF set to: %f", f_value);
ESP_LOGI(TAG, "VIN OFF set to: %.2f", f_value);

/* VOUT_MAX */
smb_read_word(PMBUS_VOUT_MAX, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout Max set to: %f V", f_value);
ESP_LOGI(TAG, "Vout Max set to: %.2f V", f_value);

/* VOUT_OV_FAULT_LIMIT */
smb_read_word(PMBUS_VOUT_OV_FAULT_LIMIT, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout OV Fault Limit: %f V", f_value);
ESP_LOGI(TAG, "Vout OV Fault Limit: %.2f V", f_value);

/* VOUT_OV_WARN_LIMIT */
smb_read_word(PMBUS_VOUT_OV_WARN_LIMIT, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout OV Warn Limit: %f V", f_value);
ESP_LOGI(TAG, "Vout OV Warn Limit: %.2f V", f_value);

/* VOUT_MARGIN_HIGH */
smb_read_word(PMBUS_VOUT_MARGIN_HIGH, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout Margin HIGH: %f V", f_value);
ESP_LOGI(TAG, "Vout Margin HIGH: %.2f V", f_value);

/* --- VOUT_COMMAND --- */
smb_read_word(PMBUS_VOUT_COMMAND, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout set to: %f V", f_value);
ESP_LOGI(TAG, "Vout set to: %.2f V", f_value);

/* VOUT_MARGIN_LOW */
smb_read_word(PMBUS_VOUT_MARGIN_LOW, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout Margin LOW: %f V", f_value);
ESP_LOGI(TAG, "Vout Margin LOW: %.2f V", f_value);

/* VOUT_UV_WARN_LIMIT */
smb_read_word(PMBUS_VOUT_UV_WARN_LIMIT, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout UV Warn Limit: %f V", f_value);
ESP_LOGI(TAG, "Vout UV Warn Limit: %.2f V", f_value);

/* VOUT_UV_FAULT_LIMIT */
smb_read_word(PMBUS_VOUT_UV_FAULT_LIMIT, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout UV Fault Limit: %f V", f_value);
ESP_LOGI(TAG, "Vout UV Fault Limit: %.2f V", f_value);

/* VOUT_MIN */
smb_read_word(PMBUS_VOUT_MIN, &u16_value);
f_value = ulinear16_2_float(u16_value);
ESP_LOGI(TAG, "Vout Min set to: %f V", f_value);
ESP_LOGI(TAG, "Vout Min set to: %.2f V", f_value);
}

11 changes: 11 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "serial.h"
#include "stratum_task.h"
#include "user_input_task.h"
#include "i2c_bitaxe.h"

static GlobalState GLOBAL_STATE = {
.extranonce_str = NULL,
Expand All @@ -31,6 +32,14 @@ static const double NONCE_SPACE = 4294967296.0; // 2^32
void app_main(void)
{
ESP_LOGI(TAG, "Welcome to the bitaxe - hack the planet!");

// Init I2C
ESP_ERROR_CHECK(i2c_bitaxe_init());
ESP_LOGI(TAG, "I2C initialized successfully");

//wait for I2C to init
vTaskDelay(100 / portTICK_PERIOD_MS);

ESP_ERROR_CHECK(nvs_flash_init());

GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY);
Expand Down Expand Up @@ -144,6 +153,8 @@ void app_main(void)
vTaskDelay(60 * 60 * 1000 / portTICK_PERIOD_MS);
}

SYSTEM_init_system(&GLOBAL_STATE);

xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void *) &GLOBAL_STATE, 3, NULL);
xTaskCreate(POWER_MANAGEMENT_task, "power mangement", 8192, (void *) &GLOBAL_STATE, 10, NULL);

Expand Down
Loading

0 comments on commit 59fc875

Please sign in to comment.