Skip to content

Commit

Permalink
Fix overtemp and self tests for gamma (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-wilson authored Sep 20, 2024
1 parent 669d81b commit b700c6b
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 33 deletions.
6 changes: 3 additions & 3 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,12 @@ void BM1366_send_work(void * pvParameters, bm_job * next_bm_job)

pthread_mutex_lock(&GLOBAL_STATE->valid_jobs_lock);
GLOBAL_STATE->valid_jobs[job.job_id] = 1;

pthread_mutex_unlock(&GLOBAL_STATE->valid_jobs_lock);

//debug sent jobs - this can get crazy if the interval is short
#if BM1368_DEBUG_JOBS
#if BM1366_DEBUG_JOBS
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
#endif
pthread_mutex_unlock(&GLOBAL_STATE->valid_jobs_lock);

_send_BM1366((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1366_job), BM1366_DEBUG_WORK);
}
Expand Down
2 changes: 1 addition & 1 deletion components/asic/bm1368.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ void BM1368_send_work(void * pvParameters, bm_job * next_bm_job)

pthread_mutex_lock(&GLOBAL_STATE->valid_jobs_lock);
GLOBAL_STATE->valid_jobs[job.job_id] = 1;
pthread_mutex_unlock(&GLOBAL_STATE->valid_jobs_lock);

#if BM1368_DEBUG_JOBS
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
#endif
pthread_mutex_unlock(&GLOBAL_STATE->valid_jobs_lock);

_send_BM1368((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1368_job), BM1368_DEBUG_WORK);
}
Expand Down
38 changes: 22 additions & 16 deletions components/asic/bm1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ static void _send_BM1370(uint8_t header, uint8_t * data, uint8_t data_len, bool
}

// send serial data
SERIAL_send(buf, total_length, packet_type == CMD_PACKET ? BM1370_SERIALTX_DEBUG : false);
if (SERIAL_send(buf, total_length, debug) == 0) {
ESP_LOGE(TAG, "Failed to send data to BM1370");
}

free(buf);
}
Expand All @@ -115,15 +117,15 @@ static void _send_chain_inactive(void)

unsigned char read_address[2] = {0x00, 0x00};
// send serial data
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, false);
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, BM1370_SERIALTX_DEBUG);
}

static void _set_chip_address(uint8_t chipAddr)
{

unsigned char read_address[2] = {chipAddr, 0x00};
// send serial data
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, false);
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, BM1370_SERIALTX_DEBUG);
}

void BM1370_send_hash_frequency(int id, float target_freq, float max_diff) {
Expand Down Expand Up @@ -174,7 +176,7 @@ void BM1370_send_hash_frequency(int id, float target_freq, float max_diff) {
_send_BM1370(TYPE_CMD | GROUP_ALL | CMD_WRITE, freqbuf, 6, BM1370_SERIALTX_DEBUG);
}

//ESP_LOGI(TAG, "Setting Frequency to %.2fMHz (%.2f)", target_freq, best_freq);
ESP_LOGI(TAG, "Setting Frequency to %.2fMHz (%.2f)", target_freq, best_freq);
}

static void do_frequency_ramp_up(float target_frequency) {
Expand All @@ -189,7 +191,7 @@ static void do_frequency_ramp_up(float target_frequency) {
float next_step = fminf(step, target_frequency - current);
current += next_step;
BM1370_send_hash_frequency(-1, current, 0.001);
vTaskDelay(pdMS_TO_TICKS(100));
vTaskDelay(pdMS_TO_TICKS(10));
}
}

