mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-12-09 04:01:41 +01:00
Several refactors and cleanups (#1102)
- Extract BM##_set_job_difficulty_mask into a single function - Set self_test difficulty before ASIC_init to eliminate ASIC_set_job_difficulty_mask - Fixed some capitalisations of GLOBAL_STATE and some others - Thermal.c: pass DEVICE_CONFIG by pointer instead of by value
This commit is contained in:
@@ -62,24 +62,6 @@ int ASIC_set_max_baud(GlobalState * GLOBAL_STATE)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ASIC_set_job_difficulty_mask(GlobalState * GLOBAL_STATE, uint8_t mask)
|
||||
{
|
||||
switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
|
||||
case BM1397:
|
||||
BM1397_set_job_difficulty_mask(mask);
|
||||
break;
|
||||
case BM1366:
|
||||
BM1366_set_job_difficulty_mask(mask);
|
||||
break;
|
||||
case BM1368:
|
||||
BM1368_set_job_difficulty_mask(mask);
|
||||
break;
|
||||
case BM1370:
|
||||
BM1370_set_job_difficulty_mask(mask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ASIC_send_work(GlobalState * GLOBAL_STATE, void * next_job)
|
||||
{
|
||||
switch (GLOBAL_STATE->DEVICE_CONFIG.family.asic.id) {
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
#define CORE_REGISTER_CONTROL 0x3C
|
||||
#define PLL3_PARAMETER 0x68
|
||||
#define FAST_UART_CONFIGURATION 0x28
|
||||
#define TICKET_MASK 0x14
|
||||
#define MISC_CONTROL 0x18
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
@@ -245,8 +244,10 @@ uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count, uint16_t difficulty
|
||||
unsigned char init136[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x3C, 0x80, 0x00, 0x80, 0x20, 0x19};
|
||||
_send_simple(init136, 11);
|
||||
|
||||
//{0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08};
|
||||
BM1366_set_job_difficulty_mask(difficulty);
|
||||
//set difficulty mask
|
||||
uint8_t difficulty_mask[6];
|
||||
get_difficulty_mask(difficulty, difficulty_mask);
|
||||
_send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), difficulty_mask, 6, BM1366_SERIALTX_DEBUG);
|
||||
|
||||
unsigned char init138[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x1D};
|
||||
_send_simple(init138, 11);
|
||||
@@ -317,35 +318,6 @@ int BM1366_set_max_baud(void)
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
void BM1366_set_job_difficulty_mask(int difficulty)
|
||||
{
|
||||
|
||||
// Default mask of 256 diff
|
||||
unsigned char job_difficulty_mask[9] = {0x00, TICKET_MASK, 0b00000000, 0b00000000, 0b00000000, 0b11111111};
|
||||
|
||||
// The mask must be a power of 2 so there are no holes
|
||||
// Correct: {0b00000000, 0b00000000, 0b11111111, 0b11111111}
|
||||
// Incorrect: {0b00000000, 0b00000000, 0b11100111, 0b11111111}
|
||||
// (difficulty - 1) if it is a pow 2 then step down to second largest for more hashrate sampling
|
||||
difficulty = _largest_power_of_two(difficulty) - 1;
|
||||
|
||||
// convert difficulty into char array
|
||||
// Ex: 256 = {0b00000000, 0b00000000, 0b00000000, 0b11111111}, {0x00, 0x00, 0x00, 0xff}
|
||||
// Ex: 512 = {0b00000000, 0b00000000, 0b00000001, 0b11111111}, {0x00, 0x00, 0x01, 0xff}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
char value = (difficulty >> (8 * i)) & 0xFF;
|
||||
// The char is read in backwards to the register so we need to reverse them
|
||||
// So a mask of 512 looks like 0b00000000 00000000 00000001 1111111
|
||||
// and not 0b00000000 00000000 10000000 1111111
|
||||
|
||||
job_difficulty_mask[5 - i] = _reverse_bits(value);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Setting job ASIC mask to %d", difficulty);
|
||||
|
||||
_send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1366_SERIALTX_DEBUG);
|
||||
}
|
||||
|
||||
static uint8_t id = 0;
|
||||
|
||||
void BM1366_send_work(void * pvParameters, bm_job * next_bm_job)
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
#define CORE_REGISTER_CONTROL 0x3C
|
||||
#define PLL3_PARAMETER 0x68
|
||||
#define FAST_UART_CONFIGURATION 0x28
|
||||
#define TICKET_MASK 0x14
|
||||
#define MISC_CONTROL 0x18
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
@@ -230,7 +229,9 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count, uint16_t difficulty
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
|
||||
BM1368_set_job_difficulty_mask(difficulty);
|
||||
uint8_t difficulty_mask[6];
|
||||
get_difficulty_mask(difficulty, difficulty_mask);
|
||||
_send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), difficulty_mask, 6, BM1368_SERIALTX_DEBUG);
|
||||
|
||||
do_frequency_ramp_up((float)frequency);
|
||||
|
||||
@@ -256,22 +257,6 @@ int BM1368_set_max_baud(void)
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
void BM1368_set_job_difficulty_mask(int difficulty)
|
||||
{
|
||||
unsigned char job_difficulty_mask[9] = {0x00, TICKET_MASK, 0b00000000, 0b00000000, 0b00000000, 0b11111111};
|
||||
|
||||
difficulty = _largest_power_of_two(difficulty) - 1;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
char value = (difficulty >> (8 * i)) & 0xFF;
|
||||
job_difficulty_mask[5 - i] = _reverse_bits(value);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Setting job ASIC mask to %d", difficulty);
|
||||
|
||||
_send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1368_SERIALTX_DEBUG);
|
||||
}
|
||||
|
||||
static uint8_t id = 0;
|
||||
|
||||
void BM1368_send_work(void * pvParameters, bm_job * next_bm_job)
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
#define CORE_REGISTER_CONTROL 0x3C
|
||||
#define PLL3_PARAMETER 0x68
|
||||
#define FAST_UART_CONFIGURATION 0x28
|
||||
#define TICKET_MASK 0x14
|
||||
#define MISC_CONTROL 0x18
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
@@ -262,9 +261,10 @@ uint8_t BM1370_init(uint64_t frequency, uint16_t asic_count, uint16_t difficulty
|
||||
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), (uint8_t[]){0x00, 0x3C, 0x80, 0x00, 0x80, 0x0C}, 6, BM1370_SERIALTX_DEBUG); //from S21Pro dump
|
||||
//_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), (uint8_t[]){0x00, 0x3C, 0x80, 0x00, 0x80, 0x18}, 6, BM1370_SERIALTX_DEBUG); //from S21 dump
|
||||
|
||||
//set ticket mask
|
||||
// unsigned char init11[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08};
|
||||
BM1370_set_job_difficulty_mask(difficulty);
|
||||
//set difficulty mask
|
||||
uint8_t difficulty_mask[6];
|
||||
get_difficulty_mask(difficulty, difficulty_mask);
|
||||
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), difficulty_mask, 6, BM1370_SERIALTX_DEBUG);
|
||||
|
||||
//Analog Mux Control -- not sent on S21 Pro?
|
||||
// unsigned char init12[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x1D};
|
||||
@@ -348,40 +348,10 @@ int BM1370_set_max_baud(void)
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
|
||||
void BM1370_set_job_difficulty_mask(int difficulty)
|
||||
{
|
||||
// Default mask of 256 diff
|
||||
unsigned char job_difficulty_mask[9] = {0x00, TICKET_MASK, 0b00000000, 0b00000000, 0b00000000, 0b11111111};
|
||||
|
||||
// The mask must be a power of 2 so there are no holes
|
||||
// Correct: {0b00000000, 0b00000000, 0b11111111, 0b11111111}
|
||||
// Incorrect: {0b00000000, 0b00000000, 0b11100111, 0b11111111}
|
||||
// (difficulty - 1) if it is a pow 2 then step down to second largest for more hashrate sampling
|
||||
difficulty = _largest_power_of_two(difficulty) - 1;
|
||||
|
||||
// convert difficulty into char array
|
||||
// Ex: 256 = {0b00000000, 0b00000000, 0b00000000, 0b11111111}, {0x00, 0x00, 0x00, 0xff}
|
||||
// Ex: 512 = {0b00000000, 0b00000000, 0b00000001, 0b11111111}, {0x00, 0x00, 0x01, 0xff}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
char value = (difficulty >> (8 * i)) & 0xFF;
|
||||
// The char is read in backwards to the register so we need to reverse them
|
||||
// So a mask of 512 looks like 0b00000000 00000000 00000001 1111111
|
||||
// and not 0b00000000 00000000 10000000 1111111
|
||||
|
||||
job_difficulty_mask[5 - i] = _reverse_bits(value);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Setting ASIC difficulty mask to %d", difficulty);
|
||||
|
||||
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1370_SERIALTX_DEBUG);
|
||||
}
|
||||
|
||||
static uint8_t id = 0;
|
||||
|
||||
void BM1370_send_work(void * pvParameters, bm_job * next_bm_job)
|
||||
{
|
||||
|
||||
GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;
|
||||
|
||||
BM1370_job job;
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#define CORE_REGISTER_CONTROL 0x3C
|
||||
#define PLL3_PARAMETER 0x68
|
||||
#define FAST_UART_CONFIGURATION 0x28
|
||||
#define TICKET_MASK 0x14
|
||||
#define MISC_CONTROL 0x18
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
@@ -253,7 +252,10 @@ uint8_t BM1397_init(uint64_t frequency, uint16_t asic_count, uint16_t difficulty
|
||||
unsigned char init4[9] = {0x00, CORE_REGISTER_CONTROL, 0x80, 0x00, 0x80, 0x74}; // init4 - init_4_?
|
||||
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init4, 6, BM1397_SERIALTX_DEBUG);
|
||||
|
||||
BM1397_set_job_difficulty_mask(difficulty);
|
||||
//set difficulty mask
|
||||
uint8_t difficulty_mask[6];
|
||||
get_difficulty_mask(difficulty, difficulty_mask);
|
||||
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), difficulty_mask, 6, BM1397_SERIALTX_DEBUG);
|
||||
|
||||
unsigned char init5[9] = {0x00, PLL3_PARAMETER, 0xC0, 0x70, 0x01, 0x11}; // init5 - pll3_parameter
|
||||
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init5, 6, BM1397_SERIALTX_DEBUG);
|
||||
@@ -288,35 +290,6 @@ int BM1397_set_max_baud(void)
|
||||
return 3125000;
|
||||
}
|
||||
|
||||
void BM1397_set_job_difficulty_mask(int difficulty)
|
||||
{
|
||||
|
||||
// Default mask of 256 diff
|
||||
unsigned char job_difficulty_mask[9] = {0x00, TICKET_MASK, 0b00000000, 0b00000000, 0b00000000, 0b11111111};
|
||||
|
||||
// The mask must be a power of 2 so there are no holes
|
||||
// Correct: {0b00000000, 0b00000000, 0b11111111, 0b11111111}
|
||||
// Incorrect: {0b00000000, 0b00000000, 0b11100111, 0b11111111}
|
||||
difficulty = _largest_power_of_two(difficulty) - 1; // (difficulty - 1) if it is a pow 2 then step down to second largest for more hashrate sampling
|
||||
|
||||
// convert difficulty into char array
|
||||
// Ex: 256 = {0b00000000, 0b00000000, 0b00000000, 0b11111111}, {0x00, 0x00, 0x00, 0xff}
|
||||
// Ex: 512 = {0b00000000, 0b00000000, 0b00000001, 0b11111111}, {0x00, 0x00, 0x01, 0xff}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
char value = (difficulty >> (8 * i)) & 0xFF;
|
||||
// The char is read in backwards to the register so we need to reverse them
|
||||
// So a mask of 512 looks like 0b00000000 00000000 00000001 1111111
|
||||
// and not 0b00000000 00000000 10000000 1111111
|
||||
|
||||
job_difficulty_mask[5 - i] = _reverse_bits(value);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Setting job ASIC mask to %d", difficulty);
|
||||
|
||||
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1397_SERIALTX_DEBUG);
|
||||
}
|
||||
|
||||
static uint8_t id = 0;
|
||||
|
||||
void BM1397_send_work(void *pvParameters, bm_job *next_bm_job)
|
||||
|
||||
@@ -126,3 +126,22 @@ esp_err_t receive_work(uint8_t * buffer, int buffer_size)
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void get_difficulty_mask(uint16_t difficulty, uint8_t *job_difficulty_mask)
|
||||
{
|
||||
// The mask must be a power of 2 so there are no holes
|
||||
// Correct: {0b00000000, 0b00000000, 0b11111111, 0b11111111}
|
||||
// Incorrect: {0b00000000, 0b00000000, 0b11100111, 0b11111111}
|
||||
difficulty = _largest_power_of_two(difficulty) - 1;
|
||||
|
||||
job_difficulty_mask[0] = 0x00;
|
||||
job_difficulty_mask[1] = 0x14; // TICKET_MASK
|
||||
|
||||
// convert difficulty into char array
|
||||
// Ex: 256 = {0b00000000, 0b00000000, 0b00000000, 0b11111111}, {0x00, 0x00, 0x00, 0xff}
|
||||
// Ex: 512 = {0b00000000, 0b00000000, 0b00000001, 0b11111111}, {0x00, 0x00, 0x01, 0xff}
|
||||
job_difficulty_mask[2] = _reverse_bits((difficulty >> 24) & 0xFF);
|
||||
job_difficulty_mask[3] = _reverse_bits((difficulty >> 16) & 0xFF);
|
||||
job_difficulty_mask[4] = _reverse_bits((difficulty >> 8) & 0xFF);
|
||||
job_difficulty_mask[5] = _reverse_bits( difficulty & 0xFF);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
uint8_t ASIC_init(GlobalState * GLOBAL_STATE);
|
||||
task_result * ASIC_process_work(GlobalState * GLOBAL_STATE);
|
||||
int ASIC_set_max_baud(GlobalState * GLOBAL_STATE);
|
||||
void ASIC_set_job_difficulty_mask(GlobalState * GLOBAL_STATE, uint8_t mask);
|
||||
void ASIC_send_work(GlobalState * GLOBAL_STATE, void * next_job);
|
||||
void ASIC_set_version_mask(GlobalState * GLOBAL_STATE, uint32_t mask);
|
||||
bool ASIC_set_frequency(GlobalState * GLOBAL_STATE, float target_frequency);
|
||||
|
||||
@@ -23,7 +23,6 @@ typedef struct __attribute__((__packed__))
|
||||
|
||||
uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count, uint16_t difficulty);
|
||||
void BM1366_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
|
||||
void BM1366_set_job_difficulty_mask(int);
|
||||
void BM1366_set_version_mask(uint32_t version_mask);
|
||||
int BM1366_set_max_baud(void);
|
||||
int BM1366_set_default_baud(void);
|
||||
|
||||
@@ -23,7 +23,6 @@ typedef struct __attribute__((__packed__))
|
||||
|
||||
uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count, uint16_t difficulty);
|
||||
void BM1368_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
|
||||
void BM1368_set_job_difficulty_mask(int);
|
||||
void BM1368_set_version_mask(uint32_t version_mask);
|
||||
int BM1368_set_max_baud(void);
|
||||
int BM1368_set_default_baud(void);
|
||||
|
||||
@@ -23,7 +23,6 @@ typedef struct __attribute__((__packed__))
|
||||
|
||||
uint8_t BM1370_init(uint64_t frequency, uint16_t asic_count, uint16_t difficulty);
|
||||
void BM1370_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
|
||||
void BM1370_set_job_difficulty_mask(int);
|
||||
void BM1370_set_version_mask(uint32_t version_mask);
|
||||
int BM1370_set_max_baud(void);
|
||||
int BM1370_set_default_baud(void);
|
||||
|
||||
@@ -25,7 +25,6 @@ typedef struct __attribute__((__packed__))
|
||||
|
||||
uint8_t BM1397_init(uint64_t frequency, uint16_t asic_count, uint16_t difficulty);
|
||||
void BM1397_send_work(void * GLOBAL_STATE, bm_job * next_bm_job);
|
||||
void BM1397_set_job_difficulty_mask(int);
|
||||
void BM1397_set_version_mask(uint32_t version_mask);
|
||||
int BM1397_set_max_baud(void);
|
||||
int BM1397_set_default_baud(void);
|
||||
|
||||
@@ -16,5 +16,6 @@ int _largest_power_of_two(int num);
|
||||
|
||||
int count_asic_chips(uint16_t asic_count, uint16_t chip_id, int chip_id_response_length);
|
||||
esp_err_t receive_work(uint8_t * buffer, int buffer_size);
|
||||
void get_difficulty_mask(uint16_t difficulty, uint8_t *job_difficulty_mask);
|
||||
|
||||
#endif /* COMMON_H_ */
|
||||
|
||||
@@ -729,20 +729,20 @@ float TPS546_get_vout(void)
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t TPS546_check_status(GlobalState * global_state) {
|
||||
esp_err_t TPS546_check_status(GlobalState * GLOBAL_STATE) {
|
||||
|
||||
SystemModule * SYSTEM_MODULE = &GLOBAL_STATE->SYSTEM_MODULE;
|
||||
uint16_t status;
|
||||
SystemModule * sys_module = &global_state->SYSTEM_MODULE;
|
||||
|
||||
ESP_RETURN_ON_ERROR(smb_read_word(PMBUS_STATUS_WORD, &status), TAG, "Failed to read STATUS_WORD");
|
||||
//determine if this is a fault we care about
|
||||
if (status & (TPS546_STATUS_OFF | TPS546_STATUS_VOUT_OV | TPS546_STATUS_IOUT_OC | TPS546_STATUS_VIN_UV | TPS546_STATUS_TEMP)) {
|
||||
if (sys_module->power_fault == 0) {
|
||||
if (SYSTEM_MODULE->power_fault == 0) {
|
||||
ESP_RETURN_ON_ERROR(TPS546_parse_status(status), TAG, "Failed to parse STATUS_WORD");
|
||||
sys_module->power_fault = 1;
|
||||
SYSTEM_MODULE->power_fault = 1;
|
||||
}
|
||||
} else {
|
||||
sys_module->power_fault = 0;
|
||||
SYSTEM_MODULE->power_fault = 0;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ esp_err_t TPS546_set_vout(float volts);
|
||||
void TPS546_show_voltage_settings(void);
|
||||
void TPS546_print_status(void);
|
||||
|
||||
esp_err_t TPS546_check_status(GlobalState * global_state);
|
||||
esp_err_t TPS546_check_status(GlobalState * GLOBAL_STATE);
|
||||
esp_err_t TPS546_clear_faults(void);
|
||||
|
||||
const char* TPS546_get_error_message(void); //Get the current TPS error message
|
||||
|
||||
@@ -84,7 +84,7 @@ esp_err_t VCORE_init(GlobalState * GLOBAL_STATE) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t VCORE_set_voltage(float core_voltage, GlobalState * GLOBAL_STATE)
|
||||
esp_err_t VCORE_set_voltage(GlobalState * GLOBAL_STATE, float core_voltage)
|
||||
{
|
||||
ESP_LOGI(TAG, "Set ASIC voltage = %.3fV", core_voltage);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "global_state.h"
|
||||
|
||||
esp_err_t VCORE_init(GlobalState * GLOBAL_STATE);
|
||||
esp_err_t VCORE_set_voltage(float core_voltage, GlobalState * GLOBAL_STATE);
|
||||
esp_err_t VCORE_set_voltage(GlobalState * GLOBAL_STATE, float core_voltage);
|
||||
int16_t VCORE_get_voltage_mv(GlobalState * GLOBAL_STATE);
|
||||
esp_err_t VCORE_check_fault(GlobalState * GLOBAL_STATE);
|
||||
const char* VCORE_get_fault_string(GlobalState * GLOBAL_STATE);
|
||||
|
||||
@@ -46,6 +46,9 @@
|
||||
//Test Power Consumption
|
||||
#define POWER_CONSUMPTION_MARGIN 3 //+/- watts
|
||||
|
||||
//Test Difficulty
|
||||
#define DIFFICULTY 8
|
||||
|
||||
static const char * TAG = "self_test";
|
||||
|
||||
static SemaphoreHandle_t longPressSemaphore;
|
||||
@@ -79,7 +82,7 @@ static void display_msg(char * msg, GlobalState * GLOBAL_STATE)
|
||||
|
||||
static esp_err_t test_fan_sense(GlobalState * GLOBAL_STATE)
|
||||
{
|
||||
uint16_t fan_speed = Thermal_get_fan_speed(GLOBAL_STATE->DEVICE_CONFIG);
|
||||
uint16_t fan_speed = Thermal_get_fan_speed(&GLOBAL_STATE->DEVICE_CONFIG);
|
||||
ESP_LOGI(TAG, "fanSpeed: %d", fan_speed);
|
||||
if (fan_speed > FAN_SPEED_TARGET_MIN) {
|
||||
return ESP_OK;
|
||||
@@ -170,7 +173,7 @@ esp_err_t test_screen(GlobalState * GLOBAL_STATE) {
|
||||
esp_err_t init_voltage_regulator(GlobalState * GLOBAL_STATE) {
|
||||
ESP_RETURN_ON_ERROR(VCORE_init(GLOBAL_STATE), TAG, "VCORE init failed!");
|
||||
|
||||
ESP_RETURN_ON_ERROR(VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, GLOBAL_STATE), TAG, "VCORE set voltage failed!");
|
||||
ESP_RETURN_ON_ERROR(VCORE_set_voltage(GLOBAL_STATE, nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0), TAG, "VCORE set voltage failed!");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -329,6 +332,8 @@ bool self_test(void * pvParameters)
|
||||
GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY);
|
||||
ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %f", (float)GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value);
|
||||
|
||||
GLOBAL_STATE->DEVICE_CONFIG.family.asic.difficulty = DIFFICULTY;
|
||||
|
||||
uint8_t chips_detected = ASIC_init(GLOBAL_STATE);
|
||||
uint8_t chips_expected = GLOBAL_STATE->DEVICE_CONFIG.family.asic_count;
|
||||
ESP_LOGI(TAG, "%u chips detected, %u expected", chips_detected, chips_expected);
|
||||
@@ -406,11 +411,6 @@ bool self_test(void * pvParameters)
|
||||
|
||||
bm_job job = construct_bm_job(¬ify_message, merkle_root, 0x1fffe000, 1000000);
|
||||
|
||||
uint8_t difficulty_mask = 8;
|
||||
|
||||
//(*GLOBAL_STATE->ASIC_functions.set_difficulty_mask_fn)(difficulty_mask);
|
||||
ASIC_set_job_difficulty_mask(GLOBAL_STATE, difficulty_mask);
|
||||
|
||||
ESP_LOGI(TAG, "Sending work");
|
||||
|
||||
//(*GLOBAL_STATE->ASIC_functions.send_work_fn)(GLOBAL_STATE, &job);
|
||||
@@ -427,7 +427,7 @@ bool self_test(void * pvParameters)
|
||||
if (asic_result != NULL) {
|
||||
// check the nonce difficulty
|
||||
double nonce_diff = test_nonce_value(&job, asic_result->nonce, asic_result->rolled_version);
|
||||
sum += difficulty_mask;
|
||||
sum += DIFFICULTY;
|
||||
|
||||
hash_rate = (sum * 4294967296) / (duration * 1000000000);
|
||||
ESP_LOGI(TAG, "Nonce %lu Nonce difficulty %.32f.", asic_result->nonce, nonce_diff);
|
||||
@@ -483,7 +483,7 @@ bool self_test(void * pvParameters)
|
||||
|
||||
static void tests_done(GlobalState * GLOBAL_STATE, bool isTestPassed)
|
||||
{
|
||||
VCORE_set_voltage(0.0f, GLOBAL_STATE);
|
||||
VCORE_set_voltage(GLOBAL_STATE, 0.0f);
|
||||
|
||||
if (isTestPassed) {
|
||||
if (isFactoryTest) {
|
||||
|
||||
@@ -102,9 +102,9 @@ esp_err_t SYSTEM_init_peripherals(GlobalState * GLOBAL_STATE) {
|
||||
|
||||
// Initialize the core voltage regulator
|
||||
ESP_RETURN_ON_ERROR(VCORE_init(GLOBAL_STATE), TAG, "VCORE init failed!");
|
||||
ESP_RETURN_ON_ERROR(VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, GLOBAL_STATE), TAG, "VCORE set voltage failed!");
|
||||
ESP_RETURN_ON_ERROR(VCORE_set_voltage(GLOBAL_STATE, nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0), TAG, "VCORE set voltage failed!");
|
||||
|
||||
ESP_RETURN_ON_ERROR(Thermal_init(GLOBAL_STATE->DEVICE_CONFIG), TAG, "Thermal init failed!");
|
||||
ESP_RETURN_ON_ERROR(Thermal_init(&GLOBAL_STATE->DEVICE_CONFIG), TAG, "Thermal init failed!");
|
||||
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
|
||||
|
||||
@@ -72,14 +72,13 @@ void POWER_MANAGEMENT_task(void * pvParameters)
|
||||
uint16_t last_asic_frequency = power_management->frequency_value;
|
||||
|
||||
while (1) {
|
||||
|
||||
// Refresh PID setpoint from NVS in case it was changed via API
|
||||
pid_setPoint = (double)nvs_config_get_u16(NVS_CONFIG_TEMP_TARGET, pid_setPoint);
|
||||
|
||||
power_management->voltage = Power_get_input_voltage(GLOBAL_STATE);
|
||||
power_management->power = Power_get_power(GLOBAL_STATE);
|
||||
|
||||
power_management->fan_rpm = Thermal_get_fan_speed(GLOBAL_STATE->DEVICE_CONFIG);
|
||||
power_management->fan_rpm = Thermal_get_fan_speed(&GLOBAL_STATE->DEVICE_CONFIG);
|
||||
power_management->chip_temp_avg = Thermal_get_chip_temp(GLOBAL_STATE);
|
||||
|
||||
power_management->vr_temp = Power_get_vreg_temp(GLOBAL_STATE);
|
||||
@@ -93,10 +92,10 @@ void POWER_MANAGEMENT_task(void * pvParameters)
|
||||
if ((power_management->vr_temp > TPS546_THROTTLE_TEMP || power_management->chip_temp_avg > THROTTLE_TEMP) && (power_management->frequency_value > 50 || power_management->voltage > 1000)) {
|
||||
ESP_LOGE(TAG, "OVERHEAT! VR: %fC ASIC %fC", power_management->vr_temp, power_management->chip_temp_avg );
|
||||
power_management->fan_perc = 100;
|
||||
Thermal_set_fan_percent(GLOBAL_STATE->DEVICE_CONFIG, 1);
|
||||
Thermal_set_fan_percent(&GLOBAL_STATE->DEVICE_CONFIG, 1);
|
||||
|
||||
// Turn off core voltage
|
||||
VCORE_set_voltage(0.0f, GLOBAL_STATE);
|
||||
VCORE_set_voltage(GLOBAL_STATE, 0.0f);
|
||||
|
||||
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 1000);
|
||||
nvs_config_set_u16(NVS_CONFIG_ASIC_FREQ, 50);
|
||||
@@ -142,14 +141,14 @@ void POWER_MANAGEMENT_task(void * pvParameters)
|
||||
// ESP_LOGD(TAG, "DEBUG: PID raw output: %.2f%%, Input: %.1f, SetPoint: %.1f", pid_output, pid_input, pid_setPoint);
|
||||
|
||||
power_management->fan_perc = (uint16_t) pid_output;
|
||||
Thermal_set_fan_percent(GLOBAL_STATE->DEVICE_CONFIG, pid_output / 100.0);
|
||||
Thermal_set_fan_percent(&GLOBAL_STATE->DEVICE_CONFIG, pid_output / 100.0);
|
||||
ESP_LOGI(TAG, "Temp: %.1f°C, SetPoint: %.1f°C, Output: %.1f%% (P:%.1f I:%.1f D_val:%.1f D_start_val:%.1f)",
|
||||
pid_input, pid_setPoint, pid_output, pid.dispKp, pid.dispKi, pid.dispKd, pid_d_startup); // Log current effective Kp, Ki, Kd
|
||||
} else {
|
||||
if (GLOBAL_STATE->SYSTEM_MODULE.ap_enabled) {
|
||||
ESP_LOGW(TAG, "AP mode with invalid temperature reading: %.1f°C - Setting fan to 70%%", power_management->chip_temp_avg);
|
||||
power_management->fan_perc = 70;
|
||||
Thermal_set_fan_percent(GLOBAL_STATE->DEVICE_CONFIG, 0.7);
|
||||
Thermal_set_fan_percent(&GLOBAL_STATE->DEVICE_CONFIG, 0.7);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Ignoring invalid temperature reading: %.1f°C", power_management->chip_temp_avg);
|
||||
}
|
||||
@@ -157,7 +156,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
|
||||
} else { // Manual fan speed
|
||||
float fs = (float) nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100);
|
||||
power_management->fan_perc = fs;
|
||||
Thermal_set_fan_percent(GLOBAL_STATE->DEVICE_CONFIG, (float) fs / 100.0);
|
||||
Thermal_set_fan_percent(&GLOBAL_STATE->DEVICE_CONFIG, (float) fs / 100.0);
|
||||
}
|
||||
|
||||
uint16_t core_voltage = nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE);
|
||||
@@ -165,7 +164,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
|
||||
|
||||
if (core_voltage != last_core_voltage) {
|
||||
ESP_LOGI(TAG, "setting new vcore voltage to %umV", core_voltage);
|
||||
VCORE_set_voltage((double) core_voltage / 1000.0, GLOBAL_STATE);
|
||||
VCORE_set_voltage(GLOBAL_STATE, (double) core_voltage / 1000.0);
|
||||
last_core_voltage = core_voltage;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,21 +4,21 @@
|
||||
|
||||
static const char * TAG = "thermal";
|
||||
|
||||
esp_err_t Thermal_init(DeviceConfig device_config)
|
||||
esp_err_t Thermal_init(DeviceConfig * DEVICE_CONFIG)
|
||||
{
|
||||
if (device_config.EMC2101) {
|
||||
ESP_LOGI(TAG, "Initializing EMC2101 (Temperature offset: %dC)", device_config.emc_temp_offset);
|
||||
if (DEVICE_CONFIG->EMC2101) {
|
||||
ESP_LOGI(TAG, "Initializing EMC2101 (Temperature offset: %dC)", DEVICE_CONFIG->emc_temp_offset);
|
||||
esp_err_t res = EMC2101_init();
|
||||
// TODO: Improve this check.
|
||||
if (device_config.emc_ideality_factor != 0x00) {
|
||||
ESP_LOGI(TAG, "EMC2101 configuration: Ideality Factor: %02x, Beta Compensation: %02x", device_config.emc_ideality_factor, device_config.emc_beta_compensation);
|
||||
EMC2101_set_ideality_factor(device_config.emc_ideality_factor);
|
||||
EMC2101_set_beta_compensation(device_config.emc_beta_compensation);
|
||||
if (DEVICE_CONFIG->emc_ideality_factor != 0x00) {
|
||||
ESP_LOGI(TAG, "EMC2101 configuration: Ideality Factor: %02x, Beta Compensation: %02x", DEVICE_CONFIG->emc_ideality_factor, DEVICE_CONFIG->emc_beta_compensation);
|
||||
EMC2101_set_ideality_factor(DEVICE_CONFIG->emc_ideality_factor);
|
||||
EMC2101_set_beta_compensation(DEVICE_CONFIG->emc_beta_compensation);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
if (device_config.EMC2103) {
|
||||
ESP_LOGI(TAG, "Initializing EMC2103 (Temperature offset: %dC)", device_config.emc_temp_offset);
|
||||
if (DEVICE_CONFIG->EMC2103) {
|
||||
ESP_LOGI(TAG, "Initializing EMC2103 (Temperature offset: %dC)", DEVICE_CONFIG->emc_temp_offset);
|
||||
return EMC2103_init();
|
||||
}
|
||||
|
||||
@@ -26,23 +26,23 @@ esp_err_t Thermal_init(DeviceConfig device_config)
|
||||
}
|
||||
|
||||
//percent is a float between 0.0 and 1.0
|
||||
esp_err_t Thermal_set_fan_percent(DeviceConfig device_config, float percent)
|
||||
esp_err_t Thermal_set_fan_percent(DeviceConfig * DEVICE_CONFIG, float percent)
|
||||
{
|
||||
if (device_config.EMC2101) {
|
||||
if (DEVICE_CONFIG->EMC2101) {
|
||||
EMC2101_set_fan_speed(percent);
|
||||
}
|
||||
if (device_config.EMC2103) {
|
||||
if (DEVICE_CONFIG->EMC2103) {
|
||||
EMC2103_set_fan_speed(percent);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint16_t Thermal_get_fan_speed(DeviceConfig device_config)
|
||||
uint16_t Thermal_get_fan_speed(DeviceConfig * DEVICE_CONFIG)
|
||||
{
|
||||
if (device_config.EMC2101) {
|
||||
if (DEVICE_CONFIG->EMC2101) {
|
||||
return EMC2101_get_fan_speed();
|
||||
}
|
||||
if (device_config.EMC2103) {
|
||||
if (DEVICE_CONFIG->EMC2103) {
|
||||
return EMC2103_get_fan_speed();
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#include "EMC2103.h"
|
||||
#include "global_state.h"
|
||||
|
||||
esp_err_t Thermal_init(DeviceConfig device_config);
|
||||
esp_err_t Thermal_set_fan_percent(DeviceConfig device_config, float percent);
|
||||
uint16_t Thermal_get_fan_speed(DeviceConfig device_config);
|
||||
esp_err_t Thermal_init(DeviceConfig * DEVICE_CONFIG);
|
||||
esp_err_t Thermal_set_fan_percent(DeviceConfig * DEVICE_CONFIG, float percent);
|
||||
uint16_t Thermal_get_fan_speed(DeviceConfig * DEVICE_CONFIG);
|
||||
|
||||
float Thermal_get_chip_temp(GlobalState * GLOBAL_STATE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user