Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
Part Number/2000/2900/2974/faultlog/faultlog.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology LTC2974 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/LTC2974
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 LTC2974
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_2974FaultLog.h"
63 
64 #define FILE_TEXT_LINE_MAX 132
65 
66 #define LTC2974_I2C_ADDRESS 0x32
67 
68 // Global variables
69 static uint8_t ltc2974_i2c_address;
70 
71 static LT_SMBus *smbus = new LT_SMBusPec();
72 static LT_PMBus *pmbus = new LT_PMBus(smbus);
73 
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();
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_2974FaultLog::FaultLogLtc2974 *ltc2974_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:
107  if (status & LTC2974_SFL_EEPROM)
108  {
109  faultLog2974->read(ltc2974_i2c_address);
110 
111  faultLog2974->dumpBinary(&Serial);
112  Serial.println();
113 
114  faultLog2974->print(&Serial);
115 
116  faultLog2974->release();
117  }
118  else
119  Serial.println(F("No LTC2974 Fault Log"));
120 
121  break;
122  case 2:
123  faultLog2974->clearFaultLog(ltc2974_i2c_address);
124 
125  break;
126  case 3:
128 
129  break;
130  case 4:
132  delete faultLog2974;
133  delete smbus;
134  delete pmbus;
135  smbus = new LT_SMBusPec();
136  pmbus = new LT_PMBus(smbus);
137  faultLog2974 = new LT_2974FaultLog(pmbus);
138  break;
139  case 5:
141  delete faultLog2974;
142  delete smbus;
143  delete pmbus;
144  smbus = new LT_SMBusNoPec();
145  pmbus = new LT_PMBus(smbus);
146  faultLog2974 = new LT_2974FaultLog(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:
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
177 {
178  Serial.print(F("\n***************************************************************\n"));
179  Serial.print(F("* LTC2974 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
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 
#define LTC2974_SFL_EEPROM
Definition: LT_PMBus.h:277
class that handles LTC2974 fault logs.
unsigned char user_command
static void setup()
Initialize Linduino.
LTC SMBus Support: Implementation for a shared SMBus layer.
String status(void)
Returns a descriptive string based on status of pins.
Definition: DC2364A.ino:217
void dumpBinary(Print *printer=0)
Dumps binary of the fault log to a Print inheriting object, or Serial if none specified.
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 disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
void resetGlobal(void)
Issue reset to all devices.
Definition: LT_PMBus.cpp:2906
#define MFR_FAULT_LOG_STORE
Definition: LT_PMBus.h:135
static void print_title()
Prints the title block when program first starts.
void release()
Frees the memory reserved for the fault log.
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
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.
static void print_prompt()
Prints main menu.
uint8_t readMfrFaultLogStatusByte(uint8_t address)
Get the fault log status byte.
Definition: LT_PMBus.cpp:2358
void print(Print *printer=0)
Pretty prints this part&#39;s fault log to a Print inheriting object, or Serial if none specified...
LTC SMBus Support: Implementation for a shared SMBus layer.
static LT_2974FaultLog * faultLog2974
int32_t read_int()
static void loop()
Repeats Linduino loop.
LTC PMBus Support.
LTC SMBus Support: Implementation for a LTC2974 Fault Log.
void clearFaultLog(uint8_t address)
void restoreFromNvmGlobal(void)
Restore all devices from NVM.
Definition: LT_PMBus.cpp:2683
LT_2974FaultLog(LT_PMBus *pmbus)
Constructor.
PMBus communication.
Definition: LT_PMBus.h:370