Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1890249
splitt modules
KillerInk Jul 11, 2025
219eff0
switch back to float
KillerInk Jul 12, 2025
d75028c
move extern declaration to their matching structs. remove pvParameter…
KillerInk Jul 12, 2025
c1a6fbb
drop global_state from asics
KillerInk Jul 12, 2025
2fc179a
drop powermanagment module from asic
KillerInk Jul 13, 2025
31f9d47
drop device_config from asic
KillerInk Jul 13, 2025
5503d3c
init asic befor powermanagment task start
KillerInk Jul 13, 2025
670c1b9
init all asic methods after device info got loaded
KillerInk Jul 13, 2025
21c382b
add system_module.h
KillerInk Jul 13, 2025
9216487
add self_test_module.h
KillerInk Jul 13, 2025
1295e6b
move RejectedReasonStat to system_module
KillerInk Jul 14, 2025
3ee37c8
Merge branch 'master' into splitt-module
KillerInk Jul 14, 2025
966bf4a
add mining_module
KillerInk Jul 14, 2025
d850103
clean global_state
KillerInk Jul 14, 2025
f510865
drop global_state.h
KillerInk Jul 14, 2025
3673a92
add power_management_module
KillerInk Jul 14, 2025
6e78323
clean thermal
KillerInk Jul 14, 2025
c0bd0df
clean main includes
KillerInk Jul 14, 2025
1264288
clean some includes
KillerInk Jul 14, 2025
b134797
add state pool and wifi module
KillerInk Jul 14, 2025
f792bdb
remove not needed include
KillerInk Jul 14, 2025
4856272
move asic_task_module into own file
KillerInk Jul 14, 2025
e097540
Merge remote-tracking branch 'origin/master' into splitt-module2
KillerInk Jul 16, 2025
a91bdc2
Merge remote-tracking branch 'killerink/master' into splitt-module2
KillerInk Jul 17, 2025
bb5856a
add back new_stratum_version_rolling_msg
KillerInk Jul 17, 2025
efb7668
Merge branch 'master' into splitt-module
KillerInk Jul 18, 2025
802a2bf
Merge branch 'master' into splitt-module
KillerInk Jul 26, 2025
9911a6b
Merge branch 'master' into splitt-module
KillerInk Jul 28, 2025
caa8a31
revert asic.c changes
KillerInk Jul 30, 2025
3a9ad31
remove thermal changes and whitespace
KillerInk Jul 30, 2025
aa0c51c
remove pragma once
KillerInk Jul 30, 2025
2f6aa1f
clean power_management_task
KillerInk Jul 30, 2025
47466c5
selftest fix
KillerInk Jul 30, 2025
be10716
clean screen
KillerInk Jul 30, 2025
757242c
remove should_test, remove NULL
KillerInk Jul 30, 2025
14ef7f1
move duration_start historical_hashrate_rolling_index historical_hash…
KillerInk Jul 30, 2025
be11cdb
lastClockSync sync can get used local
KillerInk Jul 30, 2025
272741a
best_nonce_diff can get used local
KillerInk Jul 30, 2025
773f540
make stratum uid and sock local
KillerInk Jul 30, 2025
ce7f0f9
Merge remote-tracking branch 'killerink/master' into splitt-module2
KillerInk Aug 5, 2025
31c47fd
Merge remote-tracking branch 'origin/master' into splitt-module
KillerInk Aug 17, 2025
452734e
Merge remote-tracking branch 'killerink/master' into splitt-module2
KillerInk Sep 17, 2025
cfb69ea
Merge remote-tracking branch 'killerink/splitt-module' into splitt-mo…
KillerInk Sep 17, 2025
a123edb
pool switch refactor mvp
0xf0xx0 Sep 16, 2025
1fc209b
ok mvp done
0xf0xx0 Sep 17, 2025
857a40b
forgot to cherry-pick the pool array size constant lol
0xf0xx0 Sep 17, 2025
378bd14
Merge pull request #2 from 0xf0xx0/splitt-module
KillerInk Sep 19, 2025
62d88da
fix build error
0xf0xx0 Sep 19, 2025
5f3d3b0
Merge pull request #3 from 0xf0xx0/splitt-module
KillerInk Sep 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 30 additions & 32 deletions components/asic/asic.c
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
#include <string.h>

#include <esp_log.h>

#include "bm1397.h"
#include "bm1366.h"
#include "bm1368.h"
#include "bm1370.h"

#include "asic.h"
#include "device_config.h"
#include "power_management_task.h"

static const double NONCE_SPACE = 4294967296.0; // 2^32

static const char *TAG = "asic";

