Skip to content

Commit

Permalink
doc: update readme to mention recovery page (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdb3 authored and eandersson committed Nov 23, 2024
1 parent 142649e commit c743039
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 23 deletions.
22 changes: 14 additions & 8 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,7 @@ static void do_frequency_ramp_up()
_send_simple(init793, 11);
}

static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
{

// set version mask
for (int i = 0; i < 3; i++) {
BM1366_set_version_mask(STRATUM_DEFAULT_VERSION_MASK);
}

int BM1366_count_asic_chips() {
// read register 00 on all chips
unsigned char init3[7] = {0x55, 0xAA, 0x52, 0x05, 0x00, 0x00, 0x0A};
_send_simple(init3, 7);
Expand All @@ -430,6 +423,19 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
break;
}
}

return chip_counter;
}

static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
{

// set version mask
for (int i = 0; i < 3; i++) {
BM1366_set_version_mask(STRATUM_DEFAULT_VERSION_MASK);
}

int chip_counter = BM1366_count_asic_chips();
ESP_LOGI(TAG, "%i chip(s) detected on the chain, expected %i", chip_counter, asic_count);

unsigned char init4[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0xA8, 0x00, 0x07, 0x00, 0x00, 0x03};
Expand Down
6 changes: 2 additions & 4 deletions components/asic/bm1368.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bool BM1368_set_frequency(float target_freq) {
return do_frequency_transition(target_freq);
}

static int count_asic_chips(void) {
int BM1368_count_asic_chips() {
_send_BM1368(TYPE_CMD | GROUP_ALL | CMD_READ, (uint8_t[]){0x00, 0x00}, 2, false);

int chip_counter = 0;
Expand All @@ -229,8 +229,6 @@ static int count_asic_chips(void) {
return chip_counter;
}



static void do_frequency_ramp_up(float target_frequency) {
ESP_LOGI(TAG, "Ramping up frequency from %.2f MHz to %.2f MHz", current_frequency, target_frequency);
do_frequency_transition(target_frequency);
Expand All @@ -252,7 +250,7 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count)
BM1368_set_version_mask(STRATUM_DEFAULT_VERSION_MASK);
}

int chip_counter = count_asic_chips();
int chip_counter = BM1368_count_asic_chips();

if (chip_counter != asic_count) {
ESP_LOGE(TAG, "Chip count mismatch. Expected: %d, Actual: %d", asic_count, chip_counter);
Expand Down
1 change: 1 addition & 0 deletions components/asic/include/bm1366.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct __attribute__((__packed__))
} BM1366_job;

uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count);
int BM1366_count_asic_chips();

void BM1366_send_init(void);
void BM1366_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
Expand Down
1 change: 1 addition & 0 deletions components/asic/include/bm1368.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct __attribute__((__packed__))
} BM1368_job;

uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count);
int BM1368_count_asic_chips();

uint8_t BM1368_send_init(void);
void BM1368_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
Expand Down
1 change: 1 addition & 0 deletions components/asic/include/bm1370.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct __attribute__((__packed__))
} BM1370_job;

uint8_t BM1370_init(uint64_t frequency, uint16_t asic_count);
int BM1370_count_asic_chips();

uint8_t BM1370_send_init(void);
void BM1370_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
Expand Down
1 change: 1 addition & 0 deletions components/asic/include/bm1397.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef struct __attribute__((__packed__))
} job_packet;

uint8_t BM1397_init(uint64_t frequency, uint16_t asic_count);
int BM1397_count_asic_chips();

void BM1397_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
void BM1397_set_job_difficulty_mask(int);
Expand Down
2 changes: 1 addition & 1 deletion components/asic/include/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ void SERIAL_init(void);
void SERIAL_debug_rx(void);
int16_t SERIAL_rx(uint8_t *, uint16_t, uint16_t);
void SERIAL_clear_buffer(void);
void SERIAL_set_baud(int baud);
void SERIAL_set_baud(int baud, bool wait);

#endif /* SERIAL_H_ */
20 changes: 14 additions & 6 deletions components/asic/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ void SERIAL_init(void)
uart_driver_install(UART_NUM_1, BUF_SIZE * 2, BUF_SIZE * 2, 0, NULL, 0);
}

