iLLD_TC27xC  1.0
IfxI2c.h
Go to the documentation of this file.
1 /**
2  * \file IfxI2c.h
3  * \brief I2C basic functionality
4  * \ingroup IfxLld_I2c
5  *
6  * \version iLLD_0_1_0_10
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  * \defgroup IfxLld_I2c I2C
25  * \ingroup IfxLld
26  * \defgroup IfxLld_I2c_Std Standard Driver
27  * \ingroup IfxLld_I2c
28  * \defgroup IfxLld_I2c_Std_enums Enumerations
29  * \ingroup IfxLld_I2c_Std
30  * \defgroup IfxLld_I2c_Std_functions Functions
31  * \ingroup IfxLld_I2c_Std
32  * \defgroup IfxLld_I2c_Std_structures Data Structures
33  * \ingroup IfxLld_I2c_Std
34  */
35 
36 #ifndef IFXI2C_H
37 #define IFXI2C_H 1
38 
39 /******************************************************************************/
40 /*----------------------------------Includes----------------------------------*/
41 /******************************************************************************/
42 
43 #include "_Impl/IfxI2c_cfg.h"
44 #include "Scu/Std/IfxScuWdt.h"
45 #include "Scu/Std/IfxScuCcu.h"
46 
47 /******************************************************************************/
48 /*--------------------------------Enumerations--------------------------------*/
49 /******************************************************************************/
50 
51 /** \addtogroup IfxLld_I2c_Std_enums
52  * \{ */
53 typedef enum
54 {
55  IfxI2c_BusStatus_idle = 0, /**< \brief idle */
56  IfxI2c_BusStatus_started = 1, /**< \brief started */
57  IfxI2c_BusStatus_busyMaster = 2, /**< \brief busy Master */
58  IfxI2c_BusStatus_remoteSlave = 3 /**< \brief remote Slave */
60 
61 typedef enum
62 {
72 
73 /** \} */
74 
75 /******************************************************************************/
76 /*-----------------------------Data Structures--------------------------------*/
77 /******************************************************************************/
78 
79 /** \addtogroup IfxLld_I2c_Std_structures
80  * \{ */
81 /** \brief Pin Structure
82  */
83 typedef struct
84 {
88 } IfxI2c_Pins;
89 
90 /** \} */
91 
92 /** \addtogroup IfxLld_I2c_Std_functions
93  * \{ */
94 
95 /******************************************************************************/
96 /*-------------------------Inline Function Prototypes-------------------------*/
97 /******************************************************************************/
98 
99 /** \brief returns the Arbitration Lost Flag
100  */
101 IFX_INLINE boolean IfxI2c_arbitrationLostFlag(Ifx_I2C *i2c);
102 
103 /** \brief Returns if the bus is free
104  */
105 IFX_INLINE boolean IfxI2c_busIsFree(Ifx_I2C *i2c);
106 
107 /** \brief Clears the Arbitration Lost Flag
108  * \return None
109  */
111 
112 /**
113  * \return None
114  */
115 IFX_INLINE void IfxI2c_clearErrorInterrupts(Ifx_I2C *i2c);
116 
117 /**
118  * \return None
119  */
120 IFX_INLINE void IfxI2c_clearFifoRequests(Ifx_I2C *i2c);
121 
122 /** \brief Clears the Protocol Interrupt Flags
123  * \return None
124  */
125 IFX_INLINE void IfxI2c_clearProtocolInterrupts(Ifx_I2C *i2c);
126 
127 /** \brief Clears the NAK Flag
128  * \return None
129  */
130 IFX_INLINE void IfxI2c_clearReceivedNakFlag(Ifx_I2C *i2c);
131 
132 /**
133  * \return None
134  */
135 IFX_INLINE void IfxI2c_clearTxEndInterrupt(Ifx_I2C *i2c);
136 
137 /**
138  * \return BusStatus
139  */
141 
142 /** \brief Returns if the Fifo is requesting new data
143  */
144 IFX_INLINE boolean IfxI2c_isFifoRequest(Ifx_I2C *i2c);
145 
146 /**
147  * \return is Tx interrupt
148  */
149 IFX_INLINE boolean IfxI2c_isTxEndInterrupt(Ifx_I2C *i2c);
150 
151 /** \brief returns the NAK Flag
152  * \return
153  */
154 IFX_INLINE boolean IfxI2c_receivedNakFlag(Ifx_I2C *i2c);
155 
156 /**
157  * \param i2c
158  * \return None
159  */
160 IFX_INLINE void IfxI2c_run(Ifx_I2C *i2c);
161 
162 /**
163  * \return None
164  */
165 IFX_INLINE void IfxI2c_setPinSelection(Ifx_I2C *i2c, IfxI2c_PinSelect pisel);
166 
167 /** \brief Sets the number of bytes to be received
168  * \return None
169  */
170 IFX_INLINE void IfxI2c_setReceivePacketSize(Ifx_I2C *i2c, Ifx_SizeT size);
171 
172 /**
173  * \return None
174  */
175 IFX_INLINE void IfxI2c_setSlaveDeviceAddress(Ifx_I2C *i2c, uint16 address);
176 
177 /** \brief Sets the number of bytes to be tansmitted
178  * \return None
179  */
180 IFX_INLINE void IfxI2c_setTransmitPacketSize(Ifx_I2C *i2c, Ifx_SizeT size);
181 
182 /**
183  * \return None
184  */
185 IFX_INLINE void IfxI2c_stop(Ifx_I2C *i2c);
186 
187 /**
188  * \return None
189  */
190 IFX_INLINE void IfxI2c_waitBusFree(Ifx_I2C *i2c);
191 
192 /** \brief Writes a packet (4 bytes) into the Fifo
193  * \return None
194  */
195 IFX_INLINE void IfxI2c_writeFifo(Ifx_I2C *i2c, uint32 packet);
196 
197 /******************************************************************************/
198 /*-------------------------Global Function Prototypes-------------------------*/
199 /******************************************************************************/
200 
201 /** \brief Configures the Module as Master
202  * \return None
203  */
204 IFX_EXTERN void IfxI2c_configureAsMaster(Ifx_I2C *i2c);
205 
206 /** \brief Disables the I2c Module
207  * \return None
208  */
209 IFX_EXTERN void IfxI2c_disableModule(Ifx_I2C *i2c);
210 
211 /** \brief Enables the I2c Module
212  * \return None
213  */
214 IFX_EXTERN void IfxI2c_enableModule(Ifx_I2C *i2c);
215 
216 /** \brief Returns the real Baudrate
217  * \return Baudrate
218  */
220 
221 /**
222  * \return None
223  */
225 
226 /** \brief Releases the bus, i.e puts a stop condition on the bus
227  * \return None
228  */
229 IFX_EXTERN void IfxI2c_releaseBus(Ifx_I2C *i2c);
230 
231 /**
232  * \return None
233  */
234 IFX_EXTERN void IfxI2c_resetFifo(Ifx_I2C *i2c);
235 
236 /** \brief Calculates the desired baudrate
237  * \return None
238  */
239 IFX_EXTERN void IfxI2c_setBaudrate(Ifx_I2C *i2c, float32 baudrate);
240 
241 /** \} */
242 
243 /******************************************************************************/
244 /*---------------------Inline Function Implementations------------------------*/
245 /******************************************************************************/
246 
248 {
249  return i2c->PIRQSS.B.AL;
250 }
251 
252 
253 IFX_INLINE boolean IfxI2c_busIsFree(Ifx_I2C *i2c)
254 {
255  boolean free = FALSE;
256 
257  if (i2c->BUSSTAT.B.BS == IfxI2c_BusStatus_idle)
258  {
259  free = TRUE;
260  }
261 
262  return free;
263 }
264 
265 
267 {
268  i2c->PIRQSC.B.AL = 1;
269 }
270 
271 
273 {
274  i2c->ERRIRQSC.U = (1 << IFX_I2C_ERRIRQSC_RXF_UFL_OFF) | (1 << IFX_I2C_ERRIRQSC_RXF_OFL_OFF) | (1 << IFX_I2C_ERRIRQSC_TXF_UFL_OFF) | (1 << IFX_I2C_ERRIRQSC_TXF_OFL_OFF);
275 }
276 
277 
279 {
280  i2c->ICR.U = (1 << IFX_I2C_ICR_LSREQ_INT_OFF) | (1 << IFX_I2C_ICR_SREQ_INT_OFF) | (1 << IFX_I2C_ICR_LBREQ_INT_OFF) | (1 << IFX_I2C_ICR_BREQ_INT_OFF);
281 }
282 
283 
285 {
286  i2c->PIRQSC.U = (1 << IFX_I2C_PIRQSC_AM_OFF) | (1 << IFX_I2C_PIRQSC_GC_OFF) | (1 << IFX_I2C_PIRQSC_MC_OFF) | (1 << IFX_I2C_PIRQSC_AL_OFF) | (1 << IFX_I2C_PIRQSC_NACK_OFF) | (1 << IFX_I2C_PIRQSC_TX_END_OFF) | (1 << IFX_I2C_PIRQSC_RX_OFF);
287 }
288 
289 
291 {
292  i2c->PIRQSC.B.NACK = 1;
293 }
294 
295 
297 {
298  i2c->PIRQSC.B.TX_END = 1;
299 }
300 
301 
303 {
304  return (IfxI2c_BusStatus)i2c->BUSSTAT.B.BS;
305 }
306 
307 
308 IFX_INLINE boolean IfxI2c_isFifoRequest(Ifx_I2C *i2c)
309 {
310  return i2c->RIS.U & 0x0F ? TRUE : FALSE;
311 }
312 
313 
314 IFX_INLINE boolean IfxI2c_isTxEndInterrupt(Ifx_I2C *i2c)
315 {
316  return (i2c->PIRQSS.B.TX_END != 0) ? TRUE : FALSE;
317 }
318 
319 
320 IFX_INLINE boolean IfxI2c_receivedNakFlag(Ifx_I2C *i2c)
321 {
322  return i2c->PIRQSS.B.NACK;
323 }
324 
325 
326 IFX_INLINE void IfxI2c_run(Ifx_I2C *i2c)
327 {
328  i2c->RUNCTRL.U = 1;
329 }
330 
331 
333 {
334  i2c->GPCTL.B.PISEL = pisel;
335 }
336 
337 
339 {
340  i2c->MRPSCTRL.B.MRPS = size;
341 }
342 
343 
344 IFX_INLINE void IfxI2c_setSlaveDeviceAddress(Ifx_I2C *i2c, uint16 address)
345 {
346  i2c->ADDRCFG.B.ADR = address;
347 }
348 
349 
351 {
352  i2c->TPSCTRL.B.TPS = size;
353 }
354 
355 
356 IFX_INLINE void IfxI2c_stop(Ifx_I2C *i2c)
357 {
358  i2c->RUNCTRL.U = 0;
359 }
360 
361 
362 IFX_INLINE void IfxI2c_waitBusFree(Ifx_I2C *i2c)
363 {
365  {}
366 }
367 
368 
369 IFX_INLINE void IfxI2c_writeFifo(Ifx_I2C *i2c, uint32 packet)
370 {
371  i2c->TXD.U = packet;
372 }
373 
374 
375 #endif /* IFXI2C_H */