uint8_t ASIC_init(GlobalState * GLOBAL_STATE)
uint8_t ASIC_init()
{
ESP_LOGI(TAG, "Initializing %s", GLOBAL_STATE->DEVICE_CONFIG.family.asic.name);
ESP_LOGI(TAG, "Initializing %s", DEVICE_CONFIG.family.asic.name);
switch (DEVICE_CONFIG.family.asic.id) {

switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
case BM1397:
return BM1397_init(GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value, GLOBAL_STATE->DEVICE_CONFIG.family.asic_count, GLOBAL_STATE->DEVICE_CONFIG.family.asic.difficulty);
return BM1397_init(POWER_MANAGEMENT_MODULE.frequency_value, DEVICE_CONFIG.family.asic_count, DEVICE_CONFIG.family.asic.difficulty);
case BM1366:
return BM1366_init(GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value, GLOBAL_STATE->DEVICE_CONFIG.family.asic_count, GLOBAL_STATE->DEVICE_CONFIG.family.asic.difficulty);
return BM1366_init(POWER_MANAGEMENT_MODULE.frequency_value, DEVICE_CONFIG.family.asic_count, DEVICE_CONFIG.family.asic.difficulty);
case BM1368:
return BM1368_init(GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value, GLOBAL_STATE->DEVICE_CONFIG.family.asic_count, GLOBAL_STATE->DEVICE_CONFIG.family.asic.difficulty);
return BM1368_init(POWER_MANAGEMENT_MODULE.frequency_value, DEVICE_CONFIG.family.asic_count, DEVICE_CONFIG.family.asic.difficulty);
case BM1370:
return BM1370_init(GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value, GLOBAL_STATE->DEVICE_CONFIG.family.asic_count, GLOBAL_STATE->DEVICE_CONFIG.family.asic.difficulty);
return BM1370_init(POWER_MANAGEMENT_MODULE.frequency_value, DEVICE_CONFIG.family.asic_count, DEVICE_CONFIG.family.asic.difficulty);
default:
}
return ESP_OK;
}

task_result * ASIC_process_work(GlobalState * GLOBAL_STATE)
task_result * ASIC_process_work()
{
switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
switch (DEVICE_CONFIG.family.asic.id) {
case BM1397:
return BM1397_process_work(GLOBAL_STATE);
return BM1397_process_work();
case BM1366:
return BM1366_process_work(GLOBAL_STATE);
return BM1366_process_work();
case BM1368:
return BM1368_process_work(GLOBAL_STATE);
return BM1368_process_work();
case BM1370:
return BM1370_process_work(GLOBAL_STATE);
return BM1370_process_work();
}
return NULL;
}