Expand Down Expand Up @@ -277,20 +279,20 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
for (uint8_t i = 0; i < chip_counter; i++) {
//Reg_A8
unsigned char set_a8_register[6] = {i * address_interval, 0xA8, 0x00, 0x07, 0x01, 0xF0};
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_a8_register, 6, false);
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_a8_register, 6, BM1370_SERIALTX_DEBUG);
//Misc Control
unsigned char set_18_register[6] = {i * address_interval, 0x18, 0xF0, 0x00, 0xC1, 0x00};
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_18_register, 6, false);
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_18_register, 6, BM1370_SERIALTX_DEBUG);
//Core Register Control
unsigned char set_3c_register_first[6] = {i * address_interval, 0x3C, 0x80, 0x00, 0x8B, 0x00};
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_first, 6, false);
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_first, 6, BM1370_SERIALTX_DEBUG);
//Core Register Control
//unsigned char set_3c_register_second[6] = {i * address_interval, 0x3C, 0x80, 0x00, 0x80, 0x0C}; //from S21Pro dump
unsigned char set_3c_register_second[6] = {i * address_interval, 0x3C, 0x80, 0x00, 0x80, 0x18};
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_second, 6, false);
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_second, 6, BM1370_SERIALTX_DEBUG);
//Core Register Control
unsigned char set_3c_register_third[6] = {i * address_interval, 0x3C, 0x80, 0x00, 0x82, 0xAA};
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_third, 6, false);
_send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_third, 6, BM1370_SERIALTX_DEBUG);
}

do_frequency_ramp_up(frequency);
Expand All @@ -305,7 +307,7 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
//unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x00, 0x15, 0xA4}; //S21-Stock Default
unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x00, 0x1E, 0xB5}; //S21 Pro-Stock Default
// unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x0F, 0x00, 0x00}; //supposedly the "full" 32bit nonce range
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), set_10_hash_counting, 6, false);
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), set_10_hash_counting, 6, BM1370_SERIALTX_DEBUG);

return chip_counter;
}
Expand All @@ -330,7 +332,7 @@ static void _send_read_address(void)

unsigned char read_address[2] = {0x00, 0x00};
// send serial data
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, false);
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, BM1370_SERIALTX_DEBUG);
}

uint8_t BM1370_init(uint64_t frequency, uint16_t asic_count)
Expand All @@ -354,7 +356,7 @@ int BM1370_set_default_baud(void)
{
// default divider of 26 (11010) for 115,749
unsigned char baudrate[9] = {0x00, MISC_CONTROL, 0x00, 0x00, 0b01111010, 0b00110001}; // baudrate - misc_control
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, false);
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1370_SERIALTX_DEBUG);
return 115749;
}

Expand Down Expand Up @@ -394,7 +396,7 @@ void BM1370_set_job_difficulty_mask(int difficulty)

ESP_LOGI(TAG, "Setting ASIC difficulty mask to %d", difficulty);

_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, false);
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1370_SERIALTX_DEBUG);
}

static uint8_t id = 0;
Expand Down Expand Up @@ -423,10 +425,14 @@ void BM1370_send_work(void * pvParameters, bm_job * next_bm_job)

pthread_mutex_lock(&GLOBAL_STATE->valid_jobs_lock);
GLOBAL_STATE->valid_jobs[job.job_id] = 1;
//ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
pthread_mutex_unlock(&GLOBAL_STATE->valid_jobs_lock);

_send_BM1370((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1370_job), false);
//debug sent jobs - this can get crazy if the interval is short
#if BM1370_DEBUG_JOBS
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
#endif

_send_BM1370((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1370_job), BM1370_DEBUG_WORK);
}

asic_result * BM1370_receive_work(void)
Expand Down
5 changes: 4 additions & 1 deletion components/asic/bm1397.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,12 @@ void BM1397_send_work(void *pvParameters, bm_job *next_bm_job)

pthread_mutex_lock(&GLOBAL_STATE->valid_jobs_lock);
GLOBAL_STATE->valid_jobs[job.job_id] = 1;
// ESP_LOGI(TAG, "Added Job: %i", job.job_id);
pthread_mutex_unlock(&GLOBAL_STATE->valid_jobs_lock);

