Skip to content

Commit

Permalink
Merge branch 'skot:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SatsForFreedom authored Sep 24, 2023
2 parents 9047211 + f7d06a7 commit 78525f4
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 50 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '20'
- name: Build web dist
working-directory: ./main/http_server/axe-os
run: |
Expand All @@ -22,6 +22,7 @@ jobs:
with:
esp_idf_version: v5.1
target: esp32s2
command: GITHUB_ACTIONS="true" idf.py build
path: '.'
- name: upload esp-miner.bin
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions components/connect/include/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ void toggle_wifi_softap(void);
void wifi_softap_off(void);
void wifi_init(const char * wifi_ssid, const char * wifi_pass);
EventBits_t wifi_connect(void);
void generate_ssid(char * ssid);
2 changes: 1 addition & 1 deletion components/stratum/include/stratum_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void STRATUM_V1_initialize_buffer();

char *STRATUM_V1_receive_jsonrpc_line(int sockfd);

int STRATUM_V1_subscribe(int socket, char **extranonce, int *extranonce2_len);
int STRATUM_V1_subscribe(int socket, char ** extranonce, int * extranonce2_len, char * model);

void STRATUM_V1_parse(StratumApiV1Message *message, const char *stratum_json);

Expand Down
6 changes: 3 additions & 3 deletions components/stratum/stratum_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ int _parse_stratum_subscribe_result_message(const char *result_json_str,
return 0;
}

int STRATUM_V1_subscribe(int socket, char **extranonce, int *extranonce2_len)
int STRATUM_V1_subscribe(int socket, char ** extranonce, int * extranonce2_len, char * model)
{
// Subscribe
char subscribe_msg[BUFFER_SIZE];
sprintf(subscribe_msg, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"bitaxe %s\"]}\n", send_uid++, CONFIG_ASIC_MODEL);
sprintf(subscribe_msg, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"bitaxe %s\"]}\n", send_uid++, model);
debug_stratum_tx(subscribe_msg);
write(socket, subscribe_msg, strlen(subscribe_msg));
char *line;
char * line;
line = STRATUM_V1_receive_jsonrpc_line(socket);

ESP_LOGI(TAG, "Received result %s", line);
Expand Down
7 changes: 5 additions & 2 deletions config.cvs.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ stratumurl,data,string,public-pool.io
stratumport,data,u16,21496
stratumuser,data,string,1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.bitaxe
stratumpass,data,string,x
asicfrequency,data,u16,450
asicvoltage,data,u16,1400
asicfrequency,data,u16,485
asicvoltage,data,u16,1320
asicmodel,data,string,BM1366
devicemodel,data,string,ultra
boardversion,data,string,0.11
34 changes: 31 additions & 3 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,37 @@ INCLUDE_DIRS
)

