Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LT_EEDataFaultLog.h
Go to the documentation of this file.
1 /*!
2 LTC PMBus Support: Implementation for a LTC Controller 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 /*! @file
47  @ingroup LT_FaultLog
48  Library Header File for LT_EEDataFaultLog
49 */
50 
51 #ifndef LT_EEDataFaultLog_H_
52 #define LT_EEDataFaultLog_H_
53 
54 #include "LT_FaultLog.h"
55 
57 {
58  public:
59 
61  {
62 
63  }
64 
65  void getNvmBlock(uint8_t address, uint16_t offset, uint16_t numWords, uint8_t command, uint8_t *data)
66  {
67  bool pecMatch = true;
68 
69  // Tell the device to get ready and set the index at the beginning of EEPROM
70  while ((pmbus_->smbus()->readByte(address, 0xEF) & 0x40) != 0x40); // Wait until not busy
71  pmbus_->smbus()->writeByte(address, 0xBD, 0x2B);
72  while ((pmbus_->smbus()->readByte(address, 0xEF) & 0x40) != 0x40); // Wait until not busy
73  pmbus_->smbus()->writeByte(address, 0xBD, 0x91);
74  while ((pmbus_->smbus()->readByte(address, 0xEF) & 0x40) != 0x40); // Wait until not busy
75  pmbus_->smbus()->writeByte(address, 0xBD, 0xE4);
76  // Read the ID
77  while ((pmbus_->smbus()->readByte(address, 0xEF) & 0x40) != 0x40); // Wait until not busy
78  pmbus_->smbus()->readWord(address, 0xBF);
79  // Read the size and ingore it because we know it will not change
80  while ((pmbus_->smbus()->readByte(address, 0xEF) & 0x40) != 0x40); // Wait until not busy
81  pmbus_->smbus()->readWord(address, 0xBF);
82  // Consume words we need to ignore
83  for (uint16_t i = 0; i < offset; i++)
84  {
85  while ((pmbus_->smbus()->readByte(address, 0xEF) & 0x40) != 0x40); // Wait until not busy
86  pmbus_->smbus()->readWord(address, 0xBF);
87  }
88  // Consume words of the fault log and check the CRC
89  int pos = 0;
90  pmbus_->smbus()->pecClear();
91  for (uint16_t i = 0; i < numWords; i++)
92  {
93  while ((pmbus_->smbus()->readByte(address, 0xEF) & 0x40) != 0x40); // Wait until not busy
94  uint16_t w = pmbus_->smbus()->readWord(address, 0xBF);
95  // Toss CRC every 32 bytes
96  if ((i + 1) % 16 == 0)
97  {
98  data[pos] = 0xFF & w; // If this is not obvious, consider the endianess. This is the 32nd byte.
99  pmbus_->smbus()->pecAdd(data[pos]);
100  pos++;
101  uint8_t calcPec = pmbus_->smbus()->pecGet();
102  uint8_t devPec = 0xFF & (w >> 8); // This depends on endianess as well.
103  pmbus_->smbus()->pecClear();
104  if (calcPec != devPec)
105  pecMatch = false;
106  }
107  else // And endianess applies here too.
108  {
109  data[pos] = 0xFF & w;
110  pmbus_->smbus()->pecAdd(data[pos]);
111  pos++;
112  data[pos] = 0xFF & (w >> 8);
113  pmbus_->smbus()->pecAdd(data[pos]);
114  pos++;
115  }
116  }
117  // It is possible to have a partial good/bad CRC. The device will not load any Fault Log data
118  // to RAM if there is ANY CRC mismatch. Then the read Fault Log will return all zero data or
119  // random data depending on revision of silicon. This code mimics the most recent silicon
120  // and returns all zeros if there is a CRC mismatch.
121  if (!pecMatch)
122  memset (data, 0x00, numWords*2);
123 
124  pmbus_->smbus()->writeByte(address, 0xBD, 0x00);
125  while ((pmbus_->smbus()->readByte(address, 0xEF) & 0x40) != 0x40); // Wait until not busy
126  }
127 };
128 
129 #endif /* LT_EEDataFaultLog_H_ */
static LT_PMBus * pmbus
Definition: DC2875A.ino:82
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
static int16_t pos
uint8_t pecGet(void)
Get the current pec result.
Definition: LT_SMBus.cpp:192
LTC PMBus Support: Implementation for a LTC Fault Log.
void getNvmBlock(uint8_t address, uint16_t offset, uint16_t numWords, uint8_t command, uint8_t *data)
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.
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
LT_EEDataFaultLog(LT_PMBus *pmbus)
void pecClear(void)
Clear the pec value so it can start a new calculation.
Definition: LT_SMBus.cpp:162
static int i
Definition: DC2430A.ino:184
void pecAdd(uint8_t byte_value)
Add a byte to the pec calculation.
Definition: LT_SMBus.cpp:170
virtual uint16_t readWord(uint8_t address, uint8_t command)=0
SMBus read word command.
PMBus communication.
Definition: LT_PMBus.h:370