Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC2022A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2022A Demonstration Board
3 LTC2975: Power System 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/LTC2975
14 
15 http://www.linear.com/demo/DC2022A
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 LTC2975
54 */
55 
56 #include <Arduino.h>
57 #include <stdint.h>
58 #include "Linduino.h"
59 #include "UserInterface.h"
60 #include "LT_I2CBus.h"
61 #include "LT_SMBusNoPec.h"
62 #include "LT_SMBusPec.h"
63 #include "LT_PMBusMath.h"
64 #include "LT_PMBus.h"
65 
66 #define LTC2975_I2C_ADDRESS 0x30
67 
68 // Global variables
69 static uint8_t ltc2975_i2c_address;
70 static LT_PMBusMath *math = new LT_PMBusMath();
71 static LT_SMBus *smbus = new LT_SMBusPec();
72 static LT_PMBus *pmbus = new LT_PMBus(smbus);
73 
74 //! Initialize Linduino
75 //! @return void
76 void setup()
77 {
78  Serial.begin(115200); //! Initialize the serial port to the PC
79  print_title();
81  print_prompt();
82 }
83 
84 //! Repeats Linduino loop
85 //! @return void
86 void loop()
87 {
88  uint8_t user_command;
89  uint8_t res;
90  uint8_t model[7];
91  uint8_t revision[10];
92  uint8_t *addresses = NULL;
93 
94  if (Serial.available()) //! Checks for user input
95  {
96  user_command = read_int(); //! Reads the user command
97  if (user_command != 'm')
98  Serial.println(user_command);
99 
100  switch (user_command) //! Prints the appropriate submenu
101  {
102  case 1:
103  menu_1_basic_commands(); // Print single-ended voltage menu
104  break;
105  case 2:
107  delete smbus;
108  delete pmbus;
109  smbus = new LT_SMBusPec();
110  pmbus = new LT_PMBus(smbus);
111  break;
112  case 3:
114  delete smbus;
115  delete pmbus;
116  smbus = new LT_SMBusNoPec();
117  pmbus = new LT_PMBus(smbus);
118  break;
119  case 4:
120  addresses = smbus->probe(0);
121  while (*addresses != 0)
122  {
123  Serial.print(F("ADDR 0x"));
124  Serial.println(*addresses++, HEX);
125  }
126  break;
127  case 5 :
128  pmbus->startGroupProtocol();
130  pmbus->executeGroupProtocol();
131  break;
132  default:
133  Serial.println(F("Incorrect Option"));
134  break;
135  }
136  print_prompt();
137  }
138 
139 }
140 
141 // Function Definitions
142 
143 //! Prints the title block when program first starts.
144 //! @return void
146 {
147  Serial.print(F("\n*****************************************************************\n"));
148  Serial.print(F("* DC2022AC Hello World Demonstration Program *\n"));
149  Serial.print(F("* *\n"));
150  Serial.print(F("* This program demonstrates how to send and receive data from *\n"));
151  Serial.print(F("* the LTC2022A demo board. *\n"));
152  Serial.print(F("* *\n"));
153  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
154  Serial.print(F("* *\n"));
155  Serial.print(F("*****************************************************************\n"));
156 }
157 
158 //! Prints main menu.
159 //! @return void
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.
171 //! @return void
173 {
174  Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
175 }
176 
177 //! Print all voltages
179 {
180  float voltage;
181  uint8_t page;
182 
183  for (page = 0; page < 4; page++)
184  {
185  pmbus->setPage(ltc2975_i2c_address, page);
186  voltage = pmbus->readVout(ltc2975_i2c_address, false);
187  Serial.print(F("LTC2975 VOUT "));
188  Serial.println(voltage, DEC);
189  }
190 }
191 
192 //! Print all currents
194 {
195  float current;
196  uint8_t page;
197 
198  for (page = 0; page < 4; page++)
199  {
200  pmbus->setPage(ltc2975_i2c_address, page);
201  current = pmbus->readIout(ltc2975_i2c_address, false);
202  Serial.print(F("LTC2975 IOUT "));
203  Serial.println(current, DEC);
204  }
205 }
206 
207 //! Print all status bytes and words
208 //! @return void
210 {
211  uint8_t b;
212  uint16_t w;
213  uint8_t page;
214 
215  for (page = 0; page < 4; page++)
216  {
217  Serial.print(F("PAGE "));
218  Serial.println(page, DEC);
219  pmbus->setPage(ltc2975_i2c_address, page);
221  Serial.print(F("LTC2975 STATUS BYTE 0x"));
222  Serial.println(b, HEX);
224  Serial.print(F("LTC2975 STATUS WORD 0x"));
225  Serial.println(w, HEX);
226  }
227 }
228 
229 //! Sequence off then on
231 {
232  pmbus->sequenceOffGlobal();
233  delay (2000);
234  pmbus->sequenceOnGlobal();
235 }
236 
237 //! Margin high
238 //! @return void
240 {
241  pmbus->marginHighGlobal();
242 }
243 
244 //! Margin low
245 //! @return void
247 {
248  pmbus->marginLowGlobal();
249 }
250 
251 //! Go to nominal
252 //! @return void
254 {
255  pmbus->sequenceOnGlobal();
256 }
257 
258 //! Display menu 1
259 //! @return void
261 {
262  uint8_t user_command;
263 
264  do
265  {
266  //! Displays the Read/Write menu
267  Serial.print(F(" 1-Read All Voltages\n"));
268  Serial.print(F(" 2-Read All Currents\n"));
269  Serial.print(F(" 3-Read All Status\n"));
270  Serial.print(F(" 4-Sequence Off/On\n"));
271  Serial.print(F(" 5-Margin High\n"));
272  Serial.print(F(" 6-Margin Low\n"));
273  Serial.print(F(" 7-Margin Off\n"));
274  Serial.print(F(" m-Main Menu\n"));
275  Serial.print(F("\nEnter a command: "));
276 
277  user_command = read_int(); //! Reads the user command
278  if (user_command == 'm') // Print m if it is entered
279  {
280  Serial.print(F("m\n"));
281  }
282  else
283  Serial.println(user_command); // Print user command
284 
285  switch (user_command)
286  {
287  case 1:
289  break;
290  case 2:
292  break;
293  case 3:
295  break;
296  case 4:
297  sequence_off_on();
298  break;
299  case 5:
300  margin_high();
301  break;
302  case 6:
303  margin_low();
304  break;
305  case 7:
306  margin_off();
307  break;
308  default:
309  if (user_command != 'm')
310  Serial.println(F("Invalid Selection"));
311  break;
312  }
313  }
314  while (user_command != 'm');
315 }
316 
317 
318 
319 
static void margin_low()
Margin low.
Definition: DC2022A.ino:246
unsigned char user_command
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.
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
static void print_all_currents()
Print all currents.
Definition: DC2022A.ino:193
static LT_SMBus * smbus
Definition: DC2022A.ino:71
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
float readIout(uint8_t address, bool polling)
Get the measured output current.
Definition: LT_PMBus.cpp:1898
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
static void margin_high()
Margin high.
Definition: DC2022A.ino:239
static void print_title()
Prints the title block when program first starts.
Definition: DC2022A.ino:145
static void print_all_voltages()
Print all voltages.
Definition: DC2022A.ino:178
static uint8_t ltc2975_i2c_address
Definition: DC2022A.ino:69
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
static LT_PMBusMath * math
Definition: DC2022A.ino:70
static void margin_off()
Go to nominal.
Definition: DC2022A.ino:253
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 LT_PMBus * pmbus
Definition: DC2022A.ino:72
static void loop()
Repeats Linduino loop.
Definition: DC2022A.ino:86
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
static void setup()
Initialize Linduino.
Definition: DC2022A.ino:76
static void menu_1_basic_commands()
Display menu 1.
Definition: DC2022A.ino:260
void marginLowGlobal(void)
Margin all rails low.
Definition: LT_PMBus.cpp:3078
static void sequence_off_on()
Sequence off then on.
Definition: DC2022A.ino:230
void sequenceOnGlobal(void)
Sequence on all rails.
Definition: LT_PMBus.cpp:2896
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
static void print_all_status()
Print all status bytes and words.
Definition: DC2022A.ino:209
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
#define LTC2975_I2C_ADDRESS
Definition: DC2022A.ino:66
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
static uint16_t current
the current measurement from the LTC3335&#39;s counter test mode.
Definition: DC2343A.ino:114
void marginHighGlobal(void)
Margin all rails high.
Definition: LT_PMBus.cpp:3068
LTC PMBus Support: Math conversion routines.
static void print_prompt()
Prints main menu.
Definition: DC2022A.ino:160
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: DC2022A.ino:172
PMBus communication.
Definition: LT_PMBus.h:370