Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LT_SMBusARA.h
Go to the documentation of this file.
1 /*!
2 LTC PSM ARA Handling
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_SMBusAra LT_SMBusAra: Implementation of Device Alert
48 //! @}
49 
50 /*! @file
51  @ingroup LT_SMBusAra
52  Library Header File for LT_SMBusAlert
53 */
54 
55 #ifndef LT_SMBusARA_H_
56 #define LT_SMBusARA_H_
57 
58 
59 #include <stdint.h>
60 #include <LT_PMBus.h>
61 #include <LT_SMBusARA.h>
62 #include <LT_PMBusDevice.h>
63 
65 {
66  protected:
68 
69 
70  public:
71  LT_SMBusARA(LT_SMBus *smbus):smbus_(smbus)
72  {
73  }
74  virtual ~LT_SMBusARA() {}
75 
76  //! Get the ARA addresses (user must free)
77  //! @return addresses
78  uint8_t *getAddresses (
79  )
80  {
81  uint8_t *addresses;
82  uint16_t count = 0;
83  uint8_t address = 0xFF;
84 
85  addresses = (uint8_t *) malloc (sizeof(uint8_t));
86  do
87  {
88  address = smbus_->readAlert();
89  addresses[count++] = address;
90  delay(1);
91  addresses = (uint8_t *) realloc(addresses, (count + 1) * sizeof(uint8_t));
92  }
93  while (address != 0);
94 
95  addresses[count] = 0;
96 
97  return addresses;
98  }
99 
100  //! Get all the ARA devices.
101  //! @return a list of devices (call must free list, but not devices in list)
102  LT_PMBusDevice **getDevices(LT_PMBusDevice **devices //!< A list of known devices //!< The number of devices in the list
103  )
104  {
105  uint8_t *addresses;
106  uint8_t *address;
108  LT_PMBusDevice **matchingDevices;
109  LT_PMBusDevice **matchingDevice;
110  int devCount;
111 
112  devCount = 0;
113  device = devices;
114  while ((*device) != 0)
115  {
116  device++;
117  devCount++;
118  }
119 
120  addresses = getAddresses();
121  matchingDevice = (matchingDevices = (LT_PMBusDevice **) calloc(devCount + 1, sizeof(LT_PMBusDevice *)));
122 
123  // Bad algorithm lies here and needs replacing
124  address = addresses;
125  while (*address != 0)
126  {
127  device = devices;
128  while ((*device) != 0)
129  {
130  if ((*address) == (*device)->getAddress())
131  {
132  *matchingDevice = *device;
133  matchingDevice++;
134  }
135  device++;
136  }
137  address++;
138  }
139  free (addresses);
140  return matchingDevices;
141  }
142 
143 };
144 
145 #endif /* LT_SMBusDevice_H_ */
virtual uint8_t readAlert(void)=0
Perform ARA.
LT_PMBusDevice ** getDevices(LT_PMBusDevice **devices)
Get all the ARA devices.
Definition: LT_SMBusARA.h:102
virtual ~LT_SMBusARA()
Definition: LT_SMBusARA.h:74
static LT_PMBusDevice ** devices
static uint8_t address
Definition: DC2091A.ino:83
LT_SMBusGroup * smbus
Definition: retention.ino:139
LT_SMBus * smbus_
Definition: LT_SMBusARA.h:67
Library Header File for LT_SMBusAlert.
LT_SMBusARA(LT_SMBus *smbus)
Definition: LT_SMBusARA.h:71
uint8_t * getAddresses()
Get the ARA addresses (user must free)
Definition: LT_SMBusARA.h:78
Library Header File for LT_PMBusDevice.
LTC PMBus Support.
ad5933_dev * device
Definition: CN-0413.ino:67