From dc4afcdbdec99b24fcfc9bad5f7adf35d5851a05 Mon Sep 17 00:00:00 2001 From: Erik Olof Gunnar Andersson Date: Sat, 9 Nov 2024 19:08:45 +0100 Subject: [PATCH] No need to wait for everything --- components/asic/bm1366.c | 32 +++++++++++++++--------------- components/asic/bm1368.c | 28 +++++++++++++------------- components/asic/bm1370.c | 34 ++++++++++++++++---------------- components/asic/bm1397.c | 34 ++++++++++++++++---------------- components/asic/include/serial.h | 2 +- components/asic/serial.c | 8 +++++--- 6 files changed, 70 insertions(+), 68 deletions(-) diff --git a/components/asic/bm1366.c b/components/asic/bm1366.c index 097db33dd..ff3e67d4e 100644 --- a/components/asic/bm1366.c +++ b/components/asic/bm1366.c @@ -67,7 +67,7 @@ static task_result result; /// @param header /// @param data /// @param len -static void _send_BM1366(uint8_t header, uint8_t * data, uint8_t data_len, bool debug) +static void _send_BM1366(uint8_t header, uint8_t * data, uint8_t data_len, bool debug, bool wait) { packet_type_t packet_type = (header & TYPE_JOB) ? JOB_PACKET : CMD_PACKET; uint8_t total_length = (packet_type == JOB_PACKET) ? (data_len + 6) : (data_len + 5); @@ -98,7 +98,7 @@ static void _send_BM1366(uint8_t header, uint8_t * data, uint8_t data_len, bool } // send serial data - SERIAL_send(buf, total_length, debug); + SERIAL_send(buf, total_length, debug, wait); free(buf); } @@ -107,7 +107,7 @@ static void _send_simple(uint8_t * data, uint8_t total_length) { unsigned char * buf = malloc(total_length); memcpy(buf, data, total_length); - SERIAL_send(buf, total_length, BM1366_SERIALTX_DEBUG); + SERIAL_send(buf, total_length, BM1366_SERIALTX_DEBUG, true); free(buf); } @@ -117,7 +117,7 @@ static void _send_chain_inactive(void) unsigned char read_address[2] = {0x00, 0x00}; // send serial data - _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, BM1366_SERIALTX_DEBUG, true); } static void _set_chip_address(uint8_t chipAddr) @@ -125,7 +125,7 @@ static void _set_chip_address(uint8_t chipAddr) unsigned char read_address[2] = {chipAddr, 0x00}; // send serial data - _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, BM1366_SERIALTX_DEBUG, true); } void BM1366_set_version_mask(uint32_t version_mask) @@ -134,7 +134,7 @@ void BM1366_set_version_mask(uint32_t version_mask) uint8_t version_byte0 = (versions_to_roll >> 8); uint8_t version_byte1 = (versions_to_roll & 0xFF); uint8_t version_cmd[] = {0x00, 0xA4, 0x90, 0x00, version_byte0, version_byte1}; - _send_BM1366(TYPE_CMD | GROUP_ALL | CMD_WRITE, version_cmd, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366(TYPE_CMD | GROUP_ALL | CMD_WRITE, version_cmd, 6, BM1366_SERIALTX_DEBUG, true); } void BM1366_send_hash_frequency(float target_freq) @@ -190,7 +190,7 @@ void BM1366_send_hash_frequency(float target_freq) } } - _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), freqbuf, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), freqbuf, 6, BM1366_SERIALTX_DEBUG, true); ESP_LOGI(TAG, "Setting Frequency to %.2fMHz (%.2f)", target_freq, newf); } @@ -474,15 +474,15 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count) for (uint8_t i = 0; i < chip_counter; i++) { unsigned char set_a8_register[6] = {i * address_interval, 0xA8, 0x00, 0x07, 0x01, 0xF0}; - _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_a8_register, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_a8_register, 6, BM1366_SERIALTX_DEBUG, true); unsigned char set_18_register[6] = {i * address_interval, 0x18, 0xF0, 0x00, 0xC1, 0x00}; - _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_18_register, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_18_register, 6, BM1366_SERIALTX_DEBUG, true); unsigned char set_3c_register_first[6] = {i * address_interval, 0x3C, 0x80, 0x00, 0x85, 0x40}; - _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_first, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_first, 6, BM1366_SERIALTX_DEBUG, true); unsigned char set_3c_register_second[6] = {i * address_interval, 0x3C, 0x80, 0x00, 0x80, 0x20}; - _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_second, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_second, 6, BM1366_SERIALTX_DEBUG, true); unsigned char set_3c_register_third[6] = {i * address_interval, 0x3C, 0x80, 0x00, 0x82, 0xAA}; - _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_third, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_third, 6, BM1366_SERIALTX_DEBUG, true); } do_frequency_ramp_up(); @@ -495,7 +495,7 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count) // unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x00, 0x14, 0x46}; //S19XP-Luxos Default unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x00, 0x15, 0x1C}; //S19XP-Stock Default // unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x0F, 0x00, 0x00}; //supposedly the "full" 32bit nonce range - _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), set_10_hash_counting, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), set_10_hash_counting, 6, BM1366_SERIALTX_DEBUG, true); unsigned char init795[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF, 0x1C}; _send_simple(init795, 11); @@ -547,7 +547,7 @@ int BM1366_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_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1366_SERIALTX_DEBUG, true); return 115749; } @@ -591,7 +591,7 @@ void BM1366_set_job_difficulty_mask(int difficulty) ESP_LOGI(TAG, "Setting job ASIC mask to %d", difficulty); - _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1366_SERIALTX_DEBUG); + _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1366_SERIALTX_DEBUG, true); } static uint8_t id = 0; @@ -627,7 +627,7 @@ void BM1366_send_work(void * pvParameters, bm_job * next_bm_job) ESP_LOGI(TAG, "Send Job: %02X", job.job_id); #endif - _send_BM1366((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1366_job), BM1366_DEBUG_WORK); + _send_BM1366((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1366_job), BM1366_DEBUG_WORK, false); } asic_result * BM1366_receive_work(void) diff --git a/components/asic/bm1368.c b/components/asic/bm1368.c index 12ec8c4a5..aef808706 100644 --- a/components/asic/bm1368.c +++ b/components/asic/bm1368.c @@ -63,7 +63,7 @@ static task_result result; static float current_frequency = 56.25; -static void _send_BM1368(uint8_t header, uint8_t * data, uint8_t data_len, bool debug) +static void _send_BM1368(uint8_t header, uint8_t * data, uint8_t data_len, bool debug, bool wait) { packet_type_t packet_type = (header & TYPE_JOB) ? JOB_PACKET : CMD_PACKET; uint8_t total_length = (packet_type == JOB_PACKET) ? (data_len + 6) : (data_len + 5); @@ -84,7 +84,7 @@ static void _send_BM1368(uint8_t header, uint8_t * data, uint8_t data_len, bool buf[4 + data_len] = crc5(buf + 2, data_len + 2); } - SERIAL_send(buf, total_length, debug); + SERIAL_send(buf, total_length, debug, wait); free(buf); } @@ -93,7 +93,7 @@ static void _send_simple(uint8_t * data, uint8_t total_length) { unsigned char * buf = malloc(total_length); memcpy(buf, data, total_length); - SERIAL_send(buf, total_length, BM1368_SERIALTX_DEBUG); + SERIAL_send(buf, total_length, BM1368_SERIALTX_DEBUG, true); free(buf); } @@ -101,13 +101,13 @@ static void _send_simple(uint8_t * data, uint8_t total_length) static void _send_chain_inactive(void) { unsigned char read_address[2] = {0x00, 0x00}; - _send_BM1368((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, BM1368_SERIALTX_DEBUG); + _send_BM1368((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, BM1368_SERIALTX_DEBUG, true); } static void _set_chip_address(uint8_t chipAddr) { unsigned char read_address[2] = {chipAddr, 0x00}; - _send_BM1368((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, BM1368_SERIALTX_DEBUG); + _send_BM1368((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, BM1368_SERIALTX_DEBUG, true); } void BM1368_set_version_mask(uint32_t version_mask) @@ -116,7 +116,7 @@ void BM1368_set_version_mask(uint32_t version_mask) uint8_t version_byte0 = (versions_to_roll >> 8); uint8_t version_byte1 = (versions_to_roll & 0xFF); uint8_t version_cmd[] = {0x00, 0xA4, 0x90, 0x00, version_byte0, version_byte1}; - _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_WRITE, version_cmd, 6, BM1368_SERIALTX_DEBUG); + _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_WRITE, version_cmd, 6, BM1368_SERIALTX_DEBUG, true); } static void _reset(void) @@ -171,7 +171,7 @@ bool BM1368_send_hash_frequency(float target_freq) { freqbuf[4] = best_refdiv; freqbuf[5] = (((best_postdiv1 - 1) & 0xf) << 4) | ((best_postdiv2 - 1) & 0xf); - _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_WRITE, freqbuf, sizeof(freqbuf), BM1368_SERIALTX_DEBUG); + _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_WRITE, freqbuf, sizeof(freqbuf), BM1368_SERIALTX_DEBUG, true); ESP_LOGI(TAG, "Setting Frequency to %.2fMHz (%.2f)", target_freq, best_freq); current_frequency = target_freq; @@ -212,7 +212,7 @@ bool BM1368_set_frequency(float target_freq) { } static int count_asic_chips(void) { - _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_READ, (uint8_t[]){0x00, 0x00}, 2, false); + _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_READ, (uint8_t[]){0x00, 0x00}, 2, false, true); int chip_counter = 0; while (true) { @@ -270,7 +270,7 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count) }; for (int i = 0; i < sizeof(init_cmds) / sizeof(init_cmds[0]); i++) { - _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_WRITE, init_cmds[i], 6, false); + _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_WRITE, init_cmds[i], 6, false, true); } uint8_t address_interval = (uint8_t) (256 / chip_counter); @@ -288,7 +288,7 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count) }; for (int j = 0; j < sizeof(chip_init_cmds) / sizeof(chip_init_cmds[0]); j++) { - _send_BM1368(TYPE_CMD | GROUP_SINGLE | CMD_WRITE, chip_init_cmds[j], 6, false); + _send_BM1368(TYPE_CMD | GROUP_SINGLE | CMD_WRITE, chip_init_cmds[j], 6, false, true); } vTaskDelay(pdMS_TO_TICKS(500)); } @@ -297,7 +297,7 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count) do_frequency_ramp_up((float)frequency); - _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_WRITE, (uint8_t[]){0x00, 0x10, 0x00, 0x00, 0x15, 0xa4}, 6, false); + _send_BM1368(TYPE_CMD | GROUP_ALL | CMD_WRITE, (uint8_t[]){0x00, 0x10, 0x00, 0x00, 0x15, 0xa4}, 6, false, true); BM1368_set_version_mask(STRATUM_DEFAULT_VERSION_MASK); ESP_LOGI(TAG, "%i chip(s) detected on the chain, expected %i", chip_counter, asic_count); @@ -307,7 +307,7 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count) int BM1368_set_default_baud(void) { unsigned char baudrate[9] = {0x00, MISC_CONTROL, 0x00, 0x00, 0b01111010, 0b00110001}; - _send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1368_SERIALTX_DEBUG); + _send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1368_SERIALTX_DEBUG, true); return 115749; } @@ -333,7 +333,7 @@ void BM1368_set_job_difficulty_mask(int difficulty) ESP_LOGI(TAG, "Setting job ASIC mask to %d", difficulty); - _send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1368_SERIALTX_DEBUG); + _send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1368_SERIALTX_DEBUG, true); } static uint8_t id = 0; @@ -367,7 +367,7 @@ void BM1368_send_work(void * pvParameters, bm_job * next_bm_job) ESP_LOGI(TAG, "Send Job: %02X", job.job_id); #endif - _send_BM1368((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1368_job), BM1368_DEBUG_WORK); + _send_BM1368((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1368_job), BM1368_DEBUG_WORK, false); } asic_result * BM1368_receive_work(void) diff --git a/components/asic/bm1370.c b/components/asic/bm1370.c index 7cf778046..1ac4699a9 100644 --- a/components/asic/bm1370.c +++ b/components/asic/bm1370.c @@ -69,7 +69,7 @@ static task_result result; /// @param header /// @param data /// @param len -static void _send_BM1370(uint8_t header, uint8_t * data, uint8_t data_len, bool debug) +static void _send_BM1370(uint8_t header, uint8_t * data, uint8_t data_len, bool debug, bool wait) { packet_type_t packet_type = (header & TYPE_JOB) ? JOB_PACKET : CMD_PACKET; uint8_t total_length = (packet_type == JOB_PACKET) ? (data_len + 6) : (data_len + 5); @@ -100,7 +100,7 @@ static void _send_BM1370(uint8_t header, uint8_t * data, uint8_t data_len, bool } // send serial data - if (SERIAL_send(buf, total_length, debug) != ESP_OK) { + if (SERIAL_send(buf, total_length, debug, wait) != ESP_OK) { ESP_LOGE(TAG, "Failed to send data to BM1370"); } @@ -111,7 +111,7 @@ static void _send_simple(uint8_t * data, uint8_t total_length) { unsigned char * buf = malloc(total_length); memcpy(buf, data, total_length); - SERIAL_send(buf, total_length, false); + SERIAL_send(buf, total_length, false, true); free(buf); } @@ -121,7 +121,7 @@ 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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, BM1370_SERIALTX_DEBUG, true); } static void _set_chip_address(uint8_t chipAddr) @@ -129,7 +129,7 @@ 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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, BM1370_SERIALTX_DEBUG, true); } void BM1370_set_version_mask(uint32_t version_mask) @@ -138,7 +138,7 @@ void BM1370_set_version_mask(uint32_t version_mask) uint8_t version_byte0 = (versions_to_roll >> 8); uint8_t version_byte1 = (versions_to_roll & 0xFF); uint8_t version_cmd[] = {0x00, 0xA4, 0x90, 0x00, version_byte0, version_byte1}; - _send_BM1370(TYPE_CMD | GROUP_ALL | CMD_WRITE, version_cmd, 6, BM1370_SERIALTX_DEBUG); + _send_BM1370(TYPE_CMD | GROUP_ALL | CMD_WRITE, version_cmd, 6, BM1370_SERIALTX_DEBUG, true); } void BM1370_send_hash_frequency(int id, float target_freq, float max_diff) { @@ -184,9 +184,9 @@ void BM1370_send_hash_frequency(int id, float target_freq, float max_diff) { if (id != -1) { freqbuf[0] = id * 2; - _send_BM1370(TYPE_CMD | GROUP_SINGLE | CMD_WRITE, freqbuf, 6, BM1370_SERIALTX_DEBUG); + _send_BM1370(TYPE_CMD | GROUP_SINGLE | CMD_WRITE, freqbuf, 6, BM1370_SERIALTX_DEBUG, true); } else { - _send_BM1370(TYPE_CMD | GROUP_ALL | CMD_WRITE, freqbuf, 6, BM1370_SERIALTX_DEBUG); + _send_BM1370(TYPE_CMD | GROUP_ALL | CMD_WRITE, freqbuf, 6, BM1370_SERIALTX_DEBUG, true); } ESP_LOGI(TAG, "Setting Frequency to %.2fMHz (%.2f)", target_freq, best_freq); @@ -283,20 +283,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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_a8_register, 6, BM1370_SERIALTX_DEBUG, true); //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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_18_register, 6, BM1370_SERIALTX_DEBUG, true); //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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_first, 6, BM1370_SERIALTX_DEBUG, true); //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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_second, 6, BM1370_SERIALTX_DEBUG, true); //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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_SINGLE | CMD_WRITE), set_3c_register_third, 6, BM1370_SERIALTX_DEBUG, true); } do_frequency_ramp_up(frequency); @@ -311,7 +311,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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), set_10_hash_counting, 6, BM1370_SERIALTX_DEBUG, true); return chip_counter; } @@ -360,7 +360,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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1370_SERIALTX_DEBUG, true); return 115749; } @@ -400,7 +400,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, BM1370_SERIALTX_DEBUG); + _send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1370_SERIALTX_DEBUG, true); } static uint8_t id = 0; @@ -436,7 +436,7 @@ void BM1370_send_work(void * pvParameters, bm_job * next_bm_job) ESP_LOGI(TAG, "Send Job: %02X", job.job_id); #endif - _send_BM1370((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1370_job), BM1370_DEBUG_WORK); + _send_BM1370((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1370_job), BM1370_DEBUG_WORK, false); } asic_result * BM1370_receive_work(void) diff --git a/components/asic/bm1397.c b/components/asic/bm1397.c index ae1001604..953aa2ac4 100644 --- a/components/asic/bm1397.c +++ b/components/asic/bm1397.c @@ -68,7 +68,7 @@ static task_result result; /// @param header /// @param data /// @param len -static void _send_BM1397(uint8_t header, uint8_t *data, uint8_t data_len, bool debug) +static void _send_BM1397(uint8_t header, uint8_t *data, uint8_t data_len, bool debug, bool wait) { packet_type_t packet_type = (header & TYPE_JOB) ? JOB_PACKET : CMD_PACKET; uint8_t total_length = (packet_type == JOB_PACKET) ? (data_len + 6) : (data_len + 5); @@ -102,7 +102,7 @@ static void _send_BM1397(uint8_t header, uint8_t *data, uint8_t data_len, bool d } // send serial data - SERIAL_send(buf, total_length, debug); + SERIAL_send(buf, total_length, debug, wait); free(buf); } @@ -111,7 +111,7 @@ static void _send_read_address(void) { unsigned char read_address[2] = {0x00, 0x00}; // send serial data - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, BM1937_SERIALTX_DEBUG, true); } static void _send_chain_inactive(void) @@ -119,7 +119,7 @@ static void _send_chain_inactive(void) unsigned char read_address[2] = {0x00, 0x00}; // send serial data - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_INACTIVE), read_address, 2, BM1937_SERIALTX_DEBUG, true); } static void _set_chip_address(uint8_t chipAddr) @@ -127,7 +127,7 @@ static void _set_chip_address(uint8_t chipAddr) unsigned char read_address[2] = {chipAddr, 0x00}; // send serial data - _send_BM1397((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_SINGLE | CMD_SETADDRESS), read_address, 2, BM1937_SERIALTX_DEBUG, true); } void BM1397_set_version_mask(uint32_t version_mask) { @@ -211,12 +211,12 @@ void BM1397_send_hash_frequency(float frequency) for (i = 0; i < 2; i++) { vTaskDelay(10 / portTICK_PERIOD_MS); - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), prefreq1, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), prefreq1, 6, BM1937_SERIALTX_DEBUG, true); } for (i = 0; i < 2; i++) { vTaskDelay(10 / portTICK_PERIOD_MS); - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), freqbuf, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), freqbuf, 6, BM1937_SERIALTX_DEBUG, true); } vTaskDelay(10 / portTICK_PERIOD_MS); @@ -249,24 +249,24 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count) } unsigned char init[6] = {0x00, CLOCK_ORDER_CONTROL_0, 0x00, 0x00, 0x00, 0x00}; // init1 - clock_order_control0 - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init, 6, BM1937_SERIALTX_DEBUG, true); unsigned char init2[6] = {0x00, CLOCK_ORDER_CONTROL_1, 0x00, 0x00, 0x00, 0x00}; // init2 - clock_order_control1 - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init2, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init2, 6, BM1937_SERIALTX_DEBUG, true); unsigned char init3[9] = {0x00, ORDERED_CLOCK_ENABLE, 0x00, 0x00, 0x00, 0x01}; // init3 - ordered_clock_enable - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init3, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init3, 6, BM1937_SERIALTX_DEBUG, true); unsigned char init4[9] = {0x00, CORE_REGISTER_CONTROL, 0x80, 0x00, 0x80, 0x74}; // init4 - init_4_? - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init4, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init4, 6, BM1937_SERIALTX_DEBUG, true); BM1397_set_job_difficulty_mask(BM1397_ASIC_DIFFICULTY); unsigned char init5[9] = {0x00, PLL3_PARAMETER, 0xC0, 0x70, 0x01, 0x11}; // init5 - pll3_parameter - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init5, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init5, 6, BM1937_SERIALTX_DEBUG, true); unsigned char init6[9] = {0x00, FAST_UART_CONFIGURATION, 0x06, 0x00, 0x00, 0x0F}; // init6 - fast_uart_configuration - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init6, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init6, 6, BM1937_SERIALTX_DEBUG, true); BM1397_set_default_baud(); @@ -311,7 +311,7 @@ int BM1397_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_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1937_SERIALTX_DEBUG, true); return 115749; } @@ -321,7 +321,7 @@ int BM1397_set_max_baud(void) ESP_LOGI(TAG, "Setting max baud of 3125000"); unsigned char baudrate[9] = {0x00, MISC_CONTROL, 0x00, 0x00, 0b01100000, 0b00110001}; ; // baudrate - misc_control - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, BM1937_SERIALTX_DEBUG, true); return 3125000; } @@ -351,7 +351,7 @@ void BM1397_set_job_difficulty_mask(int difficulty) ESP_LOGI(TAG, "Setting job ASIC mask to %d", difficulty); - _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1937_SERIALTX_DEBUG); + _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1937_SERIALTX_DEBUG, true); } static uint8_t id = 0; @@ -397,7 +397,7 @@ void BM1397_send_work(void *pvParameters, bm_job *next_bm_job) ESP_LOGI(TAG, "Send Job: %02X", job.job_id); #endif - _send_BM1397((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(job_packet), BM1397_DEBUG_WORK); + _send_BM1397((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(job_packet), BM1397_DEBUG_WORK, false); } asic_result *BM1397_receive_work(void) diff --git a/components/asic/include/serial.h b/components/asic/include/serial.h index 81d9b3447..d87189dc1 100644 --- a/components/asic/include/serial.h +++ b/components/asic/include/serial.h @@ -4,7 +4,7 @@ #define SERIAL_BUF_SIZE 16 #define CHUNK_SIZE 1024 -esp_err_t SERIAL_send(uint8_t *, int, bool); +esp_err_t SERIAL_send(uint8_t *, int, bool, bool); void SERIAL_init(void); void SERIAL_debug_rx(void); int16_t SERIAL_rx(uint8_t *, uint16_t, uint16_t); diff --git a/components/asic/serial.c b/components/asic/serial.c index 6c5bc3d28..05022b3cb 100644 --- a/components/asic/serial.c +++ b/components/asic/serial.c @@ -49,7 +49,7 @@ void SERIAL_set_baud(int baud) uart_set_baudrate(UART_NUM_1, baud); } -esp_err_t SERIAL_send(uint8_t *data, int len, bool debug) +esp_err_t SERIAL_send(uint8_t *data, int len, bool debug, bool wait) { int written = uart_write_bytes(UART_NUM_1, (const char *)data, len); @@ -64,8 +64,10 @@ esp_err_t SERIAL_send(uint8_t *data, int len, bool debug) return ESP_FAIL; } - if (uart_wait_tx_done(UART_NUM_1, 1000 / portTICK_PERIOD_MS) != ESP_OK) { - return ESP_FAIL; + if (wait) { + if (uart_wait_tx_done(UART_NUM_1, 1000 / portTICK_PERIOD_MS) != ESP_OK) { + return ESP_FAIL; + } } return ESP_OK;