mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-04-10 04:49:16 +02:00
WIP: Fix job interval timing (#249)
* add extended nonce debugging * switch to semaphore for job timing * clean up nonce debugging. hardcode 1366 job interval to 2s and show when new jobs are sent * set nonce range to 0x0F0000 set job interval to 20s. better stratum debugging, * testing out longer intervals on 1368 * looking at exact serial commands sent * fix log value digit count * add core from nonce debug * set BM1366 initial chip difficulty to 32 * add version rolling debug * improve debug printing again * fix diff * fix core_id extraction * printf fix * debug cleanup * setup BM1368 for testing. reg10 to S21 default, job interval @ 0.5s * set init diff on 1366 and 1368 back to 256 --------- Co-authored-by: Georges Palauqui <g.palauqui@gptechinno.com>
This commit is contained in:
parent
248df91543
commit
04c8b80287
@ -96,7 +96,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, BM1366_DEBUG_CHIP_SERIAL);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
@ -105,7 +105,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, BM1366_DEBUG_CHIP_SERIAL);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
@ -402,38 +402,6 @@ static void do_frequency_ramp_up()
|
||||
static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
|
||||
{
|
||||
|
||||
// //send serial data
|
||||
// vTaskDelay(SLEEP_TIME / portTICK_PERIOD_MS);
|
||||
|
||||
// unsigned char init[6] = { 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF};
|
||||
|
||||
// _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), init, 6, true);
|
||||
|
||||
// unsigned char init18[7] = { 0x55, 0xAA, 0x52, 0x05, 0x00, 0x00, 0x0A };
|
||||
// _send_simple(init18, 7);
|
||||
|
||||
// unsigned char init2[6] = { 0x00, 0xA8, 0x00, 0x07, 0x00, 0x00};
|
||||
// _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), init2, 6, true);
|
||||
|
||||
// unsigned char init3[6] = { 0x00, 0x18, 0xFF, 0x0F, 0xC1, 0x00 };
|
||||
// _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), init3, 6, true);
|
||||
|
||||
// _send_chain_inactive();
|
||||
// // unsigned char init4[7] = { 0x55, 0xAA, 0x53, 0x05, 0x00, 0x00, 0x03 };
|
||||
// // _send_simple(init4, 7);
|
||||
|
||||
// unsigned char init5[7] = { 0x55, 0xAA, 0x40, 0x05, 0x00, 0x00, 0x1C };
|
||||
// _send_simple(init5, 7);
|
||||
|
||||
// unsigned char init6[6] = { 0x00, 0x3C, 0x80, 0x00, 0x85, 0x40 };
|
||||
// _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), init6, 6, true);
|
||||
|
||||
// unsigned char init7[6] = { 0x00, 0x3C, 0x80, 0x00, 0x80, 0x20};
|
||||
// _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), init7, 6, true);
|
||||
|
||||
// unsigned char init17[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF, 0x1C};
|
||||
// _send_simple(init17, 11);
|
||||
|
||||
unsigned char init0[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF, 0x1C};
|
||||
_send_simple(init0, 11);
|
||||
|
||||
@ -481,8 +449,9 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
|
||||
unsigned char init136[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x3C, 0x80, 0x00, 0x80, 0x20, 0x19};
|
||||
_send_simple(init136, 11);
|
||||
|
||||
unsigned char init137[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08};
|
||||
_send_simple(init137, 11);
|
||||
// unsigned char init137[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08};
|
||||
// _send_simple(init137, 11);
|
||||
BM1366_set_job_difficulty_mask(BM1366_INITIAL_DIFFICULTY);
|
||||
|
||||
unsigned char init138[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x1D};
|
||||
_send_simple(init138, 11);
|
||||
@ -513,8 +482,13 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
|
||||
|
||||
BM1366_send_hash_frequency(frequency);
|
||||
|
||||
unsigned char init794[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x10, 0x00, 0x00, 0x15, 0x1C, 0x02};
|
||||
_send_simple(init794, 11);
|
||||
//register 10 is still a bit of a mystery. discussion: https://github.com/skot/ESP-Miner/pull/167
|
||||
|
||||
// unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x00, 0x11, 0x5A}; //S19k Pro Default
|
||||
// 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, false);
|
||||
|
||||
unsigned char init795[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF, 0x1C};
|
||||
_send_simple(init795, 11);
|
||||
@ -573,21 +547,20 @@ int BM1366_set_default_baud(void)
|
||||
int BM1366_set_max_baud(void)
|
||||
{
|
||||
|
||||
/// return 115749;
|
||||
|
||||
// divider of 0 for 3,125,000
|
||||
ESP_LOGI(TAG, "Setting max baud of 1000000 ");
|
||||
|
||||
unsigned char init8[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x28, 0x11, 0x30, 0x02, 0x00, 0x03};
|
||||
_send_simple(init8, 11);
|
||||
return 1000000;
|
||||
|
||||
// // divider of 0 for 3,125,000
|
||||
// ESP_LOGI(TAG, "Setting max baud of 1000000 ");
|
||||
|
||||
// unsigned char init8[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x28, 0x11, 0x30, 0x02, 0x00, 0x03};
|
||||
// _send_simple(init8, 11);
|
||||
// return 1000000;
|
||||
}
|
||||
|
||||
void BM1366_set_job_difficulty_mask(int difficulty)
|
||||
{
|
||||
|
||||
return;
|
||||
|
||||
// Default mask of 256 diff
|
||||
unsigned char job_difficulty_mask[9] = {0x00, TICKET_MASK, 0b00000000, 0b00000000, 0b00000000, 0b11111111};
|
||||
|
||||
@ -640,7 +613,9 @@ 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;
|
||||
// ESP_LOGI(TAG, "Added Job: %i", job.job_id);
|
||||
|
||||
//debug sent jobs - this can get crazy if the interval is short
|
||||
//ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
|
||||
pthread_mutex_unlock(&GLOBAL_STATE->valid_jobs_lock);
|
||||
|
||||
_send_BM1366((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1366_job), false);
|
||||
@ -673,6 +648,14 @@ static uint16_t reverse_uint16(uint16_t num)
|
||||
return (num >> 8) | (num << 8);
|
||||
}
|
||||
|
||||
static uint32_t reverse_uint32(uint32_t val)
|
||||
{
|
||||
return ((val >> 24) & 0xff) | // Move byte 3 to byte 0
|
||||
((val << 8) & 0xff0000) | // Move byte 1 to byte 2
|
||||
((val >> 8) & 0xff00) | // Move byte 2 to byte 1
|
||||
((val << 24) & 0xff000000); // Move byte 0 to byte 3
|
||||
}
|
||||
|
||||
task_result * BM1366_proccess_work(void * pvParameters)
|
||||
{
|
||||
|
||||
@ -682,23 +665,22 @@ task_result * BM1366_proccess_work(void * pvParameters)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t job_id = asic_result->job_id;
|
||||
uint8_t rx_job_id = job_id & 0xf8;
|
||||
ESP_LOGI(TAG, "Job ID: %02X, RX: %02X", job_id, rx_job_id);
|
||||
uint8_t job_id = asic_result->job_id & 0xf8;
|
||||
uint8_t core_id = (uint8_t)((reverse_uint32(asic_result->nonce) >> 25) & 0x7f); // BM1366 has 112 cores, so it should be coded on 7 bits
|
||||
uint8_t small_core_id = asic_result->job_id & 0x07; // BM1366 has 8 small cores, so it should be coded on 3 bits
|
||||
uint32_t version_bits = (reverse_uint16(asic_result->version) << 13); // shift the 16 bit value left 13
|
||||
ESP_LOGI(TAG, "Job ID: %02X, Core: %d/%d, Ver: %08" PRIX32, job_id, core_id, small_core_id, version_bits);
|
||||
|
||||
GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;
|
||||
|
||||
if (GLOBAL_STATE->valid_jobs[rx_job_id] == 0) {
|
||||
ESP_LOGE(TAG, "Invalid job nonce found, id=%d", rx_job_id);
|
||||
if (GLOBAL_STATE->valid_jobs[job_id] == 0) {
|
||||
ESP_LOGE(TAG, "Invalid job found, 0x%02X", job_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t rolled_version = GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[rx_job_id]->version;
|
||||
uint32_t rolled_version = GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->version | version_bits;
|
||||
|
||||
// // // shift the 16 bit value left 13
|
||||
rolled_version = (reverse_uint16(asic_result->version) << 13) | rolled_version;
|
||||
|
||||
result.job_id = rx_job_id;
|
||||
result.job_id = job_id;
|
||||
result.nonce = asic_result->nonce;
|
||||
result.rolled_version = rolled_version;
|
||||
|
||||
|
@ -363,6 +363,15 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
|
||||
|
||||
BM1368_send_hash_frequency(frequency);
|
||||
|
||||
//register 10 is still a bit of a mystery. discussion: https://github.com/skot/ESP-Miner/pull/167
|
||||
|
||||
// unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x00, 0x11, 0x5A}; //S19k Pro Default
|
||||
// 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, 0x00, 0x15, 0xA4}; //S21-Stock Default
|
||||
// unsigned char set_10_hash_counting[6] = {0x00, 0x10, 0x00, 0x0F, 0x00, 0x00}; //supposedly the "full" 32bit nonce range
|
||||
_send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), set_10_hash_counting, 6, false);
|
||||
|
||||
return chip_counter;
|
||||
}
|
||||
|
||||
@ -482,7 +491,7 @@ 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;
|
||||
// ESP_LOGI(TAG, "Added Job: %i", job.job_id);
|
||||
//ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
|
||||
pthread_mutex_unlock(&GLOBAL_STATE->valid_jobs_lock);
|
||||
|
||||
_send_BM1368((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1368_job), false);
|
||||
@ -515,6 +524,14 @@ static uint16_t reverse_uint16(uint16_t num)
|
||||
return (num >> 8) | (num << 8);
|
||||
}
|
||||
|
||||
static uint32_t reverse_uint32(uint32_t val)
|
||||
{
|
||||
return ((val >> 24) & 0xff) | // Move byte 3 to byte 0
|
||||
((val << 8) & 0xff0000) | // Move byte 1 to byte 2
|
||||
((val >> 8) & 0xff00) | // Move byte 2 to byte 1
|
||||
((val << 24) & 0xff000000); // Move byte 0 to byte 3
|
||||
}
|
||||
|
||||
task_result * BM1368_proccess_work(void * pvParameters)
|
||||
{
|
||||
|
||||
@ -524,23 +541,29 @@ task_result * BM1368_proccess_work(void * pvParameters)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t job_id = asic_result->job_id;
|
||||
uint8_t rx_job_id = ((int8_t)job_id & 0xf0) >> 1;
|
||||
ESP_LOGI(TAG, "Job ID: %02X, RX: %02X", job_id, rx_job_id);
|
||||
// uint8_t job_id = asic_result->job_id;
|
||||
// uint8_t rx_job_id = ((int8_t)job_id & 0xf0) >> 1;
|
||||
// ESP_LOGI(TAG, "Job ID: %02X, RX: %02X", job_id, rx_job_id);
|
||||
|
||||
// uint8_t job_id = asic_result->job_id & 0xf8;
|
||||
// ESP_LOGI(TAG, "Job ID: %02X, Core: %01X", job_id, asic_result->job_id & 0x07);
|
||||
|
||||
uint8_t job_id = (asic_result->job_id & 0xf0) >> 1;
|
||||
uint8_t core_id = (uint8_t)((reverse_uint32(asic_result->nonce) >> 25) & 0x7f); // BM1368 has 80 cores, so it should be coded on 7 bits
|
||||
uint8_t small_core_id = asic_result->job_id & 0x0f; // BM1368 has 16 small cores, so it should be coded on 4 bits
|
||||
uint32_t version_bits = (reverse_uint16(asic_result->version) << 13); // shift the 16 bit value left 13
|
||||
ESP_LOGI(TAG, "Job ID: %02X, Core: %d/%d, Ver: %08" PRIX32, job_id, core_id, small_core_id, version_bits);
|
||||
|
||||
GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;
|
||||
|
||||
if (GLOBAL_STATE->valid_jobs[rx_job_id] == 0) {
|
||||
ESP_LOGE(TAG, "Invalid job nonce found, 0x%02X", rx_job_id);
|
||||
if (GLOBAL_STATE->valid_jobs[job_id] == 0) {
|
||||
ESP_LOGE(TAG, "Invalid job nonce found, 0x%02X", job_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t rolled_version = GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[rx_job_id]->version;
|
||||
uint32_t rolled_version = GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->version | version_bits;
|
||||
|
||||
// // // shift the 16 bit value left 13
|
||||
rolled_version = (reverse_uint16(asic_result->version) << 13) | rolled_version;
|
||||
|
||||
result.job_id = rx_job_id;
|
||||
result.job_id = job_id;
|
||||
result.nonce = asic_result->nonce;
|
||||
result.rolled_version = rolled_version;
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
#define CRC5_MASK 0x1F
|
||||
#define BM1366_INITIAL_DIFFICULTY 256
|
||||
|
||||
#define BM1366_DEBUG_CHIP_SERIAL false
|
||||
|
||||
static const uint64_t BM1366_CORE_COUNT = 112;
|
||||
static const uint64_t BM1366_SMALL_CORE_COUNT = 894;
|
||||
|
||||
|
@ -356,7 +356,7 @@ void STRATUM_V1_configure_version_rolling(int socket, uint32_t * version_mask)
|
||||
"{\"id\": %d, \"method\": \"mining.configure\", \"params\": [[\"version-rolling\"], {\"version-rolling.mask\": "
|
||||
"\"ffffffff\"}]}\n",
|
||||
send_uid++);
|
||||
ESP_LOGI(TAG, "tx: %s", configure_msg);
|
||||
debug_stratum_tx(configure_msg);
|
||||
write(socket, configure_msg, strlen(configure_msg));
|
||||
|
||||
return;
|
||||
@ -364,5 +364,15 @@ void STRATUM_V1_configure_version_rolling(int socket, uint32_t * version_mask)
|
||||
|
||||
static void debug_stratum_tx(const char * msg)
|
||||
{
|
||||
//remove the trailing newline
|
||||
char * newline = strchr(msg, '\n');
|
||||
if (newline != NULL) {
|
||||
*newline = '\0';
|
||||
}
|
||||
ESP_LOGI(TAG, "tx: %s", msg);
|
||||
|
||||
//put it back!
|
||||
if (newline != NULL) {
|
||||
*newline = '\n';
|
||||
}
|
||||
}
|
||||
|
16
main/main.c
16
main/main.c
@ -19,11 +19,12 @@
|
||||
|
||||
static GlobalState GLOBAL_STATE = {.extranonce_str = NULL, .extranonce_2_len = 0, .abandon_work = 0, .version_mask = 0};
|
||||
|
||||
static const char * TAG = "miner";
|
||||
static const char * TAG = "bitaxe";
|
||||
static const double NONCE_SPACE = 4294967296.0; // 2^32
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Welcome to the bitaxe - hack the planet!");
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
|
||||
GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY);
|
||||
@ -59,31 +60,33 @@ void app_main(void)
|
||||
|
||||
GLOBAL_STATE.asic_model_str = nvs_config_get_string(NVS_CONFIG_ASIC_MODEL, "");
|
||||
if (strcmp(GLOBAL_STATE.asic_model_str, "BM1366") == 0) {
|
||||
ESP_LOGI(TAG, "ASIC: BM1366");
|
||||
ESP_LOGI(TAG, "ASIC: %dx BM1366 (%" PRIu64 " cores)", GLOBAL_STATE.asic_count, BM1366_CORE_COUNT);
|
||||
GLOBAL_STATE.asic_model = ASIC_BM1366;
|
||||
AsicFunctions ASIC_functions = {.init_fn = BM1366_init,
|
||||
.receive_result_fn = BM1366_proccess_work,
|
||||
.set_max_baud_fn = BM1366_set_max_baud,
|
||||
.set_difficulty_mask_fn = BM1366_set_job_difficulty_mask,
|
||||
.send_work_fn = BM1366_send_work};
|
||||
GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1366_SMALL_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space
|
||||
//GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1366_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space
|
||||
GLOBAL_STATE.asic_job_frequency_ms = 2000; //ms
|
||||
GLOBAL_STATE.initial_ASIC_difficulty = BM1366_INITIAL_DIFFICULTY;
|
||||
|
||||
GLOBAL_STATE.ASIC_functions = ASIC_functions;
|
||||
} else if (strcmp(GLOBAL_STATE.asic_model_str, "BM1368") == 0) {
|
||||
ESP_LOGI(TAG, "ASIC: BM1368");
|
||||
ESP_LOGI(TAG, "ASIC: %dx BM1368 (%" PRIu64 " cores)", GLOBAL_STATE.asic_count, BM1368_CORE_COUNT);
|
||||
GLOBAL_STATE.asic_model = ASIC_BM1368;
|
||||
AsicFunctions ASIC_functions = {.init_fn = BM1368_init,
|
||||
.receive_result_fn = BM1368_proccess_work,
|
||||
.set_max_baud_fn = BM1368_set_max_baud,
|
||||
.set_difficulty_mask_fn = BM1368_set_job_difficulty_mask,
|
||||
.send_work_fn = BM1368_send_work};
|
||||
GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1368_SMALL_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space
|
||||
//GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1368_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space
|
||||
GLOBAL_STATE.asic_job_frequency_ms = 500; //ms
|
||||
GLOBAL_STATE.initial_ASIC_difficulty = BM1368_INITIAL_DIFFICULTY;
|
||||
|
||||
GLOBAL_STATE.ASIC_functions = ASIC_functions;
|
||||
} else if (strcmp(GLOBAL_STATE.asic_model_str, "BM1397") == 0) {
|
||||
ESP_LOGI(TAG, "ASIC: BM1397");
|
||||
ESP_LOGI(TAG, "ASIC: %dx BM1397 (%" PRIu64 " cores)", GLOBAL_STATE.asic_count, BM1397_SMALL_CORE_COUNT);
|
||||
GLOBAL_STATE.asic_model = ASIC_BM1397;
|
||||
AsicFunctions ASIC_functions = {.init_fn = BM1397_init,
|
||||
.receive_result_fn = BM1397_proccess_work,
|
||||
@ -115,7 +118,6 @@ void app_main(void)
|
||||
|
||||
xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void *) &GLOBAL_STATE, 3, NULL);
|
||||
xTaskCreate(POWER_MANAGEMENT_task, "power mangement", 8192, (void *) &GLOBAL_STATE, 10, NULL);
|
||||
ESP_LOGI(TAG, "Welcome to the bitaxe!");
|
||||
|
||||
// pull the wifi credentials and hostname out of NVS
|
||||
char * wifi_ssid = nvs_config_get_string(NVS_CONFIG_WIFI_SSID, WIFI_SSID);
|
||||
|
@ -29,7 +29,7 @@ void ASIC_result_task(void *pvParameters)
|
||||
|
||||
if (GLOBAL_STATE->valid_jobs[job_id] == 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "Invalid job nonce found, id=%d", job_id);
|
||||
ESP_LOGI(TAG, "Invalid job nonce found, 0x%02X", job_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -39,7 +39,8 @@ void ASIC_result_task(void *pvParameters)
|
||||
asic_result->nonce,
|
||||
asic_result->rolled_version);
|
||||
|
||||
ESP_LOGI(TAG, "Nonce difficulty %.2f of %ld.", nonce_diff, GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->pool_diff);
|
||||
//log the ASIC response
|
||||
ESP_LOGI(TAG, "Ver: %08" PRIX32 " Nonce %08" PRIX32 " diff %.1f of %ld.", asic_result->rolled_version, asic_result->nonce, nonce_diff, GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->pool_diff);
|
||||
|
||||
if (nonce_diff > GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->pool_diff)
|
||||
{
|
||||
|
@ -14,20 +14,23 @@ static const char *TAG = "ASIC_task";
|
||||
|
||||
void ASIC_task(void *pvParameters)
|
||||
{
|
||||
|
||||
GlobalState *GLOBAL_STATE = (GlobalState *)pvParameters;
|
||||
|
||||
//initialize the semaphore
|
||||
GLOBAL_STATE->ASIC_TASK_MODULE.semaphore = xSemaphoreCreateBinary();
|
||||
|
||||
GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs = malloc(sizeof(bm_job *) * 128);
|
||||
GLOBAL_STATE->valid_jobs = malloc(sizeof(uint8_t) * 128);
|
||||
for (int i = 0; i < 128; i++)
|
||||
{
|
||||
|
||||
GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[i] = NULL;
|
||||
GLOBAL_STATE->valid_jobs[i] = 0;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "ASIC Job Interval: %.2f ms", GLOBAL_STATE->asic_job_frequency_ms);
|
||||
SYSTEM_notify_mining_started(GLOBAL_STATE);
|
||||
ESP_LOGI(TAG, "ASIC Ready!");
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
@ -36,13 +39,14 @@ void ASIC_task(void *pvParameters)
|
||||
if (next_bm_job->pool_diff != GLOBAL_STATE->stratum_difficulty)
|
||||
{
|
||||
ESP_LOGI(TAG, "New pool difficulty %lu", next_bm_job->pool_diff);
|
||||
//(*GLOBAL_STATE->ASIC_functions.set_difficulty_mask_fn)(next_bm_job->pool_diff);
|
||||
GLOBAL_STATE->stratum_difficulty = next_bm_job->pool_diff;
|
||||
}
|
||||
|
||||
(*GLOBAL_STATE->ASIC_functions.send_work_fn)(GLOBAL_STATE, next_bm_job); // send the job to the ASIC
|
||||
|
||||
// Time to execute the above code is ~0.3ms
|
||||
vTaskDelay((GLOBAL_STATE->asic_job_frequency_ms - 0.3) / portTICK_PERIOD_MS);
|
||||
// Delay for ASIC(s) to finish the job
|
||||
//vTaskDelay((GLOBAL_STATE->asic_job_frequency_ms - 0.3) / portTICK_PERIOD_MS);
|
||||
xSemaphoreTake(GLOBAL_STATE->ASIC_TASK_MODULE.semaphore, (GLOBAL_STATE->asic_job_frequency_ms / portTICK_PERIOD_MS));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef ASIC_TASK_H_
|
||||
#define ASIC_TASK_H_
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "mining.h"
|
||||
typedef struct
|
||||
{
|
||||
@ -8,6 +9,8 @@ typedef struct
|
||||
// it also may return a previous nonce under some circumstances
|
||||
// so we keep a list of jobs indexed by the job id
|
||||
bm_job **active_jobs;
|
||||
//semaphone
|
||||
SemaphoreHandle_t semaphore;
|
||||
} AsicTaskModule;
|
||||
|
||||
void ASIC_task(void *pvParameters);
|
||||
|
@ -48,6 +48,7 @@ void create_jobs_task(void *pvParameters)
|
||||
{
|
||||
GLOBAL_STATE->abandon_work = 0;
|
||||
ASIC_jobs_queue_clear(&GLOBAL_STATE->ASIC_jobs_queue);
|
||||
xSemaphoreGive(GLOBAL_STATE->ASIC_TASK_MODULE.semaphore);
|
||||
}
|
||||
|
||||
STRATUM_V1_free_mining_notify(mining_notification);
|
||||
|
@ -171,8 +171,7 @@ void stratum_task(void * pvParameters)
|
||||
SYSTEM_notify_new_ntime(GLOBAL_STATE, stratum_api_v1_message.mining_notification->ntime);
|
||||
if (stratum_api_v1_message.should_abandon_work &&
|
||||
(GLOBAL_STATE->stratum_queue.count > 0 || GLOBAL_STATE->ASIC_jobs_queue.count > 0)) {
|
||||
ESP_LOGI(TAG, "abandoning work");
|
||||
|
||||
ESP_LOGI(TAG, "Clean Jobs: clearing queue");
|
||||
GLOBAL_STATE->abandon_work = 1;
|
||||
queue_clear(&GLOBAL_STATE->stratum_queue);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user