| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LT_SMBus.h
Go to the documentation of this file.
1 /*!
2 LTC SMBus Support: API for a shared SMBus layer
3
4 @verbatim
5
6 This API is shared with Linduino and RTOS code. End users should code to this
7 API to enable use of the PMBus code without modifications.
8
9 @endverbatim
10
11
12 Copyright 2018(c) Analog Devices, Inc.
13
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18 - Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 - Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in
22 the documentation and/or other materials provided with the
23 distribution.
24 - Neither the name of Analog Devices, Inc. nor the names of its
25 contributors may be used to endorse or promote products derived
26 from this software without specific prior written permission.
27 - The use of this software may or may not infringe the patent rights
28 of one or more patent holders. This license does not release you
29 from the requirement that you obtain separate licenses from these
30 patent holders to use this software.
31 - Use of the software either in source or binary form, must be run
32 on or directly connected to an Analog Devices Inc. component.
33
34 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
35 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
36 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
37 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
38 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
40 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45
46 /*! @file
47 @ingroup LT_SMBus
48 Library Header File for LT_SMBus
49 */
50
51 #ifndef LT_SMBus_H_
52 #define LT_SMBus_H_
53
54 #include <Arduino.h>
55 #include <stdint.h>
56 #include <LT_I2CBus.h>
57
58 #define SUCCESS 1
59 #define FAILURE 0
60
61 class LT_SMBus
62 {
63 protected:
64 bool pec_enabled_;
65
66 uint8_t running_pec_; //!< Temporary pec calc value
67 unsigned char poly_; //!< The poly used in the calc
68 uint16_t crc_polynomial_; //!< The crc poly used in the calc
69
70
71 //! Initialize the table used to speed up pec calculations
72 //! @return void
73 void constructTable(uint16_t user_polynomial //!< The controlling polynomial
74 );
75
76 //! Helper function for pec
77 //! @return value
78 uint8_t doCalculate(uint8_t data,
79 uint8_t begining_value //!< The initial value
80 );
81
82 LT_SMBus ();
83
84 public:
85 virtual ~LT_SMBus() {}
86
87 virtual LT_I2CBus *i2cbus(void) = 0;
88 virtual void i2cbus(LT_I2CBus *i2cbus) = 0;
89
90 //! Check if PEC is enabled
91 //! @return true if enabled
92 bool pecEnabled(void)
93 {
94 return pec_enabled_;
95 }
96
97 //! Clear the pec value so it can start a new calculation
98 //! @return void
99 void pecClear(void);
100
101 //! Add a byte to the pec calculation
102 //! @return void
103 void pecAdd(uint8_t byte_value);
104
105 //! Get the current pec result
106 //! @return the pec
107 uint8_t pecGet(void);
108
109 //! Check CRC of block data organized as 31 data bytes plus CRC.
110 //! Do not mix with PEC calculations.
111 //! Return true if CRC does not match.
112 bool checkCRC (uint8_t *data);
113
114 //! Get CRC of block data organized as 31 bytes pluse CRC.
115 //! Do not mix with PEC calculations.
116 //! Return PEC
117 uint8_t getCRC (uint8_t *data);
118
119 //! Helper function for pec
120 //! @return value
121 uint8_t calculate(uint8_t *data, //!< Data to be pec'ed
122 uint8_t begining_value, //!< Starting value for pec
123 uint8_t start_index, //!< Starting index
124 uint8_t length //!< Length of data
125 );
126
127 //! Perform ARA
128 //! @return address
129 virtual uint8_t readAlert(void) = 0;
130
131 //! SMBus write byte command
132 //! @return void
133 virtual void writeByte(uint8_t address, //!< Slave address
134 uint8_t command, //!< Command byte
135 uint8_t data //!< Data to send
136 ) = 0;
137
138 //! SMBus write byte command for a list of addresses
139 //! @return void
140 virtual void writeBytes(uint8_t *addresses, //!< Slave Addresses
141 uint8_t *commands, //!< Command bytes
142 uint8_t *data, //!< Data to send
143 uint8_t no_addresses
144 ) = 0;
145
146 //! SMBus read byte command
147 //! @return byte
148 virtual uint8_t readByte(uint8_t address, //!< Slave Address
149 uint8_t command //!< Command byte
150 ) = 0;
151
152 //! SMBus write word command
153 //! @return void
154 virtual void writeWord(uint8_t address, //!< Slave Address
155 uint8_t command, //!< Command byte
156 uint16_t data //!< Data to send
157 ) = 0;
158
159 //! SMBus read word command
160 //! @return word
161 virtual uint16_t readWord(uint8_t address, //!< Slave Address
162 uint8_t command //!< Command byte
163 ) = 0;
164
165 //! SMBus write block command
166 //! @return void
167 virtual void writeBlock(uint8_t address, //!< Slave Address
168 uint8_t command, //!< Command byte
169 uint8_t *block, //!< Data to send
170 uint16_t block_size
171 ) = 0;
172
173 //! SMBus write then read block command
174 //! @return actual value
175 virtual uint8_t writeReadBlock(uint8_t address, //!< Slave Address
176 uint8_t command, //!< Command byte
177 uint8_t *block_out, //!< Data to send
178 uint16_t block_out_size, //!< Size of data to send
179 uint8_t *block_in, //!< Memory to receive data
180 uint16_t block_in_size //!< Size of receive data memory
181 ) = 0;
182
183 //! SMBus read block command
184 //! @return actual size
185 virtual uint8_t readBlock(uint8_t address, //!< Slave Address
186 uint8_t command, //!< Command byte
187 uint8_t *block, //!< Memory to receive data
188 uint16_t block_size //!< Size of receive data memory
189 ) = 0;
190
191 //! SMBus send byte command
192 //! @return void
193 virtual void sendByte(uint8_t address, //!< Slave Address
194 uint8_t command //!< Command byte
195 ) = 0;
196
197 //! Read with the address and command in loop until ack, then issue stop
198 //! @return void
199 virtual uint8_t waitForAck(uint8_t address, //!< Slave Address
200 uint8_t command //!< Command byte
201 ) = 0;
202
203 //! SMBus bus probe
204 //! @return array of addresses (caller must not delete return memory)
205 virtual uint8_t *probe(uint8_t command //!< Command byte
206 ) = 0;
207
208 //! SMBus bus probe
209 //! @return array of unique addresses (no global addresses)
210 virtual uint8_t *probeUnique(uint8_t command //!< Command byte
211 ) = 0;
212
213 };
214
215 #endif /* LT_SMBus_H_ */
LT_SMBus::readAlert
virtual uint8_t readAlert(void)=0
Perform ARA.
LT_SMBus::sendByte
virtual void sendByte(uint8_t address, uint8_t command)=0
SMBus send byte command.
LT_SMBus::pecEnabled
bool pecEnabled(void)
Check if PEC is enabled.
Definition: LT_SMBus.h:92
LT_SMBus::getCRC
uint8_t getCRC(uint8_t *data)
Get CRC of block data organized as 31 bytes pluse CRC.
Definition: LT_SMBus.cpp:220
LT_SMBus::pec_enabled_
bool pec_enabled_
Definition: LT_SMBus.h:64
LT_SMBus::writeWord
virtual void writeWord(uint8_t address, uint8_t command, uint16_t data)=0
SMBus write word command.
address
static uint8_t address
Definition: DC2091A.ino:83
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
LT_SMBus::doCalculate
uint8_t doCalculate(uint8_t data, uint8_t begining_value)
Helper function for pec.
Definition: LT_SMBus.cpp:138
LT_SMBus::writeBytes
virtual void writeBytes(uint8_t *addresses, uint8_t *commands, uint8_t *data, uint8_t no_addresses)=0
SMBus write byte command for a list of addresses.
LT_SMBus::constructTable
void constructTable(uint16_t user_polynomial)
Initialize the table used to speed up pec calculations.
Definition: LT_SMBus.cpp:105
LT_SMBus
Definition: LT_SMBus.h:61
LT_SMBus::checkCRC
bool checkCRC(uint8_t *data)
Check CRC of block data organized as 31 data bytes plus CRC.
Definition: LT_SMBus.cpp:200
LT_SMBus::pecGet
uint8_t pecGet(void)
Get the current pec result.
Definition: LT_SMBus.cpp:192
LT_SMBus::waitForAck
virtual uint8_t waitForAck(uint8_t address, uint8_t command)=0
Read with the address and command in loop until ack, then issue stop.
LT_I2CBus.h
LT_I2CBus: Routines to communicate to I2C by Wire Library.
LT_SMBus::poly_
unsigned char poly_
The poly used in the calc.
Definition: LT_SMBus.h:67
LT_SMBus::crc_polynomial_
uint16_t crc_polynomial_
The crc poly used in the calc.
Definition: LT_SMBus.h:68
LT_SMBus::probeUnique
virtual uint8_t * probeUnique(uint8_t command)=0
SMBus bus probe.
LT_I2CBus
Definition: LT_I2CBus.h:50
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_SMBus::running_pec_
uint8_t running_pec_
Temporary pec calc value.
Definition: LT_SMBus.h:66
LT_SMBus::probe
virtual uint8_t * probe(uint8_t command)=0
SMBus bus probe.
LT_SMBus::i2cbus
virtual LT_I2CBus * i2cbus(void)=0
LT_SMBus::LT_SMBus
LT_SMBus()
Definition: LT_SMBus.cpp:91
LT_SMBus::pecClear
void pecClear(void)
Clear the pec value so it can start a new calculation.
Definition: LT_SMBus.cpp:162
LT_SMBus::readBlock
virtual uint8_t readBlock(uint8_t address, uint8_t command, uint8_t *block, uint16_t block_size)=0
SMBus read block command.
LT_SMBus::calculate
uint8_t calculate(uint8_t *data, uint8_t begining_value, uint8_t start_index, uint8_t length)
Helper function for pec.
Definition: LT_SMBus.cpp:146
LT_SMBus::writeBlock
virtual void writeBlock(uint8_t address, uint8_t command, uint8_t *block, uint16_t block_size)=0
SMBus write block command.
LT_SMBus::writeReadBlock
virtual uint8_t writeReadBlock(uint8_t address, uint8_t command, uint8_t *block_out, uint16_t block_out_size, uint8_t *block_in, uint16_t block_in_size)=0
SMBus write then read block command.
LT_SMBus::~LT_SMBus
virtual ~LT_SMBus()
Definition: LT_SMBus.h:85
LT_SMBus::pecAdd
void pecAdd(uint8_t byte_value)
Add a byte to the pec calculation.
Definition: LT_SMBus.cpp:170
LT_SMBus::readWord
virtual uint16_t readWord(uint8_t address, uint8_t command)=0
SMBus read word command.