#if BM1397_DEBUG_JOBS
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
#endif

_send_BM1397((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(job_packet), BM1397_DEBUG_WORK);
}

Expand Down
2 changes: 1 addition & 1 deletion components/asic/include/bm1366.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define BM1366_SERIALTX_DEBUG false
#define BM1366_SERIALRX_DEBUG false
#define BM1366_DEBUG_WORK false //causes insane amount of debug output
#define BM1368_DEBUG_JOBS false //causes insane amount of debug output
#define BM1366_DEBUG_JOBS false //causes insane amount of debug output

static const uint64_t BM1366_CORE_COUNT = 112;
static const uint64_t BM1366_SMALL_CORE_COUNT = 894;
Expand Down
1 change: 1 addition & 0 deletions components/asic/include/bm1370.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define BM1370_SERIALTX_DEBUG true
#define BM1370_SERIALRX_DEBUG false
#define BM1370_DEBUG_WORK false //causes insane amount of debug output
#define BM1370_DEBUG_JOBS false //causes insane amount of debug output

static const uint64_t BM1370_CORE_COUNT = 128;
static const uint64_t BM1370_SMALL_CORE_COUNT = 2040;
Expand Down
1 change: 1 addition & 0 deletions components/asic/include/bm1397.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define BM1937_SERIALTX_DEBUG false
#define BM1937_SERIALRX_DEBUG false
#define BM1397_DEBUG_WORK false //causes insane amount of debug output
#define BM1397_DEBUG_JOBS false //causes insane amount of debug output

static const uint64_t BM1397_CORE_COUNT = 168;
static const uint64_t BM1397_SMALL_CORE_COUNT = 672;
Expand Down
5 changes: 5 additions & 0 deletions main/EMC2101.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ float EMC2101_get_external_temp(void)
}

float result = (float) reading / 8.0;

// Greater than 200C is probably an erroneous reading...
if (result > 200){
return EMC2101_get_internal_temp();
}
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion main/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ typedef struct
uint32_t version_mask;

int sock;

bool ASIC_initalized;
} GlobalState;

#endif /* GLOBAL_STATE_H_ */
10 changes: 9 additions & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
#include "stratum_task.h"
#include "user_input_task.h"

static GlobalState GLOBAL_STATE = {.extranonce_str = NULL, .extranonce_2_len = 0, .abandon_work = 0, .version_mask = 0};
static GlobalState GLOBAL_STATE = {
.extranonce_str = NULL,
.extranonce_2_len = 0,
.abandon_work = 0,
.version_mask = 0,
.ASIC_initalized = false
};

static const char * TAG = "bitaxe";
static const double NONCE_SPACE = 4294967296.0; // 2^32
Expand Down Expand Up @@ -195,6 +201,8 @@ void app_main(void)
SERIAL_set_baud((*GLOBAL_STATE.ASIC_functions.set_max_baud_fn)());
SERIAL_clear_buffer();

GLOBAL_STATE.ASIC_initalized = true;

xTaskCreate(stratum_task, "stratum admin", 8192, (void *) &GLOBAL_STATE, 5, NULL);
xTaskCreate(create_jobs_task, "stratum miner", 8192, (void *) &GLOBAL_STATE, 10, NULL);
xTaskCreate(ASIC_task, "asic", 8192, (void *) &GLOBAL_STATE, 10, NULL);
Expand Down
54 changes: 48 additions & 6 deletions main/self_test/self_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "vcore.h"
#include "utils.h"
#include "string.h"
#include "TPS546.h"

static const char * TAG = "self_test";

Expand Down Expand Up @@ -51,11 +52,23 @@ static bool fan_sense_pass(GlobalState * GLOBAL_STATE)
return false;
}

