| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LT_PMBusDevice.cpp
Go to the documentation of this file.
1 /*!
2 LTC PSM Device
3
4 @verbatim
5
6 Representation of a device and its capabilities.
7
8 @endverbatim
9
10
11 Copyright 2018(c) Analog Devices, Inc.
12
13 All rights reserved.
14
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions are met:
17 - Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19 - Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in
21 the documentation and/or other materials provided with the
22 distribution.
23 - Neither the name of Analog Devices, Inc. nor the names of its
24 contributors may be used to endorse or promote products derived
25 from this software without specific prior written permission.
26 - The use of this software may or may not infringe the patent rights
27 of one or more patent holders. This license does not release you
28 from the requirement that you obtain separate licenses from these
29 patent holders to use this software.
30 - Use of the software either in source or binary form, must be run
31 on or directly connected to an Analog Devices Inc. component.
32
33 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
34 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
35 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
37 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
39 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
40 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44
45 //! @ingroup PMBus_SMBus
46 //! @{
47 //! @defgroup LT_PMBusDevice LT_PMBusDevice: Implementation of Device Detection and Capability
48 //! @}
49
50 /*! @file
51 @ingroup LT_PMBusDevice
52 Library Header File for LT_PMBusDevice
53 */
54
55 #include "LT_PMBusDevice.h"
56
57 void LT_PMBusDevice::probeSpeed()
58 {
59 if (address_ == 0)
60 maxSpeed_ = 0;
61 else
62 {
63 LT_PMBusSpeedTest *speedTest = new LT_PMBusSpeedTest(pmbus_);
64 maxSpeed_ = speedTest->test(address_, 10);
65 delete speedTest;
66 }
67 }
68
69
70 LT_PMBus *LT_PMBusDevice::pmbus()
71 {
72 return pmbus_;
73 }
74 LT_SMBus *LT_PMBusDevice::smbus()
75 {
76 return pmbus_->smbus();
77 }
78
79 //! Change the pmbus
80 void LT_PMBusDevice::changePMBus(LT_PMBus *pmbus)
81 {
82 pmbus_ = pmbus;
83 }
84
85 //! Get the address
86 //! @return address
87 uint8_t LT_PMBusDevice::getAddress (
88 )
89 {
90 return address_;
91 }
92
93 char *LT_PMBusDevice::getType(void)
94 {
95 pmbus_->readModel(address_, model_);
96 return (char *) model_;
97 }
98
99 void LT_PMBusDevice::setPage(uint8_t page)
100 {
101 pmbus_->setPage(address_, page);
102 }
103
104 uint32_t LT_PMBusDevice::getMaxSpeed(void)
105 {
106 return maxSpeed_;
107 }
108
109 void LT_PMBusDevice::setSpeed(uint32_t speed //!< Speed
110 )
111 {
112 uint8_t configAll;
113
114 if (speed > 100000)
115 {
116 configAll = pmbus_->smbus()->readByte(address_, 0xD1);
117 configAll |= 1 << 1;
118 pmbus_->smbus()->writeByte(address_, 0xD1, configAll);
119 }
120 else
121 {
122 configAll = pmbus_->smbus()->readByte(address_, 0xD1);
123 configAll &= ~(1 << 1);
124 pmbus_->smbus()->writeByte(address_, 0xD1, configAll);
125 }
126 pmbus_->smbus()->i2cbus()->changeSpeed(speed);
127 }
128
129 LT_PMBusRail **LT_PMBusDevice::getRails()
130 {
131 return NULL;
132 }
133
134 bool LT_PMBusDevice::hasFaultLog()
135 {
136 return false;
137 }
138
139 char *LT_PMBusDevice::getFaultLog()
140 {
141 return NULL;
142 }
143
144 void LT_PMBusDevice::setVout(float voltage)
145 {
146 if (hasCapability(HAS_VOUT))
147 pmbus_->setVout(address_, voltage);
148 }
149
150 float LT_PMBusDevice::readVin(bool polling)
151 {
152 if (hasCapability(HAS_VIN))
153 return pmbus_->readVin(address_, polling);
154 return 0.0;
155 }
156
157 float LT_PMBusDevice::readVout(bool polling)
158 {
159 if (hasCapability(HAS_VOUT))
160 return pmbus_->readVout(address_, polling);
161 return 0.0;
162 }
163
164 float LT_PMBusDevice::readIin(bool polling)
165 {
166 float current = 0.0;
167
168 if (hasCapability(HAS_IIN))
169 current = pmbus_->readIin(address_, polling);
170
171 return current;
172 }
173
174 float LT_PMBusDevice::readIout(bool polling)
175 {
176 float current = 0.0;
177
178 if (hasCapability(HAS_IOUT))
179 current = pmbus_->readIout(address_, polling);
180
181 return current;
182 }
183
184 float LT_PMBusDevice::readPin(bool polling)
185 {
186 float power = 0.0;
187
188 if (hasCapability(HAS_PIN))
189 power = pmbus_->readPin(address_, polling);
190
191 return power;
192 }
193
194 float LT_PMBusDevice::readPout(bool polling)
195 {
196 float power = 0.0;
197
198 if (hasCapability(HAS_POUT))
199 power = pmbus_->readPout(address_, polling);
200
201 return power;
202 }
203
204 float LT_PMBusDevice::readExternalTemperature(bool polling)
205 {
206 float temp = 0.0;
207
208 if (hasCapability(HAS_TEMP))
209 temp = pmbus_->readExternalTemperature(address_, polling);
210
211 return temp;
212 }
213
214 float LT_PMBusDevice::readInternalTemperature(bool polling)
215 {
216 float temp = 0.0;
217
218 if (hasCapability(HAS_TEMP))
219 temp = pmbus_->readInternalTemperature(address_, polling);
220
221 return temp;
222 }
223
224 float LT_PMBusDevice::readDutyCycle(bool polling)
225 {
226 float dc = 0.0;
227
228 if (hasCapability(HAS_DC))
229 dc = pmbus_->readDutyCycle(address_, polling);
230
231 return dc;
232 }
233
234 uint16_t LT_PMBusDevice::readStatusWord()
235 {
236 uint16_t sw = 0;
237
238 if (hasCapability(HAS_STATUS_WORD))
239 sw = pmbus_->readStatusWord(address_);
240
241 return sw;
242 }
243
244 uint16_t LT_PMBusDevice::readMfrSpecialId()
245 {
246 uint16_t id = 0;
247
248 id = pmbus_->readMfrSpecialId(address_);
249
250 return id;
251 }
252
253 void LT_PMBusDevice::clearFaults()
254 {
255 pmbus_->clearAllFaults(address_);
256 }
257
258 void LT_PMBusDevice::marginHigh()
259 {
260 pmbus_->marginHigh(address_);
261 }
262
263 void LT_PMBusDevice::marginLow()
264 {
265 pmbus_->marginLow(address_);
266 }
267
268 void LT_PMBusDevice::marginOff()
269 {
270 pmbus_->marginOff(address_);
271 }
id
static int id
Definition: rail_logger.ino:99
LT_PMBusDevice::getRails
virtual LT_PMBusRail ** getRails()=0
Return a list of rails if any page is part of a rail.
Definition: LT_PMBusDevice.cpp:129
LT_PMBusDevice::getMaxSpeed
uint32_t getMaxSpeed(void)
Get the maximum speed the device can communicate with.
Definition: LT_PMBusDevice.cpp:104
LT_PMBus::readPout
float readPout(uint8_t address, bool polling)
Get the measured output power.
Definition: LT_PMBus.cpp:1963
LT_PMBusDevice::readPout
float readPout(bool polling)
Definition: LT_PMBusDevice.cpp:194
HAS_VIN
#define HAS_VIN
Definition: LT_PMBusDevice.h:59
LT_PMBusDevice::maxSpeed_
uint32_t maxSpeed_
Definition: LT_PMBusDevice.h:80
LT_PMBusDevice::address_
uint8_t address_
Definition: LT_PMBusDevice.h:79
LT_PMBus::marginOff
void marginOff(uint8_t address)
Margin rails off.
Definition: LT_PMBus.cpp:3059
LT_PMBusDevice::getAddress
uint8_t getAddress()
Get the address.
Definition: LT_PMBusDevice.cpp:87
LT_PMBusDevice::setSpeed
virtual void setSpeed(uint32_t speed)
Set the speed. If > 100000, enable clock stretching.
Definition: LT_PMBusDevice.cpp:109
HAS_TEMP
#define HAS_TEMP
Definition: LT_PMBusDevice.h:64
LT_PMBusDevice::readVout
float readVout(bool polling)
Definition: LT_PMBusDevice.cpp:157
LT_PMBusDevice::readStatusWord
uint16_t readStatusWord()
Definition: LT_PMBusDevice.cpp:234
LT_PMBusSpeedTest
Definition: LT_PMBusSpeedTest.h:55
LT_PMBus::readStatusWord
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
LT_PMBusDevice::getFaultLog
virtual char * getFaultLog()
Get the fault log text (call must free)
Definition: LT_PMBusDevice.cpp:139
LT_PMBus::readIout
float readIout(uint8_t address, bool polling)
Get the measured output current.
Definition: LT_PMBus.cpp:1898
LT_PMBus::readModel
void readModel(uint8_t address, uint8_t *model)
Get the model.
Definition: LT_PMBus.cpp:2409
LT_PMBusDevice::pmbus_
LT_PMBus * pmbus_
Definition: LT_PMBusDevice.h:78
HAS_POUT
#define HAS_POUT
Definition: LT_PMBusDevice.h:62
LT_PMBusDevice::readIout
float readIout(bool polling)
Definition: LT_PMBusDevice.cpp:174
HAS_DC
#define HAS_DC
Definition: LT_PMBusDevice.h:65
LT_PMBusDevice::changePMBus
void changePMBus(LT_PMBus *pmbus)
Change the pmbus.
Definition: LT_PMBusDevice.cpp:80
LT_PMBusDevice::getType
virtual char * getType(void)
Definition: LT_PMBusDevice.cpp:93
LT_PMBus::marginHigh
void marginHigh(uint8_t address)
Margin rail high.
Definition: LT_PMBus.cpp:3041
LT_SMBus
Definition: LT_SMBus.h:61
LT_PMBusDevice::readExternalTemperature
float readExternalTemperature(bool polling)
Definition: LT_PMBusDevice.cpp:204
LT_PMBus::readPin
float readPin(uint8_t address, bool polling)
Get the measured input power.
Definition: LT_PMBus.cpp:2027
LT_PMBus::readVout
float readVout(uint8_t address, bool polling)
Get the measured output voltage.
Definition: LT_PMBus.cpp:1598
LT_PMBusDevice::pmbus
LT_PMBus * pmbus()
Definition: LT_PMBusDevice.cpp:70
LT_PMBusDevice::readMfrSpecialId
uint16_t readMfrSpecialId()
Definition: LT_PMBusDevice.cpp:244
LT_I2CBus::changeSpeed
void changeSpeed(uint32_t speed)
Change the speed of the bus.
Definition: LT_I2CBus.cpp:73
LT_PMBusDevice::readIin
float readIin(bool polling)
Definition: LT_PMBusDevice.cpp:164
LT_SMBus::writeByte
virtual void writeByte(uint8_t address, uint8_t command, uint8_t data)=0
SMBus write byte command.
LT_SMBus::readByte
virtual uint8_t readByte(uint8_t address, uint8_t command)=0
SMBus read byte command.
LT_PMBusDevice::readInternalTemperature
float readInternalTemperature(bool polling)
Definition: LT_PMBusDevice.cpp:214
LT_PMBusDevice::clearFaults
void clearFaults()
Definition: LT_PMBusDevice.cpp:253
LT_PMBus::setPage
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
LT_PMBusDevice::setVout
void setVout(float voltage)
Definition: LT_PMBusDevice.cpp:144
LT_PMBus::readExternalTemperature
float readExternalTemperature(uint8_t address, bool polling)
Get the measured external temperature.
Definition: LT_PMBus.cpp:2052
LT_PMBus::smbus
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
LT_PMBus::clearAllFaults
void clearAllFaults(uint8_t address)
Clear all the faults for all pages.
Definition: LT_PMBus.cpp:2576
LT_PMBus::marginLow
void marginLow(uint8_t address)
Margin rails low.
Definition: LT_PMBus.cpp:3050
LT_PMBus::readInternalTemperature
float readInternalTemperature(uint8_t address, bool polling)
Get the measured internal temperature.
Definition: LT_PMBus.cpp:2077
LT_PMBusDevice::readVin
float readVin(bool polling)
Definition: LT_PMBusDevice.cpp:150
LT_PMBus::readIin
float readIin(uint8_t address, bool polling)
Get the input current.
Definition: LT_PMBus.cpp:1805
LT_SMBus::i2cbus
virtual LT_I2CBus * i2cbus(void)=0
HAS_IOUT
#define HAS_IOUT
Definition: LT_PMBusDevice.h:60
LT_PMBusDevice::marginHigh
void marginHigh()
Definition: LT_PMBusDevice.cpp:258
LT_PMBusDevice.h
Library Header File for LT_PMBusDevice.
LT_PMBusDevice::hasCapability
virtual bool hasCapability(uint32_t capability)=0
Is/are these capability(s) supported?
LT_PMBusSpeedTest::test
uint32_t test(uint8_t address, uint8_t tries)
Definition: LT_PMBusSpeedTest.cpp:56
LT_PMBus::readVin
float readVin(uint8_t address, bool polling)
Get the input voltage.
Definition: LT_PMBus.cpp:1487
HAS_PIN
#define HAS_PIN
Definition: LT_PMBusDevice.h:63
LT_PMBusDevice::readDutyCycle
float readDutyCycle(bool polling)
Definition: LT_PMBusDevice.cpp:224
LT_PMBusDevice::probeSpeed
void probeSpeed()
Definition: LT_PMBusDevice.cpp:57
LT_PMBus::setVout
void setVout(uint8_t address, float voltage)
Set output voltage.
Definition: LT_PMBus.cpp:239
LT_PMBusDevice::model_
uint8_t model_[9]
Definition: LT_PMBusDevice.h:81
LT_PMBus::readMfrSpecialId
uint16_t readMfrSpecialId(uint8_t address)
Get speical ID.
Definition: LT_PMBus.cpp:3361
HAS_IIN
#define HAS_IIN
Definition: LT_PMBusDevice.h:61
LT_PMBusDevice::hasFaultLog
virtual bool hasFaultLog()
Is there a fault log?
Definition: LT_PMBusDevice.cpp:134
voltage
static float voltage
Definition: DC2289AA.ino:71
current
static uint16_t current
the current measurement from the LTC3335&#39;s counter test mode.
Definition: DC2343A.ino:114
LT_PMBusDevice::readPin
float readPin(bool polling)
Definition: LT_PMBusDevice.cpp:184
HAS_STATUS_WORD
#define HAS_STATUS_WORD
Definition: LT_PMBusDevice.h:66
LT_PMBusDevice::setPage
void setPage(uint8_t page)
Definition: LT_PMBusDevice.cpp:99
LT_PMBusDevice::marginLow
void marginLow()
Definition: LT_PMBusDevice.cpp:263
LT_PMBusDevice::smbus
LT_SMBus * smbus()
Definition: LT_PMBusDevice.cpp:74
LT_PMBusDevice::marginOff
void marginOff()
Definition: LT_PMBusDevice.cpp:268
LT_PMBusRail
PMBusRail communication. For Multiphase Rails.
Definition: LT_PMBusRail.h:72
HAS_VOUT
#define HAS_VOUT
Definition: LT_PMBusDevice.h:58
LT_PMBus::readDutyCycle
float readDutyCycle(uint8_t address, bool polling)
Get the duty cycle.
Definition: LT_PMBus.cpp:2102
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370