| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LT_2978FaultLog.cpp
Go to the documentation of this file.
1 /*!
2 LTC SMBus Support: API for a LTC2978 Fault Log
3
4 @verbatim
5
6 This API is shared with Linduino and RTOS code. End users should code to this
7 API to enable use of the PMBus code without modifications.
8
9 @endverbatim
10
11
12 Copyright 2018(c) Analog Devices, Inc.
13
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18 - Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 - Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in
22 the documentation and/or other materials provided with the
23 distribution.
24 - Neither the name of Analog Devices, Inc. nor the names of its
25 contributors may be used to endorse or promote products derived
26 from this software without specific prior written permission.
27 - The use of this software may or may not infringe the patent rights
28 of one or more patent holders. This license does not release you
29 from the requirement that you obtain separate licenses from these
30 patent holders to use this software.
31 - Use of the software either in source or binary form, must be run
32 on or directly connected to an Analog Devices Inc. component.
33
34 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
35 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
36 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
37 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
38 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
40 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45
46 //! @ingroup PMBus_SMBus
47 //! @{
48 //! @defgroup LT_2978FaultLog LT_2978FaultLog
49 //! @}
50
51 /*! @file
52 @ingroup LT_2978FaultLog
53 Library Header File for LT_2978FaultLog
54 */
55
56 #include <Arduino.h>
57 #include "LT_2978FaultLog.h"
58
59
60 LT_2978FaultLog::LT_2978FaultLog(LT_PMBus *pmbus):LT_EEDataFaultLog(pmbus)
61 {
62 faultLog2978 = NULL;
63
64 buffer = NULL;
65 voutPeaks = NULL;
66 voutDatas = NULL;
67 }
68
69
70 bool LT_2978FaultLog::FaultLogLtc2978::isValidData(void *pos, uint8_t size)
71 {
72 return (uint8_t *)pos >= (uint8_t *)this + firstValidByte && (uint8_t *)pos + (size - 1) <= (uint8_t *)this + lastValidByte;
73 }
74
75 /*
76 * Read LTC2978 fault log
77 *
78 * address: PMBUS address
79 */
80 void
81 LT_2978FaultLog::read(uint8_t address)
82 {
83 uint16_t size = sizeof(struct LT_2978FaultLog::FaultLogLtc2978);
84 uint8_t *data = (uint8_t *) malloc(size);
85 if (data == 0)
86 Serial.print(F("bad malloc."));
87 data[0] = 0x00;
88
89
90 // Copy to RAM
91 pmbus_->smbus()->sendByte(address, MFR_FAULT_LOG_RESTORE);
92 // MFR_FAULT_LOG_RESTORE requires a delay (see datasheet), typical delay is 2ms, multiplying by 10 for safety
93 delay(20);
94 // Read block data with log
95 pmbus_->smbus()->readBlock(address, MFR_FAULT_LOG, data, 255);
96
97 struct LT_2978FaultLog::FaultLogLtc2978 *log = (struct LT_2978FaultLog::FaultLogLtc2978 *)data;
98
99 log->firstValidByte = 47;
100
101 log->lastValidByte = 237;
102
103 uint8_t cycle_start = log->preamble.position_last;
104
105 log->loops = (LT_2978FaultLog::FaultLogReadLoopLtc2978 *) (log->telemetryData - 39 + cycle_start);
106
107 faultLog2978 = log;
108 }
109
110
111 void LT_2978FaultLog::release()
112 {
113 free(faultLog2978);
114 faultLog2978 = 0;
115 }
116
117 uint8_t *LT_2978FaultLog::getBinary()
118 {
119 return (uint8_t *)faultLog2978;
120 }
121
122 uint16_t LT_2978FaultLog::getBinarySize()
123 {
124 return 255;
125 }
126
127 void LT_2978FaultLog::dumpBinary(Print *printer)
128 {
129 dumpBin(printer, (uint8_t *)faultLog2978, 255);
130 }
131
132 void LT_2978FaultLog::print(Print *printer)
133 {
134 if (printer == 0)
135 printer = &Serial;
136 buffer = new char[FILE_TEXT_LINE_MAX];
137
138 printTitle(printer);
139
140 printTime(printer);
141
142 printPeaks(printer);
143
144 printAllLoops(printer);
145
146
147 delete [] buffer;
148 }
149
150
151 void LT_2978FaultLog::printTitle(Print *printer)
152 {
153 printer->print(F("LTC2978 Log Data\n"));
154 }
155
156 void LT_2978FaultLog::printTime(Print *printer)
157 {
158 uint8_t *time = (uint8_t *)&faultLog2978->preamble.shared_time;
159 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Time 0x%02x%02x%02x%02x%02x%02x\n"), time[5], time[4], time[3], time[2], time[1], time[0]);
160 printer->print(buffer);
161 printer->print((long) getSharedTime200us(faultLog2978->preamble.shared_time));
162 printer->println(F(" Ticks (200us each)"));
163 }
164
165 void LT_2978FaultLog::printPeaks(Print *printer)
166 {
167 voutPeaks = new Peak16Words*[8];
168
169 voutPeaks[0] = &faultLog2978->preamble.peaks.vout0_peaks;
170 voutPeaks[1] = &faultLog2978->preamble.peaks.vout1_peaks;
171 voutPeaks[2] = &faultLog2978->preamble.peaks.vout2_peaks;
172 voutPeaks[3] = &faultLog2978->preamble.peaks.vout3_peaks;
173 voutPeaks[4] = &faultLog2978->preamble.peaks.vout4_peaks;
174 voutPeaks[5] = &faultLog2978->preamble.peaks.vout5_peaks;
175 voutPeaks[6] = &faultLog2978->preamble.peaks.vout6_peaks;
176 voutPeaks[7] = &faultLog2978->preamble.peaks.vout7_peaks;
177
178
179 printer->println(F("\nPeak Values:"));
180 printer->println(F("--------"));
181
182 printFastChannel(0, printer);
183 printFastChannel(1, printer);
184
185 float vin_max, vin_min;
186 vin_max = math_.lin11_to_float(getLin5_11WordVal(faultLog2978->preamble.peaks.vin_peaks.peak));
187 vin_min = math_.lin11_to_float(getLin5_11WordVal(faultLog2978->preamble.peaks.vin_peaks.min));
188 printer->print(F("Vin: Min: "));
189 printer->print(vin_min, 6);
190 printer->print(F(", Peak: "));
191 printer->print(vin_max, 6);
192 printer->println();
193
194 printFastChannel(2, printer);
195 printFastChannel(3, printer);
196
197 float temp_max, temp_min;
198 temp_max = math_.lin11_to_float(getLin5_11WordVal(faultLog2978->preamble.peaks.temp_peaks.peak));
199 temp_min = math_.lin11_to_float(getLin5_11WordVal(faultLog2978->preamble.peaks.temp_peaks.min));
200 printer->print(F("Temp: Min: "));
201 printer->print(temp_min, 6);
202 printer->print(F(", Peak: "));
203 printer->print(temp_max, 6);
204 printer->println();
205
206 printFastChannel(4, printer);
207 printFastChannel(5, printer);
208 printFastChannel(6, printer);
209 printFastChannel(7, printer);
210
211 delete [] voutPeaks;
212 }
213
214 void LT_2978FaultLog::printFastChannel(uint8_t index, Print *printer)
215 {
216 float vout_peak, vout_min;
217 vout_peak = math_.lin16_to_float(getLin16WordVal(voutPeaks[index]->peak), 0x13);
218 vout_min = math_.lin16_to_float(getLin16WordVal(voutPeaks[index]->min), 0x13);
219 printer->print(F("Vout"));
220 printer->print(index);
221 printer->print(F(": Min: "));
222 printer->print(vout_min, 6);
223 printer->print(F(", Peak: "));
224 printer->println(vout_peak, 6);
225 }
226
227 void LT_2978FaultLog::printAllLoops(Print *printer)
228 {
229 voutDatas = new VoutData*[8];
230
231 printer->println(F("Fault Log Loops Follow:"));
232 printer->println(F("(most recent data first)"));
233
234 for (int index = 0; index <= 5 && (index < 5 || faultLog2978->isValidData(&faultLog2978->loops[index])); index++)
235 {
236 printLoop(index, printer);
237 }
238
239 delete [] voutDatas;
240 }
241
242 void LT_2978FaultLog::printLoop(uint8_t index, Print *printer)
243 {
244 printer->println(F("-------"));
245 printer->print(F("Loop: "));
246 printer->println(index);
247 printer->println(F("-------"));
248
249 voutDatas[0] = &faultLog2978->loops[index].vout_data0;
250 voutDatas[1] = &faultLog2978->loops[index].vout_data1;
251 voutDatas[2] = &faultLog2978->loops[index].vout_data2;
252 voutDatas[3] = &faultLog2978->loops[index].vout_data3;
253 voutDatas[4] = &faultLog2978->loops[index].vout_data4;
254 voutDatas[5] = &faultLog2978->loops[index].vout_data5;
255 voutDatas[6] = &faultLog2978->loops[index].vout_data6;
256 voutDatas[7] = &faultLog2978->loops[index].vout_data7;
257
258 uint8_t stat;
259 float val;
260
261 printLoopChannel(7, printer);
262 printLoopChannel(6, printer);
263 printLoopChannel(5, printer);
264 printLoopChannel(4, printer);
265
266 if (faultLog2978->isValidData(&faultLog2978->loops[index].temp_data.status_temp, 1))
267 {
268 printer->println(F("TEMPERATURE:"));
269 stat = getRawByteVal(faultLog2978->loops[index].temp_data.status_temp);
270 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_TEMP: 0x%02x\n"), stat);
271 printer->print(buffer);
272 }
273 if (faultLog2978->isValidData(&faultLog2978->loops[index].temp_data.read_temp1))
274 {
275 val = math_.lin11_to_float(getLin5_11WordReverseVal(faultLog2978->loops[index].temp_data.read_temp1));
276 printer->print(F(" READ_TEMP: "));
277 printer->print(val, 6);
278 printer->println(F(" C"));
279 }
280
281 printLoopChannel(3, printer);
282 printLoopChannel(2, printer);
283
284 if (faultLog2978->isValidData(&faultLog2978->loops[index].vin_data.status_vin, 1))
285 {
286 printer->println(F("VIN:"));
287 stat = getRawByteVal(faultLog2978->loops[index].vin_data.status_vin);
288 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_INPUT: 0x%02x\n"), stat);
289 printer->print(buffer);
290 }
291 if (faultLog2978->isValidData(&faultLog2978->loops[index].vin_data.vin))
292 {
293 val = math_.lin11_to_float(getLin5_11WordReverseVal(faultLog2978->loops[index].vin_data.vin));
294 printer->print(F(" READ_VIN: "));
295 printer->print(val, 6);
296 printer->println(F(" V"));
297 }
298
299 printLoopChannel(1, printer);
300 printLoopChannel(0, printer);
301 printer->println();
302
303 }
304
305 void LT_2978FaultLog::printLoopChannel(uint8_t index, Print *printer)
306 {
307 uint8_t stat;
308 float val;
309
310 if (faultLog2978->isValidData(&voutDatas[index]->status_mfr, 1))
311 {
312 printer->print(F("CHAN"));
313 printer->print(index);
314 printer->println(F(":"));
315 stat = getRawByteVal(voutDatas[index]->status_mfr);
316 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_MFR: 0x%02x\n"), stat);
317 printer->print(buffer);
318 }
319 if (faultLog2978->isValidData(&voutDatas[index]->status_vout, 1))
320 {
321 stat = getRawByteVal(voutDatas[index]->status_vout);
322 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_VOUT: 0x%02x\n"), stat);
323 printer->print(buffer);
324 }
325 if (faultLog2978->isValidData(&voutDatas[index]->read_vout))
326 {
327 val = math_.lin16_to_float(getLin16WordReverseVal(voutDatas[index]->read_vout), 0x13);
328 printer->print(F(" READ_VOUT: "));
329 printer->print(val, 6);
330 printer->println(F(" V"));
331 }
332 }
333
334
335
LT_2978FaultLog::FaultLogPreambleLtc2978::position_last
uint8_t position_last
Definition: LT_2978FaultLog.h:132
LT_2978FaultLog::FaultLogReadLoopLtc2978::vout_data4
struct VoutData vout_data4
Definition: LT_2978FaultLog.h:143
LT_2978FaultLog::FaultLogReadLoopLtc2978::vout_data5
struct VoutData vout_data5
Definition: LT_2978FaultLog.h:142
LT_2978FaultLog::VoutData::read_vout
struct Lin16WordReverse read_vout
Definition: LT_2978FaultLog.h:77
LT_FaultLog::getLin5_11WordReverseVal
uint16_t getLin5_11WordReverseVal(Lin5_11WordReverse value)
Definition: LT_FaultLog.cpp:291
LT_FaultLog::dumpBin
void dumpBin(Print *printer, uint8_t *log, uint8_t size)
Definition: LT_FaultLog.cpp:217
LT_2978FaultLog::FaultLogPreambleLtc2978::shared_time
struct FaultLogTimeStamp shared_time
Definition: LT_2978FaultLog.h:133
MFR_FAULT_LOG
#define MFR_FAULT_LOG
Definition: LT_PMBus.h:140
LT_2978FaultLog::VinData::vin
struct Lin5_11WordReverse vin
Definition: LT_2978FaultLog.h:97
LT_2978FaultLog::FaultLogReadLoopLtc2978::vout_data3
struct VoutData vout_data3
Definition: LT_2978FaultLog.h:146
LT_2978FaultLog::read
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
Definition: LT_2978FaultLog.cpp:81
LT_2978FaultLog::FaultLogLtc2978::telemetryData
uint8_t telemetryData[208]
Definition: LT_2978FaultLog.h:158
LT_PMBusMath::lin16_to_float
float lin16_to_float(lin16_t lin16_mant, lin16m_t vout_mode)
Definition: LT_PMBusMath.cpp:435
LT_2978FaultLog::FaultLogPeaksLtc2978::vout2_peaks
struct Peak16Words vout2_peaks
Definition: LT_2978FaultLog.h:120
LT_2978FaultLog::FaultLogLtc2978::lastValidByte
uint8_t lastValidByte
Definition: LT_2978FaultLog.h:161
LT_2978FaultLog::FaultLogReadLoopLtc2978::vin_data
struct VinData vin_data
Definition: LT_2978FaultLog.h:149
LT_2978FaultLog::VoutData::status_mfr
struct RawByte status_mfr
Definition: LT_2978FaultLog.h:75
LT_2978FaultLog::FaultLogPeaksLtc2978::vout1_peaks
struct Peak16Words vout1_peaks
Definition: LT_2978FaultLog.h:118
LT_SMBus::sendByte
virtual void sendByte(uint8_t address, uint8_t command)=0
SMBus send byte command.
LT_2978FaultLog::dumpBinary
void dumpBinary(Print *printer=0)
Dumps binary of the fault log to a Print inheriting object, or Serial if none specified.
Definition: LT_2978FaultLog.cpp:127
LT_FaultLog::getLin5_11WordVal
uint16_t getLin5_11WordVal(Lin5_11Word value)
Definition: LT_FaultLog.cpp:285
LT_2978FaultLog::FaultLogPeaksLtc2978::temp_peaks
struct Peak5_11Words temp_peaks
Definition: LT_2978FaultLog.h:122
LT_2978FaultLog::FaultLogReadLoopLtc2978::vout_data0
struct VoutData vout_data0
Definition: LT_2978FaultLog.h:151
LT_2978FaultLog::print
void print(Print *printer=0)
Pretty prints this part&#39;s fault log to a Print inheriting object, or Serial if none specified...
Definition: LT_2978FaultLog.cpp:132
LT_2978FaultLog::release
void release()
Frees the memory reserved for the fault log.
Definition: LT_2978FaultLog.cpp:111
LT_2978FaultLog::FaultLogPeaksLtc2978::vout6_peaks
struct Peak16Words vout6_peaks
Definition: LT_2978FaultLog.h:125
math_
LT_PMBusMath math_
Definition: LT_PMBusMath.cpp:460
pmbus
static LT_PMBus * pmbus
Definition: DC2875A.ino:82
LT_PMBusMath::lin11_to_float
float lin11_to_float(lin11_t xin)
Definition: LT_PMBusMath.cpp:427
LT_2978FaultLog::FaultLogReadLoopLtc2978::temp_data
struct TempData temp_data
Definition: LT_2978FaultLog.h:145
LT_2978FaultLog::FaultLogLtc2978
Definition: LT_2978FaultLog.h:154
FILE_TEXT_LINE_MAX
#define FILE_TEXT_LINE_MAX
Definition: LT_FaultLog.h:60
min
#define min(a, b)
Definition: Adafruit_GFX.cpp:66
LT_FaultLog::pmbus_
LT_PMBus * pmbus_
Definition: LT_FaultLog.h:129
LT_2978FaultLog::getBinary
uint8_t * getBinary()
Get binary of the fault log or NULL if no log.
Definition: LT_2978FaultLog.cpp:117
address
static uint8_t address
Definition: DC2091A.ino:83
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
LT_2978FaultLog::FaultLogLtc2978::preamble
struct FaultLogPreambleLtc2978 preamble
Definition: LT_2978FaultLog.h:157
pos
static int16_t pos
Definition: Precision_Voltage_Source.ino:73
LT_2978FaultLog::FaultLogPeaksLtc2978::vout7_peaks
struct Peak16Words vout7_peaks
Definition: LT_2978FaultLog.h:126
LT_FaultLog::getLin16WordVal
uint16_t getLin16WordVal(Lin16Word value)
Definition: LT_FaultLog.cpp:297
LT_2978FaultLog::FaultLogReadLoopLtc2978
Definition: LT_2978FaultLog.h:137
LT_2978FaultLog::FaultLogReadLoopLtc2978::vout_data7
struct VoutData vout_data7
Definition: LT_2978FaultLog.h:140
LT_2978FaultLog::LT_2978FaultLog
LT_2978FaultLog(LT_PMBus *pmbus)
Constructor.
Definition: LT_2978FaultLog.cpp:60
LT_2978FaultLog::Peak16Words
Definition: LT_2978FaultLog.h:100
LT_2978FaultLog::FaultLogReadLoopLtc2978::vout_data1
struct VoutData vout_data1
Definition: LT_2978FaultLog.h:150
LT_2978FaultLog::FaultLogPeaksLtc2978::vout3_peaks
struct Peak16Words vout3_peaks
Definition: LT_2978FaultLog.h:121
LT_PMBus::smbus
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
LT_EEDataFaultLog
Definition: LT_EEDataFaultLog.h:56
LT_2978FaultLog.h
LTC SMBus Support: Implementation for a LTC2978 Fault Log.
LT_FaultLog::getSharedTime200us
uint64_t getSharedTime200us(FaultLogTimeStamp time_stamp)
Definition: LT_FaultLog.cpp:247
LT_2978FaultLog::Peak5_11Words::min
struct Lin5_11Word min
Definition: LT_2978FaultLog.h:111
LT_2978FaultLog::VinData::status_vin
struct RawByte status_vin
Definition: LT_2978FaultLog.h:96
LT_2978FaultLog::FaultLogPeaksLtc2978::vout0_peaks
struct Peak16Words vout0_peaks
Definition: LT_2978FaultLog.h:117
LT_2978FaultLog::FaultLogLtc2978::isValidData
bool isValidData(void *pos, uint8_t size=2)
Definition: LT_2978FaultLog.cpp:70
LT_2978FaultLog::VoutData::status_vout
struct RawByte status_vout
Definition: LT_2978FaultLog.h:76
LT_2978FaultLog::FaultLogReadLoopLtc2978::vout_data2
struct VoutData vout_data2
Definition: LT_2978FaultLog.h:147
index
static int index
Definition: device_logger.ino:91
LT_2978FaultLog::VoutData
Definition: LT_2978FaultLog.h:72
LT_SMBus::readBlock
virtual uint8_t readBlock(uint8_t address, uint8_t command, uint8_t *block, uint16_t block_size)=0
SMBus read block command.
LT_2978FaultLog::FaultLogPreambleLtc2978::peaks
struct FaultLogPeaksLtc2978 peaks
Definition: LT_2978FaultLog.h:134
LT_2978FaultLog::FaultLogLtc2978::loops
struct FaultLogReadLoopLtc2978 * loops
Definition: LT_2978FaultLog.h:159
LT_2978FaultLog::faultLog2978
FaultLogLtc2978 * faultLog2978
Definition: LT_2978FaultLog.h:169
LT_2978FaultLog::TempData::read_temp1
struct Lin5_11WordReverse read_temp1
Definition: LT_2978FaultLog.h:84
LT_FaultLog::getRawByteVal
uint8_t getRawByteVal(RawByte value)
Definition: LT_FaultLog.cpp:267
LT_FaultLog::getLin16WordReverseVal
uint16_t getLin16WordReverseVal(Lin16WordReverse value)
Definition: LT_FaultLog.cpp:303
LT_2978FaultLog::FaultLogReadLoopLtc2978::vout_data6
struct VoutData vout_data6
Definition: LT_2978FaultLog.h:141
LT_2978FaultLog::FaultLogPeaksLtc2978::vout5_peaks
struct Peak16Words vout5_peaks
Definition: LT_2978FaultLog.h:124
MFR_FAULT_LOG_RESTORE
#define MFR_FAULT_LOG_RESTORE
Definition: LT_PMBus.h:136
LT_2978FaultLog::Peak5_11Words::peak
struct Lin5_11Word peak
Definition: LT_2978FaultLog.h:110
LT_2978FaultLog::FaultLogPeaksLtc2978::vin_peaks
struct Peak5_11Words vin_peaks
Definition: LT_2978FaultLog.h:119
LT_2978FaultLog::getBinarySize
uint16_t getBinarySize()
Get size of binary data.
Definition: LT_2978FaultLog.cpp:122
LT_2978FaultLog::FaultLogLtc2978::firstValidByte
uint8_t firstValidByte
Definition: LT_2978FaultLog.h:160
LT_2978FaultLog::FaultLogPeaksLtc2978::vout4_peaks
struct Peak16Words vout4_peaks
Definition: LT_2978FaultLog.h:123
LT_2978FaultLog::TempData::status_temp
struct RawByte status_temp
Definition: LT_2978FaultLog.h:83
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370