| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

Part Number/3000/3800/3882/faultlog/faultlog.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology LTC3882 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/LTC3882
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 LTC3882
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_3882FaultLog.h"
63
64 #define FILE_TEXT_LINE_MAX 132
65
66 #define LTC3882_I2C_ADDRESS 0x5C
67
68 // Global variables
69 static uint8_t ltc3882_i2c_address;
70
71 static LT_SMBus *smbus = new LT_SMBusPec();
72 static LT_PMBus *pmbus = new LT_PMBus(smbus);
73
74 static LT_3882FaultLog *faultLog3882 = new LT_3882FaultLog(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 ltc3882_i2c_address = LTC3882_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_3882FaultLog::FaultLogLtc3882 *ltc3882_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->readMfrStatusByte(ltc3882_i2c_address);
107 if (status & LTC3882_SMFR_FAULT_LOG)
108 {
109 faultLog3882->read(ltc3882_i2c_address);
110
111 faultLog3882->dumpBinary(&Serial);
112 Serial.println();
113 faultLog3882->print(&Serial);
114
115 faultLog3882->release();
116 }
117 else
118 Serial.println(F("No LTC3882 Fault Log"));
119
120 break;
121 case 2:
122 faultLog3882->clearFaultLog(ltc3882_i2c_address);
123
124 break;
125 case 3:
126 pmbus->clearAllFaults(ltc3882_i2c_address);
127
128 break;
129 case 4:
130 pmbus->enablePec(ltc3882_i2c_address);
131 delete faultLog3882;
132 delete smbus;
133 delete pmbus;
134 smbus = new LT_SMBusPec();
135 pmbus = new LT_PMBus(smbus);
136 faultLog3882 = new LT_3882FaultLog(pmbus);
137 break;
138 case 5:
139 pmbus->disablePec(ltc3882_i2c_address);
140 delete faultLog3882;
141 delete smbus;
142 delete pmbus;
143 smbus = new LT_SMBusNoPec();
144 pmbus = new LT_PMBus(smbus);
145 faultLog3882 = new LT_3882FaultLog(pmbus);
146 break;
147 case 6:
148 addresses = smbus->probe(0);
149 while (*addresses != 0)
150 {
151 Serial.print(F("ADDR 0x"));
152 Serial.println(*addresses++, HEX);
153 }
154 break;
155 case 7:
156 pmbus->restoreFromNvmGlobal();
157 delay(2000);
158 pmbus->resetGlobal();
159 break;
160 case 8:
161 smbus->sendByte(ltc3882_i2c_address, MFR_FAULT_LOG_STORE);
162 break;
163 default:
164 Serial.println(F("Incorrect Option"));
165 break;
166 }
167 print_prompt();
168 }
169 }
170
171 // Function Definitions
172
173 //! Prints the title block when program first starts.
174 //! @return void
175 void print_title()
176 {
177 Serial.print(F("\n***************************************************************\n"));
178 Serial.print(F("* LTC3882 Fault Log Program *\n"));
179 Serial.print(F("* *\n"));
180 Serial.print(F("* This program dumps fault logs *\n"));
181 Serial.print(F("* *\n"));
182 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
183 Serial.print(F("* *\n"));
184 Serial.print(F("*****************************************************************\n"));
185 }
186
187 //! Prints main menu.
188 //! @return void
189 void print_prompt()
190 {
191 Serial.print(F("\n 1-Dump Fault Logs\n"));
192 Serial.print(F(" 2-Clear Fault Logs\n"));
193 Serial.print(F(" 3-Clear Faults\n"));
194 Serial.print(F(" 4-PEC On\n"));
195 Serial.print(F(" 5-PEC Off\n"));
196 Serial.print(F(" 6-Bus Probe\n"));
197 Serial.print(F(" 7-Reset\n"));
198 Serial.print(F(" 8-Store Fault Log\n"));
199 Serial.print(F("\nEnter a command:"));
200 }
201
202
LT_3882FaultLog::read
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
Definition: LT_3882FaultLog.cpp:75
LT_3882FaultLog::FaultLogLtc3882
Definition: LT_3882FaultLog.h:119
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
LT_3882FaultLog::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_3882FaultLog.cpp:112
LT_3882FaultLog
class that handles LTC3882 fault logs.
Definition: LT_3882FaultLog.h:61
LT_SMBusPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
print_title
static void print_title()
Prints the title block when program first starts.
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:175
status
String status(void)
Returns a descriptive string based on status of pins.
Definition: DC2364A.ino:217
pmbus
static LT_PMBus * pmbus
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:72
ltc3882_i2c_address
static uint8_t ltc3882_i2c_address
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:69
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
LTC3882_I2C_ADDRESS
#define LTC3882_I2C_ADDRESS
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:66
LT_PMBus::disablePec
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
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
loop
static void loop()
Repeats Linduino loop.
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:88
LT_PMBus::readMfrStatusByte
uint8_t readMfrStatusByte(uint8_t address)
Get the MFR status byte.
Definition: LT_PMBus.cpp:2350
LT_3882FaultLog.h
LTC SMBus Support: Implementation for a LTC3882 Fault Log.
LT_PMBus::resetGlobal
void resetGlobal(void)
Issue reset to all devices.
Definition: LT_PMBus.cpp:2906
MFR_FAULT_LOG_STORE
#define MFR_FAULT_LOG_STORE
Definition: LT_PMBus.h:135
LT_3882FaultLog::release
void release()
Frees the memory reserved for the fault log.
Definition: LT_3882FaultLog.cpp:91
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_3882FaultLog::LT_3882FaultLog
LT_3882FaultLog(LT_PMBus *pmbus)
Constructor.
Definition: LT_3882FaultLog.cpp:61
LT_3882FaultLog::dumpBinary
void dumpBinary(Print *printer=0)
Dumps binary of the fault log to a Print inheriting object, or Serial if none specified.
Definition: LT_3882FaultLog.cpp:107
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
setup
static void setup()
Initialize Linduino.
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:78
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
smbus
static LT_SMBus * smbus
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:71
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
print_prompt
static void print_prompt()
Prints main menu.
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:189
LTC3882_SMFR_FAULT_LOG
#define LTC3882_SMFR_FAULT_LOG
Definition: LT_PMBus.h:191
faultLog3882
static LT_3882FaultLog * faultLog3882
Definition: Part Number/3000/3800/3882/faultlog/faultlog.ino:74
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370