-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathq1373.cpp
More file actions
147 lines (121 loc) · 4.54 KB
/
Copy pathq1373.cpp
File metadata and controls
147 lines (121 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "q1373.h"
#include "./drivers/TPS53667.h"
#include "bm1373.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "i2c_master.h"
static const char *TAG = "q1373";
// strap resistors on the FXL6408, read as inputs with pull-up:
// 0R to GND populated = low, not populated = high
#define PHASE_DETECT_EXP_PIN 6 // low = 6-phase VR (TPS53667), high = 4-phase (TPS53647)
#define ETH_DETECT_EXP_PIN 7 // low = no ethernet, high = ethernet populated
Q1373B::Q1373B() : Q1370B()
{
m_deviceModel = "Q1373";
m_miningAgent = m_deviceModel;
m_asicModel = "BM1373";
m_asicCount = 4;
m_numPhases = 4;
// formula from the tps53647 datasheet
// Rmon=48.7k, Imax=122,17A
m_imax = (int) round(0.85 / 48700.0 / 5.0e-3 * 35000.0);
m_ifault = (float) 160.0f;
m_maxPin = 180.0;
m_minPin = 50.0;
m_maxVin = 13.0;
m_minVin = 11.0;
m_minCurrentA = 0.0f;
m_maxCurrentA = 15.0f;
m_asicFrequencies = {250, 275, 300, 325, 350, 375, 400, 425, 475, 500, 550};
m_asicVoltages = {980, 990, 1000, 1010, 1020, 1030, 1040, 1050, 1060, 1070, 1080};
m_defaultAsicFrequency = m_asicFrequency = 425;
m_defaultAsicVoltageMillis = m_asicVoltageMillis = 1010;
m_absMaxAsicFrequency = 730;
m_absMinAsicVoltageMillis = 900;
m_absMaxAsicVoltageMillis = 1200;
m_initVoltageMillis = 1050;
m_pidSettings[0].targetTemp = 60;
m_pidSettings[0].p = 600; // 6.00
m_pidSettings[0].i = 10; // 0.10
m_pidSettings[0].d = 1000; // 10.00
m_pidSettings[1].targetTemp = 65; // target temp for vreg
m_pidSettings[1].p = 600; // 6.00
m_pidSettings[1].i = 10; // 0.10
m_pidSettings[1].d = 1000; // 10.00
// ship with PID fan control by default (ch1 stays linked); with target 60°C
// the fan holds max(ASIC, VReg) for good out-of-the-box efficiency
m_fanMode[0] = 2; // PID
m_asicMaxDifficulty = 4096;
m_asicMinDifficulty = 1024;
m_asicMinDifficultyDualPool = 512;
#ifdef Q1373
m_theme = new ThemeGeneric();
#endif
m_asics = new BM1373();
// strap detection has to happen in the constructor because
// hasEthernet() and loadSettings() are called before initBoard()
detectBoardOptions();
if (m_isTPS53667) {
delete m_tps;
m_tps = new TPS53667();
// formula from tps53667 datasheet (33.2k 0.1% Rmon)
m_imax = (int) round(0.85 / 33200.0 / 5.0e-3 * 35000.0);
m_numPhases = m_is6Phase ? 6 : 4;
m_ifault = (float) m_numPhases * 40.0f;
m_maxPin = (float) m_numPhases * 45.0f;
m_maxCurrentA = m_maxPin / 12.0f;
} else if (m_is6Phase) {
// 6 phases are only possible with the TPS53667
ESP_LOGE(TAG, "6-phase strap set but no TPS53667 found; staying with 4-phase TPS53647");
}
}
void Q1373B::detectBoardOptions()
{
// the straps hang on the FXL6408, so I2C and the expander must be
// brought up here already; initBoard() inits them again later
if (i2c_master_init() != ESP_OK) {
ESP_LOGE(TAG, "I2C init failed; keeping defaults (4 phases, ethernet)");
return;
}
if (!m_io.init()) {
ESP_LOGE(TAG, "FXL6408 init failed; keeping defaults (4 phases, ethernet)");
return;
}
m_io.enable_pull_up(PHASE_DETECT_EXP_PIN);
m_io.enable_pull_up(ETH_DETECT_EXP_PIN);
// let the pins settle
vTaskDelay(pdMS_TO_TICKS(1));
bool level = true;
if (m_io.read_pin(PHASE_DETECT_EXP_PIN, &level) == ESP_OK) {
m_is6Phase = !level;
} else {
ESP_LOGE(TAG, "failed to read phase detect pin; assuming 4 phases");
}
if (m_io.read_pin(ETH_DETECT_EXP_PIN, &level) == ESP_OK) {
m_hasEth = level;
} else {
ESP_LOGE(TAG, "failed to read ETH detect pin; assuming ethernet");
}
// detect the VR chip via its PMBus device code, independently of the
// phase strap (the new board revision has a TPS53667 that BOM variants
// can populate with only 4 phases)
uint16_t device_code = 0;
{
TPS53647 probe;
device_code = probe.get_device_code();
}
m_isTPS53667 = (device_code == TPS53667::DEVICE_CODE);
ESP_LOGI(TAG, "detection: VR device code %04x (%s), %d phases, ethernet %s", device_code,
m_isTPS53667 ? "TPS53667" : "TPS53647", m_is6Phase ? 6 : 4, m_hasEth ? "populated" : "not populated");
}
bool Q1373B::initBoard()
{
if (!Q1370B::initBoard()) {
return false;
}
if (m_tmp451) {
m_tmp451->set_temp_cal(1.06f, -25.4f, -25.4f, -25.4f, -25.4f);
}
return true;
}