void SERIAL_set_baud(int baud)
void SERIAL_set_baud(int baud, bool wait)
{
ESP_LOGI(TAG, "Changing UART baud to %i", baud);

// Make sure that we are done writing before setting a new baudrate.
uart_wait_tx_done(UART_NUM_1, 1000 / portTICK_PERIOD_MS);
if (wait) {
if (uart_wait_tx_done(UART_NUM_1, 10000 / portTICK_PERIOD_MS) != ESP_OK) {
ESP_LOGE(TAG, "Timed out waiting for TX to finish before setting baud rate");
}
}
if (uart_set_baudrate(UART_NUM_1, baud) != ESP_OK) {
ESP_LOGE(TAG, "Failed to set baudrate");
}

uart_set_baudrate(UART_NUM_1, baud);
uint32_t baud_rate;
uart_get_baudrate(UART_NUM_1, &baud_rate);
if (baud_rate != baud) {
ESP_LOGE(TAG, "Unexpected baud rate: %lu", baud_rate);
}
}

int SERIAL_send(uint8_t *data, int len, bool debug)
Expand Down
1 change: 1 addition & 0 deletions main/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ typedef struct
void (*set_difficulty_mask_fn)(int);
void (*send_work_fn)(void * GLOBAL_STATE, bm_job * next_bm_job);
void (*set_version_mask)(uint32_t);
int (*count_chips)();
} AsicFunctions;

typedef struct
Expand Down
15 changes: 13 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void app_main(void)
{
ESP_LOGI(TAG, "Welcome to the bitaxe - hack the planet!");

// This is an easy way to break serial communication with the Supra.
esp_log_level_set("*", ESP_LOG_WARN);

// Init I2C
ESP_ERROR_CHECK(i2c_bitaxe_init());
ESP_LOGI(TAG, "I2C initialized successfully");
Expand Down Expand Up @@ -79,7 +82,8 @@ void app_main(void)

SYSTEM_init_peripherals(&GLOBAL_STATE);

xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void *) &GLOBAL_STATE, 3, NULL);
// eandersson has no oled so it is causing spam lol
//xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void *) &GLOBAL_STATE, 3, NULL);
xTaskCreate(POWER_MANAGEMENT_task, "power mangement", 8192, (void *) &GLOBAL_STATE, 10, NULL);

//start the API for AxeOS
Expand Down Expand Up @@ -126,9 +130,16 @@ void app_main(void)

SERIAL_init();
(*GLOBAL_STATE.ASIC_functions.init_fn)(GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value, GLOBAL_STATE.asic_count);
SERIAL_set_baud((*GLOBAL_STATE.ASIC_functions.set_max_baud_fn)());
SERIAL_set_baud((*GLOBAL_STATE.ASIC_functions.set_max_baud_fn), (GLOBAL_STATE.board_version >= 400));
SERIAL_clear_buffer();

// Run count chips as a way to sanity check that we can still communicate with the ASIC(s).
int chip_count = (*GLOBAL_STATE.ASIC_functions.count_chips)();
if (chip_count == 0) {
ESP_LOGE(TAG, "Failed serial initialization.");
// Maybe do something more drastic?
}

GLOBAL_STATE.ASIC_initalized = true;

xTaskCreate(stratum_task, "stratum admin", 8192, (void *) &GLOBAL_STATE, 5, NULL);
Expand Down
3 changes: 2 additions & 1 deletion main/nvs_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ esp_err_t NVSDevice_parse_config(GlobalState * GLOBAL_STATE) {
.set_max_baud_fn = BM1368_set_max_baud,
.set_difficulty_mask_fn = BM1368_set_job_difficulty_mask,
.send_work_fn = BM1368_send_work,
.set_version_mask = BM1368_set_version_mask};
.set_version_mask = BM1368_set_version_mask,
.count_chips = BM1368_count_asic_chips};
//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->ASIC_difficulty = BM1368_ASIC_DIFFICULTY;
Expand Down
2 changes: 1 addition & 1 deletion main/self_test/self_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void self_test(void * pvParameters)

int baud = (*GLOBAL_STATE->ASIC_functions.set_max_baud_fn)();
vTaskDelay(10 / portTICK_PERIOD_MS);
SERIAL_set_baud(baud);
SERIAL_set_baud(baud, GLOBAL_STATE->board_version >= 400);

vTaskDelay(1000 / portTICK_PERIOD_MS);

Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ Some API examples in curl:
## Administration

The firmware hosts a small web server on port 80 for administrative purposes. Once the Bitaxe device is connected to the local network, the admin web front end may be accessed via a web browser connected to the same network at `http://<IP>`, replacing `IP` with the LAN IP address of the Bitaxe device, or `http://bitaxe`, provided your network supports mDNS configuration.

### Recovery

In the event that the admin web front end is inaccessible, for example because of an unsuccessful firmware update (`www.bin`), a recovery page can be accessed at `http://<IP>/recovery`.

0 comments on commit c743039

Please sign in to comment.