| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

User Contributed/DC1962C/faultlog/faultlog.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1962C Demonstration Board
3 LTC3880, LTC2974, LTC2977: Power Management Solution for Application Processors
4 Setups for training.
5
6 @verbatim
7
8 NOTES
9 Setup:
10 Set the terminal baud rate to 115200 and select the newline terminator.
11
12 @endverbatim
13
14 http://www.linear.com/product/LTC3880
15
16 http://www.linear.com/product/LTC2974
17
18 http://www.linear.com/product/LTC2977
19
20 http://www.linear.com/demo/DC1962C
21
22
23 Copyright 2018(c) Analog Devices, Inc.
24
25 All rights reserved.
26
27 Redistribution and use in source and binary forms, with or without
28 modification, are permitted provided that the following conditions are met:
29 - Redistributions of source code must retain the above copyright
30 notice, this list of conditions and the following disclaimer.
31 - Redistributions in binary form must reproduce the above copyright
32 notice, this list of conditions and the following disclaimer in
33 the documentation and/or other materials provided with the
34 distribution.
35 - Neither the name of Analog Devices, Inc. nor the names of its
36 contributors may be used to endorse or promote products derived
37 from this software without specific prior written permission.
38 - The use of this software may or may not infringe the patent rights
39 of one or more patent holders. This license does not release you
40 from the requirement that you obtain separate licenses from these
41 patent holders to use this software.
42 - Use of the software either in source or binary form, must be run
43 on or directly connected to an Analog Devices Inc. component.
44
45 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
46 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
47 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
49 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
51 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */
56
57 /*! @file
58 @ingroup DC1962
59 */
60
61 #include <Arduino.h>
62 #include <stdint.h>
63 #include <avr/pgmspace.h>
64 #include "Linduino.h"
65 #include "UserInterface.h"
66 #include "LT_Wire.h"
67 #include "LT_SMBusNoPec.h"
68 #include "LT_SMBusPec.h"
69 #include "LT_PMBus.h"
70 #include "LT_2977FaultLog.h"
71 #include "LT_2974FaultLog.h"
72 #include "LT_3880FaultLog.h"
73
74
75 #define FILE_TEXT_LINE_MAX 132
76
77 #define LTC3880_I2C_ADDRESS 0x30
78 #define LTC2974_I2C_ADDRESS 0x32
79 #define LTC2977_I2C_ADDRESS 0x33
80
81 // Global variables
82 static uint8_t ltc3880_i2c_address;
83 static uint8_t ltc2974_i2c_address;
84 static uint8_t ltc2977_i2c_address;
85
86 static LT_SMBus *smbus = new LT_SMBusPec();
87 static LT_PMBus *pmbus = new LT_PMBus(smbus);
88
89 static LT_2977FaultLog *faultLog2977 = new LT_2977FaultLog(pmbus);
90 static LT_2974FaultLog *faultLog2974 = new LT_2974FaultLog(pmbus);
91 static LT_3880FaultLog *faultLog3880 = new LT_3880FaultLog(pmbus);
92
93 //! Initialize Linduino
94 //! @return void
95 void setup()
96 {
97 Serial.begin(115200); //! Initialize the serial port to the PC
98 print_title();
99 ltc3880_i2c_address = LTC3880_I2C_ADDRESS;
100 ltc2974_i2c_address = LTC2974_I2C_ADDRESS;
101 ltc2977_i2c_address = LTC2977_I2C_ADDRESS;
102 print_prompt();
103 }
104
105 //! Repeats Linduino loop
106 //! @return void
107 void loop()
108 {
109 uint8_t user_command;
110 uint8_t *addresses = NULL;
111 struct LT_3880FaultLog::FaultLogLtc3880 *ltc3880_fault_log;
112 struct LT_2977FaultLog::FaultLogLtc2977 *ltc2977_fault_log;
113 struct LT_2974FaultLog::FaultLogLtc2974 *ltc2974_fault_log;
114 uint16_t timeout;
115
116 if (Serial.available()) //! Checks for user input
117 {
118 while ((user_command = read_int()) == 0); //! Reads the user command
119 if (user_command != 'm')
120 Serial.println(user_command);
121
122 switch (user_command) //! Prints the appropriate submenu
123 {
124 case 1:
125 Serial.println();
126 if (faultLog3880->hasFaultLog(ltc3880_i2c_address))
127 {
128 faultLog3880->read(ltc3880_i2c_address);
129 faultLog3880->print(&Serial);
130 faultLog3880->release();
131 }
132 else
133 Serial.println(F("No LTC3880 Fault Log"));
134
135 Serial.println();
136 if (faultLog2974->hasFaultLog(ltc2974_i2c_address))
137 {
138 faultLog2974->read(ltc2974_i2c_address);
139 faultLog2974->print(&Serial);
140 faultLog2974->release();
141 }
142 else
143 Serial.println(F("No LTC2974 Fault Log"));
144
145 Serial.println();
146 if (faultLog2977->hasFaultLog(ltc2977_i2c_address))
147 {
148 faultLog2977->read(ltc2977_i2c_address);
149 faultLog2977->print(&Serial);
150 faultLog2977->release();
151 }
152 else
153 Serial.println(F("No LTC2977 Fault Log"));
154
155 break;
156 case 2:
157 faultLog3880->clearFaultLog(ltc3880_i2c_address);
158 delay(2);
159 smbus->waitForAck(ltc3880_i2c_address, 0x00);
160 pmbus->waitForNotBusy(ltc3880_i2c_address);
161
162 timeout = 4096;
163 while (timeout-- > 0)
164 {
165 if (0 == pmbus->readMfrStatusByte(ltc3880_i2c_address) & ~(1 << 3))
166 break;
167 }
168
169 faultLog2974->clearFaultLog(ltc2974_i2c_address);
170 delay(2);
171 pmbus->waitForNotBusy(ltc2974_i2c_address);
172 faultLog2977->clearFaultLog(ltc2977_i2c_address);
173 delay(2);
174 pmbus->waitForNotBusy(ltc2977_i2c_address);
175 break;
176 case 3:
177 pmbus->clearAllFaults(ltc3880_i2c_address);
178 pmbus->clearAllFaults(ltc2974_i2c_address);
179 pmbus->clearAllFaults(ltc2977_i2c_address);
180 break;
181 case 4:
182 addresses = smbus->probe(0);
183 while (*addresses != 0)
184 {
185 Serial.print(F("ADDR 0x"));
186 Serial.println(*addresses++, HEX);
187 }
188 break;
189 case 5:
190 pmbus->startGroupProtocol();
191 pmbus->reset(ltc3880_i2c_address);
192 pmbus->restoreFromNvm(ltc2974_i2c_address);
193 pmbus->restoreFromNvm(ltc2977_i2c_address);
194 pmbus->executeGroupProtocol();
195 break;
196 case 6:
197 smbus->sendByte(ltc3880_i2c_address, MFR_FAULT_LOG_STORE);
198 delay(2);
199 smbus->waitForAck(ltc3880_i2c_address, 0x00);
200 pmbus->waitForNotBusy(ltc3880_i2c_address);
201
202 timeout = 4096;
203 while (timeout-- > 0)
204 {
205 if (0 != pmbus->readMfrStatusByte(ltc3880_i2c_address) & ~(1 << 3))
206 break;
207 }
208
209 smbus->sendByte(ltc2974_i2c_address, MFR_FAULT_LOG_STORE);
210 delay(2);
211 pmbus->waitForNotBusy(ltc2974_i2c_address);
212
213 smbus->sendByte(ltc2977_i2c_address, MFR_FAULT_LOG_STORE);
214 delay(2);
215 pmbus->waitForNotBusy(ltc2977_i2c_address);
216
217 break;
218 default:
219 Serial.println(F("Incorrect Option"));
220 break;
221 }
222 print_prompt();
223 }
224 }
225
226 // Function Definitions
227
228 //! Prints the title block when program first starts.
229 //! @return void
230 void print_title()
231 {
232 Serial.print(F("\n***************************************************************\n"));
233 Serial.print(F("* DC1962C Fault Log Program *\n"));
234 Serial.print(F("* *\n"));
235 Serial.print(F("* This program dumps fault logs *\n"));
236 Serial.print(F("* *\n"));
237 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
238 Serial.print(F("* *\n"));
239 Serial.print(F("*****************************************************************\n"));
240 }
241
242 //! Prints main menu.
243 //! @return void
244 void print_prompt()
245 {
246 Serial.print(F("\n 1-Dump Fault Logs\n"));
247 Serial.print(F(" 2-Clear Fault Logs\n"));
248 Serial.print(F(" 3-Clear Faults\n"));
249 Serial.print(F(" 4-Bus Probe\n"));
250 Serial.print(F(" 5-Reset\n"));
251 Serial.print(F(" 6-Store Fault Log\n"));
252 Serial.print(F("\nEnter a command:"));
253 }
254
255
LT_2977FaultLog::FaultLogLtc2977
Definition: LT_2977FaultLog.h:181
LT_2974FaultLog
class that handles LTC2974 fault logs.
Definition: LT_2974FaultLog.h:61
LT_2977FaultLog
class that handles LTC2977 fault logs.
Definition: LT_2977FaultLog.h:60
print_prompt
static void print_prompt()
Prints main menu.
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:244
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
LT_2974FaultLog::FaultLogLtc2974
Definition: LT_2974FaultLog.h:203
smbus
static LT_SMBus * smbus
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:86
LT_3880FaultLog
class that handles LTC3880 fault logs.
Definition: LT_3880FaultLog.h:61
faultLog2977
static LT_2977FaultLog * faultLog2977
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:89
LT_SMBusPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LT_PMBus::reset
void reset(uint8_t address)
Issue reset to one device.
Definition: LT_PMBus.cpp:2912
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.
LTC2977_I2C_ADDRESS
#define LTC2977_I2C_ADDRESS
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:79
LT_3880FaultLog::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_3880FaultLog.cpp:113
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_PMBus::waitForNotBusy
uint8_t waitForNotBusy(uint8_t address)
Read MFR_COMMON until not Busy.
Definition: LT_PMBus.cpp:3254
LT_SMBus
Definition: LT_SMBus.h:61
LT_3880FaultLog.h
LTC SMBus Support: Implementation for a LTC3880 Fault Log.
LT_PMBus::startGroupProtocol
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
LT_FaultLog::hasFaultLog
bool hasFaultLog(uint8_t address)
Definition: LT_FaultLog.cpp:101
LT_SMBus::waitForAck
virtual uint8_t waitForAck(uint8_t address, uint8_t command)=0
Read with the address and command in loop until ack, then issue stop.
LT_PMBus::readMfrStatusByte
uint8_t readMfrStatusByte(uint8_t address)
Get the MFR status byte.
Definition: LT_PMBus.cpp:2350
LTC3880_I2C_ADDRESS
#define LTC3880_I2C_ADDRESS
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:77
setup
static void setup()
Initialize Linduino.
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:95
MFR_FAULT_LOG_STORE
#define MFR_FAULT_LOG_STORE
Definition: LT_PMBus.h:135
LT_2974FaultLog::release
void release()
Frees the memory reserved for the fault log.
Definition: LT_2974FaultLog.cpp:165
print_title
static void print_title()
Prints the title block when program first starts.
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:230
LT_2974FaultLog::read
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
Definition: LT_2974FaultLog.cpp:118
LT_3880FaultLog::release
void release()
Frees the memory reserved for the fault log.
Definition: LT_3880FaultLog.cpp:92
faultLog2974
static LT_2974FaultLog * faultLog2974
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:90
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.
timeout
long timeout
Definition: EVAL-AD7124-8.ino:144
ltc2974_i2c_address
static uint8_t ltc2974_i2c_address
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:83
LT_2974FaultLog::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_2974FaultLog.cpp:186
pmbus
static LT_PMBus * pmbus
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:87
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
LTC2974_I2C_ADDRESS
#define LTC2974_I2C_ADDRESS
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:78
ltc2977_i2c_address
static uint8_t ltc2977_i2c_address
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:84
LT_3880FaultLog::read
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
Definition: LT_3880FaultLog.cpp:76
LT_PMBus::executeGroupProtocol
void executeGroupProtocol(void)
ends group protocol
Definition: LT_PMBus.cpp:3356
LT_PMBus::restoreFromNvm
void restoreFromNvm(uint8_t address)
Restore device from NVM.
Definition: LT_PMBus.cpp:2663
LT_PMBus.h
LTC PMBus Support.
LT_2974FaultLog.h
LTC SMBus Support: Implementation for a LTC2974 Fault Log.
LT_FaultLog::clearFaultLog
void clearFaultLog(uint8_t address)
Definition: LT_FaultLog.cpp:240
faultLog3880
static LT_3880FaultLog * faultLog3880
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:91
LT_2977FaultLog::release
void release()
Frees the memory reserved for the fault log.
Definition: LT_2977FaultLog.cpp:119
LT_3880FaultLog::FaultLogLtc3880
Definition: LT_3880FaultLog.h:119
loop
static void loop()
Repeats Linduino loop.
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:107
ltc3880_i2c_address
static uint8_t ltc3880_i2c_address
Definition: User Contributed/DC1962C/faultlog/faultlog.ino:82
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370