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 
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 
71 {
72  return pmbus_;
73 }
75 {
76  return pmbus_->smbus();
77 }
78 
79 //! Change the pmbus
81 {
82  pmbus_ = pmbus;
83 }
84 
85 //! Get the address
86 //! @return address
88 )
89 {
90  return address_;
91 }
92 
94 {
96  return (char *) model_;
97 }
98 
99 void LT_PMBusDevice::setPage(uint8_t page)
100 {
101  pmbus_->setPage(address_, page);
102 }
103 
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 
130 {
131  return NULL;
132 }
133 
135 {
136  return false;
137 }
138 
140 {
141  return NULL;
142 }
143 
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 
205 {
206  float temp = 0.0;
207 
208  if (hasCapability(HAS_TEMP))
209  temp = pmbus_->readExternalTemperature(address_, polling);
210 
211  return temp;
212 }
213 
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 
235 {
236  uint16_t sw = 0;
237 
240 
241  return sw;
242 }
243 
245 {
246  uint16_t id = 0;
247 
249 
250  return id;
251 }
252 
254 {
256 }
257 
259 {
261 }
262 
264 {
266 }
267 
269 {
271 }
static int id
Definition: rail_logger.ino:99
virtual LT_PMBusRail ** getRails()=0
Return a list of rails if any page is part of a rail.
uint32_t getMaxSpeed(void)
Get the maximum speed the device can communicate with.
float readPout(uint8_t address, bool polling)
Get the measured output power.
Definition: LT_PMBus.cpp:1963
float readPout(bool polling)
#define HAS_VIN
uint32_t maxSpeed_
void marginOff(uint8_t address)
Margin rails off.
Definition: LT_PMBus.cpp:3059
uint8_t getAddress()
Get the address.
virtual void setSpeed(uint32_t speed)
Set the speed. If > 100000, enable clock stretching.
#define HAS_TEMP
float readVout(bool polling)
uint16_t readStatusWord()
uint16_t readStatusWord(uint8_t address)
Get the status word.
Definition: LT_PMBus.cpp:2470
virtual char * getFaultLog()
Get the fault log text (call must free)
float readIout(uint8_t address, bool polling)
Get the measured output current.
Definition: LT_PMBus.cpp:1898
void readModel(uint8_t address, uint8_t *model)
Get the model.
Definition: LT_PMBus.cpp:2409
LT_PMBus * pmbus_
#define HAS_POUT
float readIout(bool polling)
#define HAS_DC
void changePMBus(LT_PMBus *pmbus)
Change the pmbus.
virtual char * getType(void)
void marginHigh(uint8_t address)
Margin rail high.
Definition: LT_PMBus.cpp:3041
float readExternalTemperature(bool polling)
float readPin(uint8_t address, bool polling)
Get the measured input power.
Definition: LT_PMBus.cpp:2027
float readVout(uint8_t address, bool polling)
Get the measured output voltage.
Definition: LT_PMBus.cpp:1598
LT_PMBus * pmbus()
uint16_t readMfrSpecialId()
void changeSpeed(uint32_t speed)
Change the speed of the bus.
Definition: LT_I2CBus.cpp:73
float readIin(bool polling)
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.
float readInternalTemperature(bool polling)
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
void setVout(float voltage)
float readExternalTemperature(uint8_t address, bool polling)
Get the measured external temperature.
Definition: LT_PMBus.cpp:2052
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
void clearAllFaults(uint8_t address)
Clear all the faults for all pages.
Definition: LT_PMBus.cpp:2576
void marginLow(uint8_t address)
Margin rails low.
Definition: LT_PMBus.cpp:3050
float readInternalTemperature(uint8_t address, bool polling)
Get the measured internal temperature.
Definition: LT_PMBus.cpp:2077
float readVin(bool polling)
float readIin(uint8_t address, bool polling)
Get the input current.
Definition: LT_PMBus.cpp:1805
virtual LT_I2CBus * i2cbus(void)=0
#define HAS_IOUT
Library Header File for LT_PMBusDevice.
virtual bool hasCapability(uint32_t capability)=0
Is/are these capability(s) supported?
uint32_t test(uint8_t address, uint8_t tries)
float readVin(uint8_t address, bool polling)
Get the input voltage.
Definition: LT_PMBus.cpp:1487
#define HAS_PIN
float readDutyCycle(bool polling)
void setVout(uint8_t address, float voltage)
Set output voltage.
Definition: LT_PMBus.cpp:239
uint8_t model_[9]
uint16_t readMfrSpecialId(uint8_t address)
Get speical ID.
Definition: LT_PMBus.cpp:3361
#define HAS_IIN
virtual bool hasFaultLog()
Is there a fault log?
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
float readPin(bool polling)
#define HAS_STATUS_WORD
void setPage(uint8_t page)
LT_SMBus * smbus()
PMBusRail communication. For Multiphase Rails.
Definition: LT_PMBusRail.h:72
#define HAS_VOUT
float readDutyCycle(uint8_t address, bool polling)
Get the duty cycle.
Definition: LT_PMBus.cpp:2102
PMBus communication.
Definition: LT_PMBus.h:370