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 
62 {
63  pmbus_ = pmbus;
64 }
65 
66 /*
67  * Read the status byte
68  *
69  * address: PMBUS address
70  */
71 uint8_t
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
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
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
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
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
241 {
243 }
244 
245 
246 uint64_t
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
261 {
262  double ms = getSharedTime200us(time_stamp)/5.0;
263  return ms;
264 }
265 
266 uint8_t
268 {
269  return (uint8_t) value.uint8_tValue;
270 }
271 
272 uint16_t
274 {
275  return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
276 }
277 
278 uint16_t
280 {
281  return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
282 }
283 
284 uint16_t
286 {
287  return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
288 }
289 
290 uint16_t
292 {
293  return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
294 }
295 
296 uint16_t
298 {
299  return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
300 }
301 
302 uint16_t
304 {
305  return (uint16_t) (value.lo_byte | (value.hi_byte << 8));
306 }
#define LTC2974_SFL_EEPROM
Definition: LT_PMBus.h:277
uint16_t getLin5_11WordReverseVal(Lin5_11WordReverse value)
void dumpBin(Print *printer, uint8_t *log, uint8_t size)
String status(void)
Returns a descriptive string based on status of pins.
Definition: DC2364A.ino:217
virtual void sendByte(uint8_t address, uint8_t command)=0
SMBus send byte command.
uint16_t getRawWordReverseVal(RawWordReverse value)
uint16_t getLin5_11WordVal(Lin5_11Word value)
LT_FaultLog(LT_PMBus *pmbus)
Definition: LT_FaultLog.cpp:61
static LT_PMBus * pmbus
Definition: DC2875A.ino:82
virtual void writeWord(uint8_t address, uint8_t command, uint16_t data)=0
SMBus write word command.
LT_PMBus * pmbus_
Definition: LT_FaultLog.h:129
#define LTC2974_CFGALL_EFL
Definition: LT_PMBus.h:251
static uint8_t address
Definition: DC2091A.ino:83
uint16_t getLin16WordVal(Lin16Word value)
uint16_t getRawWordVal(RawWord value)
bool hasFaultLog(uint8_t address)
void enableFaultLog(uint8_t address)
uint8_t readMfrFaultLogStatusByte(uint8_t address)
Definition: LT_FaultLog.cpp:86
LTC PMBus Support: Implementation for a LTC Fault Log.
virtual void writeByte(uint8_t address, uint8_t command, uint8_t data)=0
SMBus write byte command.
virtual uint8_t readByte(uint8_t address, uint8_t command)=0
SMBus read byte command.
#define MFR_CONFIG_ALL
Definition: LT_PMBus.h:129
#define LTC3880_SMFR_FAULT_LOG
Definition: LT_PMBus.h:175
PsmDeviceType
Definition: LT_PMBus.h:345
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
#define MFR_FAULT_LOG_STATUS
Definition: LT_PMBus.h:139
uint64_t getSharedTime200us(FaultLogTimeStamp time_stamp)
#define LTC2978_SFL_EEPROM
Definition: LT_PMBus.h:334
#define STATUS_MFR_SPECIFIC
Definition: LT_PMBus.h:112
uint8_t readMfrStatusByte(uint8_t address)
Definition: LT_FaultLog.cpp:72
void disableFaultLog(uint8_t address)
uint8_t getRawByteVal(RawByte value)
void clearFaultLog(uint8_t address)
#define CFGALL_EFL
Definition: LT_PMBus.h:165
uint16_t getLin16WordReverseVal(Lin16WordReverse value)
static int i
Definition: DC2430A.ino:184
PsmDeviceType deviceType(uint8_t address)
Get the type of PSM device.
Definition: LT_PMBus.cpp:96
float getTimeInMs(FaultLogTimeStamp time_stamp)
#define MFR_FAULT_LOG_CLEAR
Definition: LT_PMBus.h:137
#define LTC3882_SMFR_FAULT_LOG
Definition: LT_PMBus.h:191
virtual uint16_t readWord(uint8_t address, uint8_t command)=0
SMBus read word command.
#define LTC3883_SMFR_FAULT_LOG
Definition: LT_PMBus.h:221
PMBus communication.
Definition: LT_PMBus.h:370