Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
Part Number/2000/2900/2987/faultlog/faultlog.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology LTM2987 Fault Logging
3 Note that LTM2987 = 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/LTM2987
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 
51 #include <Arduino.h>
52 #include <stdint.h>
53 #include <avr/pgmspace.h>
54 #include "Linduino.h"
55 #include "UserInterface.h"
56 #include "LT_Wire.h"
57 #include "LT_SMBusNoPec.h"
58 #include "LT_SMBusPec.h"
59 #include "LT_PMBus.h"
60 #include "LT_2977FaultLog.h"
61 
62 #define FILE_TEXT_LINE_MAX 132
63 
64 #define LTC2977_I2C_ADDRESS_A 0x30
65 #define LTC2977_I2C_ADDRESS_B 0x32
66 
67 // Global variables
68 static uint8_t ltc2977_i2c_address_a;
69 static uint8_t ltc2977_i2c_address_b;
70 
71 static LT_SMBus *smbus = new LT_SMBusPec();
72 static LT_PMBus *pmbus = new LT_PMBus(smbus);
73 
76 
77 //! Initialize Linduino
78 //! @return void
79 void setup()
80 {
81  Serial.begin(115200); //! Initialize the serial port to the PC
82  print_title();
85  print_prompt();
86 }
87 
88 //! Repeats Linduino loop
89 //! @return void
90 void loop()
91 {
92  uint8_t user_command;
93  uint8_t *addresses = NULL;
94 
95  struct LT_2977FaultLog::FaultLogLtc2977 *ltc2977_fault_log_a;
96  struct LT_2977FaultLog::FaultLogLtc2977 *ltc2977_fault_log_b;
97 
98 
99  if (Serial.available()) //! Checks for user input
100  {
101  while ((user_command = read_int()) == 0); //! Reads the user command
102  if (user_command != 'm')
103  Serial.println(user_command);
104 
105  uint8_t status_a;
106  uint8_t status_b;
107 
108  switch (user_command) //! Prints the appropriate submenu
109  {
110  case 1:
113 
114  if (status_a & LTC2977_SFL_EEPROM) // A is one of the two LTC2977's inside of the LTM2987
115  {
116  Serial.println(F("LTM2987 A Fault Log"));
117  faultLog2977_a->read(ltc2977_i2c_address_a);
118 
119  faultLog2977_a->dumpBinary(&Serial);
120  Serial.println();
121  faultLog2977_a->print(&Serial);
122 
123  faultLog2977_a->release();
124  }
125  else
126  Serial.println(F("No LTM2987 A Fault Log"));
127 
128  if (status_b & LTC2977_SFL_EEPROM) // B is one of the two LTC2977's inside of the LTM2987
129  {
130  Serial.println(F("LTM2987 B Fault Log"));
131  faultLog2977_b->read(ltc2977_i2c_address_b);
132 
133  faultLog2977_b->dumpBinary(&Serial);
134  Serial.println();
135  faultLog2977_b->print(&Serial);
136 
137  faultLog2977_b->release();
138  }
139  else
140  Serial.println(F("No LTM2987 B Fault Log"));
141 
142  break;
143  case 2:
144  faultLog2977_a->clearFaultLog(ltc2977_i2c_address_a);
145  faultLog2977_b->clearFaultLog(ltc2977_i2c_address_b);
146 
147  break;
148  case 3:
151 
152  break;
153  case 4:
156  delete faultLog2977_a;
157  delete faultLog2977_b;
158  delete smbus;
159  delete pmbus;
160  smbus = new LT_SMBusPec();
161  pmbus = new LT_PMBus(smbus);
162  faultLog2977_a = new LT_2977FaultLog(pmbus);
163  faultLog2977_b = new LT_2977FaultLog(pmbus);
164  break;
165  case 5:
168  delete faultLog2977_a;
169  delete faultLog2977_b;
170  delete smbus;
171  delete pmbus;
172  smbus = new LT_SMBusNoPec();
173  pmbus = new LT_PMBus(smbus);
174  faultLog2977_a = new LT_2977FaultLog(pmbus);
175  faultLog2977_b = new LT_2977FaultLog(pmbus);
176  break;
177  case 6:
178  addresses = smbus->probe(0);
179  while (*addresses != 0)
180  {
181  Serial.print(F("ADDR 0x"));
182  Serial.println(*addresses++, HEX);
183  }
184  break;
185  case 7:
186  pmbus->restoreFromNvmGlobal();
187  delay(2000);
188  pmbus->resetGlobal();
189  break;
190  case 8:
193  break;
194  default:
195  Serial.println(F("Incorrect Option"));
196  break;
197  }
198  print_prompt();
199  }
200 }
201 
202 // Function Definitions
203 
204 //! Prints the title block when program first starts.
205 //! @return void
207 {
208  Serial.print(F("\n***************************************************************\n"));
209  Serial.print(F("* LTC2987 Fault Log Program *\n"));
210  Serial.print(F("* *\n"));
211  Serial.print(F("* This program dumps fault logs *\n"));
212  Serial.print(F("* *\n"));
213  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
214  Serial.print(F("* *\n"));
215  Serial.print(F("*****************************************************************\n"));
216 }
217 
218 //! Prints main menu.
219 //! @return void
221 {
222  Serial.print(F("\n 1-Dump Fault Logs\n"));
223  Serial.print(F(" 2-Clear Fault Logs\n"));
224  Serial.print(F(" 3-Clear Faults\n"));
225  Serial.print(F(" 4-PEC On\n"));
226  Serial.print(F(" 5-PEC Off\n"));
227  Serial.print(F(" 6-Bus Probe\n"));
228  Serial.print(F(" 7-Reset\n"));
229  Serial.print(F(" 8-Store Fault Log\n"));
230  Serial.print(F("\nEnter a command:"));
231 }
232 
233 
class that handles LTC2977 fault logs.
unsigned char user_command
LTC SMBus Support: Implementation for a shared SMBus layer.
LTC SMBus Support: Implementation for a LTC2977 Fault Log.
Header File for Linduino Libraries and Demo Code.
virtual void sendByte(uint8_t address, uint8_t command)=0
SMBus send byte command.
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
void dumpBinary(Print *printer=0)
Dumps binary of the fault log to a Print inheriting object, or Serial if none specified.
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
static void print_title()
Prints the title block when program first starts.
static LT_2977FaultLog * faultLog2977_a
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
static LT_2977FaultLog * faultLog2977_b
void resetGlobal(void)
Issue reset to all devices.
Definition: LT_PMBus.cpp:2906
static void loop()
Repeats Linduino loop.
#define MFR_FAULT_LOG_STORE
Definition: LT_PMBus.h:135
static void print_prompt()
Prints main menu.
void clearAllFaults(uint8_t address)
Clear all the faults for all pages.
Definition: LT_PMBus.cpp:2576
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
uint8_t readMfrFaultLogStatusByte(uint8_t address)
Get the fault log status byte.
Definition: LT_PMBus.cpp:2358
LTC SMBus Support: Implementation for a shared SMBus layer.
void print(Print *printer=0)
Pretty prints this part&#39;s fault log to a Print inheriting object, or Serial if none specified...
int32_t read_int()
#define LTC2977_SFL_EEPROM
Definition: LT_PMBus.h:282
LT_2977FaultLog(LT_PMBus *pmbus)
Constructor.
static void setup()
Initialize Linduino.
LTC PMBus Support.
void clearFaultLog(uint8_t address)
void release()
Frees the memory reserved for the fault log.
void restoreFromNvmGlobal(void)
Restore all devices from NVM.
Definition: LT_PMBus.cpp:2683
static uint8_t ltc2977_i2c_address_a
static uint8_t ltc2977_i2c_address_b
PMBus communication.
Definition: LT_PMBus.h:370