@@ -73,7 +73,37 @@ static const float I_MON_RESOLUTION = 0.02f;
7373static GPIO_TypeDef *SPI_IRQ_GPIO_Port[] = { SPI2_IRQ_GPIO_Port, SPI4_IRQ_GPIO_Port, SPI5_IRQ_GPIO_Port };
7474static 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-
142161struct 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 {
656627struct DcmChannelModuleInfo : public PsuChannelModuleInfo {
657628public:
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
0 commit comments