Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
User Contributed/DC1962C/faultlog/faultlog.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC1962C Demonstration Board
3 LTC3880, LTC2974, LTC2977: Power Management Solution for Application Processors
4 Setups for training.
5 
6 @verbatim
7 
8 NOTES
9  Setup:
10  Set the terminal baud rate to 115200 and select the newline terminator.
11 
12 @endverbatim
13 
14 http://www.linear.com/product/LTC3880
15 
16 http://www.linear.com/product/LTC2974
17 
18 http://www.linear.com/product/LTC2977
19 
20 http://www.linear.com/demo/DC1962C
21 
22 
23 Copyright 2018(c) Analog Devices, Inc.
24 
25 All rights reserved.
26 
27 Redistribution and use in source and binary forms, with or without
28 modification, are permitted provided that the following conditions are met:
29  - Redistributions of source code must retain the above copyright
30  notice, this list of conditions and the following disclaimer.
31  - Redistributions in binary form must reproduce the above copyright
32  notice, this list of conditions and the following disclaimer in
33  the documentation and/or other materials provided with the
34  distribution.
35  - Neither the name of Analog Devices, Inc. nor the names of its
36  contributors may be used to endorse or promote products derived
37  from this software without specific prior written permission.
38  - The use of this software may or may not infringe the patent rights
39  of one or more patent holders. This license does not release you
40  from the requirement that you obtain separate licenses from these
41  patent holders to use this software.
42  - Use of the software either in source or binary form, must be run
43  on or directly connected to an Analog Devices Inc. component.
44 
45 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
46 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
47 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
49 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
51 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */
56 
57 /*! @file
58  @ingroup DC1962
59 */
60 
61 #include <Arduino.h>
62 #include <stdint.h>
63 #include <avr/pgmspace.h>
64 #include "Linduino.h"
65 #include "UserInterface.h"
66 #include "LT_Wire.h"
67 #include "LT_SMBusNoPec.h"
68 #include "LT_SMBusPec.h"
69 #include "LT_PMBus.h"
70 #include "LT_2977FaultLog.h"
71 #include "LT_2974FaultLog.h"
72 #include "LT_3880FaultLog.h"
73 
74 
75 #define FILE_TEXT_LINE_MAX 132
76 
77 #define LTC3880_I2C_ADDRESS 0x30
78 #define LTC2974_I2C_ADDRESS 0x32
79 #define LTC2977_I2C_ADDRESS 0x33
80 
81 // Global variables
82 static uint8_t ltc3880_i2c_address;
83 static uint8_t ltc2974_i2c_address;
84 static uint8_t ltc2977_i2c_address;
85 
86 static LT_SMBus *smbus = new LT_SMBusPec();
87 static LT_PMBus *pmbus = new LT_PMBus(smbus);
88 
92 
93 //! Initialize Linduino
94 //! @return void
95 void setup()
96 {
97  Serial.begin(115200); //! Initialize the serial port to the PC
98  print_title();
102  print_prompt();
103 }
104 
105 //! Repeats Linduino loop
106 //! @return void
107 void loop()
108 {
109  uint8_t user_command;
110  uint8_t *addresses = NULL;
111  struct LT_3880FaultLog::FaultLogLtc3880 *ltc3880_fault_log;
112  struct LT_2977FaultLog::FaultLogLtc2977 *ltc2977_fault_log;
113  struct LT_2974FaultLog::FaultLogLtc2974 *ltc2974_fault_log;
114  uint16_t timeout;
115 
116  if (Serial.available()) //! Checks for user input
117  {
118  while ((user_command = read_int()) == 0); //! Reads the user command
119  if (user_command != 'm')
120  Serial.println(user_command);
121 
122  switch (user_command) //! Prints the appropriate submenu
123  {
124  case 1:
125  Serial.println();
126  if (faultLog3880->hasFaultLog(ltc3880_i2c_address))
127  {
128  faultLog3880->read(ltc3880_i2c_address);
129  faultLog3880->print(&Serial);
130  faultLog3880->release();
131  }
132  else
133  Serial.println(F("No LTC3880 Fault Log"));
134 
135  Serial.println();
136  if (faultLog2974->hasFaultLog(ltc2974_i2c_address))
137  {
138  faultLog2974->read(ltc2974_i2c_address);
139  faultLog2974->print(&Serial);
140  faultLog2974->release();
141  }
142  else
143  Serial.println(F("No LTC2974 Fault Log"));
144 
145  Serial.println();
146  if (faultLog2977->hasFaultLog(ltc2977_i2c_address))
147  {
148  faultLog2977->read(ltc2977_i2c_address);
149  faultLog2977->print(&Serial);
150  faultLog2977->release();
151  }
152  else
153  Serial.println(F("No LTC2977 Fault Log"));
154 
155  break;
156  case 2:
157  faultLog3880->clearFaultLog(ltc3880_i2c_address);
158  delay(2);
159  smbus->waitForAck(ltc3880_i2c_address, 0x00);
161 
162  timeout = 4096;
163  while (timeout-- > 0)
164  {
165  if (0 == pmbus->readMfrStatusByte(ltc3880_i2c_address) & ~(1 << 3))
166  break;
167  }
168 
169  faultLog2974->clearFaultLog(ltc2974_i2c_address);
170  delay(2);
172  faultLog2977->clearFaultLog(ltc2977_i2c_address);
173  delay(2);
175  break;
176  case 3:
180  break;
181  case 4:
182  addresses = smbus->probe(0);
183  while (*addresses != 0)
184  {
185  Serial.print(F("ADDR 0x"));
186  Serial.println(*addresses++, HEX);
187  }
188  break;
189  case 5:
190  pmbus->startGroupProtocol();
191  pmbus->reset(ltc3880_i2c_address);
194  pmbus->executeGroupProtocol();
195  break;
196  case 6:
198  delay(2);
199  smbus->waitForAck(ltc3880_i2c_address, 0x00);
201 
202  timeout = 4096;
203  while (timeout-- > 0)
204  {
205  if (0 != pmbus->readMfrStatusByte(ltc3880_i2c_address) & ~(1 << 3))
206  break;
207  }
208 
210  delay(2);
212 
214  delay(2);
216 
217  break;
218  default:
219  Serial.println(F("Incorrect Option"));
220  break;
221  }
222  print_prompt();
223  }
224 }
225 
226 // Function Definitions
227 
228 //! Prints the title block when program first starts.
229 //! @return void
231 {
232  Serial.print(F("\n***************************************************************\n"));
233  Serial.print(F("* DC1962C Fault Log Program *\n"));
234  Serial.print(F("* *\n"));
235  Serial.print(F("* This program dumps fault logs *\n"));
236  Serial.print(F("* *\n"));
237  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
238  Serial.print(F("* *\n"));
239  Serial.print(F("*****************************************************************\n"));
240 }
241 
242 //! Prints main menu.
243 //! @return void
245 {
246  Serial.print(F("\n 1-Dump Fault Logs\n"));
247  Serial.print(F(" 2-Clear Fault Logs\n"));
248  Serial.print(F(" 3-Clear Faults\n"));
249  Serial.print(F(" 4-Bus Probe\n"));
250  Serial.print(F(" 5-Reset\n"));
251  Serial.print(F(" 6-Store Fault Log\n"));
252  Serial.print(F("\nEnter a command:"));
253 }
254 
255 
class that handles LTC2974 fault logs.
class that handles LTC2977 fault logs.
static void print_prompt()
Prints main menu.
unsigned char user_command
class that handles LTC3880 fault logs.
static LT_2977FaultLog * faultLog2977
LTC SMBus Support: Implementation for a shared SMBus layer.
void reset(uint8_t address)
Issue reset to one device.
Definition: LT_PMBus.cpp:2912
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 print(Print *printer=0)
Pretty prints this part&#39;s fault log to a Print inheriting object, or Serial if none specified...
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.
uint8_t waitForNotBusy(uint8_t address)
Read MFR_COMMON until not Busy.
Definition: LT_PMBus.cpp:3254
LTC SMBus Support: Implementation for a LTC3880 Fault Log.
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
bool hasFaultLog(uint8_t address)
virtual uint8_t waitForAck(uint8_t address, uint8_t command)=0
Read with the address and command in loop until ack, then issue stop.
uint8_t readMfrStatusByte(uint8_t address)
Get the MFR status byte.
Definition: LT_PMBus.cpp:2350
static void setup()
Initialize Linduino.
#define MFR_FAULT_LOG_STORE
Definition: LT_PMBus.h:135
void release()
Frees the memory reserved for the fault log.
static void print_title()
Prints the title block when program first starts.
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
void release()
Frees the memory reserved for the fault log.
static LT_2974FaultLog * faultLog2974
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.
long timeout
static uint8_t ltc2974_i2c_address
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.
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()
static uint8_t ltc2977_i2c_address
void read(uint8_t address)
Reads the fault log from the specified address, reserves memory to hold the data. ...
void executeGroupProtocol(void)
ends group protocol
Definition: LT_PMBus.cpp:3356
void restoreFromNvm(uint8_t address)
Restore device from NVM.
Definition: LT_PMBus.cpp:2663
LTC PMBus Support.
LTC SMBus Support: Implementation for a LTC2974 Fault Log.
void clearFaultLog(uint8_t address)
static LT_3880FaultLog * faultLog3880
void release()
Frees the memory reserved for the fault log.
static void loop()
Repeats Linduino loop.
static uint8_t ltc3880_i2c_address
PMBus communication.
Definition: LT_PMBus.h:370