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