set(WEB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/http_server/axe-os")
if(EXISTS ${WEB_SRC_DIR}/dist/axe-os)

if("$ENV{GITHUB_ACTIONS}" STREQUAL "true")
message(STATUS "Running on GitHub Actions. Web ui will be prebuilt.")

spiffs_create_partition_image(www ${WEB_SRC_DIR}/dist/axe-os FLASH_IN_PROJECT)
else()
message(FATAL_ERROR "${WEB_SRC_DIR}/dist doesn't exit. Please run 'npm i && npm run build' in ${WEB_SRC_DIR}")
find_program(NPM_EXECUTABLE npm)
if(NOT NPM_EXECUTABLE AND NOT EXISTS ${WEB_SRC_DIR}/dist)
message(FATAL_ERROR "npm is not found! Please install it to proceed.")
endif()

ExternalProject_Add(
web_ui_dist
PREFIX ${CMAKE_BINARY_DIR}/web_ui_dist
SOURCE_DIR ${WEB_SRC_DIR}
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env
PATH=$ENV{PATH}
${NPM_EXECUTABLE} i
USES_TERMINAL_BUILD true
BUILD_COMMAND ${CMAKE_COMMAND} -E env
PATH=$ENV{PATH}
${NPM_EXECUTABLE} run build
INSTALL_COMMAND ""
BUILD_ALWAYS OFF
BUILD_IN_SOURCE TRUE
BUILD_BYPRODUCTS
"${WEB_SRC_DIR}/dist/axe-os/index.html"
)

add_dependencies(${COMPONENT_LIB} web_ui_dist)

endif()
spiffs_create_partition_image(www ${WEB_SRC_DIR}/dist/axe-os FLASH_IN_PROJECT DEPENDS web_ui_dist)
endif()
7 changes: 0 additions & 7 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
menu "Bitaxe Configuration"

config ASIC_MODEL
string "ASIC Model"
default "BM1397"
help
BM1397 or BM1366

config ASIC_VOLTAGE
int "ASIC Core Voltage (mV)"
range 1000 1800
Expand Down
21 changes: 11 additions & 10 deletions main/global_state.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
#ifndef GLOBAL_STATE_H_
#define GLOBAL_STATE_H_

#include "work_queue.h"
#include "bm1397.h"
#include "bm1366.h"
#include "system.h"
#include "stratum_api.h"
#include "asic_task.h"
#include "bm1366.h"
#include "bm1397.h"
#include "common.h"
#include "power_management_task.h"
#include "serial.h"
#include "common.h"
#include "stratum_api.h"
#include "system.h"
#include "work_queue.h"

#define STRATUM_USER CONFIG_STRATUM_USER

typedef struct
{
void (*init_fn)(u_int64_t);
task_result *(*receive_result_fn)(void *GLOBAL_STATE);
task_result * (*receive_result_fn)(void * GLOBAL_STATE);
int (*set_max_baud_fn)(void);
void (*set_difficulty_mask_fn)(int);
void (*send_work_fn)(void *GLOBAL_STATE, bm_job *next_bm_job);
void (*send_work_fn)(void * GLOBAL_STATE, bm_job * next_bm_job);
} AsicFunctions;

typedef struct
{
char * asic_model;
AsicFunctions ASIC_functions;
double asic_job_frequency_ms;

Expand All @@ -35,11 +36,11 @@ typedef struct
AsicTaskModule ASIC_TASK_MODULE;
PowerManagementModule POWER_MANAGEMENT_MODULE;

char *extranonce_str;
char * extranonce_str;
int extranonce_2_len;
int abandon_work;

uint8_t *valid_jobs;
uint8_t * valid_jobs;
pthread_mutex_t valid_jobs_lock;

uint32_t stratum_difficulty;
Expand Down
2 changes: 1 addition & 1 deletion main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted);
cJSON_AddNumberToObject(root, "sharesRejected", GLOBAL_STATE->SYSTEM_MODULE.shares_rejected);
cJSON_AddNumberToObject(root, "uptimeSeconds", (esp_timer_get_time() - GLOBAL_STATE->SYSTEM_MODULE.start_time) / 1000000);
cJSON_AddStringToObject(root, "ASICModel", CONFIG_ASIC_MODEL);
cJSON_AddStringToObject(root, "ASICModel", GLOBAL_STATE->asic_model);
cJSON_AddStringToObject(root, "stratumURL", stratumURL);
cJSON_AddNumberToObject(root, "stratumPort", nvs_config_get_u16(NVS_CONFIG_STRATUM_PORT, CONFIG_STRATUM_PORT));
cJSON_AddStringToObject(root, "stratumUser", stratumUser);
Expand Down
10 changes: 5 additions & 5 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "stratum_task.h"
#include "user_input_task.h"

#define ASIC_MODEL CONFIG_ASIC_MODEL

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

static const char * TAG = "miner";
Expand All @@ -30,7 +28,8 @@ void app_main(void)
ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %f", (float) nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY));
GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY);

