Skip to content

Commit

Permalink
update system hashrate on every chip share, not just pool shares. (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
skot authored Jun 2, 2024
1 parent 11c1d08 commit 4bda726
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
11 changes: 5 additions & 6 deletions components/bm1397/bm1368.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ static uint8_t _send_init(uint64_t frequency)
_send_simple(init10, 11);

//set ticket mask
unsigned char init11[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08};
_send_simple(init11, 11);
// unsigned char init11[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08};
// _send_simple(init11, 11);
BM1368_set_job_difficulty_mask(BM1368_INITIAL_DIFFICULTY);

//Analog Mux Control
unsigned char init12[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x1D};
Expand Down Expand Up @@ -426,11 +427,9 @@ int BM1368_set_max_baud(void)
return 1000000;
}


void BM1368_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};

Expand All @@ -452,7 +451,7 @@ void BM1368_set_job_difficulty_mask(int difficulty)
job_difficulty_mask[5 - i] = _reverse_bits(value);
}

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

_send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, false);
}
Expand Down
1 change: 1 addition & 0 deletions components/bm1397/include/bm1366.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "mining.h"

#define CRC5_MASK 0x1F
#define BM1366_INITIAL_DIFFICULTY 256

// static const uint64_t BM1366_FREQUENCY = CONFIG_ASIC_FREQUENCY;
static const uint64_t BM1366_CORE_COUNT = 672;
Expand Down
2 changes: 2 additions & 0 deletions components/bm1397/include/bm1368.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#define CRC5_MASK 0x1F

#define BM1368_INITIAL_DIFFICULTY 256

// static const uint64_t BM1368_FREQUENCY = CONFIG_ASIC_FREQUENCY;
static const uint64_t BM1368_CORE_COUNT = 672;
// static const uint64_t BM1368_HASHRATE_S = BM1368_FREQUENCY * BM1368_CORE_COUNT * 1000000;
Expand Down
1 change: 1 addition & 0 deletions components/bm1397/include/bm1397.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "mining.h"

#define CRC5_MASK 0x1F
#define BM1397_INITIAL_DIFFICULTY 256

// static const uint64_t ASIC_FREQUENCY = CONFIG_ASIC_FREQUENCY;
static const uint64_t BM1397_CORE_COUNT = 672;
Expand Down
1 change: 1 addition & 0 deletions main/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct
char * asic_model;
AsicFunctions ASIC_functions;
double asic_job_frequency_ms;
uint32_t initial_ASIC_difficulty;

work_queue stratum_queue;
work_queue ASIC_jobs_queue;
Expand Down
3 changes: 3 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void app_main(void)
.set_difficulty_mask_fn = BM1366_set_job_difficulty_mask,
.send_work_fn = BM1366_send_work};
GLOBAL_STATE.asic_job_frequency_ms = BM1366_FULLSCAN_MS;
GLOBAL_STATE.initial_ASIC_difficulty = BM1366_INITIAL_DIFFICULTY;

GLOBAL_STATE.ASIC_functions = ASIC_functions;
} else if (strcmp(GLOBAL_STATE.asic_model, "BM1368") == 0) {
Expand All @@ -49,6 +50,7 @@ void app_main(void)

uint64_t bm1368_hashrate = GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1368_CORE_COUNT * 1000000;
GLOBAL_STATE.asic_job_frequency_ms = ((double) NONCE_SPACE / (double) bm1368_hashrate) * 1000;
GLOBAL_STATE.initial_ASIC_difficulty = BM1368_INITIAL_DIFFICULTY;

GLOBAL_STATE.ASIC_functions = ASIC_functions;
} else if (strcmp(GLOBAL_STATE.asic_model, "BM1397") == 0) {
Expand All @@ -61,6 +63,7 @@ void app_main(void)

uint64_t bm1397_hashrate = GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1397_CORE_COUNT * 1000000;
GLOBAL_STATE.asic_job_frequency_ms = ((double) NONCE_SPACE / (double) bm1397_hashrate) * 1000;
GLOBAL_STATE.initial_ASIC_difficulty = BM1397_INITIAL_DIFFICULTY;

GLOBAL_STATE.ASIC_functions = ASIC_functions;
} else {
Expand Down
1 change: 0 additions & 1 deletion main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ void SYSTEM_notify_new_ntime(SystemModule * module, uint32_t ntime)
void SYSTEM_notify_found_nonce(SystemModule * module, double pool_diff, double found_diff, uint32_t nbits, float power)
{
// Calculate the time difference in seconds with sub-second precision

// hashrate = (nonce_difficulty * 2^32) / time_to_find

module->historical_hashrate[module->historical_hashrate_rolling_index] = pool_diff;
Expand Down
7 changes: 4 additions & 3 deletions main/tasks/asic_result_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ void ASIC_result_task(void *pvParameters)
asic_result->nonce,
asic_result->rolled_version ^ GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->version);

SYSTEM_notify_found_nonce(&GLOBAL_STATE->SYSTEM_MODULE, GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->pool_diff,
nonce_diff, GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->target,
GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power);
}

SYSTEM_notify_found_nonce(&GLOBAL_STATE->SYSTEM_MODULE, GLOBAL_STATE->initial_ASIC_difficulty,
nonce_diff, GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->target,
GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power);
}
}
4 changes: 2 additions & 2 deletions main/tasks/asic_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void ASIC_task(void *pvParameters)

if (next_bm_job->pool_diff != GLOBAL_STATE->stratum_difficulty)
{
// ESP_LOGI(TAG, "New difficulty %d", next_bm_job->pool_diff);
(*GLOBAL_STATE->ASIC_functions.set_difficulty_mask_fn)(next_bm_job->pool_diff);
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;
}

Expand Down

0 comments on commit 4bda726

Please sign in to comment.