| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LT_PMBusDetect.cpp
Go to the documentation of this file.
1 /*!
2 LTC LT_PMBusDetect
3
4 @verbatim
5
6 Support for Detection
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 /*! @file
46 @ingroup LT_PMBusDevice
47 Library Header File for LT_PMBusDetect
48 */
49
50 #include <string.h>
51
52 #include "../LT_PMBUS/LT_PMBusDetect.h"
53 #include "LT_PMBusDeviceLTC3880.h"
54 #include "LT_PMBusDeviceLTC3882.h"
55 #include "LT_PMBusDeviceLTC3883.h"
56 #include "LT_PMBusDeviceLTC3886.h"
57 #include "LT_PMBusDeviceLTC3887.h"
58 #include "LT_PMBusDeviceLTM4675.h"
59 #include "LT_PMBusDeviceLTM4676.h"
60 #include "LT_PMBusDeviceLTM4677.h"
61 #include "LT_PMBusDeviceLTC2974.h"
62 #include "LT_PMBusDeviceLTC2975.h"
63 #include "LT_PMBusDeviceLTC2977.h"
64 #include "LT_PMBusDeviceLTC2978.h"
65 #include "LT_PMBusDeviceLTC2980.h"
66 #include "LT_PMBusDeviceLTM2987.h"
67
68 LT_PMBusDetect::LT_PMBusDetect(LT_PMBus *pmbus):pmbus_(pmbus)
69 {
70 }
71
72 LT_PMBusDevice **LT_PMBusDetect::getDevices(
73 )
74 {
75 return devices_;
76 }
77
78 LT_PMBusRail **LT_PMBusDetect::getRails(
79 )
80 {
81 return rails_;
82 }
83
84
85 void LT_PMBusDetect::detect ()
86 {
87 devices_ = NULL;
88 rails_ = NULL;
89 deviceCnt_ = 0;
90 railCnt_ = 0;
91
92 uint8_t *addresses;
93 LT_PMBusDevice *device;
94 unsigned int i, j;
95
96 if (deviceCnt_ > 0)
97 {
98 while (deviceCnt_ > 0)
99 delete (*(devices_ + (--deviceCnt_)));
100 free(devices_);
101 }
102
103 if (railCnt_ > 0)
104 {
105 while (railCnt_ > 0)
106 delete (*(rails_ + (--railCnt_)));
107 free(rails_);
108 }
109
110 addresses = pmbus_->smbus()->probeUnique(0x00);
111
112 // May be more than required. Can add code to trim based on deviceCnt_
113 // +1 and calloc so there is a terminating NULL
114 devices_ = (LT_PMBusDevice **) calloc(strlen((char *)addresses) + 1, sizeof(LT_PMBusDevice *));
115
116 // Check each device type one by one. Trading generality and composability
117 // for performance. For better performance, cache IDs or write decoder here
118 // and then call detect on the correct device first time.
119 for (i = 0; i < strlen((char *)addresses); i++)
120 {
121 if ((device = LT_PMBusDeviceLTC3880::detect(pmbus_, addresses[i])) != NULL)
122 devices_[deviceCnt_++] = device;
123 else if ((device = LT_PMBusDeviceLTC3882::detect(pmbus_, addresses[i])) != NULL)
124 devices_[deviceCnt_++] = device;
125 else if ((device = LT_PMBusDeviceLTC3883::detect(pmbus_, addresses[i])) != NULL)
126 devices_[deviceCnt_++] = device;
127 else if ((device = LT_PMBusDeviceLTC3886::detect(pmbus_, addresses[i])) != NULL)
128 devices_[deviceCnt_++] = device;
129 else if ((device = LT_PMBusDeviceLTC3887::detect(pmbus_, addresses[i])) != NULL)
130 devices_[deviceCnt_++] = device;
131 else if ((device = LT_PMBusDeviceLTM4675::detect(pmbus_, addresses[i])) != NULL)
132 devices_[deviceCnt_++] = device;
133 else if ((device = LT_PMBusDeviceLTM4676::detect(pmbus_, addresses[i])) != NULL)
134 devices_[deviceCnt_++] = device;
135 else if ((device = LT_PMBusDeviceLTM4677::detect(pmbus_, addresses[i])) != NULL)
136 devices_[deviceCnt_++] = device;
137 else if ((device = LT_PMBusDeviceLTC2974::detect(pmbus_, addresses[i])) != NULL)
138 devices_[deviceCnt_++] = device;
139 else if ((device = LT_PMBusDeviceLTC2975::detect(pmbus_, addresses[i])) != NULL)
140 devices_[deviceCnt_++] = device;
141 else if ((device = LT_PMBusDeviceLTC2977::detect(pmbus_, addresses[i])) != NULL)
142 devices_[deviceCnt_++] = device;
143 else if ((device = LT_PMBusDeviceLTC2978::detect(pmbus_, addresses[i])) != NULL)
144 devices_[deviceCnt_++] = device;
145 else if ((device = LT_PMBusDeviceLTC2980::detect(pmbus_, addresses[i])) != NULL)
146 devices_[deviceCnt_++] = device;
147 else if ((device = LT_PMBusDeviceLTM2987::detect(pmbus_, addresses[i])) != NULL)
148 devices_[deviceCnt_++] = device;
149
150 }
151
152 // Get all the rails, while merging duplicates.
153 for (i = 0; i < deviceCnt_; i++)
154 {
155 LT_PMBusRail **new_rail;
156 void *m;
157 bool merged;
158
159 new_rail = devices_[i]->getRails();
160
161 // Loop if device has rail support, and if there are rails to process.
162 while (new_rail != NULL && *new_rail != NULL)
163 {
164 // See if we are already in the list.
165 merged = false;
166 for (j = 0; j < railCnt_; j++)
167 {
168 if (rails_[j]->isMultiphase() && rails_[j]->getAddress() == (*new_rail)->getAddress())
169 {
170 rails_[j]->merge(*new_rail);
171 delete (*new_rail);
172 merged = true;
173 break;
174 }
175 }
176 if (!merged)
177 {
178 if (rails_ == NULL)
179 rails_ = (LT_PMBusRail **) malloc(sizeof(LT_PMBusRail *));
180 else
181 {
182 m = realloc(rails_, (railCnt_ + 1) * sizeof(LT_PMBusRail *));
183 if (m == NULL)
184 free(m);
185 else
186 rails_ = (LT_PMBusRail **) m;
187 }
188 if (rails_ != NULL)
189 rails_[railCnt_++] = *new_rail;
190 }
191
192 new_rail++;
193 }
194 }
195
196 rails_ = (LT_PMBusRail **) realloc(rails_, (railCnt_ + 1) * sizeof(LT_PMBusRail *));
197 rails_[railCnt_] = NULL;
198 }
LT_PMBusDeviceLTM4676.h
LTC PSM Device.
LT_PMBusDetect::pmbus_
LT_PMBus * pmbus_
Definition: LT_PMBusDetect.h:59
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_PMBusDeviceLTC2977::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC2977.h:95
LT_PMBusDetect::LT_PMBusDetect
LT_PMBusDetect(LT_PMBus *pmbus)
Definition: LT_PMBusDetect.cpp:68
LT_PMBusDetect::getRails
LT_PMBusRail ** getRails()
Definition: LT_PMBusDetect.cpp:78
LT_PMBusDeviceLTC3880.h
LTC PSM Device.
LT_PMBusDeviceLTC3883.h
LTC PSM Device.
LT_PMBusRail::getAddress
uint8_t getAddress()
Get ther rail address.
Definition: LT_PMBusRail.cpp:98
LT_PMBusDeviceLTC3882.h
LTC PSM Device.
LT_PMBusDevice
Definition: LT_PMBusDevice.h:75
LT_PMBusDeviceLTC2980.h
LTC PSM Device.
LT_PMBusDeviceLTC3886::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC3886.h:80
LT_PMBusDeviceLTC3882::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC3882.h:81
LT_PMBusRail::merge
void merge(LT_PMBusRail *rail)
Merge a rail into this one. No delete of incomming rail.
Definition: LT_PMBusRail.cpp:71
pmbus
static LT_PMBus * pmbus
Definition: DC2875A.ino:82
LT_PMBusDeviceLTC3883::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC3883.h:81
LT_PMBusDeviceLTC3887.h
LTC PSM Device.
LT_PMBusDetect::getDevices
LT_PMBusDevice ** getDevices()
Definition: LT_PMBusDetect.cpp:72
LT_PMBusDeviceLTC3886.h
LTC PSM Device.
LT_PMBusDeviceLTM2987::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTM2987.h:88
LT_PMBusDeviceLTM4676::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTM4676.h:81
LT_SMBus::probeUnique
virtual uint8_t * probeUnique(uint8_t command)=0
SMBus bus probe.
LT_PMBusDetect::rails_
LT_PMBusRail ** rails_
Definition: LT_PMBusDetect.h:61
LT_PMBus::smbus
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
LT_PMBusDeviceLTM4675::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTM4675.h:88
LT_PMBusDeviceLTC3880::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC3880.h:67
LT_PMBusDetect::railCnt_
unsigned int railCnt_
Definition: LT_PMBusDetect.h:63
LT_PMBusDeviceLTC2975::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC2975.h:92
LT_PMBusDeviceLTC2978.h
LTC PSM Device.
LT_PMBusDeviceLTM2987.h
LTC PSM Device.
LT_PMBusDetect::detect
void detect()
Detect devices on bus.
Definition: LT_PMBusDetect.cpp:85
LT_PMBusDeviceLTC2974::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC2974.h:93
i
static int i
Definition: DC2430A.ino:184
LT_PMBusDeviceLTC2975.h
LTC PSM Device.
LT_PMBusDeviceLTM4677::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTM4677.h:81
LT_PMBusDeviceLTC2978::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC2978.h:93
LT_PMBusDetect::devices_
LT_PMBusDevice ** devices_
Definition: LT_PMBusDetect.h:60
LT_PMBusDeviceLTC2974.h
LTC PSM Device.
LT_PMBusDeviceLTC2980::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC2980.h:93
LT_PMBusDeviceLTC2977.h
LTC PSM Device.
device
ad5933_dev * device
Definition: CN-0413.ino:67
LT_PMBusRail
PMBusRail communication. For Multiphase Rails.
Definition: LT_PMBusRail.h:72
LT_PMBusDeviceLTM4675.h
LTC PSM Device.
LT_PMBusDeviceLTC3887::detect
static LT_PMBusDevice * detect(LT_PMBus *pmbus, uint8_t address)
Definition: LT_PMBusDeviceLTC3887.h:80
LT_PMBusDetect::deviceCnt_
unsigned int deviceCnt_
Definition: LT_PMBusDetect.h:62
LT_PMBusDeviceLTM4677.h
LTC PSM Device.
LT_PMBus
PMBus communication.
Definition: LT_PMBus.h:370