| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

Part Number/2000/2900/2980/faultlog/faultlog.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology LTC2980 Fault Logging
3 Note that LTC2980 = LTC2977 x 2
4
5 @verbatim
6
7 NOTES
8 Setup:
9 Set the terminal baud rate to 115200 and select the newline terminator.
10
11 @endverbatim
12
13 http://www.linear.com/product/LTC2980
14
15
16 Copyright 2018(c) Analog Devices, Inc.
17
18 All rights reserved.
19
20 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions are met:
22 - Redistributions of source code must retain the above copyright
23 notice, this list of conditions and the following disclaimer.
24 - Redistributions in binary form must reproduce the above copyright
25 notice, this list of conditions and the following disclaimer in
26 the documentation and/or other materials provided with the
27 distribution.
28 - Neither the name of Analog Devices, Inc. nor the names of its
29 contributors may be used to endorse or promote products derived
30 from this software without specific prior written permission.
31 - The use of this software may or may not infringe the patent rights
32 of one or more patent holders. This license does not release you
33 from the requirement that you obtain separate licenses from these
34 patent holders to use this software.
35 - Use of the software either in source or binary form, must be run
36 on or directly connected to an Analog Devices Inc. component.
37
38 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
39 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
40 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
41 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
42 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
44 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 */
49
50 /*! @file
51 @ingroup LTC2980
52 */
53
54 #include <Arduino.h>
55 #include <stdint.h>
56 #include <avr/pgmspace.h>
57 #include "Linduino.h"
58 #include "UserInterface.h"
59 #include "LT_Wire.h"
60 #include "LT_SMBusNoPec.h"
61 #include "LT_SMBusPec.h"
62 #include "LT_PMBus.h"
63 #include "LT_2977FaultLog.h"
64
65 #define FILE_TEXT_LINE_MAX 132
66
67 #define LTC2977_I2C_ADDRESS_A 0x30
68 #define LTC2977_I2C_ADDRESS_B 0x32
69
70 // Global variables
71 static uint8_t ltc2977_i2c_address_a;
72 static uint8_t ltc2977_i2c_address_b;
73
74 static LT_SMBus *smbus = new LT_SMBusPec();
75 static LT_PMBus *pmbus = new LT_PMBus(smbus);
76
77 static LT_2977FaultLog *faultLog2977_a = new LT_2977FaultLog(pmbus);
78 static LT_2977FaultLog *faultLog2977_b = new LT_2977FaultLog(pmbus);
79
80 //! Initialize Linduino
81 //! @return void
82 void setup()
83 {
84 Serial.begin(115200); //! Initialize the serial port to the PC
85 print_title();
86 ltc2977_i2c_address_a = LTC2977_I2C_ADDRESS_A;
87 ltc2977_i2c_address_b = LTC2977_I2C_ADDRESS_B;
88 print_prompt();
89 }
90
91 //! Repeats Linduino loop
92 //! @return void
93 void loop()
94 {
95 uint8_t user_command;
96 uint8_t *addresses = NULL;
97
98 struct LT_2977FaultLog::FaultLogLtc2977 *ltc2977_fault_log_a;
99 struct LT_2977FaultLog::FaultLogLtc2977 *ltc2977_fault_log_b;
100
101
102 if (Serial.available()) //! Checks for user input
103 {
104 while ((user_command = read_int()) == 0); //! Reads the user command
105 if (user_command != 'm')
106 Serial.println(user_command);
107
108 uint8_t status_a;
109 uint8_t status_b;
110
111 switch (user_command) //! Prints the appropriate submenu
112 {
113 case 1:
114 status_a = pmbus->readMfrFaultLogStatusByte(ltc2977_i2c_address_a);
115 status_b = pmbus->readMfrFaultLogStatusByte(ltc2977_i2c_address_b);
116
117 if (status_a & LTC2977_SFL_EEPROM) // A is one of the two LTC2977's inside of the LTC2980
118 {
119 Serial.println(F("LTC2980 A Fault Log"));
120 faultLog2977_a->read(ltc2977_i2c_address_a);
121
122 faultLog2977_a->dumpBinary(&Serial);
123 Serial.println();
124 faultLog2977_a->print(&Serial);
125
126 faultLog2977_a->release();
127 }
128 else
129 Serial.println(F("No LTC2980 A Fault Log"));
130
131 if (status_b & LTC2977_SFL_EEPROM) // B is one of the two LTC2977's inside of the LTC2980
132 {
133 Serial.println(F("LTC2980 B Fault Log"));
134 faultLog2977_b->read(ltc2977_i2c_address_b);
135
136 faultLog2977_b->dumpBinary(&Serial);
137 Serial.println();
138 faultLog2977_b->print(&Serial);
139
140 faultLog2977_b->release();
141 }
142 else
143 Serial.println(F("No LTC2980 B Fault Log"));
144
145 break;
146 case 2:
147 faultLog2977_a->clearFaultLog(ltc2977_i2c_address_a);
148 faultLog2977_b->clearFaultLog(ltc2977_i2c_address_b);
149
150 break;
151 case 3:
152 pmbus->clearAllFaults(ltc2977_i2c_address_a);
153 pmbus->clearAllFaults(ltc2977_i2c_address_b);
154
155 break;
156 case 4:
157 pmbus->enablePec(ltc2977_i2c_address_a);
158 pmbus->enablePec(ltc2977_i2c_address_b);
159 delete faultLog2977_a;
160 delete faultLog2977_b;
161 delete smbus;
162 delete pmbus;
163 smbus = new LT_SMBusPec();
164 pmbus = new LT_PMBus(smbus);
165 faultLog2977_a = new LT_2977FaultLog(pmbus);
166 faultLog2977_b = new LT_2977FaultLog(pmbus);
167 break;
168 case 5:
169 pmbus->disablePec(ltc2977_i2c_address_a);
170 pmbus->disablePec(ltc2977_i2c_address_b);
171 delete faultLog2977_a;
172 delete faultLog2977_b;
173 delete smbus;
174 delete pmbus;
175 smbus = new LT_SMBusNoPec();
176 pmbus = new LT_PMBus(smbus);
177 faultLog2977_a = new LT_2977FaultLog(pmbus);
178 faultLog2977_b = new LT_2977FaultLog(pmbus);
179 break;
180 case 6:
181 addresses = smbus->probe(0);
182 while (*addresses != 0)
183 {
184 Serial.print(F("ADDR 0x"));
185 Serial.println(*addresses++, HEX);
186 }
187 break;
188 case 7:
189 pmbus->restoreFromNvmGlobal();
190 delay(2000);
191 pmbus->resetGlobal();
192 break;
193 case 8:
194 smbus->sendByte(ltc2977_i2c_address_a, MFR_FAULT_LOG_STORE);
195 smbus->sendByte(ltc2977_i2c_address_b, MFR_FAULT_LOG_STORE);
196 break;
197 default:
198 Serial.println(F("Incorrect Option"));
199 break;
200 }
201 print_prompt();
202 }
203 }
204
205 // Function Definitions
206
207 //! Prints the title block when program first starts.
208 //! @return void
209 void print_title()
210 {
211 Serial.print(F("\n***************************************************************\n"));
212 Serial.print(F("* LTC2980 Fault Log Program *\n"));
213 Serial.print(F("* *\n"));
214 Serial.print(F("* This program dumps fault logs *\n"));
215 Serial.print(F("* *\n"));
216 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
217 Serial.print(F("* *\n"));
218 Serial.print(F("*****************************************************************\n"));
219 }
220
221 //! Prints main menu.
222 //! @return void
223 void print_prompt()
224 {
225 Serial.print(F("\n 1-Dump Fault Logs\n"));
226 Serial.print(F(" 2-Clear Fault Logs\n"));
227 Serial.print(F(" 3-Clear Faults\n"));
228 Serial.print(F(" 4-PEC On\n"));
229 Serial.print(F(" 5-PEC Off\n"));
230 Serial.print(F(" 6-Bus Probe\n"));
231 Serial.print(F(" 7-Reset\n"));
232 Serial.print(F(" 8-Store Fault Log\n"));
233 Serial.print(F("\nEnter a command:"));
234 }
235
236
loop
static void loop()
Repeats Linduino loop.
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:93
LT_2977FaultLog::FaultLogLtc2977
Definition: LT_2977FaultLog.h:181
LT_2977FaultLog
class that handles LTC2977 fault logs.
Definition: LT_2977FaultLog.h:60
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
print_prompt
static void print_prompt()
Prints main menu.
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:223
smbus
static LT_SMBus * smbus
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:74
LT_SMBusPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LT_2977FaultLog.h
LTC SMBus Support: Implementation for a LTC2977 Fault Log.
Linduino.h
Header File for Linduino Libraries and Demo Code.
LT_SMBus::sendByte
virtual void sendByte(uint8_t address, uint8_t command)=0
SMBus send byte command.
LT_PMBus::enablePec
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
LT_SMBusNoPec
Definition: LT_SMBusNoPec.h:60
LT_2977FaultLog::dumpBinary
void dumpBinary(Print *printer=0)
Dumps binary of the fault log to a Print inheriting object, or Serial if none specified.
Definition: LT_2977FaultLog.cpp:135
LTC2977_I2C_ADDRESS_B
#define LTC2977_I2C_ADDRESS_B
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:68
LT_PMBus::disablePec
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
setup
static void setup()
Initialize Linduino.
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:82
LT_2977FaultLog::read
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
Definition: LT_2977FaultLog.cpp:83
LT_SMBusPec
Definition: LT_SMBusPec.h:61
LT_Wire.h
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
LT_SMBus
Definition: LT_SMBus.h:61
LTC2977_I2C_ADDRESS_A
#define LTC2977_I2C_ADDRESS_A
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:67
ltc2977_i2c_address_a
static uint8_t ltc2977_i2c_address_a
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:71
pmbus
static LT_PMBus * pmbus
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:75
LT_PMBus::resetGlobal
void resetGlobal(void)
Issue reset to all devices.
Definition: LT_PMBus.cpp:2906
ltc2977_i2c_address_b
static uint8_t ltc2977_i2c_address_b
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:72
MFR_FAULT_LOG_STORE
#define MFR_FAULT_LOG_STORE
Definition: LT_PMBus.h:135
LT_PMBus::clearAllFaults
void clearAllFaults(uint8_t address)
Clear all the faults for all pages.
Definition: LT_PMBus.cpp:2576
LT_SMBus::probe
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
LT_PMBus::readMfrFaultLogStatusByte
uint8_t readMfrFaultLogStatusByte(uint8_t address)
Get the fault log status byte.
Definition: LT_PMBus.cpp:2358
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LT_2977FaultLog::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_2977FaultLog.cpp:140
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LTC2977_SFL_EEPROM
#define LTC2977_SFL_EEPROM
Definition: LT_PMBus.h:282
LT_2977FaultLog::LT_2977FaultLog
LT_2977FaultLog(LT_PMBus *pmbus)
Constructor.
Definition: LT_2977FaultLog.cpp:61
print_title
static void print_title()
Prints the title block when program first starts.
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:209
LT_PMBus.h
LTC PMBus Support.
LT_FaultLog::clearFaultLog
void clearFaultLog(uint8_t address)
Definition: LT_FaultLog.cpp:240
LT_2977FaultLog::release
void release()
Frees the memory reserved for the fault log.
Definition: LT_2977FaultLog.cpp:119
LT_PMBus::restoreFromNvmGlobal
void restoreFromNvmGlobal(void)
Restore all devices from NVM.
Definition: LT_PMBus.cpp:2683
faultLog2977_a
static LT_2977FaultLog * faultLog2977_a
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:77
faultLog2977_b
static LT_2977FaultLog * faultLog2977_b
Definition: Part Number/2000/2900/2980/faultlog/faultlog.ino:78
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370