Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
ultra_fix.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 
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/LTC3880
14 
15 http://www.linear.com/product/LTC2974
16 
17 http://www.linear.com/product/LTC2977
18 
19 http://www.linear.com/demo/DC1962C
20 
21 
22 Copyright 2018(c) Analog Devices, Inc.
23 
24 All rights reserved.
25 
26 Redistribution and use in source and binary forms, with or without
27 modification, are permitted provided that the following conditions are met:
28  - Redistributions of source code must retain the above copyright
29  notice, this list of conditions and the following disclaimer.
30  - Redistributions in binary form must reproduce the above copyright
31  notice, this list of conditions and the following disclaimer in
32  the documentation and/or other materials provided with the
33  distribution.
34  - Neither the name of Analog Devices, Inc. nor the names of its
35  contributors may be used to endorse or promote products derived
36  from this software without specific prior written permission.
37  - The use of this software may or may not infringe the patent rights
38  of one or more patent holders. This license does not release you
39  from the requirement that you obtain separate licenses from these
40  patent holders to use this software.
41  - Use of the software either in source or binary form, must be run
42  on or directly connected to an Analog Devices Inc. component.
43 
44 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
45 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
46 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
48 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
50 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
52 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
55 
56 /*! @file
57  @ingroup DC1962
58 */
59 
60 #include <Arduino.h>
61 #include <stdint.h>
62 #include "Linduino.h"
63 #include "UserInterface.h"
64 #include "LT_I2CBus.h"
65 #include "LT_SMBusNoPec.h"
66 #include "LT_SMBusPec.h"
67 #include "LT_PMBus.h"
68 
69 #define LTC3880_I2C_ADDRESS 0x30
70 #define LTC2974_I2C_ADDRESS 0x32
71 #define LTC2977_I2C_ADDRESS 0x33
72 
73 // Global variables
74 static uint8_t ltc3880_i2c_address;
75 static uint8_t ltc2974_i2c_address;
76 static uint8_t ltc2977_i2c_address;
77 static uint8_t ltc_i2c_addresses[3];
78 static LT_SMBus *smbus = new LT_SMBusNoPec();
79 static LT_PMBus *pmbus = new LT_PMBus(smbus);
80 
81 //! Initialize Linduino
82 //! @return void
83 void setup()
84 {
85  Serial.begin(115200); //! Initialize the serial port to the PC
86  print_title();
93  print_prompt();
94 }
95 
96 //! Initialize Linduino
97 //! @return void
98 void loop()
99 {
100  uint8_t user_command;
101  uint8_t res;
102  uint8_t model[7];
103  uint8_t *addresses = NULL;
104 
105  if (Serial.available()) //! Checks for user input
106  {
107  user_command = read_int(); //! Reads the user command
108  if (user_command != 'm')
109  Serial.println(user_command);
110 
111  switch (user_command) //! Prints the appropriate submenu
112  {
113  case 1:
114 
115  smbus->writeByte(ltc3880_i2c_address, 0xBD, 0x2B); // Unlock byte 1
116  smbus->writeByte(ltc3880_i2c_address, 0xBD, 0xD4); // Unlock byte 2
117  smbus->writeByte(ltc3880_i2c_address,0xBE, 0x2B); // Erase EEPROM
118 
119  smbus->writeByte(ltc2974_i2c_address, 0xBD, 0x2B); // Unlock byte 1
120  res = 0;
121  while (res == 0)
122  res = smbus->readByte(ltc2974_i2c_address, 0xEF) & 0x40;
123  smbus->writeByte(ltc2974_i2c_address, 0xBD, 0xD4); // Unlock byte 2
124  res = 0;
125  while (res == 0)
126  res = smbus->readByte(ltc2974_i2c_address, 0xEF) & 0x40;
127  smbus->writeByte(ltc2974_i2c_address,0xBE, 0x2B); // Erase EEPROM
128  res = 0;
129  while (res == 0)
130  res = smbus->readByte(ltc2974_i2c_address, 0xEF) & 0x40;
131 
132  smbus->writeByte(ltc2977_i2c_address, 0xBD, 0x2B); // Unlock byte 1
133  res = 0;
134  while (res == 0)
135  res = smbus->readByte(ltc2977_i2c_address, 0xEF) & 0x40;
136  smbus->writeByte(ltc2977_i2c_address, 0xBD, 0xD4); // Unlock byte 2
137  res = 0;
138  while (res == 0)
139  res = smbus->readByte(ltc2977_i2c_address, 0xEF) & 0x40;
140  smbus->writeByte(ltc2977_i2c_address,0xBE, 0x2B); // Erase EEPROM
141  while (res == 0)
142  res = smbus->readByte(ltc2977_i2c_address, 0xEF) & 0x40;
143 
144  break;
145  case 2:
146  smbus->writeWord(0x5B, 0x10, 0xC000); // Disable Write Protect
147  smbus->writeWord(0x5B, 0xD1, 0xC049); // Set MFR_CONFIG_ALL
148  smbus->writeByte(0x5B, 0xE6, 0x30); // Set base address
149  break;
150  case 3:
151  addresses = pmbus->bricks(ltc_i2c_addresses, 3);
152  break;
153  case 4:
154  smbus->sendByte(0x5B, 0x15); // Store user all
155  break;
156  case 5:
160  delete smbus;
161  delete pmbus;
162  smbus = new LT_SMBusPec();
163  pmbus = new LT_PMBus(smbus);
164  break;
165  case 6:
169  delete smbus;
170  delete pmbus;
171  smbus = new LT_SMBusNoPec();
172  pmbus = new LT_PMBus(smbus);
173  break;
174  case 7:
175  addresses = smbus->probe(0);
176  while (*addresses != 0)
177  {
178  Serial.print(F("ADDR 0x"));
179  Serial.println(*addresses++, HEX);
180  }
181  break;
182  case 8 :
183  pmbus->startGroupProtocol();
184  pmbus->reset(ltc3880_i2c_address);
187  pmbus->executeGroupProtocol();
188  break;
189  default:
190  Serial.println(F("Incorrect Option"));
191  break;
192  }
193  print_prompt();
194  }
195 
196 }
197 
198 // Function Definitions
199 
200 //! Prints the title block when program first starts.
201 //! @return void
203 {
204  Serial.print(F("\n*****************************************************************\n"));
205  Serial.print(F("* DC1962C Ultra Fix Demonstration Program *\n"));
206  Serial.print(F("* *\n"));
207  Serial.print(F("* This program demonstrates how to brick and unbrick an LTC3880 *\n"));
208  Serial.print(F("* using the LTC1962C demo board. *\n"));
209  Serial.print(F("* *\n"));
210  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
211  Serial.print(F("* *\n"));
212  Serial.print(F("*****************************************************************\n"));
213 }
214 
215 //! Prints main menu.
216 //! @return void
218 {
219  Serial.print(F("\n 1-Brick\n"));
220  Serial.print(F(" 2-Unbrick\n"));
221  Serial.print(F(" 3-Detect Bricks\n"));
222  Serial.print(F(" 4-Store User All\n"));
223  Serial.print(F(" 5-PEC On\n"));
224  Serial.print(F(" 6-PEC Off\n"));
225  Serial.print(F(" 7-Bus Probe\n"));
226  Serial.print(F(" 8-Reset\n"));
227  Serial.print(F("\nEnter a command:"));
228 }
229 
230 //! Prints a warning if the demo board is not detected.
231 //! @return void
233 {
234  Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
235 }
236 
237 
unsigned char user_command
#define LTC3880_I2C_ADDRESS
Definition: ultra_fix.ino:69
static void setup()
Initialize Linduino.
Definition: ultra_fix.ino:83
LTC SMBus Support: Implementation for a shared SMBus layer.
void reset(uint8_t address)
Issue reset to one device.
Definition: LT_PMBus.cpp:2912
uint8_t * bricks(uint8_t *addresses, uint8_t no_addresses)
Find bricked devices.
Definition: LT_PMBus.cpp:3295
Header File for Linduino Libraries and Demo Code.
virtual void sendByte(uint8_t address, uint8_t command)=0
SMBus send byte command.
#define LTC2977_I2C_ADDRESS
Definition: ultra_fix.ino:71
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
static uint8_t ltc2977_i2c_address
Definition: ultra_fix.ino:76
#define LTC2974_I2C_ADDRESS
Definition: ultra_fix.ino:70
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
virtual void writeWord(uint8_t address, uint8_t command, uint16_t data)=0
SMBus write word command.
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: ultra_fix.ino:232
static LT_SMBus * smbus
Definition: ultra_fix.ino:78
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
LT_I2CBus: Routines to communicate to I2C by Wire Library.
virtual void writeByte(uint8_t address, uint8_t command, uint8_t data)=0
SMBus write byte command.
virtual uint8_t readByte(uint8_t address, uint8_t command)=0
SMBus read byte command.
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
LTC SMBus Support: Implementation for a shared SMBus layer.
static uint8_t ltc3880_i2c_address
Definition: ultra_fix.ino:74
static void print_prompt()
Prints main menu.
Definition: ultra_fix.ino:217
int32_t read_int()
void executeGroupProtocol(void)
ends group protocol
Definition: LT_PMBus.cpp:3356
static LT_PMBus * pmbus
Definition: ultra_fix.ino:79
void restoreFromNvm(uint8_t address)
Restore device from NVM.
Definition: LT_PMBus.cpp:2663
LTC PMBus Support.
static uint8_t ltc_i2c_addresses[3]
Definition: ultra_fix.ino:77
static void print_title()
Prints the title block when program first starts.
Definition: ultra_fix.ino:202
static void loop()
Initialize Linduino.
Definition: ultra_fix.ino:98
static uint8_t ltc2974_i2c_address
Definition: ultra_fix.ino:75
PMBus communication.
Definition: LT_PMBus.h:370