Skip to content

Commit 3c12a44

Browse files
committed
flash new modules
1 parent 10e9e2f commit 3c12a44

File tree

13 files changed

+107
-137
lines changed

13 files changed

+107
-137
lines changed

src/eez/index.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818

1919
#include <assert.h>
20+
#include <stdio.h>
21+
#include <string.h>
2022

2123
#include <eez/index.h>
2224

@@ -32,10 +34,11 @@
3234

3335
namespace eez {
3436

35-
ModuleInfo::ModuleInfo(uint16_t moduleType_, uint16_t moduleCategory_, const char *moduleName_, uint16_t latestModuleRevision_)
37+
ModuleInfo::ModuleInfo(uint16_t moduleType_, uint16_t moduleCategory_, const char *moduleName_, const char *moduleBrand_, uint16_t latestModuleRevision_)
3638
: moduleType(moduleType_)
3739
, moduleCategory(moduleCategory_)
3840
, moduleName(moduleName_)
41+
, moduleBrand(moduleBrand_)
3942
, latestModuleRevision(latestModuleRevision_)
4043
{
4144
}
@@ -78,7 +81,7 @@ int ModuleInfo::getSlotView(SlotViewType slotViewType, int slotIndex, int cursor
7881

7982
////////////////////////////////////////////////////////////////////////////////
8083

81-
ModuleInfo noneModuleInfo(MODULE_TYPE_NONE, MODULE_CATEGORY_NONE, "None", 0);
84+
ModuleInfo noneModuleInfo(MODULE_TYPE_NONE, MODULE_CATEGORY_NONE, "None", "None", 0);
8285

8386
static ModuleInfo *g_modules[] = {
8487
dcp405::g_moduleInfo,
@@ -89,6 +92,14 @@ static ModuleInfo *g_modules[] = {
8992
dib_smx46::g_moduleInfo
9093
};
9194

95+
SlotInfo g_slots[NUM_SLOTS] = {
96+
{ &noneModuleInfo },
97+
{ &noneModuleInfo },
98+
{ &noneModuleInfo }
99+
};
100+
101+
////////////////////////////////////////////////////////////////////////////////
102+
92103
ModuleInfo *getModuleInfo(uint16_t moduleType) {
93104
for (unsigned int i = 0; i < sizeof(g_modules) / sizeof(ModuleInfo *); i++) {
94105
if (g_modules[i]->moduleType == moduleType) {
@@ -98,10 +109,14 @@ ModuleInfo *getModuleInfo(uint16_t moduleType) {
98109
return &noneModuleInfo;
99110
}
100111

101-
SlotInfo g_slots[NUM_SLOTS] = {
102-
{ &noneModuleInfo },
103-
{ &noneModuleInfo },
104-
{ &noneModuleInfo }
105-
};
112+
void getSlotSerialInfo(SlotInfo &slotInfo, char *text) {
113+
if (slotInfo.idw0 != 0 || slotInfo.idw1 != 0 || slotInfo.idw2 != 0) {
114+
sprintf(text, "%08X", (unsigned int)slotInfo.idw0);
115+
sprintf(text + 8, "%08X", (unsigned int)slotInfo.idw1);
116+
sprintf(text + 16, "%08X", (unsigned int)slotInfo.idw2);
117+
} else {
118+
strcpy(text, "N/A");
119+
}
120+
}
106121

107122
} // namespace eez

src/eez/index.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,29 @@ struct ModuleInfo {
4545
uint16_t moduleType;
4646
uint16_t moduleCategory;
4747
const char *moduleName;
48+
const char *moduleBrand;
4849
uint16_t latestModuleRevision;
4950

50-
ModuleInfo(uint16_t moduleType, uint16_t moduleCategory, const char *moduleName, uint16_t latestModuleRevision);
51+
ModuleInfo(uint16_t moduleType, uint16_t moduleCategory, const char *moduleName, const char *moduleBrand, uint16_t latestModuleRevision);
5152

5253
virtual int getSlotView(SlotViewType slotViewType, int slotIndex, int cursor);
5354
};
5455

55-
ModuleInfo *getModuleInfo(uint16_t moduleType);
56-
5756
struct SlotInfo {
5857
ModuleInfo *moduleInfo;
5958
uint16_t moduleRevision;
59+
uint8_t firmwareMajorVersion;
60+
uint8_t firmwareMinorVersion;
61+
uint32_t idw0;
62+
uint32_t idw1;
63+
uint32_t idw2;
6064
};
6165

6266
static const int NUM_SLOTS = 3;
6367
extern SlotInfo g_slots[NUM_SLOTS];
6468

69+
ModuleInfo *getModuleInfo(uint16_t moduleType);
70+
71+
void getSlotSerialInfo(SlotInfo &slotInfo, char *text);
72+
6573
} // namespace eez

src/eez/modules/dcm220/channel.cpp

Lines changed: 55 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,37 @@ static const float I_MON_RESOLUTION = 0.02f;
7373
static GPIO_TypeDef *SPI_IRQ_GPIO_Port[] = { SPI2_IRQ_GPIO_Port, SPI4_IRQ_GPIO_Port, SPI5_IRQ_GPIO_Port };
7474
static const uint16_t SPI_IRQ_Pin[] = { SPI2_IRQ_Pin, SPI4_IRQ_Pin, SPI5_IRQ_Pin };
7575

76-
bool masterSynchro(int slotIndex, uint8_t &firmwareMajorVersion, uint8_t &firmwareMinorVersion, uint32_t &idw0, uint32_t &idw1, uint32_t &idw2) {
76+
float calcTemperature(uint16_t adcValue) {
77+
if (adcValue == 65535) {
78+
// not measured yet
79+
return 25;
80+
}
81+
82+
// http://www.giangrandi.ch/electronics/ntc/ntc.shtml
83+
84+
float RF = 3300.0f;
85+
float T25 = 298.15F;
86+
float R25 = 10000;
87+
float BETA = 3570;
88+
float ADC_MAX_FOR_TEMP = 4095.0f;
89+
90+
float RT = RF * (ADC_MAX_FOR_TEMP - adcValue) / adcValue;
91+
92+
float Tkelvin = 1 / (logf(RT / R25) / BETA + 1 / T25);
93+
float Tcelsius = Tkelvin - 273.15f;
94+
95+
float TEMP_OFFSET = 10.0f; // empirically determined
96+
Tcelsius -= TEMP_OFFSET;
97+
98+
return roundPrec(Tcelsius, 1.0f);
99+
}
100+
101+
#endif
102+
103+
bool masterSynchro(int slotIndex) {
104+
auto &slot = g_slots[slotIndex];
105+
106+
#if defined(EEZ_PLATFORM_STM32)
77107
uint32_t start = millis();
78108

79109
uint8_t txBuffer[15] = { SPI_MASTER_SYNBYTE, 0, 0 };
@@ -90,11 +120,11 @@ bool masterSynchro(int slotIndex, uint8_t &firmwareMajorVersion, uint8_t &firmwa
90120
uint32_t startIrq = millis();
91121
while (true) {
92122
if (HAL_GPIO_ReadPin(SPI_IRQ_GPIO_Port[slotIndex], SPI_IRQ_Pin[slotIndex]) == GPIO_PIN_SET) {
93-
firmwareMajorVersion = rxBuffer[1];
94-
firmwareMinorVersion = rxBuffer[2];
95-
idw0 = (rxBuffer[3] << 24) | (rxBuffer[4] << 16) | (rxBuffer[5] << 8) | rxBuffer[6];
96-
idw1 = (rxBuffer[7] << 24) | (rxBuffer[8] << 16) | (rxBuffer[9] << 8) | rxBuffer[10];
97-
idw2 = (rxBuffer[11] << 24) | (rxBuffer[12] << 16) | (rxBuffer[13] << 8) | rxBuffer[14];
123+
slot.firmwareMajorVersion = rxBuffer[1];
124+
slot.firmwareMinorVersion = rxBuffer[2];
125+
slot.idw0 = (rxBuffer[3] << 24) | (rxBuffer[4] << 16) | (rxBuffer[5] << 8) | rxBuffer[6];
126+
slot.idw1 = (rxBuffer[7] << 24) | (rxBuffer[8] << 16) | (rxBuffer[9] << 8) | rxBuffer[10];
127+
slot.idw2 = (rxBuffer[11] << 24) | (rxBuffer[12] << 16) | (rxBuffer[13] << 8) | rxBuffer[14];
98128
return true;
99129
}
100130

@@ -107,46 +137,35 @@ bool masterSynchro(int slotIndex, uint8_t &firmwareMajorVersion, uint8_t &firmwa
107137

108138
int32_t diff = millis() - start;
109139
if (diff > CONF_MASTER_SYNC_TIMEOUT_MS) {
140+
slot.firmwareMajorVersion = 0;
141+
slot.firmwareMinorVersion = 0;
142+
slot.idw0 = 0;
143+
slot.idw1 = 0;
144+
slot.idw2 = 0;
110145
return false;
111146
}
112147
}
113-
}
114-
115-
float calcTemperature(uint16_t adcValue) {
116-
if (adcValue == 65535) {
117-
// not measured yet
118-
return 25;
119-
}
120-
121-
// http://www.giangrandi.ch/electronics/ntc/ntc.shtml
122-
123-
float RF = 3300.0f;
124-
float T25 = 298.15F;
125-
float R25 = 10000;
126-
float BETA = 3570;
127-
float ADC_MAX_FOR_TEMP = 4095.0f;
128-
129-
float RT = RF * (ADC_MAX_FOR_TEMP - adcValue) / adcValue;
130-
131-
float Tkelvin = 1 / (logf(RT / R25) / BETA + 1 / T25);
132-
float Tcelsius = Tkelvin - 273.15f;
148+
#endif
133149

134-
float TEMP_OFFSET = 10.0f; // empirically determined
135-
Tcelsius -= TEMP_OFFSET;
150+
#if defined(EEZ_PLATFORM_SIMULATOR)
151+
slot.firmwareMajorVersion = 1;
152+
slot.firmwareMinorVersion = 0;
153+
slot.idw0 = 0;
154+
slot.idw1 = 0;
155+
slot.idw2 = 0;
156+
return true;
157+
#endif
136158

137-
return roundPrec(Tcelsius, 1.0f);
138159
}
139160

140-
#endif
141-
142161
struct DcmChannel : public Channel {
143162
bool outputEnable;
144163

145164
uint8_t output[BUFFER_SIZE];
146165

147-
#if defined(EEZ_PLATFORM_STM32)
148166
bool synchronized;
149167

168+
#if defined(EEZ_PLATFORM_STM32)
150169
uint8_t input[BUFFER_SIZE];
151170

152171
uint16_t uSet;
@@ -164,12 +183,6 @@ struct DcmChannel : public Channel {
164183

165184
TestResult testResult;
166185

167-
uint8_t firmwareMajorVersion = 0;
168-
uint8_t firmwareMinorVersion = 0;
169-
uint32_t idw0 = 0;
170-
uint32_t idw1 = 0;
171-
uint32_t idw2 = 0;
172-
173186
float I_MAX_FOR_REMAP;
174187

175188
float U_CAL_POINTS[2];
@@ -303,40 +316,17 @@ struct DcmChannel : public Channel {
303316
#endif
304317

305318
void init() override {
306-
#if defined(EEZ_PLATFORM_STM32)
307319
if (!synchronized && subchannelIndex == 0) {
308-
if (masterSynchro(slotIndex, firmwareMajorVersion, firmwareMinorVersion, idw0, idw1, idw2)) {
320+
if (masterSynchro(slotIndex)) {
309321
//DebugTrace("DCM220 slot #%d firmware version %d.%d\n", slotIndex + 1, (int)firmwareMajorVersion, (int)firmwareMinorVersion);
310322
synchronized = true;
323+
#if defined(EEZ_PLATFORM_STM32)
311324
numCrcErrors = 0;
325+
#endif
312326
} else {
313327
event_queue::pushEvent(event_queue::EVENT_ERROR_SLOT1_SYNC_ERROR + slotIndex);
314-
firmwareMinorVersion = 0;
315-
firmwareMajorVersion = 0;
316-
idw0 = 0;
317-
idw1 = 0;
318-
idw2 = 0;
319328
}
320329
}
321-
322-
if (subchannelIndex == 1) {
323-
auto& firstChannel = (DcmChannel &)Channel::get(channelIndex - 1);
324-
325-
firmwareMinorVersion = firstChannel.firmwareMinorVersion;
326-
firmwareMajorVersion = firstChannel.firmwareMajorVersion;
327-
idw0 = firstChannel.idw0;
328-
idw1 = firstChannel.idw1;
329-
idw2 = firstChannel.idw2;
330-
}
331-
#endif
332-
333-
#if defined(EEZ_PLATFORM_SIMULATOR)
334-
firmwareMajorVersion = 1;
335-
firmwareMinorVersion = 0;
336-
idw0 = 0;
337-
idw1 = 0;
338-
idw2 = 0;
339-
#endif
340330
}
341331

342332
void onPowerDown() {
@@ -589,25 +579,6 @@ struct DcmChannel : public Channel {
589579
return false;
590580
}
591581

592-
void getFirmwareVersion(uint8_t &majorVersion, uint8_t &minorVersion) {
593-
majorVersion = firmwareMajorVersion;
594-
minorVersion = firmwareMinorVersion;
595-
}
596-
597-
const char *getBrand() {
598-
return "Envox";
599-
}
600-
601-
void getSerial(char *text) {
602-
#if defined(EEZ_PLATFORM_STM32)
603-
sprintf(text, "%08X", (unsigned int)idw0);
604-
sprintf(text + 8, "%08X", (unsigned int)idw1);
605-
sprintf(text + 16, "%08X", (unsigned int)idw2);
606-
#else
607-
strcpy(text, "N/A");
608-
#endif
609-
}
610-
611582
void getVoltageStepValues(StepValues *stepValues, bool calibrationMode) {
612583
static float values[] = { 1.0f, 0.5f, 0.1f, 0.01f };
613584
static float calibrationModeValues[] = { 1.0f, 0.1f, 0.01f, 0.001f };
@@ -656,7 +627,7 @@ struct DcmChannel : public Channel {
656627
struct DcmChannelModuleInfo : public PsuChannelModuleInfo {
657628
public:
658629
DcmChannelModuleInfo(uint16_t moduleType, const char *moduleName, uint16_t latestModuleRevision)
659-
: PsuChannelModuleInfo(moduleType, moduleName, latestModuleRevision, 2)
630+
: PsuChannelModuleInfo(moduleType, moduleName, "Envox", latestModuleRevision, 2)
660631
{
661632
}
662633

src/eez/modules/dcp405/channel.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -747,19 +747,6 @@ struct DcpChannel : public Channel {
747747
}
748748
#endif
749749

750-
void getFirmwareVersion(uint8_t &majorVersion, uint8_t &minorVersion) {
751-
majorVersion = 0;
752-
minorVersion = 0;
753-
}
754-
755-
const char *getBrand() {
756-
return "Envox";
757-
}
758-
759-
void getSerial(char *text) {
760-
strcpy(text, "N/A");
761-
}
762-
763750
void getVoltageStepValues(StepValues *stepValues, bool calibrationMode) {
764751
static float values[] = { 1.0f, 0.1f, 0.01f, 0.005f };
765752
static float calibrationModeValues[] = { 1.0f, 0.1f, 0.01f, 0.001f };
@@ -804,7 +791,7 @@ struct DcpChannel : public Channel {
804791
struct DcpChannelModuleInfo : public PsuChannelModuleInfo {
805792
public:
806793
DcpChannelModuleInfo()
807-
: PsuChannelModuleInfo(MODULE_TYPE_DCP405, "DCP405", MODULE_REVISION_DCP405_R2B7, 1)
794+
: PsuChannelModuleInfo(MODULE_TYPE_DCP405, "DCP405", "Envox", MODULE_REVISION_DCP405_R2B7, 1)
808795
{
809796
}
810797

src/eez/modules/dib-mio168/dib-mio168.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace dib_mio168 {
2828
struct Mio168ModuleInfo : public ModuleInfo {
2929
public:
3030
Mio168ModuleInfo()
31-
: ModuleInfo(MODULE_TYPE_DIB_MIO168, MODULE_CATEGORY_OTHER, "MIO168", MODULE_REVISION_R1B2)
31+
: ModuleInfo(MODULE_TYPE_DIB_MIO168, MODULE_CATEGORY_OTHER, "MIO168", "Envox", MODULE_REVISION_R1B2)
3232
{}
3333

3434
int getSlotView(SlotViewType slotViewType, int slotIndex, int cursor) override {

src/eez/modules/dib-prel6/dib-prel6.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace dib_prel6 {
2828
struct Prel6ModuleInfo : public ModuleInfo {
2929
public:
3030
Prel6ModuleInfo()
31-
: ModuleInfo(MODULE_TYPE_DIB_PREL6, MODULE_CATEGORY_OTHER, "PREL6", MODULE_REVISION_R1B2)
31+
: ModuleInfo(MODULE_TYPE_DIB_PREL6, MODULE_CATEGORY_OTHER, "PREL6", "Envox", MODULE_REVISION_R1B2)
3232
{}
3333

3434
int getSlotView(SlotViewType slotViewType, int slotIndex, int cursor) override {

src/eez/modules/dib-smx46/dib-smx46.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace dib_smx46 {
2828
struct Smx46ModuleInfo : public ModuleInfo {
2929
public:
3030
Smx46ModuleInfo()
31-
: ModuleInfo(MODULE_TYPE_DIB_SMX46, MODULE_CATEGORY_OTHER, "SMX46", MODULE_REVISION_R1B2)
31+
: ModuleInfo(MODULE_TYPE_DIB_SMX46, MODULE_CATEGORY_OTHER, "SMX46", "Envox", MODULE_REVISION_R1B2)
3232
{}
3333

3434
int getSlotView(SlotViewType slotViewType, int slotIndex, int cursor) override {

src/eez/modules/psu/channel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ namespace psu {
5050

5151
////////////////////////////////////////////////////////////////////////////////
5252

53-
PsuChannelModuleInfo::PsuChannelModuleInfo(uint16_t moduleType, const char *moduleName, uint16_t latestModuleRevision, uint8_t numChannels_)
54-
: ModuleInfo(moduleType, MODULE_CATEGORY_DCPSUPPLY, moduleName, latestModuleRevision)
53+
PsuChannelModuleInfo::PsuChannelModuleInfo(uint16_t moduleType, const char *moduleName, const char *moduleBrend, uint16_t latestModuleRevision, uint8_t numChannels_)
54+
: ModuleInfo(moduleType, MODULE_CATEGORY_DCPSUPPLY, moduleName, moduleBrend, latestModuleRevision)
5555
, numChannels(numChannels_)
5656
{
5757
}

src/eez/modules/psu/channel.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ struct Channel;
179179
struct PsuChannelModuleInfo : public ModuleInfo {
180180
uint8_t numChannels;
181181

182-
PsuChannelModuleInfo(uint16_t moduleType, const char *moduleName, uint16_t latestModuleRevision, uint8_t numChannels);
182+
PsuChannelModuleInfo(uint16_t moduleType, const char *moduleName, const char *moduleBrand, uint16_t latestModuleRevision, uint8_t numChannels);
183183

184184
int getSlotView(SlotViewType slotViewType, int slotIndex, int cursor) override;
185185

@@ -692,10 +692,6 @@ struct Channel {
692692

693693
virtual void onSpiIrq();
694694

695-
virtual void getFirmwareVersion(uint8_t &majorVersion, uint8_t &minorVersion) = 0;
696-
virtual const char *getBrand() = 0;
697-
virtual void getSerial(char *text) = 0;
698-
699695
virtual void getVoltageStepValues(StepValues *stepValues, bool calibrationMode) = 0;
700696
virtual void getCurrentStepValues(StepValues *stepValues, bool calibrationMode) = 0;
701697
virtual void getPowerStepValues(StepValues *stepValues) = 0;

0 commit comments

Comments
 (0)