int ASIC_set_max_baud(GlobalState * GLOBAL_STATE)
int ASIC_set_max_baud()
{
switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
switch (DEVICE_CONFIG.family.asic.id) {
case BM1397:
return BM1397_set_max_baud();
case BM1366:
Expand All @@ -62,27 +60,27 @@ int ASIC_set_max_baud(GlobalState * GLOBAL_STATE)
return 0;
}

void ASIC_send_work(GlobalState * GLOBAL_STATE, void * next_job)
void ASIC_send_work(void * next_job)
{
switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
switch (DEVICE_CONFIG.family.asic.id) {
case BM1397:
BM1397_send_work(GLOBAL_STATE, next_job);
BM1397_send_work(next_job);
break;
case BM1366:
BM1366_send_work(GLOBAL_STATE, next_job);
BM1366_send_work(next_job);
break;
case BM1368:
BM1368_send_work(GLOBAL_STATE, next_job);
BM1368_send_work(next_job);
break;
case BM1370:
BM1370_send_work(GLOBAL_STATE, next_job);
BM1370_send_work(next_job);
break;
}
}

void ASIC_set_version_mask(GlobalState * GLOBAL_STATE, uint32_t mask)
void ASIC_set_version_mask(uint32_t mask)
{
switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
switch (DEVICE_CONFIG.family.asic.id) {
case BM1397:
BM1397_set_version_mask(mask);
break;
Expand All @@ -98,12 +96,12 @@ void ASIC_set_version_mask(GlobalState * GLOBAL_STATE, uint32_t mask)
}
}

bool ASIC_set_frequency(GlobalState * GLOBAL_STATE, float target_frequency)
bool ASIC_set_frequency(float target_frequency)
{
ESP_LOGI(TAG, "Setting ASIC frequency to %.2f MHz", target_frequency);
//ESP_LOGI(TAG, "Setting ASIC frequency to %.2f MHz", target_frequency);
bool success = false;

switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
switch (DEVICE_CONFIG.family.asic.id) {
case BM1366:
success = BM1366_set_frequency(target_frequency);
break;
Expand All @@ -129,12 +127,12 @@ bool ASIC_set_frequency(GlobalState * GLOBAL_STATE, float target_frequency)
return success;
}

double ASIC_get_asic_job_frequency_ms(GlobalState * GLOBAL_STATE)
double ASIC_get_asic_job_frequency_ms()
{
switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
switch (DEVICE_CONFIG.family.asic.id) {
case BM1397:
// no version-rolling so same Nonce Space is splitted between Small Cores
return (NONCE_SPACE / (double) (GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value * GLOBAL_STATE->DEVICE_CONFIG.family.asic.small_core_count * 1000)) / (double) GLOBAL_STATE->DEVICE_CONFIG.family.asic_count;
return (NONCE_SPACE / (double) (POWER_MANAGEMENT_MODULE.frequency_value * DEVICE_CONFIG.family.asic.small_core_count * 1000)) / (double) DEVICE_CONFIG.family.asic_count;
case BM1366:
return 2000;
case BM1368:
Expand Down
25 changes: 11 additions & 14 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "bm1366.h"

#include "crc.h"
#include "global_state.h"
#include "serial.h"
#include "utils.h"

#include "asic_task.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down Expand Up @@ -320,10 +319,9 @@ int BM1366_set_max_baud(void)

static uint8_t id = 0;

void BM1366_send_work(void * pvParameters, bm_job * next_bm_job)
void BM1366_send_work(bm_job * next_bm_job)
{

GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;

BM1366_job job;
id = (id + 8) % 128;
Expand All @@ -336,15 +334,15 @@ void BM1366_send_work(void * pvParameters, bm_job * next_bm_job)
memcpy(job.prev_block_hash, next_bm_job->prev_block_hash_be, 32);
memcpy(&job.version, &next_bm_job->version, 4);

if (GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job.job_id] != NULL) {
free_bm_job(GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job.job_id]);
if (ASIC_TASK_MODULE.active_jobs[job.job_id] != NULL) {
free_bm_job(ASIC_TASK_MODULE.active_jobs[job.job_id]);
}

GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job.job_id] = next_bm_job;
ASIC_TASK_MODULE.active_jobs[job.job_id] = 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);
pthread_mutex_lock(&ASIC_TASK_MODULE.valid_jobs_lock);
ASIC_TASK_MODULE.valid_jobs[job.job_id] = 1;
pthread_mutex_unlock(&ASIC_TASK_MODULE.valid_jobs_lock);

//debug sent jobs - this can get crazy if the interval is short
#if BM1366_DEBUG_JOBS
Expand All @@ -354,7 +352,7 @@ void BM1366_send_work(void * pvParameters, bm_job * next_bm_job)
_send_BM1366((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1366_job), BM1366_DEBUG_WORK);
}

task_result * BM1366_process_work(void * pvParameters)
task_result * BM1366_process_work()
{
bm1366_asic_result_t asic_result = {0};

Expand All @@ -368,14 +366,13 @@ task_result * BM1366_process_work(void * pvParameters)
uint32_t version_bits = (ntohs(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[job_id] == 0) {
if (ASIC_TASK_MODULE.valid_jobs[job_id] == 0) {
ESP_LOGW(TAG, "Invalid job found, 0x%02X", job_id);
return NULL;
}

uint32_t rolled_version = GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->version | version_bits;
uint32_t rolled_version = ASIC_TASK_MODULE.active_jobs[job_id]->version | version_bits;

result.job_id = job_id;
result.nonce = asic_result.nonce;
Expand Down
24 changes: 11 additions & 13 deletions components/asic/bm1368.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "bm1368.h"

#include "crc.h"
#include "global_state.h"
#include "asic_task.h"
#include "serial.h"
#include "utils.h"

Expand Down Expand Up @@ -259,9 +259,8 @@ int BM1368_set_max_baud(void)

static uint8_t id = 0;

void BM1368_send_work(void * pvParameters, bm_job * next_bm_job)
void BM1368_send_work(bm_job * next_bm_job)
{
GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;

BM1368_job job;
id = (id + 24) % 128;
Expand All @@ -274,15 +273,15 @@ void BM1368_send_work(void * pvParameters, bm_job * next_bm_job)
memcpy(job.prev_block_hash, next_bm_job->prev_block_hash_be, 32);
memcpy(&job.version, &next_bm_job->version, 4);

if (GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job.job_id] != NULL) {
free_bm_job(GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job.job_id]);
if (ASIC_TASK_MODULE.active_jobs[job.job_id] != NULL) {
free_bm_job(ASIC_TASK_MODULE.active_jobs[job.job_id]);
}

GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job.job_id] = next_bm_job;
ASIC_TASK_MODULE.active_jobs[job.job_id] = 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);
pthread_mutex_lock(&ASIC_TASK_MODULE.valid_jobs_lock);
ASIC_TASK_MODULE.valid_jobs[job.job_id] = 1;
pthread_mutex_unlock(&ASIC_TASK_MODULE.valid_jobs_lock);

#if BM1368_DEBUG_JOBS
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
Expand All @@ -291,7 +290,7 @@ void BM1368_send_work(void * pvParameters, bm_job * next_bm_job)
_send_BM1368((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1368_job), BM1368_DEBUG_WORK);
}

task_result * BM1368_process_work(void * pvParameters)
task_result * BM1368_process_work()
{
bm1368_asic_result_t asic_result = {0};

Expand All @@ -305,14 +304,13 @@ task_result * BM1368_process_work(void * pvParameters)
uint32_t version_bits = (ntohs(asic_result.version) << 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[job_id] == 0) {
if (ASIC_TASK_MODULE.valid_jobs[job_id] == 0) {
ESP_LOGW(TAG, "Invalid job found, 0x%02X", job_id);
return NULL;
}

uint32_t rolled_version = GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->version | version_bits;
uint32_t rolled_version = ASIC_TASK_MODULE.active_jobs[job_id]->version | version_bits;

result.job_id = job_id;
result.nonce = asic_result.nonce;
Expand Down
Loading
Loading