| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

DC2198A.ino
Go to the documentation of this file.
1 /*!
2 Linear Technology DC2198A Demonstration Board
3 LTC2980: 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/LTC2980
14
15 http://www.linear.com/demo/DC2198A
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 LTC2980
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 LTC2980_I2C_ADDRESS_A 0x30
72 #define LTC2980_I2C_ADDRESS_B 0x32
73
74
75 // Global variables
76 static uint8_t ltc2980_i2c_address_a;
77 static uint8_t ltc2980_i2c_address_b;
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();
87 ltc2980_i2c_address_a = LTC2980_I2C_ADDRESS_A;
88 ltc2980_i2c_address_b = LTC2980_I2C_ADDRESS_B;
89 print_prompt();
90 }
91
92 //! Repeats Linduino loop
93 //! @return void
94 void loop()
95 {
96 uint8_t user_command;
97 uint8_t res;
98 uint8_t model[7];
99 uint8_t revision[10];
100 uint8_t *addresses = NULL;
101
102 if (Serial.available()) //! Checks for user input
103 {
104 user_command = read_int(); //! Reads the user command
105 if (user_command != 'm')
106 Serial.println(user_command);
107
108 switch (user_command) //! Prints the appropriate submenu
109 {
110 case 1:
111 menu_1_basic_commands(); // Print single-ended voltage menu
112 break;
113 case 2:
114 pmbus->enablePec(ltc2980_i2c_address_a);
115 pmbus->enablePec(ltc2980_i2c_address_b);
116 delete smbus;
117 delete pmbus;
118 smbus = new LT_SMBusPec();
119 pmbus = new LT_PMBus(smbus);
120 break;
121 case 3:
122 pmbus->disablePec(ltc2980_i2c_address_a);
123 pmbus->disablePec(ltc2980_i2c_address_b);
124 delete smbus;
125 delete pmbus;
126 smbus = new LT_SMBusNoPec();
127 pmbus = new LT_PMBus(smbus);
128 break;
129 case 4:
130 addresses = smbus->probe(0);
131 while (*addresses != 0)
132 {
133 Serial.print(F("ADDR 0x"));
134 Serial.println(*addresses++, HEX);
135 }
136 break;
137 case 5 :
138 pmbus->startGroupProtocol();
139 pmbus->restoreFromNvm(ltc2980_i2c_address_a);
140 pmbus->restoreFromNvm(ltc2980_i2c_address_b);
141 pmbus->executeGroupProtocol();
142 default:
143 Serial.println(F("Incorrect Option"));
144 break;
145 }
146 print_prompt();
147 }
148
149 }
150
151 // Function Definitions
152
153 //! Prints the title block when program first starts.
154 //! @return void
155 void print_title()
156 {
157 Serial.print(F("\n*****************************************************************\n"));
158 Serial.print(F("* DC2198A Hello World Demonstration Program *\n"));
159 Serial.print(F("* *\n"));
160 Serial.print(F("* This program demonstrates how to send and receive data from *\n"));
161 Serial.print(F("* the LTC2198A demo board. *\n"));
162 Serial.print(F("* *\n"));
163 Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
164 Serial.print(F("* *\n"));
165 Serial.print(F("*****************************************************************\n"));
166 }
167
168 //! Prints main menu.
169 //! @return void
170 void print_prompt()
171 {
172 Serial.print(F("\n 1-Basic Commands\n"));
173 Serial.print(F(" 2-PEC On\n"));
174 Serial.print(F(" 3-PEC Off\n"));
175 Serial.print(F(" 4-Bus Probe\n"));
176 Serial.print(F(" 5-Reset\n"));
177 Serial.print(F("\nEnter a command:"));
178 }
179
180 //! Prints a warning if the demo board is not detected.
181 //! @return void
182 void print_warning_prompt()
183 {
184 Serial.println(F("\nWarning: Demo board not detected. Linduino will attempt to proceed."));
185 }
186
187 // Prints all voltages
188 //! @return void
189 void print_all_voltages()
190 {
191 float voltage;
192 uint8_t page;
193
194 for (page = 0; page < 8; page++)
195 {
196 pmbus->setPage(ltc2980_i2c_address_a, page);
197 voltage = pmbus->readVout(ltc2980_i2c_address_a, false);
198 Serial.print(F("LTC2980_A VOUT "));
199 Serial.println(voltage, DEC);
200 }
201
202 for (page = 0; page < 8; page++)
203 {
204 pmbus->setPage(ltc2980_i2c_address_b, page);
205 voltage = pmbus->readVout(ltc2980_i2c_address_b, false);
206 Serial.print(F("LTC2980_B VOUT "));
207 Serial.println(voltage, DEC);
208 }
209
210
211 }
212
213 //! Prints all status bytes and words.
214 //! @return void
215 void print_all_status()
216 {
217 uint8_t b;
218 uint16_t w;
219 uint8_t page;
220
221
222 for (page = 0; page < 8; page++)
223 {
224 Serial.print(F("PAGE "));
225 Serial.println(page, DEC);
226 pmbus->setPage(ltc2980_i2c_address_a, page);
227 b = pmbus->readStatusByte(ltc2980_i2c_address_a);
228 Serial.print(F("LTC2980_A STATUS BYTE 0x"));
229 Serial.println(b, DEC);
230 w = pmbus->readStatusWord(ltc2980_i2c_address_a);
231 Serial.print(F("LTC2980_A STATUS WORD 0x"));
232 Serial.println(w, HEX);
233 }
234
235 for (page = 0; page < 8; page++)
236 {
237 Serial.print(F("PAGE "));
238 Serial.println(page, DEC);
239 pmbus->setPage(ltc2980_i2c_address_b, page);
240 b = pmbus->readStatusByte(ltc2980_i2c_address_b);
241 Serial.print(F("LTC2980_B STATUS BYTE 0x"));
242 Serial.println(b, DEC);
243 w = pmbus->readStatusWord(ltc2980_i2c_address_b);
244 Serial.print(F("LTC2980_B STATUS WORD 0x"));
245 Serial.println(w, HEX);
246 }
247
248 }
249
250 //! Sequence off then on
251 //! @return void
252 void sequence_off_on()
253 {
254 pmbus->sequenceOffGlobal();
255 delay (2000);
256 pmbus->sequenceOnGlobal();
257 }
258
259 //! Margin high
260 //! @return void
261 void margin_high()
262 {
263 pmbus->marginHighGlobal();
264 }
265
266 //! Margin low
267 //! @return void
268 void margin_low()
269 {
270 pmbus->marginLowGlobal();
271 }
272
273 //! Go to nominal
274 //! @return void
275 void margin_off()
276 {
277 pmbus->sequenceOnGlobal();
278 }
279
280 //! Display menu 1
281 //! @return void
282 void menu_1_basic_commands()
283 {
284 uint8_t user_command;
285
286 do
287 {
288 //! Displays the Read/Write menu
289 Serial.print(F(" 1-Read All Voltages\n"));
290 Serial.print(F(" 2-Read All Status\n"));
291 Serial.print(F(" 3-Sequence Off/On\n"));
292 Serial.print(F(" 4-Margin High\n"));
293 Serial.print(F(" 5-Margin Low\n"));
294 Serial.print(F(" 6-Margin Off\n"));
295 Serial.print(F(" m-Main Menu\n"));
296 Serial.print(F("\nEnter a command: "));
297
298 user_command = read_int(); //! Reads the user command
299 if (user_command == 'm') // Print m if it is entered
300 {
301 Serial.print(F("m\n"));
302 }
303 else
304 Serial.println(user_command); // Print user command
305
306 switch (user_command)
307 {
308 case 1:
309 print_all_voltages();
310 break;
311 case 2:
312 print_all_status();
313 break;
314 case 3:
315 sequence_off_on();
316 break;
317 case 4:
318 margin_high();
319 break;
320 case 5:
321 margin_low();
322 break;
323 case 6:
324 margin_off();
325 break;
326 default:
327 if (user_command != 'm')
328 Serial.println(F("Invalid Selection"));
329 break;
330 }
331 }
332 while (user_command != 'm');
333 }
334
335
margin_off
static void margin_off()
Go to nominal.
Definition: DC2198A.ino:275
user_command
unsigned char user_command
Definition: Serial_EEPROM_Test.ino:75
LT_SMBus.h
LTC SMBus Support: API for a shared SMBus layer.
menu_1_basic_commands
static void menu_1_basic_commands()
Display menu 1.
Definition: DC2198A.ino:282
LT_SMBusGroup.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LT_SMBusPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LT_PMBus::readStatusByte
uint8_t readStatusByte(uint8_t address)
Get the status byte.
Definition: LT_PMBus.cpp:2423
print_all_status
static void print_all_status()
Prints all status bytes and words.
Definition: DC2198A.ino:215
Linduino.h
Header File for Linduino Libraries and Demo Code.
LT_PMBus::enablePec
void enablePec(uint8_t address)
Enable pec for all transactions.
Definition: LT_PMBus.cpp:3173
LT_SMBusNoPec
Definition: LT_SMBusNoPec.h:60
ltc2980_i2c_address_a
static uint8_t ltc2980_i2c_address_a
Definition: DC2198A.ino:76
LT_PMBus::readStatusWord
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
pmbus
static LT_PMBus * pmbus
Definition: DC2198A.ino:79
LT_PMBus::disablePec
void disablePec(uint8_t address)
Disable pec for all transactions.
Definition: LT_PMBus.cpp:3210
print_all_voltages
static void print_all_voltages()
Definition: DC2198A.ino:189
print_warning_prompt
static void print_warning_prompt()
Prints a warning if the demo board is not detected.
Definition: DC2198A.ino:182
LTC2980_I2C_ADDRESS_B
#define LTC2980_I2C_ADDRESS_B
Definition: DC2198A.ino:72
print_prompt
static void print_prompt()
Prints main menu.
Definition: DC2198A.ino:170
LT_SMBusPec
Definition: LT_SMBusPec.h:61
LT_Wire.h
TwoWire.h - TWI/I2C library for Arduino & Wiring Copyright (c) 2006 Nicholas Zambetti.
margin_high
static void margin_high()
Margin high.
Definition: DC2198A.ino:261
print_title
static void print_title()
Prints the title block when program first starts.
Definition: DC2198A.ino:155
LT_SMBus
Definition: LT_SMBus.h:61
LT_PMBus::startGroupProtocol
void startGroupProtocol(void)
starts group protocol
Definition: LT_PMBus.cpp:3350
LT_PMBus::readVout
float readVout(uint8_t address, bool polling)
Get the measured output voltage.
Definition: LT_PMBus.cpp:1598
margin_low
static void margin_low()
Margin low.
Definition: DC2198A.ino:268
LT_I2CBus.h
LT_I2CBus: Routines to communicate to I2C by Wire Library.
LT_FaultLog.h
LTC PMBus Support: Implementation for a LTC Fault Log.
LTC2980_I2C_ADDRESS_A
#define LTC2980_I2C_ADDRESS_A
Definition: DC2198A.ino:71
LT_PMBus::setPage
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
LT_PMBus::marginLowGlobal
void marginLowGlobal(void)
Margin all rails low.
Definition: LT_PMBus.cpp:3078
ltc2980_i2c_address_b
static uint8_t ltc2980_i2c_address_b
Definition: DC2198A.ino:77
LT_PMBus::sequenceOnGlobal
void sequenceOnGlobal(void)
Sequence on all rails.
Definition: LT_PMBus.cpp:2896
LT_SMBus::probe
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
smbus
static LT_SMBus * smbus
Definition: DC2198A.ino:78
LT_SMBusNoPec.h
LTC SMBus Support: Implementation for a shared SMBus layer.
UserInterface.h
read_int
int32_t read_int()
Definition: UserInterface.cpp:93
LT_PMBus::sequenceOffGlobal
void sequenceOffGlobal(void)
Sequence off all rails.
Definition: LT_PMBus.cpp:2876
LT_PMBus::executeGroupProtocol
void executeGroupProtocol(void)
ends group protocol
Definition: LT_PMBus.cpp:3356
LT_PMBus::restoreFromNvm
void restoreFromNvm(uint8_t address)
Restore device from NVM.
Definition: LT_PMBus.cpp:2663
LT_PMBus.h
LTC PMBus Support.
voltage
static float voltage
Definition: DC2289AA.ino:71
LT_PMBus::marginHighGlobal
void marginHighGlobal(void)
Margin all rails high.
Definition: LT_PMBus.cpp:3068
sequence_off_on
static void sequence_off_on()
Sequence off then on.
Definition: DC2198A.ino:252
setup
static void setup()
Initialize Linduino.
Definition: DC2198A.ino:83
LT_PMBusMath.h
LTC PMBus Support: Math conversion routines.
loop
static void loop()
Repeats Linduino loop.
Definition: DC2198A.ino:94
LT_SMBusBase.h
LTC SMBus Support: Implementation for a shared SMBus layer.
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370