static bool power_consumption_pass()
static bool INA260_power_consumption_pass(int target_power, int margin)
{
float power = INA260_read_power() / 1000;
ESP_LOGI(TAG, "Power: %f", power);
if (power > 9 && power < 15) {
if (power > target_power -margin && power < target_power +margin) {
return true;
}
return false;
}

static bool TPS546_power_consumption_pass(int target_power, int margin)
{
float voltage = TPS546_get_vout();
float current = TPS546_get_iout();
float power = voltage * current;
ESP_LOGI(TAG, "Power: %f, Voltage: %f, Current %f", power, voltage, current);
if (power > target_power -margin && power < target_power +margin) {
return true;
}
return false;
Expand Down Expand Up @@ -143,10 +156,24 @@ void self_test(void * pvParameters)
if(!DS4432U_test()){
ESP_LOGE(TAG, "DS4432 test failed!");
display_msg("DS4432U:FAIL", GLOBAL_STATE);
return;
}
}else{
int result = TPS546_init();
if(result != 0){
ESP_LOGE(TAG, "TPS546 test failed!");
display_msg("TPS546:FAIL", GLOBAL_STATE);
return;
}
}
break;
case DEVICE_GAMMA:
int result = TPS546_init();
if(result != 0){
ESP_LOGE(TAG, "TPS546 test failed!");
display_msg("TPS546:FAIL", GLOBAL_STATE);
return;
}
break;
default:
}
Expand Down Expand Up @@ -240,12 +267,27 @@ void self_test(void * pvParameters)
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
if (INA260_installed() && !power_consumption_pass()) {
ESP_LOGE(TAG, "INA260 test failed!");
display_msg("MONITOR: FAIL", GLOBAL_STATE);
return;
if(GLOBAL_STATE->board_version != 402){
if (!INA260_power_consumption_pass(12, 3)) {
ESP_LOGE(TAG, "INA260 Power Draw Failed");
display_msg("POWER: FAIL", GLOBAL_STATE);
return;
}
} else {
if (!TPS546_power_consumption_pass(8, 2)) {
ESP_LOGE(TAG, "TPS546 Power Draw Failed, target %f", 8.0);
display_msg("POWER: FAIL", GLOBAL_STATE);
return;
}
}
break;
case DEVICE_GAMMA:
if (!TPS546_power_consumption_pass(15, 2)) {
ESP_LOGE(TAG, "TPS546 Power Draw Failed, target %f", 15.0);
display_msg("POWER: FAIL", GLOBAL_STATE);
return;
}
break;
default:
}

Expand Down
6 changes: 3 additions & 3 deletions main/tasks/power_management_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)

switch (GLOBAL_STATE->device_model) {
case DEVICE_MAX:
power_management->chip_temp_avg = EMC2101_get_external_temp();
power_management->chip_temp_avg = GLOBAL_STATE->ASIC_initalized ? EMC2101_get_external_temp() : -1;

if ((power_management->chip_temp_avg > THROTTLE_TEMP) &&
(power_management->frequency_value > 50 || power_management->voltage > 1000)) {
Expand All @@ -178,7 +178,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
case DEVICE_SUPRA:

if (GLOBAL_STATE->board_version == 402) {
power_management->chip_temp_avg = EMC2101_get_external_temp();
power_management->chip_temp_avg = GLOBAL_STATE->ASIC_initalized ? EMC2101_get_external_temp() : -1;
power_management->vr_temp = (float)TPS546_get_temperature();
} else {
power_management->chip_temp_avg = EMC2101_get_internal_temp() + 5;
Expand Down Expand Up @@ -212,7 +212,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)

break;
case DEVICE_GAMMA:
power_management->chip_temp_avg = EMC2101_get_external_temp();
power_management->chip_temp_avg = GLOBAL_STATE->ASIC_initalized ? EMC2101_get_external_temp() : -1;
power_management->vr_temp = (float)TPS546_get_temperature();

// EMC2101 will give bad readings if the ASIC is turned off
Expand Down

0 comments on commit b700c6b

Please sign in to comment.