SMBus Library for MSP430G2xx3 Devices  1.10.00.00
 All Data Structures Functions Variables Enumerations Enumerator Modules Pages
smbus_nwk.h
1 #ifndef __SMBUS_NWK_H__
2 #define __SMBUS_NWK_H__
3 
4 //*****************************************************************************
5 //
6 //! \addtogroup smbus_nwk NWK layer
7 //! @{
8 //
9 //*****************************************************************************
10 
11 //*****************************************************************************
12 //
13 // If building with a C++ compiler, make all of the definitions in this header
14 // have a C binding.
15 //
16 //*****************************************************************************
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif
21 
22 //
23 // Include files
24 //
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <stdbool.h>
28 #include "smbus.h"
29 
30 //*****************************************************************************
31 // Internal functions called by the physical layer and internal smbus
32 // processing. Application programs should not call these functions directly.
33 //*****************************************************************************
34 //*****************************************************************************
35 //
36 //! \brief Returns the number of received bytes from last transaction
37 //
38 //! \param smbus Pointer to SMBus structure
39 //
40 //! \return Number of bytes in the RX buffer. PEC byte is *not* included.
41 //
42 //*****************************************************************************
43 extern uint8_t SMBus_NWK_getRxPayloadSize(SMBus *smbus);
44 
45 //*****************************************************************************
46 //
47 //! \brief Adds a new value to CRC-8 Calculation
48 //
49 //! Follows format: C(x) = x8 + x2 + x + 1
50 //! <BR>
51 //! Two methods are available:
52 //! - SMB_CRC8_USE_LOOKUP_TABLE : Use a 256B lookup table (faster but
53 //! takes more memory)
54 //! - SMB_CRC8_CALCULATION : Calculate CRC8 manually (slower but
55 //! takes less memory)
56 //! <BR>
57 //
58 //! \param *crc Pointer to current CRC-8 value, will get updated
59 //! \param newData New byte added to CRC-8 calulation
60 //
61 //! \return None
62 //
63 //*****************************************************************************
64 extern void SMBus_NWK_addCrc8(uint8_t *crc,
65  uint8_t newData);
66 
67 //*****************************************************************************
68 //
69 //! \brief Start the TX transfer process
70 //
71 //! \param smbus Pointer to SMBus structure
72 //
73 //! \return None
74 //
75 //*****************************************************************************
76 extern void SMBus_NWK_startTxTransfer(SMBus *smbus);
77 
78 //*****************************************************************************
79 //
80 //! \brief Start the RX transfer process
81 //
82 //! \param smbus Pointer to SMBus structure
83 //
84 //! \return None
85 //
86 //*****************************************************************************
87 extern void SMBus_NWK_startRxTransfer(SMBus *smbus);
88 
89 //*****************************************************************************
90 //
91 //! \brief Start callback for SMBus
92 //
93 //! Handles the protocol when a Start is received. Depending on the
94 //! current state, the start could also mean re-start.
95 //
96 //! \param smbus Pointer to SMBus structure
97 //! \param addrRw Current Address+RW as received by PHY_DL
98 //
99 //! \return SMBus_State value as follows:
100 //! - \b SMBus_State_Slave_NotReady : Packet in progress
101 //! - \b SMBus_State_PECError : Packet was invalid
102 //! - \b SMBus_State_Slave_CmdComplete : restart received after command,
103 //! process previous packet
104 //
105 //*****************************************************************************
107  uint8_t addrRw);
108 
109 //*****************************************************************************
110 //
111 //! \brief RX callback for SMBus slave
112 //
113 //! Handles the protocol when a reception is requested.
114 //
115 //! \param smbus Pointer to SMBus structure
116 //! \param data Data byte as received by the PHY layer
117 //
118 //! \return SMBus_State value as follows:
119 //! - \b SMBus_State_OK
120 //! - \b SMBus_State_Slave_NotReady : Packet in progress
121 //! - \b SMBus_State_Slave_FirstByte : First byte (Command) was received
122 //! - \b SMBus_State_Slave_ByteReceived : Data byte (2-n) was received
123 //! - \b SMBus_State_Slave_Error : not expecting RX
124 //! - \b SMBus_State_Slave_NotReady : not ready for RX
125 //! - \b SMBus_State_DataSizeError : Max packet size exceeded
126 //
127 //*****************************************************************************
129  uint8_t data);
130 
131 //*****************************************************************************
132 //
133 //! \brief TX callback for SMBus slave
134 //
135 //! Handles the protocol when a transmission is requested.
136 //
137 //! \param smbus Pointer to SMBus structure
138 //! \param *data Pointer to tranmission byte, must be written with value
139 //! being sent
140 //
141 //! \return SMBus_State value as follows:
142 //! - \b SMBus_State_OK
143 //! - \b SMBus_State_Slave_NotReady : Buffer not initialized
144 //! - \b SMBus_State_Slave_Error : not expecting TX
145 //! - \b SMBus_State_Slave_NotReady : not ready for TX
146 //! - \b SMBus_State_DataSizeError : Max packet size exceeded
147 //
148 //*****************************************************************************
150  uint8_t *data);
151 
152 //*****************************************************************************
153 //
154 //! \brief Stop callback for SMBus-based protocol
155 //
156 //! Handles SMus protocol when a stop is detected
157 //
158 //! \param smbus Pointer to SMBus structure
159 //
160 //! \return SMBus_State value as follows:
161 //! - \b SMBus_State_OK
162 //! - \b SMBus_State_Slave_NotReady : Packet in progress
163 //! - \b SMBus_State_PECError : Packet was invalid
164 //! - \b SMBus_State_Slave_QCMD : Quick Command was detected
165 //! - \b SMBus_State_Slave_CmdComplete : Stop was detected and packet is ready
166 //! to process
167 //
168 //*****************************************************************************
170 
171 //*****************************************************************************
172 //
173 //! \brief Handles the SMBus protocol when a Timeout error is detected by PHY
174 //
175 //! Used for USCI devices that do not support timeouts inherently (as in eUSCI).
176 //! \param smbus Pointer to SMBus structure
177 //
178 //! \return SMBus_State_TimeOutError
179 //
180 //*****************************************************************************
182 
183 //*****************************************************************************
184 //
185 //! \brief RX callback for SMBus master
186 //
187 //! Handles the protocol when a reception is requested.
188 //
189 //! \param smbus Pointer to SMBus structure
190 //! \param data Data byte as received by the PHY layer
191 //
192 //! \return SMBus_State value as follows:
193 //! - \b SMBus_State_OK
194 //! - \b SMBus_State_Master_Error : not expecting RX
195 //! - \b SMBus_State_DataSizeError : Max packet size exceeded, or greater
196 //! than expected
197 //
198 //*****************************************************************************
200  uint8_t data);
201 
202 //*****************************************************************************
203 //
204 //! \brief TX callback for SMBus master
205 //
206 //! Handles the protocol when a transmission is requested.
207 //
208 //! \param smbus Pointer to SMBus structure
209 //! \param *data Pointer to tranmission byte, must be written with value
210 //! being sent
211 //
212 //! \return SMBus_State value as follows:
213 //! - \b SMBus_State_OK
214 //! - \b SMBus_State_Master_Error : not expecting TX
215 //
216 //*****************************************************************************
218  uint8_t *data);
219 
220 //*****************************************************************************
221 //
222 //! \brief Process a Stop condition
223 //
224 //
225 //! \param smbus Pointer to SMBus structure
226 //
227 //! \return SMBus_State value as follows:
228 //! - \b SMBus_State_OK
229 //! - \b SMBus_State_PECError
230 //
231 //*****************************************************************************
233 
234 //*****************************************************************************
235 //
236 //! \brief Handles the SMBus protocol when a Timeout error is detected by PHY
237 //
238 //! Used for USCI devices that do not support timeouts inherently (as in eUSCI).
239 //
240 //! \param smbus Pointer to SMBus structure
241 //
242 //! \return SMBus_State_TimeOutError
243 //
244 //*****************************************************************************
246 
247 //*****************************************************************************
248 //
249 //! \brief Handles the SMBus protocol when a NACK
250 //
251 //! \param smbus Pointer to SMBus structure
252 //
253 //! \return SMBus_State value as follows:
254 //! - \b SMBus_State_OK
255 //! - \b SMBus_State_Master_NACK
256 //
257 //*****************************************************************************
259 
260 //*****************************************************************************
261 //
262 //! \brief Resets the SMBus network layer
263 //
264 //! \param smbus Pointer to SMBus structure
265 //
266 //! \return none
267 //
268 //*****************************************************************************
269 extern void SMBus_NWK_masterReset(SMBus *smbus);
270 
271 //*****************************************************************************
272 //
273 // Mark the end of the C bindings section for C++ compilers.
274 //
275 //*****************************************************************************
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 //*****************************************************************************
281 //
282 // Close the Doxygen group.
283 //! @}
284 //
285 //*****************************************************************************
286 
287 #endif //__SMBUS_NWK_H__
SMBus_State SMBus_NWK_masterProcessTx(SMBus *smbus, uint8_t *data)
TX callback for SMBus master.
Definition: smbus_nwk.c:543
SMBus_State SMBus_NWK_slaveProcessRx(SMBus *smbus, uint8_t data)
RX callback for SMBus slave.
Definition: smbus_nwk.c:282
void SMBus_NWK_startRxTransfer(SMBus *smbus)
Start the RX transfer process.
Definition: smbus_nwk.c:155
SMBus_State SMBus_NWK_slaveProcessStart(SMBus *smbus, uint8_t addrRw)
Start callback for SMBus.
Definition: smbus_nwk.c:203
void SMBus_NWK_startTxTransfer(SMBus *smbus)
Start the TX transfer process.
Definition: smbus_nwk.c:130
SMBus_State SMBus_NWK_masterProcessNACK(SMBus *smbus)
Handles the SMBus protocol when a NACK.
Definition: smbus_nwk.c:661
SMBus_State SMBus_NWK_masterProcessTimeout(SMBus *smbus)
Handles the SMBus protocol when a Timeout error is detected by PHY.
Definition: smbus_nwk.c:649
SMBus_State SMBus_NWK_slaveProcessTimeout(SMBus *smbus)
Handles the SMBus protocol when a Timeout error is detected by PHY.
Definition: smbus_nwk.c:451
SMBus_State SMBus_NWK_masterProcessRx(SMBus *smbus, uint8_t data)
RX callback for SMBus master.
Definition: smbus_nwk.c:465
SMBus_State SMBus_NWK_masterProcessStop(SMBus *smbus)
Process a Stop condition.
Definition: smbus_nwk.c:617
uint8_t SMBus_NWK_getRxPayloadSize(SMBus *smbus)
Returns the number of received bytes from last transaction.
Definition: smbus_nwk.c:48
SMBus_State SMBus_NWK_slaveProcessTx(SMBus *smbus, uint8_t *data)
TX callback for SMBus slave.
Definition: smbus_nwk.c:345
SMBus_State SMBus_NWK_slaveProcessStop(SMBus *smbus)
Stop callback for SMBus-based protocol.
Definition: smbus_nwk.c:409
SMBus_State
SMBus state sent to application layer.
Definition: smbus.h:224
void SMBus_NWK_addCrc8(uint8_t *crc, uint8_t newData)
Adds a new value to CRC-8 Calculation.
Definition: smbus_nwk.c:86
Main SMBus object.
Definition: smbus.h:274
void SMBus_NWK_masterReset(SMBus *smbus)
Resets the SMBus network layer.
Definition: smbus_nwk.c:640

Copyright 2015, Texas Instruments Incorporated