mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-03-18 05:42:16 +01:00
distribute chip address to all chip available
This commit is contained in:
parent
8756581da6
commit
5b38d332ce
@ -399,7 +399,7 @@ static void do_frequency_ramp_up()
|
||||
_send_simple(init793, 11);
|
||||
}
|
||||
|
||||
static uint8_t _send_init(uint64_t frequency)
|
||||
static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
|
||||
{
|
||||
|
||||
// //send serial data
|
||||
@ -418,8 +418,9 @@ static uint8_t _send_init(uint64_t frequency)
|
||||
// unsigned char init3[6] = { 0x00, 0x18, 0xFF, 0x0F, 0xC1, 0x00 };
|
||||
// _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), init3, 6, true);
|
||||
|
||||
// unsigned char init4[7] = { 0x55, 0xAA, 0x53, 0x05, 0x00, 0x00, 0x03 };
|
||||
// _send_simple(init4, 7);
|
||||
// _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);
|
||||
@ -454,7 +455,7 @@ static uint8_t _send_init(uint64_t frequency)
|
||||
break;
|
||||
}
|
||||
}
|
||||
ESP_LOGI(TAG, "%i chip(s) detected on the chain", chip_counter);
|
||||
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};
|
||||
_send_simple(init4, 11);
|
||||
@ -462,11 +463,16 @@ static uint8_t _send_init(uint64_t frequency)
|
||||
unsigned char init5[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x18, 0xFF, 0x0F, 0xC1, 0x00, 0x00};
|
||||
_send_simple(init5, 11);
|
||||
|
||||
unsigned char init6[7] = {0x55, 0xAA, 0x53, 0x05, 0x00, 0x00, 0x03};
|
||||
_send_simple(init6, 7);
|
||||
_send_chain_inactive();
|
||||
// unsigned char init6[7] = {0x55, 0xAA, 0x53, 0x05, 0x00, 0x00, 0x03};
|
||||
// _send_simple(init6, 7);
|
||||
|
||||
unsigned char init7[7] = {0x55, 0xAA, 0x40, 0x05, 0x00, 0x00, 0x1C};
|
||||
_send_simple(init7, 7);
|
||||
// split the chip address space evenly
|
||||
for (uint8_t i = 0; i < chip_counter; i++) {
|
||||
_set_chip_address(i * (256 / chip_counter));
|
||||
// unsigned char init7[7] = { 0x55, 0xAA, 0x40, 0x05, 0x00, 0x00, 0x1C };
|
||||
// _send_simple(init7, 7);
|
||||
}
|
||||
|
||||
unsigned char init135[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x3C, 0x80, 0x00, 0x85, 0x40, 0x0C};
|
||||
_send_simple(init135, 11);
|
||||
@ -540,7 +546,7 @@ static void _send_read_address(void)
|
||||
_send_BM1366((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, false);
|
||||
}
|
||||
|
||||
uint8_t BM1366_init(uint64_t frequency)
|
||||
uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initializing BM1366");
|
||||
|
||||
@ -552,10 +558,7 @@ uint8_t BM1366_init(uint64_t frequency)
|
||||
// reset the bm1366
|
||||
_reset();
|
||||
|
||||
// send the init command
|
||||
//_send_read_address();
|
||||
|
||||
return _send_init(frequency);
|
||||
return _send_init(frequency, asic_count);
|
||||
}
|
||||
|
||||
// Baud formula = 25M/((denominator+1)*8)
|
||||
|
@ -266,7 +266,7 @@ static void do_frequency_ramp_up() {
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t _send_init(uint64_t frequency)
|
||||
static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
|
||||
{
|
||||
|
||||
//enable and set version rolling mask to 0xFFFF
|
||||
@ -293,7 +293,7 @@ static uint8_t _send_init(uint64_t frequency)
|
||||
break;
|
||||
}
|
||||
}
|
||||
ESP_LOGI(TAG, "%i chip(s) detected on the chain", chip_counter);
|
||||
ESP_LOGI(TAG, "%i chip(s) detected on the chain, expected %i", chip_counter, asic_count);
|
||||
|
||||
//enable and set version rolling mask to 0xFFFF (again)
|
||||
unsigned char init4[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF, 0x1C};
|
||||
@ -308,12 +308,16 @@ static uint8_t _send_init(uint64_t frequency)
|
||||
_send_simple(init6, 11);
|
||||
|
||||
//chain inactive
|
||||
unsigned char init7[7] = {0x55, 0xAA, 0x53, 0x05, 0x00, 0x00, 0x03};
|
||||
_send_simple(init7, 7);
|
||||
_send_chain_inactive();
|
||||
// unsigned char init7[7] = {0x55, 0xAA, 0x53, 0x05, 0x00, 0x00, 0x03};
|
||||
// _send_simple(init7, 7);
|
||||
|
||||
//assign address 0x00 to the first chip
|
||||
unsigned char init8[7] = {0x55, 0xAA, 0x40, 0x05, 0x00, 0x00, 0x1C};
|
||||
_send_simple(init8, 7);
|
||||
// split the chip address space evenly
|
||||
for (uint8_t i = 0; i < chip_counter; i++) {
|
||||
_set_chip_address(i * (256 / chip_counter));
|
||||
// unsigned char init8[7] = {0x55, 0xAA, 0x40, 0x05, 0x00, 0x00, 0x1C};
|
||||
// _send_simple(init8, 7);
|
||||
}
|
||||
|
||||
//Core Register Control
|
||||
unsigned char init9[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x3C, 0x80, 0x00, 0x8B, 0x00, 0x12};
|
||||
@ -386,7 +390,7 @@ static void _send_read_address(void)
|
||||
_send_BM1368((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, false);
|
||||
}
|
||||
|
||||
uint8_t BM1368_init(uint64_t frequency)
|
||||
uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initializing BM1368");
|
||||
|
||||
@ -398,10 +402,7 @@ uint8_t BM1368_init(uint64_t frequency)
|
||||
// reset the bm1368
|
||||
_reset();
|
||||
|
||||
// send the init command
|
||||
//_send_read_address();
|
||||
|
||||
return _send_init(frequency);
|
||||
return _send_init(frequency, asic_count);
|
||||
}
|
||||
|
||||
// Baud formula = 25M/((denominator+1)*8)
|
||||
|
@ -104,6 +104,13 @@ static void _send_BM1397(uint8_t header, uint8_t *data, uint8_t data_len, bool d
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static void _send_read_address(void)
|
||||
{
|
||||
unsigned char read_address[2] = {0x00, 0x00};
|
||||
// send serial data
|
||||
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, false);
|
||||
}
|
||||
|
||||
static void _send_chain_inactive(void)
|
||||
{
|
||||
|
||||
@ -209,14 +216,29 @@ void BM1397_send_hash_frequency(float frequency)
|
||||
ESP_LOGI(TAG, "Setting Frequency to %.2fMHz (%.2f)", frequency, newf);
|
||||
}
|
||||
|
||||
static void _send_init(uint64_t frequency)
|
||||
static void _send_init(uint64_t frequency, uint16_t asic_count)
|
||||
{
|
||||
// send the init command
|
||||
_send_read_address();
|
||||
|
||||
int chip_counter = 0;
|
||||
while (true) {
|
||||
if (SERIAL_rx(asic_response_buffer, 11, 1000) > 0) {
|
||||
chip_counter++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ESP_LOGI(TAG, "%i chip(s) detected on the chain, expected %i", chip_counter, asic_count);
|
||||
|
||||
// send serial data
|
||||
vTaskDelay(SLEEP_TIME / portTICK_PERIOD_MS);
|
||||
_send_chain_inactive();
|
||||
|
||||
_set_chip_address(0x00);
|
||||
// split the chip address space evenly
|
||||
for (uint8_t i = 0; i < asic_count; i++) {
|
||||
_set_chip_address(i * (256 / asic_count));
|
||||
}
|
||||
|
||||
unsigned char init[6] = {0x00, CLOCK_ORDER_CONTROL_0, 0x00, 0x00, 0x00, 0x00}; // init1 - clock_order_control0
|
||||
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init, 6, false);
|
||||
@ -258,15 +280,7 @@ static void _reset(void)
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
static void _send_read_address(void)
|
||||
{
|
||||
|
||||
unsigned char read_address[2] = {0x00, 0x00};
|
||||
// send serial data
|
||||
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, false);
|
||||
}
|
||||
|
||||
void BM1397_init(uint64_t frequency)
|
||||
void BM1397_init(uint64_t frequency, uint16_t asic_count)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initializing BM1397");
|
||||
|
||||
@ -278,10 +292,7 @@ void BM1397_init(uint64_t frequency)
|
||||
// reset the bm1397
|
||||
_reset();
|
||||
|
||||
// send the init command
|
||||
_send_read_address();
|
||||
|
||||
_send_init(frequency);
|
||||
_send_init(frequency, asic_count);
|
||||
}
|
||||
|
||||
// Baud formula = 25M/((denominator+1)*8)
|
||||
|
@ -32,7 +32,7 @@ typedef struct __attribute__((__packed__))
|
||||
uint8_t version[4];
|
||||
} BM1366_job;
|
||||
|
||||
uint8_t BM1366_init(uint64_t frequency);
|
||||
uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count);
|
||||
|
||||
void BM1366_send_init(void);
|
||||
void BM1366_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
|
||||
|
@ -33,7 +33,7 @@ typedef struct __attribute__((__packed__))
|
||||
uint8_t version[4];
|
||||
} BM1368_job;
|
||||
|
||||
uint8_t BM1368_init(uint64_t frequency);
|
||||
uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count);
|
||||
|
||||
uint8_t BM1368_send_init(void);
|
||||
void BM1368_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
|
||||
|
@ -46,7 +46,7 @@ typedef struct __attribute__((__packed__))
|
||||
uint8_t midstate3[32];
|
||||
} job_packet;
|
||||
|
||||
void BM1397_init(uint64_t frequency);
|
||||
void BM1397_init(uint64_t frequency, uint16_t asic_count);
|
||||
|
||||
void BM1397_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
|
||||
void BM1397_set_job_difficulty_mask(int);
|
||||
|
@ -30,7 +30,7 @@ typedef enum
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t (*init_fn)(uint64_t);
|
||||
uint8_t (*init_fn)(uint64_t, uint16_t);
|
||||
task_result * (*receive_result_fn)(void * GLOBAL_STATE);
|
||||
int (*set_max_baud_fn)(void);
|
||||
void (*set_difficulty_mask_fn)(int);
|
||||
|
@ -165,7 +165,7 @@ void app_main(void)
|
||||
queue_init(&GLOBAL_STATE.ASIC_jobs_queue);
|
||||
|
||||
SERIAL_init();
|
||||
(*GLOBAL_STATE.ASIC_functions.init_fn)(GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value);
|
||||
(*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_clear_buffer();
|
||||
|
||||
|
@ -98,8 +98,8 @@ void self_test(void * pvParameters)
|
||||
|
||||
|
||||
SERIAL_init();
|
||||
uint8_t chips_detected = (GLOBAL_STATE->ASIC_functions.init_fn)(GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value);
|
||||
ESP_LOGI(TAG, "%u chips detected", chips_detected);
|
||||
uint8_t chips_detected = (GLOBAL_STATE->ASIC_functions.init_fn)(GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value, GLOBAL_STATE->asic_count);
|
||||
ESP_LOGI(TAG, "%u chips detected, %u expected", chips_detected, GLOBAL_STATE->asic_count);
|
||||
|
||||
int baud = (*GLOBAL_STATE->ASIC_functions.set_max_baud_fn)();
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
|
Loading…
x
Reference in New Issue
Block a user