if (strcmp(ASIC_MODEL, "BM1366") == 0) {
GLOBAL_STATE.asic_model = nvs_config_get_string(NVS_CONFIG_ASIC_MODEL, "");
if (strcmp(GLOBAL_STATE.asic_model, "BM1366") == 0) {
ESP_LOGI(TAG, "ASIC: BM1366");
AsicFunctions ASIC_functions = {.init_fn = BM1366_init,
.receive_result_fn = BM1366_proccess_work,
Expand All @@ -40,7 +39,7 @@ void app_main(void)
GLOBAL_STATE.asic_job_frequency_ms = BM1366_FULLSCAN_MS;

GLOBAL_STATE.ASIC_functions = ASIC_functions;
} else if (strcmp(ASIC_MODEL, "BM1397") == 0) {
} else if (strcmp(GLOBAL_STATE.asic_model, "BM1397") == 0) {
ESP_LOGI(TAG, "ASIC: BM1397");
AsicFunctions ASIC_functions = {.init_fn = BM1397_init,
.receive_result_fn = BM1397_proccess_work,
Expand All @@ -53,7 +52,8 @@ void app_main(void)

GLOBAL_STATE.ASIC_functions = ASIC_functions;
} else {
ESP_LOGI(TAG, "Invalid ASIC model");
ESP_LOGE(TAG, "Unable to determine ASIC model. Please make sure the model has been written into NVS at main/asicmodel.");
vTaskDelay(10000 / portTICK_PERIOD_MS);
exit(EXIT_FAILURE);
}

Expand Down
12 changes: 7 additions & 5 deletions main/nvs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#define NVS_CONFIG_STRATUM_PASS "stratumpass"
#define NVS_CONFIG_ASIC_FREQ "asicfrequency"
#define NVS_CONFIG_ASIC_VOLTAGE "asicvoltage"
#define NVS_CONFIG_ASIC_MODEL "asicModel"
#define NVS_CONFIG_ASIC_MODEL "asicmodel"
#define NVS_CONFIG_DEVICE_MODEL "devicemodel"
#define NVS_CONFIG_BOARD_VERSION "boardversion"

char *nvs_config_get_string(const char *key, const char *default_value);
void nvs_config_set_string(const char *key, const char *default_value);
uint16_t nvs_config_get_u16(const char *key, const uint16_t default_value);
void nvs_config_set_u16(const char *key, const uint16_t value);
char * nvs_config_get_string(const char * key, const char * default_value);
void nvs_config_set_string(const char * key, const char * default_value);
uint16_t nvs_config_get_u16(const char * key, const uint16_t default_value);
void nvs_config_set_u16(const char * key, const uint16_t value);

#endif // MAIN_NVS_CONFIG_H
31 changes: 25 additions & 6 deletions main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@

static const char * TAG = "SystemModule";

#define ASIC_MODEL CONFIG_ASIC_MODEL

static void _suffix_string(uint64_t, char *, size_t, int);

static esp_netif_t * netif;
static esp_netif_ip_info_t ip_info;

static void _init_system(SystemModule * module)
static void _init_system(GlobalState * global_state, SystemModule * module)
{
module->duration_start = 0;
module->historical_hashrate_rolling_index = 0;
Expand Down Expand Up @@ -80,7 +78,7 @@ static void _init_system(SystemModule * module)

// Fan Tests
EMC2101_init();
if (strcmp(ASIC_MODEL, "BM1366") == 0) {
if (strcmp(global_state->asic_model, "BM1366") == 0) {
EMC2101_set_fan_speed(0);
} else {
EMC2101_set_fan_speed(1);
Expand Down Expand Up @@ -246,6 +244,17 @@ static void _update_system_performance(GlobalState * GLOBAL_STATE)
}
}

static void show_ap_information()
{
if (OLED_status()) {
_clear_display();
OLED_writeString(0, 0, "connect to ssid:");
char ap_ssid[13];
generate_ssid(ap_ssid);
OLED_writeString(0, 2, ap_ssid);
}
}

static double _calculate_network_difficulty(uint32_t nBits)
{
uint32_t mantissa = nBits & 0x007fffff; // Extract the mantissa from nBits
Expand Down Expand Up @@ -336,14 +345,24 @@ void SYSTEM_task(void * pvParameters)
GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;

_init_system(module);
_init_system(GLOBAL_STATE, module);

_clear_display();
_init_connection(module);

wifi_mode_t wifi_mode;
esp_err_t result;

// show the connection screen
while (!module->startup_done) {
_update_connection(module);
result = esp_wifi_get_mode(&wifi_mode);
if (result == ESP_OK && (wifi_mode == WIFI_MODE_APSTA || wifi_mode == WIFI_MODE_AP) &&
strcmp(module->wifi_status, "Failed to connect") == 0) {
show_ap_information(module);
vTaskDelay(5000 / portTICK_PERIOD_MS);
} else {
_update_connection(module);
}
vTaskDelay(100 / portTICK_PERIOD_MS);
}

Expand Down
5 changes: 2 additions & 3 deletions main/tasks/power_management_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define VOLTAGE_START_THROTTLE 4900
#define VOLTAGE_MIN_THROTTLE 3500
#define VOLTAGE_RANGE (VOLTAGE_START_THROTTLE - VOLTAGE_MIN_THROTTLE)
#define ASIC_MODEL CONFIG_ASIC_MODEL

static const char * TAG = "power_management";

Expand Down Expand Up @@ -58,7 +57,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
}
power_management->fan_speed = EMC2101_get_fan_speed();

if (strcmp(ASIC_MODEL, "BM1397") == 0) {
if (strcmp(GLOBAL_STATE->asic_model, "BM1397") == 0) {

power_management->chip_temp = EMC2101_get_external_temp();

Expand Down Expand Up @@ -115,7 +114,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
last_frequency_increase++;
}
}
} else if (strcmp(ASIC_MODEL, "BM1366") == 0) {
} else if (strcmp(GLOBAL_STATE->asic_model, "BM1366") == 0) {
power_management->chip_temp = EMC2101_get_internal_temp() + 5;

if (power_management->fan_speed < 10) {
Expand Down
3 changes: 2 additions & 1 deletion main/tasks/stratum_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void stratum_task(void *pvParameters)
break;
}

STRATUM_V1_subscribe(GLOBAL_STATE->sock, &GLOBAL_STATE->extranonce_str, &GLOBAL_STATE->extranonce_2_len);
STRATUM_V1_subscribe(GLOBAL_STATE->sock, &GLOBAL_STATE->extranonce_str, &GLOBAL_STATE->extranonce_2_len,
GLOBAL_STATE->asic_model);

STRATUM_V1_configure_version_rolling(GLOBAL_STATE->sock);

Expand Down

0 comments on commit 78525f4

Please sign in to comment.