| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LT_FaultLog.cpp
Go to the documentation of this file.
1 /*!
2
3 LTC PMBus Support: API for a shared LTC Fault Log
4
5
6 @verbatim
7
8 This API is shared with Linduino and RTOS code. End users should code to this
9 API to enable use of the PMBus code without modifications.
10
11 @endverbatim
12
13
14 Copyright 2018(c) Analog Devices, Inc.
15
16 All rights reserved.
17
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are met:
20 - Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
22 - Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in
24 the documentation and/or other materials provided with the
25 distribution.
26 - Neither the name of Analog Devices, Inc. nor the names of its
27 contributors may be used to endorse or promote products derived
28 from this software without specific prior written permission.
29 - The use of this software may or may not infringe the patent rights
30 of one or more patent holders. This license does not release you
31 from the requirement that you obtain separate licenses from these
32 patent holders to use this software.
33 - Use of the software either in source or binary form, must be run
34 on or directly connected to an Analog Devices Inc. component.
35
36 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
37 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
38 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
40 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
42 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
43 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 */
47
48 //! @ingroup PMBus_SMBus
49 //! @{
50 //! @defgroup LT_FaultLog LT_FaultLog: PLTC PSM Fault Log support
51 //! @}
52
53 /*! @file
54 @ingroup LT_FaultLog
55 Library Header File for LT_FaultLog
56 */
57
58 #include <Arduino.h>
59 #include "LT_FaultLog.h"
60
61 LT_FaultLog::LT_FaultLog(LT_PMBus *pmbus)
62 {
63 pmbus_ = pmbus;
64 }
65
66 /*
67 * Read the status byte
68 *
69 * address: PMBUS address
70 */
71 uint8_t
72 LT_FaultLog::readMfrStatusByte(uint8_t address)
73 {
74 uint8_t status_byte;
75
76 status_byte = pmbus_->smbus()->readByte(address, STATUS_MFR_SPECIFIC);
77 return status_byte;
78 }
79
80 /*
81 * Read the mfr status byte
82 *
83 * address: PMBUS address
84 */
85 uint8_t
86 LT_FaultLog::readMfrFaultLogStatusByte(uint8_t address)
87 {
88 uint8_t status_byte;
89
90 status_byte = pmbus_->smbus()->readByte(address, MFR_FAULT_LOG_STATUS);
91
92 return status_byte;
93 }
94
95 /*
96 * Check if there is a fault log
97 *
98 * address: PMBUS address
99 */
100 bool
101 LT_FaultLog::hasFaultLog(uint8_t address)
102 {
103 uint8_t status;
104 PsmDeviceType t = pmbus_->deviceType(address);
105
106 if (t == LTC3880 || t == LTC3886 || t == LTC3887 || t == LTM4675 || t == LTM4676|| t == LTM4676A || t == LTM4677)
107 {
108 status = readMfrStatusByte(address);
109 return (status & LTC3880_SMFR_FAULT_LOG) > 0;
110 }
111 else if (t == LTC3882 || t == LTC3882_1)
112 {
113 status = readMfrStatusByte(address);
114 return (status & LTC3882_SMFR_FAULT_LOG) > 0;
115 }
116 else if (t == LTC3883)
117 {
118 status = readMfrStatusByte(address);
119 return (status & LTC3883_SMFR_FAULT_LOG) > 0;
120 }
121 else if (t == LTC2974 || t == LTC2975)
122 {
123 status = readMfrFaultLogStatusByte(address);
124 return (status & LTC2974_SFL_EEPROM) > 0;
125 }
126 else if (t == LTC2977 || t == LTC2978 || t == LTC2980 || t == LTM2987)
127 {
128 status = readMfrFaultLogStatusByte(address);
129 return (status & LTC2978_SFL_EEPROM) > 0;
130 }
131 else
132 return false;
133 }
134
135 /*
136 * Enable fault log
137 *
138 * address: PMBUS address
139 */
140 void
141 LT_FaultLog::enableFaultLog(uint8_t address)
142 {
143 uint8_t config8;
144 uint16_t config16;
145 PsmDeviceType t = pmbus_->deviceType(address);
146
147 if (
148 (t == LTC3880)
149 || (t == LTC3882)
150 || (t == LTC3882_1)
151 || (t == LTC3883)
152 || (t == LTC3886)
153 || (t == LTM4675)
154 || (t == LTM4676)
155 || (t == LTM4676A)
156 || (t == LTM4677)
157 || (t == LTC2978)
158 )
159 {
160 config8 = pmbus_->smbus()->readByte(address, MFR_CONFIG_ALL);
161 pmbus_->smbus()->writeByte(address, MFR_CONFIG_ALL, config8 | CFGALL_EFL);
162 }
163 else if (
164 (t == LTC2974)
165 || (t == LTC2975)
166 || (t == LTC2977)
167 || (t == LTC2980)
168 || (t == LTM2987)
169 )
170 {
171 config16 = pmbus_->smbus()->readWord(address, MFR_CONFIG_ALL);
172 pmbus_->smbus()->writeWord(address, MFR_CONFIG_ALL, config16 | LTC2974_CFGALL_EFL);
173 }
174 }
175
176 /*
177 * Disable fault log
178 *
179 * address: PMBUS address
180 */
181 void
182 LT_FaultLog::disableFaultLog(uint8_t address)
183 {
184 uint8_t config8;
185 uint16_t config16;
186 PsmDeviceType t = pmbus_->deviceType(address);
187
188 if (
189 (t == LTC3880)
190 || (t == LTC3882)
191 || (t == LTC3882_1)
192 || (t == LTC3883)
193 || (t == LTC3886)
194 || (t == LTM4675)
195 || (t == LTM4676)
196 || (t == LTM4676A)
197 || (t == LTM4677)
198 || (t == LTC2978)
199 )
200 {
201 config8 = pmbus_->smbus()->readByte(address, MFR_CONFIG_ALL);
202 pmbus_->smbus()->writeByte(address, MFR_CONFIG_ALL, config8 & ~CFGALL_EFL);
203 }
204 else if (
205 (t == LTC2974)
206 || (t == LTC2975)
207 || (t == LTC2977)
208 || (t == LTC2980)
209 || (t == LTM2987)
210 )
211 {
212 config16 = pmbus_->smbus()->readWord(address, MFR_CONFIG_ALL);
213 pmbus_->smbus()->writeWord(address, MFR_CONFIG_ALL, config16 & ~CFGALL_EFL);
214 }
215 }
216
217 void LT_FaultLog::dumpBin(Print *printer, uint8_t *log, uint8_t size)
218 {
219 if (printer == 0)
220 printer = &Serial;
221 uint8_t *temp = log;
222 for (uint8_t i = 0; i < size; i++)
223 {
224 if (!(i % 16))
225 printer->println();
226 if (temp[i] < 0x10)
227 printer->write('0');
228 printer->print(temp[i], HEX);
229 }
230 printer->println();
231 }
232
233
234 /*
235 * Clear fault log
236 *
237 * address: PMBUS address
238 */
239 void
240 LT_FaultLog::clearFaultLog(uint8_t address)
241 {
242 pmbus_->smbus()->sendByte(address, MFR_FAULT_LOG_CLEAR);
243 }
244
245
246 uint64_t
247 LT_FaultLog::getSharedTime200us(FaultLogTimeStamp time_stamp)
248 {
249 uint64_t num200us = ((uint64_t) time_stamp.shared_time_byte5 << 40);
250 num200us = num200us | ((uint64_t) time_stamp.shared_time_byte4 << 32);
251 num200us = num200us | ((uint32_t) time_stamp.shared_time_byte3 << 24);
252 num200us = num200us | ((uint32_t) time_stamp.shared_time_byte2 << 16);
253 num200us = num200us | ((uint32_t) time_stamp.shared_time_byte1 << 8);
254 num200us = num200us | (time_stamp.shared_time_byte0);
255 return num200us;
256
257 }
258
259 float
260 LT_FaultLog::getTimeInMs(FaultLogTimeStamp time_stamp)
261 {
262 double ms = getSharedTime200us(time_stamp)/5.0;
263 return ms;
264 }
265
266 uint8_t
267 LT_FaultLog::getRawByteVal(RawByte value)
268 {
269 return (uint8_t) value.uint8_tValue;
270 }
271
272 uint16_t
273 LT_FaultLog::getRawWordVal(RawWord value)
274 {
275 return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
276 }
277
278 uint16_t
279 LT_FaultLog::getRawWordReverseVal(RawWordReverse value)
280 {
281 return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
282 }
283
284 uint16_t
285 LT_FaultLog::getLin5_11WordVal(Lin5_11Word value)
286 {
287 return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
288 }
289
290 uint16_t
291 LT_FaultLog::getLin5_11WordReverseVal(Lin5_11WordReverse value)
292 {
293 return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
294 }
295
296 uint16_t
297 LT_FaultLog::getLin16WordVal(Lin16Word value)
298 {
299 return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
300 }
301
302 uint16_t
303 LT_FaultLog::getLin16WordReverseVal(Lin16WordReverse value)
304 {
305 return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
306 }
LT_FaultLog::RawWordReverse::lo_byte
uint8_t lo_byte
Definition: LT_FaultLog.h:112
LTC2974_SFL_EEPROM
#define LTC2974_SFL_EEPROM
Definition: LT_PMBus.h:277
LT_FaultLog::Lin16Word
Definition: LT_FaultLog.h:67
LT_FaultLog::FaultLogTimeStamp::shared_time_byte1
uint8_t shared_time_byte1
Definition: LT_FaultLog.h:119
LT_FaultLog::Lin16WordReverse::hi_byte
uint8_t hi_byte
Definition: LT_FaultLog.h:77
LT_FaultLog::RawByte
Definition: LT_FaultLog.h:95
LT_FaultLog::getLin5_11WordReverseVal
uint16_t getLin5_11WordReverseVal(Lin5_11WordReverse value)
Definition: LT_FaultLog.cpp:291
LT_FaultLog::Lin5_11Word::hi_byte
uint8_t hi_byte
Definition: LT_FaultLog.h:85
LT_FaultLog::Lin5_11WordReverse
Definition: LT_FaultLog.h:88
LT_FaultLog::dumpBin
void dumpBin(Print *printer, uint8_t *log, uint8_t size)
Definition: LT_FaultLog.cpp:217
LT_FaultLog::Lin16Word::hi_byte
uint8_t hi_byte
Definition: LT_FaultLog.h:71
status
String status(void)
Returns a descriptive string based on status of pins.
Definition: DC2364A.ino:217
LTC3887
Definition: LT_PMBus.h:353
LT_SMBus::sendByte
virtual void sendByte(uint8_t address, uint8_t command)=0
SMBus send byte command.
LT_FaultLog::getRawWordReverseVal
uint16_t getRawWordReverseVal(RawWordReverse value)
Definition: LT_FaultLog.cpp:279
LT_FaultLog::getLin5_11WordVal
uint16_t getLin5_11WordVal(Lin5_11Word value)
Definition: LT_FaultLog.cpp:285
LTM4676A
Definition: LT_PMBus.h:356
LTM4675
Definition: LT_PMBus.h:354
LTC2977
Definition: LT_PMBus.h:360
LTC3886
Definition: LT_PMBus.h:352
LT_FaultLog::LT_FaultLog
LT_FaultLog(LT_PMBus *pmbus)
Definition: LT_FaultLog.cpp:61
pmbus
static LT_PMBus * pmbus
Definition: DC2875A.ino:82
LTC2980
Definition: LT_PMBus.h:362
LT_FaultLog::RawWord
Definition: LT_FaultLog.h:101
LTC2978
Definition: LT_PMBus.h:361
LT_FaultLog::FaultLogTimeStamp
Definition: LT_FaultLog.h:115
LT_FaultLog::Lin16WordReverse::lo_byte
uint8_t lo_byte
Definition: LT_FaultLog.h:78
LT_SMBus::writeWord
virtual void writeWord(uint8_t address, uint8_t command, uint16_t data)=0
SMBus write word command.
LT_FaultLog::pmbus_
LT_PMBus * pmbus_
Definition: LT_FaultLog.h:129
LTC2974_CFGALL_EFL
#define LTC2974_CFGALL_EFL
Definition: LT_PMBus.h:251
address
static uint8_t address
Definition: DC2091A.ino:83
LTC3882_1
Definition: LT_PMBus.h:349
LT_FaultLog::getLin16WordVal
uint16_t getLin16WordVal(Lin16Word value)
Definition: LT_FaultLog.cpp:297
LT_FaultLog::FaultLogTimeStamp::shared_time_byte2
uint8_t shared_time_byte2
Definition: LT_FaultLog.h:120
LT_FaultLog::getRawWordVal
uint16_t getRawWordVal(RawWord value)
Definition: LT_FaultLog.cpp:273
LT_FaultLog::hasFaultLog
bool hasFaultLog(uint8_t address)
Definition: LT_FaultLog.cpp:101
LT_FaultLog::RawByte::uint8_tValue
uint8_t uint8_tValue
Definition: LT_FaultLog.h:98
LT_FaultLog::FaultLogTimeStamp::shared_time_byte3
uint8_t shared_time_byte3
Definition: LT_FaultLog.h:121
LT_FaultLog::enableFaultLog
void enableFaultLog(uint8_t address)
Definition: LT_FaultLog.cpp:141
LT_FaultLog::RawWord::hi_byte
uint8_t hi_byte
Definition: LT_FaultLog.h:105
LT_FaultLog::readMfrFaultLogStatusByte
uint8_t readMfrFaultLogStatusByte(uint8_t address)
Definition: LT_FaultLog.cpp:86
LT_FaultLog.h
LTC PMBus Support: Implementation for a LTC Fault Log.
LTC2975
Definition: LT_PMBus.h:359
LT_SMBus::writeByte
virtual void writeByte(uint8_t address, uint8_t command, uint8_t data)=0
SMBus write byte command.
LT_SMBus::readByte
virtual uint8_t readByte(uint8_t address, uint8_t command)=0
SMBus read byte command.
LT_FaultLog::Lin16WordReverse
Definition: LT_FaultLog.h:74
LT_FaultLog::FaultLogTimeStamp::shared_time_byte0
uint8_t shared_time_byte0
Definition: LT_FaultLog.h:118
MFR_CONFIG_ALL
#define MFR_CONFIG_ALL
Definition: LT_PMBus.h:129
LTC3880_SMFR_FAULT_LOG
#define LTC3880_SMFR_FAULT_LOG
Definition: LT_PMBus.h:175
PsmDeviceType
PsmDeviceType
Definition: LT_PMBus.h:345
LT_FaultLog::RawWord::lo_byte
uint8_t lo_byte
Definition: LT_FaultLog.h:104
LT_PMBus::smbus
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
MFR_FAULT_LOG_STATUS
#define MFR_FAULT_LOG_STATUS
Definition: LT_PMBus.h:139
LT_FaultLog::getSharedTime200us
uint64_t getSharedTime200us(FaultLogTimeStamp time_stamp)
Definition: LT_FaultLog.cpp:247
LTM4676
Definition: LT_PMBus.h:355
LT_FaultLog::Lin5_11Word
Definition: LT_FaultLog.h:81
LTC2978_SFL_EEPROM
#define LTC2978_SFL_EEPROM
Definition: LT_PMBus.h:334
LTM4677
Definition: LT_PMBus.h:357
LTM2987
Definition: LT_PMBus.h:363
LTC3882
Definition: LT_PMBus.h:348
STATUS_MFR_SPECIFIC
#define STATUS_MFR_SPECIFIC
Definition: LT_PMBus.h:112
LTC3883
Definition: LT_PMBus.h:350
LT_FaultLog::Lin5_11WordReverse::lo_byte
uint8_t lo_byte
Definition: LT_FaultLog.h:92
LT_FaultLog::readMfrStatusByte
uint8_t readMfrStatusByte(uint8_t address)
Definition: LT_FaultLog.cpp:72
LTC2974
Definition: LT_PMBus.h:358
LT_FaultLog::RawWordReverse
Definition: LT_FaultLog.h:108
LT_FaultLog::disableFaultLog
void disableFaultLog(uint8_t address)
Definition: LT_FaultLog.cpp:182
LT_FaultLog::Lin5_11Word::lo_byte
uint8_t lo_byte
Definition: LT_FaultLog.h:84
LT_FaultLog::getRawByteVal
uint8_t getRawByteVal(RawByte value)
Definition: LT_FaultLog.cpp:267
LT_FaultLog::clearFaultLog
void clearFaultLog(uint8_t address)
Definition: LT_FaultLog.cpp:240
CFGALL_EFL
#define CFGALL_EFL
Definition: LT_PMBus.h:165
LT_FaultLog::getLin16WordReverseVal
uint16_t getLin16WordReverseVal(Lin16WordReverse value)
Definition: LT_FaultLog.cpp:303
i
static int i
Definition: DC2430A.ino:184
LT_PMBus::deviceType
PsmDeviceType deviceType(uint8_t address)
Get the type of PSM device.
Definition: LT_PMBus.cpp:96
LT_FaultLog::getTimeInMs
float getTimeInMs(FaultLogTimeStamp time_stamp)
Definition: LT_FaultLog.cpp:260
MFR_FAULT_LOG_CLEAR
#define MFR_FAULT_LOG_CLEAR
Definition: LT_PMBus.h:137
LT_FaultLog::FaultLogTimeStamp::shared_time_byte5
uint8_t shared_time_byte5
Definition: LT_FaultLog.h:123
LTC3882_SMFR_FAULT_LOG
#define LTC3882_SMFR_FAULT_LOG
Definition: LT_PMBus.h:191
LT_FaultLog::Lin16Word::lo_byte
uint8_t lo_byte
Definition: LT_FaultLog.h:70
LT_SMBus::readWord
virtual uint16_t readWord(uint8_t address, uint8_t command)=0
SMBus read word command.
LT_FaultLog::Lin5_11WordReverse::hi_byte
uint8_t hi_byte
Definition: LT_FaultLog.h:91
LTC3883_SMFR_FAULT_LOG
#define LTC3883_SMFR_FAULT_LOG
Definition: LT_PMBus.h:221
LTC3880
Definition: LT_PMBus.h:347
LT_FaultLog::RawWordReverse::hi_byte
uint8_t hi_byte
Definition: LT_FaultLog.h:111
LT_FaultLog::FaultLogTimeStamp::shared_time_byte4
uint8_t shared_time_byte4
Definition: LT_FaultLog.h:122
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370