| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

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