| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LT_3880FaultLog.cpp
Go to the documentation of this file.
1 /*!
2 LTC SMBus Support: API for a LTC3880 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_3380FaultLog LT_3880FaultLog
49 //! @}
50
51 /*! @file
52 @ingroup LT_3880FaultLog
53 Library Header File for LT_3880FaultLog
54 */
55
56 #include <Arduino.h>
57 #include "LT_3880FaultLog.h"
58
59 #define RAW_EEPROM
60
61 LT_3880FaultLog::LT_3880FaultLog(LT_PMBus *pmbus):LT_EEDataFaultLog(pmbus)
62 {
63
64 faultLog3880 = NULL;
65
66 buffer = NULL;
67 }
68
69
70 /*
71 * Read LTC3880 fault log
72 *
73 * address: PMBUS address
74 */
75 void
76 LT_3880FaultLog::read(uint8_t address)
77 {
78 #ifdef RAW_EEPROM
79 uint8_t *data = (uint8_t *) malloc(sizeof(uint8_t) * 80 * 2); // Becuse CRC is stripped, the acutal data size is smaller
80
81 getNvmBlock(address, 176, 80, 0x00, data);
82 #else
83 uint8_t *data = (uint8_t *) malloc(147);
84 data[0] = 0x00;
85
86 pmbus_->smbus()->readBlock(address, MFR_FAULT_LOG, data, 147);
87 #endif
88 faultLog3880 = (struct LT_3880FaultLog::FaultLogLtc3880 *) (data);
89 }
90
91
92 void LT_3880FaultLog::release()
93 {
94 free(faultLog3880);
95 faultLog3880 = 0;
96 }
97
98 uint8_t *LT_3880FaultLog::getBinary()
99 {
100 return (uint8_t *)faultLog3880;
101 }
102
103 uint16_t LT_3880FaultLog::getBinarySize()
104 {
105 return 147;
106 }
107
108 void LT_3880FaultLog::dumpBinary(Print *printer)
109 {
110 dumpBin(printer, (uint8_t *)faultLog3880, 147);
111 }
112
113 void LT_3880FaultLog::print(Print *printer)
114 {
115 if (printer == 0)
116 printer = &Serial;
117 buffer = new char[FILE_TEXT_LINE_MAX];
118
119 printTitle(printer);
120
121 printTime(printer);
122
123 printPeaks(printer);
124
125 printAllLoops(printer);
126
127
128 delete [] buffer;
129 }
130
131
132 void LT_3880FaultLog::printTitle(Print *printer)
133 {
134 printer->print(F("LTC3880 Log Data\n"));
135
136 uint8_t position = faultLog3880->preamble.position_fault;
137 switch (position)
138 {
139 case 0xFF :
140 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position MFR_FAULT_LOG_STORE\n"));
141 break;
142 case 0x00 :
143 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position TON_MAX_FAULT Channel 0\n"));
144 break;
145 case 0x01 :
146 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position VOUT_OV_FAULT Channel 0\n"));
147 break;
148 case 0x02 :
149 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position VOUT_UV_FAULT Channel 0\n"));
150 break;
151 case 0x03 :
152 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position IOUT_OC_FAULT Channel 0\n"));
153 break;
154 case 0x05 :
155 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position OT_FAULT Channel 0\n"));
156 break;
157 case 0x06 :
158 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position UT_FAULT Channel 0\n"));
159 break;
160 case 0x07 :
161 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position VIN_OV_FAULT Channel 0\n"));
162 break;
163 case 0x0A :
164 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position MFR_OT_FAULT Channel 0\n"));
165 break;
166 case 0x10 :
167 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position TON_MAX_FAULT Channel 1\n"));
168 break;
169 case 0x11 :
170 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position VOUT_OV_FAULT Channel 1\n"));
171 break;
172 case 0x12 :
173 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position VOUT_UV_FAULT Channel 1\n"));
174 break;
175 case 0x13 :
176 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position IOUT_OC_FAULT Channel 1\n"));
177 break;
178 case 0x15 :
179 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position OT_FAULT Channel 1\n"));
180 break;
181 case 0x16 :
182 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position UT_FAULT Channel 1\n"));
183 break;
184 case 0x17 :
185 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position VIN_OV_FAULT Channel 1\n"));
186 break;
187 case 0x1A :
188 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR("Fault Position MFR_OT_FAULT Channel 1\n"));
189 break;
190 }
191
192 printer->print(buffer);
193 }
194
195 void LT_3880FaultLog::printTime(Print *printer)
196 {
197 uint8_t *time = (uint8_t *)&faultLog3880->preamble.shared_time;
198 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]);
199 printer->print(buffer);
200 printer->print((long) getSharedTime200us(faultLog3880->preamble.shared_time));
201 printer->println(F(" Ticks (200us each)"));
202 }
203
204 void LT_3880FaultLog::printPeaks(Print *printer)
205 {
206 printer->println(F("\nHeader Information:\n--------"));
207
208 printer->print(F("VOUT Peak 0 "));
209 printer->println(math_.lin16_to_float(getLin16WordReverseVal(faultLog3880->preamble.peaks.mfr_vout_peak_p0), 0x14), 6);
210 printer->print(F("VOUT Peak 1 "));
211 printer->println(math_.lin16_to_float(getLin16WordReverseVal(faultLog3880->preamble.peaks.mfr_vout_peak_p1), 0x14), 6);
212 printer->print(F("IOUT Peak 0 "));
213 printer->println(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->preamble.peaks.mfr_iout_peak_p0)), 6);
214 printer->print(F("IOUT Peak 1 "));
215 printer->println(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->preamble.peaks.mfr_iout_peak_p1)), 6);
216 printer->print(F("VIN Peak "));
217 printer->println(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->preamble.peaks.mfr_vin_peak)), 6);
218 printer->print(F("Temp External Last Event Page 0 "));
219 printer->println(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->preamble.peaks.read_temperature_1_p0)), 6);
220 printer->print(F("Temp External Last Event Page 1 "));
221 printer->println(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->preamble.peaks.read_temperature_1_p1)), 6);
222 printer->print(F("Temp Internal Last Event "));
223 printer->println(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->preamble.peaks.read_temperature_2)), 6);
224 printer->print(F("Temp External Peak Page 0 "));
225 printer->println(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->preamble.peaks.mfr_temperature_1_peak_p0)), 6);
226 printer->print(F("Temp External Peak Page 1 "));
227 printer->println(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->preamble.peaks.mfr_temperature_1_peak_p1)), 6);
228 }
229
230 void LT_3880FaultLog::printAllLoops(Print *printer)
231 {
232 printer->println(F("\nFault Log Loops Follow:"));
233 printer->println(F("(most recent data first)"));
234
235 for (int index = 0; index < 6; index++)
236 {
237 printLoop(index, printer);
238 }
239 }
240
241 void LT_3880FaultLog::printLoop(uint8_t index, Print *printer)
242 {
243 printer->println(F("-------"));
244 printer->print(F("Loop: "));
245 printer->println(index);
246 printer->println(F("-------"));
247
248 printer->print(F("Input: "));
249 printer->print(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->fault_log_loop[index].read_vin)), 6);
250 printer->print(F(" V, "));
251 printer->print(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->fault_log_loop[index].read_iin)), 6);
252 printer->println(F(" A"));
253 printer->print(F("Chan0: "));
254 printer->print(math_.lin16_to_float(getLin16WordReverseVal(faultLog3880->fault_log_loop[index].read_vout_p0), 0x14), 6);
255 printer->print(F(" V, "));
256 printer->print(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->fault_log_loop[index].read_iout_p0)), 6);
257 printer->println(F(" A"));
258 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_VOUT: 0x%02x\n"), getRawByteVal(faultLog3880->fault_log_loop[index].status_vout_p0));
259 printer->print(buffer);
260 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_MFR_SPECIFIC: 0x%02x\n"), getRawByteVal(faultLog3880->fault_log_loop[index].status_mfr_specificP0));
261 printer->print(buffer);
262 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_WORD: 0x%04x\n"), getRawWordReverseVal(faultLog3880->fault_log_loop[index].status_word_p0));
263 printer->print(buffer);
264 printer->print(F("Chan1: "));
265 printer->print(math_.lin16_to_float(getLin16WordReverseVal(faultLog3880->fault_log_loop[index].read_vout_p1), 0x14), 6);
266 printer->print(F(" V, "));
267 printer->print(math_.lin11_to_float(getLin5_11WordReverseVal(faultLog3880->fault_log_loop[index].read_iout_p1)), 6);
268 printer->println(F(" A"));
269 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_VOUT: 0x%02x\n"), getRawByteVal(faultLog3880->fault_log_loop[index].status_vout_p1));
270 printer->print(buffer);
271 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_MFR_SPECIFIC: 0x%02x\n"), getRawByteVal(faultLog3880->fault_log_loop[index].status_mfr_specificP1));
272 printer->print(buffer);
273 snprintf_P(buffer, FILE_TEXT_LINE_MAX, PSTR(" STATUS_WORD: 0x%04x\n"), getRawWordReverseVal(faultLog3880->fault_log_loop[index].status_word_p1));
274 printer->print(buffer);
275 }
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::read_temperature_2
struct Lin5_11WordReverse read_temperature_2
Definition: LT_3880FaultLog.h:84
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::mfr_vout_peak_p0
struct Lin16WordReverse mfr_vout_peak_p0
Definition: LT_3880FaultLog.h:75
LT_3880FaultLog::FaultLogReadLoopLtc3880::read_iout_p1
struct Lin5_11WordReverse read_iout_p1
Definition: LT_3880FaultLog.h:104
LT_3880FaultLog::FaultLogReadLoopLtc3880::read_vout_p1
struct Lin16WordReverse read_vout_p1
Definition: LT_3880FaultLog.h:101
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_3880FaultLog::FaultLogReadLoopLtc3880::status_word_p1
struct RawWordReverse status_word_p1
Definition: LT_3880FaultLog.h:113
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::mfr_iout_peak_p0
struct Lin5_11WordReverse mfr_iout_peak_p0
Definition: LT_3880FaultLog.h:78
MFR_FAULT_LOG
#define MFR_FAULT_LOG
Definition: LT_PMBus.h:140
LT_PMBusMath::lin16_to_float
float lin16_to_float(lin16_t lin16_mant, lin16m_t vout_mode)
Definition: LT_PMBusMath.cpp:435
LT_3880FaultLog::FaultLogReadLoopLtc3880::status_word_p0
struct RawWordReverse status_word_p0
Definition: LT_3880FaultLog.h:112
LT_FaultLog::getRawWordReverseVal
uint16_t getRawWordReverseVal(RawWordReverse value)
Definition: LT_FaultLog.cpp:279
LT_3880FaultLog::FaultLogReadLoopLtc3880::read_vin
struct Lin5_11WordReverse read_vin
Definition: LT_3880FaultLog.h:106
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
FILE_TEXT_LINE_MAX
#define FILE_TEXT_LINE_MAX
Definition: LT_FaultLog.h:60
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::read_temperature_1_p0
struct Lin5_11WordReverse read_temperature_1_p0
Definition: LT_3880FaultLog.h:82
LT_3880FaultLog::getBinarySize
uint16_t getBinarySize()
Get size of binary data.
Definition: LT_3880FaultLog.cpp:103
LT_FaultLog::pmbus_
LT_PMBus * pmbus_
Definition: LT_FaultLog.h:129
LT_3880FaultLog::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_3880FaultLog.cpp:113
address
static uint8_t address
Definition: DC2091A.ino:83
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
LT_3880FaultLog::FaultLogReadLoopLtc3880::status_mfr_specificP0
struct RawByte status_mfr_specificP0
Definition: LT_3880FaultLog.h:115
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::mfr_temperature_1_peak_p0
struct Lin5_11WordReverse mfr_temperature_1_peak_p0
Definition: LT_3880FaultLog.h:85
LT_3880FaultLog.h
LTC SMBus Support: Implementation for a LTC3880 Fault Log.
LT_3880FaultLog::FaultLogLtc3880::fault_log_loop
struct FaultLogReadLoopLtc3880 fault_log_loop[6]
Definition: LT_3880FaultLog.h:123
LT_3880FaultLog::FaultLogReadLoopLtc3880::read_iin
struct Lin5_11WordReverse read_iin
Definition: LT_3880FaultLog.h:107
LT_3880FaultLog::FaultLogReadLoopLtc3880::read_vout_p0
struct Lin16WordReverse read_vout_p0
Definition: LT_3880FaultLog.h:100
LT_3880FaultLog::dumpBinary
void dumpBinary(Print *printer=0)
Dumps binary of the fault log to a Print inheriting object, or Serial if none specified.
Definition: LT_3880FaultLog.cpp:108
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::mfr_iout_peak_p1
struct Lin5_11WordReverse mfr_iout_peak_p1
Definition: LT_3880FaultLog.h:79
LT_3880FaultLog::FaultLogPreambleLtc3880::position_fault
uint8_t position_fault
Definition: LT_3880FaultLog.h:92
LT_EEDataFaultLog::getNvmBlock
void getNvmBlock(uint8_t address, uint16_t offset, uint16_t numWords, uint8_t command, uint8_t *data)
Definition: LT_EEDataFaultLog.h:65
LT_3880FaultLog::FaultLogReadLoopLtc3880::status_vout_p0
struct RawByte status_vout_p0
Definition: LT_3880FaultLog.h:109
LT_3880FaultLog::release
void release()
Frees the memory reserved for the fault log.
Definition: LT_3880FaultLog.cpp:92
LT_3880FaultLog::FaultLogReadLoopLtc3880::status_mfr_specificP1
struct RawByte status_mfr_specificP1
Definition: LT_3880FaultLog.h:116
LT_3880FaultLog::FaultLogPreambleLtc3880::peaks
struct FaultLogTelemetrySummaryLtc3880 peaks
Definition: LT_3880FaultLog.h:94
LT_3880FaultLog::FaultLogReadLoopLtc3880::read_iout_p0
struct Lin5_11WordReverse read_iout_p0
Definition: LT_3880FaultLog.h:103
LT_PMBus::smbus
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
LT_EEDataFaultLog
Definition: LT_EEDataFaultLog.h:56
LT_FaultLog::getSharedTime200us
uint64_t getSharedTime200us(FaultLogTimeStamp time_stamp)
Definition: LT_FaultLog.cpp:247
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::mfr_vout_peak_p1
struct Lin16WordReverse mfr_vout_peak_p1
Definition: LT_3880FaultLog.h:76
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::mfr_vin_peak
struct Lin5_11WordReverse mfr_vin_peak
Definition: LT_3880FaultLog.h:81
LT_3880FaultLog::LT_3880FaultLog
LT_3880FaultLog(LT_PMBus *pmbus)
Constructor.
Definition: LT_3880FaultLog.cpp:61
index
static int index
Definition: device_logger.ino:91
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_3880FaultLog::FaultLogTelemetrySummaryLtc3880::mfr_temperature_1_peak_p1
struct Lin5_11WordReverse mfr_temperature_1_peak_p1
Definition: LT_3880FaultLog.h:86
LT_3880FaultLog::read
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
Definition: LT_3880FaultLog.cpp:76
LT_FaultLog::getRawByteVal
uint8_t getRawByteVal(RawByte value)
Definition: LT_FaultLog.cpp:267
LT_3880FaultLog::FaultLogPreambleLtc3880::shared_time
struct FaultLogTimeStamp shared_time
Definition: LT_3880FaultLog.h:93
LT_3880FaultLog::FaultLogReadLoopLtc3880::status_vout_p1
struct RawByte status_vout_p1
Definition: LT_3880FaultLog.h:110
LT_FaultLog::getLin16WordReverseVal
uint16_t getLin16WordReverseVal(Lin16WordReverse value)
Definition: LT_FaultLog.cpp:303
LT_3880FaultLog::getBinary
uint8_t * getBinary()
Get binary of the fault log or NULL if no log.
Definition: LT_3880FaultLog.cpp:98
LT_3880FaultLog::FaultLogTelemetrySummaryLtc3880::read_temperature_1_p1
struct Lin5_11WordReverse read_temperature_1_p1
Definition: LT_3880FaultLog.h:83
LT_3880FaultLog::FaultLogLtc3880
Definition: LT_3880FaultLog.h:119
LT_3880FaultLog::FaultLogLtc3880::preamble
struct FaultLogPreambleLtc3880 preamble
Definition: LT_3880FaultLog.h:122
LT_3880FaultLog::faultLog3880
FaultLogLtc3880 * faultLog3880
Definition: LT_3880FaultLog.h:129
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370