| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

Part Number/3000/3800/3880/faultlog/faultlog.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology LTC3880 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/LTC3880
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 LTC3880
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_3880FaultLog.h"
63
64 #define FILE_TEXT_LINE_MAX 132
65
66 #define LTC3880_I2C_ADDRESS 0x4F
67
68 // Global variables
69 static uint8_t ltc3880_i2c_address;
70
71 static LT_SMBus *smbus = new LT_SMBusPec();
72 static LT_PMBus *pmbus = new LT_PMBus(smbus);
73
74 static LT_3880FaultLog *faultLog3880 = new LT_3880FaultLog(pmbus);
75
76 //! Initialize Linduino
77 void setup()
78 {
79 Serial.begin(115200); //! Initialize the serial port to the PC
80 print_title();
81 ltc3880_i2c_address = LTC3880_I2C_ADDRESS;
82 print_prompt();
83 }
84
85 //! Repeats Linduino loop
86 void loop()
87 {
88 uint8_t user_command;
89 uint8_t *addresses = NULL;
90 struct LT_3880FaultLog::FaultLogLtc3880 *ltc3880_fault_log;
91
92
93 if (Serial.available()) //! Checks for user input
94 {
95 while ((user_command = read_int()) == 0); //! Reads the user command
96 if (user_command != 'm')
97 Serial.println(user_command);
98
99 uint8_t status;
100
101 switch (user_command) //! Prints the appropriate submenu
102 {
103 case 1:
104 status = pmbus->readMfrStatusByte(ltc3880_i2c_address);
105 if (status & LTC3880_SMFR_FAULT_LOG)
106 {
107 faultLog3880->read(ltc3880_i2c_address);
108
109 faultLog3880->dumpBinary(&Serial);
110 Serial.println();
111 faultLog3880->print(&Serial);
112
113 faultLog3880->release();
114 }
115 else
116 Serial.println(F("No LTC3880 Fault Log"));
117
118 break;
119 case 2:
120 faultLog3880->clearFaultLog(ltc3880_i2c_address);
121
122 break;
123 case 3:
124 pmbus->clearAllFaults(ltc3880_i2c_address);
125
126 break;
127 case 4:
128 pmbus->enablePec(ltc3880_i2c_address);
129 delete faultLog3880;
130 delete smbus;
131 delete pmbus;
132 smbus = new LT_SMBusPec();
133 pmbus = new LT_PMBus(smbus);
134 faultLog3880 = new LT_3880FaultLog(pmbus);
135 break;
136 case 5:
137 pmbus->disablePec(ltc3880_i2c_address);
138 delete faultLog3880;
139 delete smbus;
140 delete pmbus;
141 smbus = new LT_SMBusNoPec();
142 pmbus = new LT_PMBus(smbus);
143 faultLog3880 = new LT_3880FaultLog(pmbus);
144 break;
145 case 6:
146 addresses = smbus->probe(0);
147 while (*addresses != 0)
148 {
149 Serial.print(F("ADDR 0x"));
150 Serial.println(*addresses++, HEX);
151 }
152 break;
153 case 7:
154 pmbus->restoreFromNvmGlobal();
155 delay(2000);
156 pmbus->resetGlobal();
157 break;
158 case 8:
159 smbus->sendByte(ltc3880_i2c_address, MFR_FAULT_LOG_STORE);
160 break;
161 default:
162 Serial.println(F("Incorrect Option"));
163 break;
164 }
165 print_prompt();
166 }
167 }
168
169 // Function Definitions
170
171 //! Prints the title block when program first starts.
172 void print_title()
173 {
174 Serial.print(F("\n***************************************************************\n"));
175 Serial.print(F("* LTC3880 Fault Log Program *\n"));
176 Serial.print(F("* *\n"));
177 Serial.print(F("* This program dumps fault logs *\n"));
178 Serial.print(F("* *\n"));
179 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
180 Serial.print(F("* *\n"));
181 Serial.print(F("*****************************************************************\n"));
182 }
183
184 //! Prints main menu.
185 void print_prompt()
186 {
187 Serial.print(F("\n 1-Dump Fault Logs\n"));
188 Serial.print(F(" 2-Clear Fault Logs\n"));
189 Serial.print(F(" 3-Clear Faults\n"));
190 Serial.print(F(" 4-PEC On\n"));
191 Serial.print(F(" 5-PEC Off\n"));
192 Serial.print(F(" 6-Bus Probe\n"));
193 Serial.print(F(" 7-Reset\n"));
194 Serial.print(F(" 8-Store Fault Log\n"));
195 Serial.print(F("\nEnter a command:"));
196 }
197
198
loop
static void loop()
Repeats Linduino loop.
Definition: Part Number/3000/3800/3880/faultlog/faultlog.ino:86
LTC3880_I2C_ADDRESS
#define LTC3880_I2C_ADDRESS
Definition: Part Number/3000/3800/3880/faultlog/faultlog.ino:66
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
print_prompt
static void print_prompt()
Prints main menu.
Definition: Part Number/3000/3800/3880/faultlog/faultlog.ino:185
LT_3880FaultLog
class that handles LTC3880 fault logs.
Definition: LT_3880FaultLog.h:61
smbus
static LT_SMBus * smbus
Definition: Part Number/3000/3800/3880/faultlog/faultlog.ino:71
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
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
faultLog3880
static LT_3880FaultLog * faultLog3880
Definition: Part Number/3000/3800/3880/faultlog/faultlog.ino:74
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/3000/3800/3880/faultlog/faultlog.ino:77
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_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
LT_3880FaultLog.h
LTC SMBus Support: Implementation for a LTC3880 Fault Log.
LT_PMBus::readMfrStatusByte
uint8_t readMfrStatusByte(uint8_t address)
Get the MFR status byte.
Definition: LT_PMBus.cpp:2350
pmbus
static LT_PMBus * pmbus
Definition: Part Number/3000/3800/3880/faultlog/faultlog.ino:72
LT_3880FaultLog::dumpBinary
void dumpBinary(Print *printer=0)
Dumps binary of the fault log to a Print inheriting object, or Serial if none specified.
Definition: LT_3880FaultLog.cpp:108
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
LTC3880_SMFR_FAULT_LOG
#define LTC3880_SMFR_FAULT_LOG
Definition: LT_PMBus.h:175
LT_3880FaultLog::release
void release()
Frees the memory reserved for the fault log.
Definition: LT_3880FaultLog.cpp:92
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_3880FaultLog::LT_3880FaultLog
LT_3880FaultLog(LT_PMBus *pmbus)
Constructor.
Definition: LT_3880FaultLog.cpp:61
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
print_title
static void print_title()
Prints the title block when program first starts.
Definition: Part Number/3000/3800/3880/faultlog/faultlog.ino:172
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.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
ltc3880_i2c_address
static uint8_t ltc3880_i2c_address
Definition: Part Number/3000/3800/3880/faultlog/faultlog.ino:69
LT_3880FaultLog::FaultLogLtc3880
Definition: LT_3880FaultLog.h:119
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370