Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC2028A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2028A Demonstration Board
3 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/LTC2977
14 
15 http://www.linear.com/demo/DC2028A
16 
17 
18 Copyright 2018(c) Analog Devices, Inc.
19 
20 All rights reserved.
21 
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions are met:
24  - Redistributions of source code must retain the above copyright
25  notice, this list of conditions and the following disclaimer.
26  - Redistributions in binary form must reproduce the above copyright
27  notice, this list of conditions and the following disclaimer in
28  the documentation and/or other materials provided with the
29  distribution.
30  - Neither the name of Analog Devices, Inc. nor the names of its
31  contributors may be used to endorse or promote products derived
32  from this software without specific prior written permission.
33  - The use of this software may or may not infringe the patent rights
34  of one or more patent holders. This license does not release you
35  from the requirement that you obtain separate licenses from these
36  patent holders to use this software.
37  - Use of the software either in source or binary form, must be run
38  on or directly connected to an Analog Devices Inc. component.
39 
40 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
41 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
42 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
44 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
46 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 */
51 
52 /*! @file
53  @ingroup LTC2977
54 */
55 
56 #include <Arduino.h>
57 #include <stdint.h>
58 #include <Linduino.h>
59 #include <UserInterface.h>
60 #include <LT_Wire.h>
61 #include <LT_PMBus.h>
62 #include <LT_SMBusPec.h>
63 #include <LT_PMBusMath.h>
64 #include <LT_SMBus.h>
65 #include <LT_I2CBus.h>
66 #include <LT_SMBusGroup.h>
67 #include <LT_FaultLog.h>
68 #include <LT_SMBusNoPec.h>
69 #include <LT_SMBusBase.h>
70 
71 #define LTC2977_I2C_ADDRESS 0x33
72 
73 // Global variables
74 static uint8_t ltc2977_i2c_address;
75 static LT_SMBus *smbus = new LT_SMBusNoPec();
76 static LT_PMBus *pmbus = new LT_PMBus(smbus);
77 
78 //! Initialize Linduino
79 void setup()
80 {
81  Serial.begin(115200); //! Initialize the serial port to the PC
82  print_title();
84  print_prompt();
85 }
86 
87 //! Repeats Linduino loop
88 //! @return void
89 void loop()
90 {
91  uint8_t user_command;
92  uint8_t res;
93  uint8_t model[7];
94  uint8_t revision[10];
95  uint8_t *addresses = NULL;
96 
97  if (Serial.available()) //! Checks for user input
98  {
99  user_command = read_int(); //! Reads the user command
100  if (user_command != 'm')
101  Serial.println(user_command);
102 
103  switch (user_command) //! Prints the appropriate submenu
104  {
105  case 1:
106  menu_1_basic_commands(); // Print single-ended voltage menu
107  break;
108  case 2:
110  delete smbus;
111  delete pmbus;
112  smbus = new LT_SMBusPec();
113  pmbus = new LT_PMBus(smbus);
114  break;
115  case 3:
117  delete smbus;
118  delete pmbus;
119  smbus = new LT_SMBusNoPec();
120  pmbus = new LT_PMBus(smbus);
121  break;
122  case 4:
123  addresses = smbus->probe(0);
124  while (*addresses != 0)
125  {
126  Serial.print(F("ADDR 0x"));
127  Serial.println(*addresses++, HEX);
128  }
129  break;
130  case 5 :
131  pmbus->startGroupProtocol();
133  pmbus->executeGroupProtocol();
134  default:
135  Serial.println(F("Incorrect Option"));
136  break;
137  }
138  print_prompt();
139  }
140 
141 }
142 
143 // Function Definitions
144 
145 //! Prints the title block when program first starts.
147 {
148  Serial.print(F("\n*****************************************************************\n"));
149  Serial.print(F("* DC2028A Hello World Demonstration Program *\n"));
150  Serial.print(F("* *\n"));
151  Serial.print(F("* This program demonstrates how to send and receive data from *\n"));
152  Serial.print(F("* the LTC2028A demo board. *\n"));
153  Serial.print(F("* *\n"));
154  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
155  Serial.print(F("* *\n"));
156  Serial.print(F("*****************************************************************\n"));
157 }
158 
159 //! Prints main menu.
161 {
162  Serial.print(F("\n 1-Basic Commands\n"));
163  Serial.print(F(" 2-PEC On\n"));
164  Serial.print(F(" 3-PEC Off\n"));
165  Serial.print(F(" 4-Bus Probe\n"));
166  Serial.print(F(" 5-Reset\n"));
167  Serial.print(F("\nEnter a command:"));
168 }
169 
170 //! Prints a warning if the demo board is not detected.
172 {
173  Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
174 }
175 
177 {
178  float voltage;
179  uint8_t page;
180 
181  for (page = 0; page < 8; page++)
182  {
183  pmbus->setPage(ltc2977_i2c_address, page);
184  voltage = pmbus->readVout(ltc2977_i2c_address, false);
185  Serial.print(F("LTC2977 VOUT "));
186  Serial.println(voltage, DEC);
187  }
188 
189 }
190 
191 
193 {
194  uint8_t b;
195  uint16_t w;
196  uint8_t page;
197 
198 
199  for (page = 0; page < 8; page++)
200  {
201  Serial.print(F("PAGE "));
202  Serial.println(page, DEC);
203  pmbus->setPage(ltc2977_i2c_address, page);
205  Serial.print(F("LTC2977 STATUS BYTE 0x"));
206  Serial.println(b, DEC);
208  Serial.print(F("LTC2977 STATUS WORD 0x"));
209  Serial.println(w, HEX);
210  }
211 }
212 
214 {
215  pmbus->sequenceOffGlobal();
216  delay (2000);
217  pmbus->sequenceOnGlobal();
218 }
219 
221 {
222  pmbus->marginHighGlobal();
223 }
224 
226 {
227  pmbus->marginLowGlobal();
228 }
229 
231 {
232  pmbus->sequenceOnGlobal();
233 }
234 
236 {
237  uint8_t user_command;
238 
239  do
240  {
241  //! Displays the Read/Write menu
242  Serial.print(F(" 1-Read All Voltages\n"));
243  Serial.print(F(" 2-Read All Status\n"));
244  Serial.print(F(" 3-Sequence Off/On\n"));
245  Serial.print(F(" 4-Margin High\n"));
246  Serial.print(F(" 5-Margin Low\n"));
247  Serial.print(F(" 6-Margin Off\n"));
248  Serial.print(F(" m-Main Menu\n"));
249  Serial.print(F("\nEnter a command: "));
250 
251  user_command = read_int(); //! Reads the user command
252  if (user_command == 'm') // Print m if it is entered
253  {
254  Serial.print(F("m\n"));
255  }
256  else
257  Serial.println(user_command); // Print user command
258 
259  switch (user_command)
260  {
261  case 1:
263  break;
264  case 2:
266  break;
267  case 3:
268  sequence_off_on();
269  break;
270  case 4:
271  margin_high();
272  break;
273  case 5:
274  margin_low();
275  break;
276  case 6:
277  margin_off();
278  break;
279  default:
280  if (user_command != 'm')
281  Serial.println(F("Invalid Selection"));
282  break;
283  }
284  }
285  while (user_command != 'm');
286 }
287 
288 
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: DC2028A.ino:171
static void setup()
Initialize Linduino.
Definition: DC2028A.ino:79
unsigned char user_command
LTC SMBus Support: API for a shared SMBus layer.
#define LTC2977_I2C_ADDRESS
Definition: DC2028A.ino:71
LTC SMBus Support: Implementation for a shared SMBus layer.
static void print_all_status()
Definition: DC2028A.ino:192
LTC SMBus Support: Implementation for a shared SMBus layer.
uint8_t readStatusByte(uint8_t address)
Get the status byte.
Definition: LT_PMBus.cpp:2423
Header File for Linduino Libraries and Demo Code.
static void margin_high()
Definition: DC2028A.ino:220
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
static void print_all_voltages()
Definition: DC2028A.ino:176
static LT_SMBus * smbus
Definition: DC2028A.ino:75
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
float readVout(uint8_t address, bool polling)
Get the measured output voltage.
Definition: LT_PMBus.cpp:1598
LT_I2CBus: Routines to communicate to I2C by Wire Library.
static void menu_1_basic_commands()
Definition: DC2028A.ino:235
LTC PMBus Support: Implementation for a LTC Fault Log.
static void sequence_off_on()
Definition: DC2028A.ino:213
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
void marginLowGlobal(void)
Margin all rails low.
Definition: LT_PMBus.cpp:3078
static void loop()
Repeats Linduino loop.
Definition: DC2028A.ino:89
void sequenceOnGlobal(void)
Sequence on all rails.
Definition: LT_PMBus.cpp:2896
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
static uint8_t ltc2977_i2c_address
Definition: DC2028A.ino:74
LTC SMBus Support: Implementation for a shared SMBus layer.
int32_t read_int()
void sequenceOffGlobal(void)
Sequence off all rails.
Definition: LT_PMBus.cpp:2876
static void print_title()
Prints the title block when program first starts.
Definition: DC2028A.ino:146
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.
static float voltage
Definition: DC2289AA.ino:71
void marginHighGlobal(void)
Margin all rails high.
Definition: LT_PMBus.cpp:3068
LTC PMBus Support: Math conversion routines.
static void margin_off()
Definition: DC2028A.ino:230
static void margin_low()
Definition: DC2028A.ino:225
static LT_PMBus * pmbus
Definition: DC2028A.ino:76
LTC SMBus Support: Implementation for a shared SMBus layer.
static void print_prompt()
Prints main menu.
Definition: DC2028A.ino:160
PMBus communication.
Definition: LT_PMBus.h:370