iLLD_TC27xD  1.0
IfxQspi.h
Go to the documentation of this file.
1 /**
2  * \file IfxQspi.h
3  * \brief QSPI basic functionality
4  * \ingroup IfxLld_Qspi
5  *
6  * \version iLLD_1_0_0_11_0
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_Qspi_Std_Enum Enumerations
25  * \ingroup IfxLld_Qspi_Std
26  * \defgroup IfxLld_Qspi_Std_Operative Operative Functions
27  * \ingroup IfxLld_Qspi_Std
28  * \defgroup IfxLld_Qspi_Std_Support Support Functions
29  * \ingroup IfxLld_Qspi_Std
30  * \defgroup IfxLld_Qspi_Std_Interrupt Interrupt Functions
31  * \ingroup IfxLld_Qspi_Std
32  * \defgroup IfxLld_Qspi_Std_IO IO Pin Configuration Functions
33  * \ingroup IfxLld_Qspi_Std
34  */
35 
36 #ifndef IFXQSPI_H
37 #define IFXQSPI_H 1
38 
39 /******************************************************************************/
40 /*----------------------------------Includes----------------------------------*/
41 /******************************************************************************/
42 
43 #include "_Impl/IfxQspi_cfg.h"
45 #include "If/SpiIf.h"
46 #include "Scu/Std/IfxScuCcu.h"
47 #include "Src/Std/IfxSrc.h"
48 #include "_PinMap/IfxQspi_PinMap.h"
49 #include "IfxQspi_reg.h"
50 
51 /******************************************************************************/
52 /*--------------------------------Enumerations--------------------------------*/
53 /******************************************************************************/
54 
55 /** \addtogroup IfxLld_Qspi_Std_Enum
56  * \{ */
57 /** \brief QSPI channel Number (BACON.CS)
58  */
59 typedef enum
60 {
61  IfxQspi_ChannelId_0, /**< \brief Channel #0 */
62  IfxQspi_ChannelId_1, /**< \brief Channel #1 */
63  IfxQspi_ChannelId_2, /**< \brief Channel #2 */
64  IfxQspi_ChannelId_3, /**< \brief Channel #3 */
65  IfxQspi_ChannelId_4, /**< \brief Channel #4 */
66  IfxQspi_ChannelId_5, /**< \brief Channel #5 */
67  IfxQspi_ChannelId_6, /**< \brief Channel #6 */
68  IfxQspi_ChannelId_7, /**< \brief Channel #7 */
69  IfxQspi_ChannelId_8, /**< \brief Channel #8 */
70  IfxQspi_ChannelId_9, /**< \brief Channel #9 */
71  IfxQspi_ChannelId_10, /**< \brief Channel #10 */
72  IfxQspi_ChannelId_11, /**< \brief Channel #11 */
73  IfxQspi_ChannelId_12, /**< \brief Channel #12 */
74  IfxQspi_ChannelId_13, /**< \brief Channel #13 */
75  IfxQspi_ChannelId_14 /**< \brief Channel #14 */
77 
78 /** \brief Data length unit of a frame (BACON.BYTE)
79  */
80 typedef enum
81 {
82  IfxQspi_DataLengthUnit_bit = 0, /**< \brief Data Length in Bits */
83  IfxQspi_DataLengthUnit_byte = 1 /**< \brief Data length in Bytes */
85 
86 /** \brief QSPI Error Flags (STATUS.ERRORFLAGS)
87  */
88 typedef enum
89 {
90  IfxQspi_Error_none = 0, /**< \brief No Error */
91  IfxQspi_Error_parity = 1, /**< \brief Parity Error */
92  IfxQspi_Error_configuration = 2, /**< \brief Configuration Error */
93  IfxQspi_Error_baudrate = 4, /**< \brief BaudRate Error */
94  IfxQspi_Error_txfifoOverflow = 8, /**< \brief TX FIFO Overflow Error */
95  IfxQspi_Error_txfifoUnderflow = 16, /**< \brief TX FIFO Underflow Error */
96  IfxQspi_Error_rxfifoOverflow = 32, /**< \brief RX FIFO Overflow Error */
97  IfxQspi_Error_rxfifoUnderflow = 64, /**< \brief RX FIFO Underflow Error */
98  IfxQspi_Error_expectTimeout = 128, /**< \brief EXPECT Timeout Error */
99  IfxQspi_Error_slsiMisplacedInactivation = 256 /**< \brief SLSI misplaced inactivation (slave mode) */
100 } IfxQspi_Error;
101 
102 /** \brief Frame Expect phase time out value
103  */
104 typedef enum
105 {
106  IfxQspi_ExpectTimeout_64 = 0, /**< \brief Expect phse time out 64 */
107  IfxQspi_ExpectTimeout_128 = 1, /**< \brief Expect phse time out 128 */
108  IfxQspi_ExpectTimeout_256 = 2, /**< \brief Expect phse time out 256 */
109  IfxQspi_ExpectTimeout_512 = 3, /**< \brief Expect phse time out 512 */
110  IfxQspi_ExpectTimeout_1024 = 4, /**< \brief Expect phse time out 1024 */
111  IfxQspi_ExpectTimeout_2048 = 5, /**< \brief Expect phse time out 2048 */
112  IfxQspi_ExpectTimeout_4096 = 6, /**< \brief Expect phse time out 4096 */
113  IfxQspi_ExpectTimeout_8192 = 7, /**< \brief Expect phse time out 8192 */
114  IfxQspi_ExpectTimeout_16384 = 8, /**< \brief Expect phse time out 16384 */
115  IfxQspi_ExpectTimeout_32768 = 9, /**< \brief Expect phse time out 32768 */
116  IfxQspi_ExpectTimeout_65536 = 10, /**< \brief Expect phse time out 65536 */
117  IfxQspi_ExpectTimeout_131072 = 11, /**< \brief Expect phse time out 131072 */
118  IfxQspi_ExpectTimeout_262144 = 12, /**< \brief Expect phse time out 262144 */
119  IfxQspi_ExpectTimeout_524288 = 13, /**< \brief Expect phse time out 524288 */
120  IfxQspi_ExpectTimeout_1048576 = 14, /**< \brief Expect phse time out 1048576 */
121  IfxQspi_ExpectTimeout_2097152 = 15 /**< \brief Expect phse time out 2097152 */
123 
124 /** \brief QSPI controller mode (GLOBALCON.MODE)
125  */
126 typedef enum
127 {
128  IfxQspi_Mode_master = 0, /**< \brief QSPI in "master" mode */
129  IfxQspi_Mode_pwmOverQspi = 1, /**< \brief QSPI in "PWM over QSPI" mode */
130  IfxQspi_Mode_slave = 2 /**< \brief QSPI in "slave" mode */
131 } IfxQspi_Mode;
132 
133 /** \brief Request between pause and Run transition
134  */
135 typedef enum
136 {
137  IfxQspi_PauseRunTransition_pause = 0, /**< \brief Request value for pause */
138  IfxQspi_PauseRunTransition_run = 1 /**< \brief Request value for Run */
140 
141 /** \brief QSPI frame phase (STATUS.PHASE)
142  */
143 typedef enum
144 {
145  IfxQspi_Phase_wait = 0, /**< \brief Frame wait phase */
146  IfxQspi_Phase_idleA = 1, /**< \brief Frame idleA phase */
147  IfxQspi_Phase_idleB = 2, /**< \brief frame idleB phase */
148  IfxQspi_Phase_lead = 3, /**< \brief Frame lead phase */
149  IfxQspi_Phase_data = 4, /**< \brief Frame data phase */
150  IfxQspi_Phase_trail = 5, /**< \brief Frame trail phase */
151  IfxQspi_Phase_expect = 6, /**< \brief Frame expect phase */
152  IfxQspi_Phase_leadStrobe = 7, /**< \brief Frame leadstrobe phase */
153  IfxQspi_Phase_trailStrobe = 8 /**< \brief Frame trailstrobe phase */
154 } IfxQspi_Phase;
155 
156 /** \brief Phase Transition Event
157  */
158 typedef enum
159 {
160  IfxQspi_PhaseTransitionEvent_endOfWait = 0, /**< \brief BUSY (end of WAIT phase) */
161  IfxQspi_PhaseTransitionEvent_serialClockPolarityChange = 1, /**< \brief SCLKPC (serial clock polarity change) */
162  IfxQspi_PhaseTransitionEvent_startOfFrame = 2, /**< \brief SOF (Start Of Frame ) */
163  IfxQspi_PhaseTransitionEvent_transmitBufferEmptied = 3, /**< \brief TBE (Transmit Buffer Emptied) */
164  IfxQspi_PhaseTransitionEvent_receiveBufferFilled = 4, /**< \brief RBF (Receive Buffer Filled) */
165  IfxQspi_PhaseTransitionEvent_endOfFrame = 5, /**< \brief EOF (End of Frame) */
166  IfxQspi_PhaseTransitionEvent_dataNotAvailable = 6, /**< \brief DNA (Data not Available = Start of Expect) */
167  IfxQspi_PhaseTransitionEvent_endOfExpect = 7 /**< \brief CONT (End of EXPECT phase) */
169 
170 /** \brief Reset Request (GLOBALCON.RESETS)
171  */
172 typedef enum
173 {
174  IfxQspi_Reset_none = 0, /**< \brief No Reset */
175  IfxQspi_Reset_stateMachineAndFifo = 1, /**< \brief State Machine, TXFIFO and RXFIFO reset, registers not reseted */
176  IfxQspi_Reset_registers = 2, /**< \brief Registers Reset */
177  IfxQspi_Reset_kernel = 3 /**< \brief Kernel / Module Reset */
178 } IfxQspi_Reset;
179 
180 /** \brief Receive Fifo Interrupt Threshold
181  */
182 typedef enum
183 {
184  IfxQspi_RxFifoInt_0, /**< \brief RxFifo Interrupt Threshold #0 */
185  IfxQspi_RxFifoInt_1, /**< \brief RxFifo Interrupt Threshold #1 */
186  IfxQspi_RxFifoInt_2, /**< \brief RxFifo Interrupt Threshold #2 */
187  IfxQspi_RxFifoInt_3 /**< \brief RxFifo Interrupt Threshold #3 */
189 
190 /** \brief Enable/disable the sensitivity of the module to sleep signal\n
191  * Definition in Ifx_QSPI.CLC.B.EDIS
192  */
193 typedef enum
194 {
195  IfxQspi_SleepMode_enable = 0, /**< \brief Sleep Mode enabled */
196  IfxQspi_SleepMode_disable = 1 /**< \brief Sleep Mode disabled */
198 
199 /** \brief STROBE delay for SLSO in delayed mode (GLOBALCON.STROBE)
200  */
201 typedef enum
202 {
203  IfxQspi_StrobeDelay_1, /**< \brief SLSO delay 1 cycle(s) */
204  IfxQspi_StrobeDelay_2, /**< \brief SLSO delay 2 cycle(s) */
205  IfxQspi_StrobeDelay_3, /**< \brief SLSO delay 3 cycle(s) */
206  IfxQspi_StrobeDelay_4, /**< \brief SLSO delay 4 cycle(s) */
207  IfxQspi_StrobeDelay_5, /**< \brief SLSO delay 5 cycle(s) */
208  IfxQspi_StrobeDelay_6, /**< \brief SLSO delay 6 cycle(s) */
209  IfxQspi_StrobeDelay_7, /**< \brief SLSO delay 7 cycle(s) */
210  IfxQspi_StrobeDelay_8, /**< \brief SLSO delay 8 cycle(s) */
211  IfxQspi_StrobeDelay_9, /**< \brief SLSO delay 9 cycle(s) */
212  IfxQspi_StrobeDelay_10, /**< \brief SLSO delay 10 cycle(s) */
213  IfxQspi_StrobeDelay_11, /**< \brief SLSO delay 11 cycle(s) */
214  IfxQspi_StrobeDelay_12, /**< \brief SLSO delay 12 cycle(s) */
215  IfxQspi_StrobeDelay_13, /**< \brief SLSO delay 13 cycle(s) */
216  IfxQspi_StrobeDelay_14, /**< \brief SLSO delay 14 cycle(s) */
217  IfxQspi_StrobeDelay_15, /**< \brief SLSO delay 15 cycle(s) */
218  IfxQspi_StrobeDelay_16, /**< \brief SLSO delay 16 cycle(s) */
219  IfxQspi_StrobeDelay_17, /**< \brief SLSO delay 17 cycle(s) */
220  IfxQspi_StrobeDelay_18, /**< \brief SLSO delay 18 cycle(s) */
221  IfxQspi_StrobeDelay_19, /**< \brief SLSO delay 19 cycle(s) */
222  IfxQspi_StrobeDelay_20, /**< \brief SLSO delay 20 cycle(s) */
223  IfxQspi_StrobeDelay_21, /**< \brief SLSO delay 21 cycle(s) */
224  IfxQspi_StrobeDelay_22, /**< \brief SLSO delay 22 cycle(s) */
225  IfxQspi_StrobeDelay_23, /**< \brief SLSO delay 23 cycle(s) */
226  IfxQspi_StrobeDelay_24, /**< \brief SLSO delay 24 cycle(s) */
227  IfxQspi_StrobeDelay_25, /**< \brief SLSO delay 25 cycle(s) */
228  IfxQspi_StrobeDelay_26, /**< \brief SLSO delay 26 cycle(s) */
229  IfxQspi_StrobeDelay_27, /**< \brief SLSO delay 27 cycle(s) */
230  IfxQspi_StrobeDelay_28, /**< \brief SLSO delay 28 cycle(s) */
231  IfxQspi_StrobeDelay_29, /**< \brief SLSO delay 29 cycle(s) */
232  IfxQspi_StrobeDelay_30, /**< \brief SLSO delay 30 cycle(s) */
233  IfxQspi_StrobeDelay_31, /**< \brief SLSO delay 31 cycle(s) */
234  IfxQspi_StrobeDelay_32 /**< \brief SLSO delay 32 cycle(s) */
236 
237 /** \brief OCDS Suspend Control (OCDS.SUS)
238  */
239 typedef enum
240 {
241  IfxQspi_Suspend_none = 0, /**< \brief No suspend */
242  IfxQspi_Suspend_hard = 1, /**< \brief Hard Suspend */
243  IfxQspi_Suspend_soft = 2 /**< \brief Soft Suspend */
245 
246 /** \brief Transmit Fifo Interrupt Threshold
247  */
248 typedef enum
249 {
250  IfxQspi_TxFifoInt_1, /**< \brief TxFifo Interrupt Threshold #1 */
251  IfxQspi_TxFifoInt_2, /**< \brief TxFifo Interrupt Threshold #2 */
252  IfxQspi_TxFifoInt_3, /**< \brief TxFifo Interrupt Threshold #3 */
253  IfxQspi_TxFifoInt_4 /**< \brief TxFifo Interrupt Threshold #4 */
255 
256 /** \} */
257 
258 /** \addtogroup IfxLld_Qspi_Std_Operative
259  * \{ */
260 
261 /******************************************************************************/
262 /*-------------------------Inline Function Prototypes-------------------------*/
263 /******************************************************************************/
264 
265 /** \brief Clear ALL service requests
266  * \param qspi Pointer to QSPI module registers
267  * \return None
268  */
269 IFX_INLINE void IfxQspi_clearAllEventFlags(Ifx_QSPI *qspi);
270 
271 /** \brief Clear RX service requests
272  * \param qspi Pointer to QSPI module registers
273  * \return None
274  */
275 IFX_INLINE void IfxQspi_clearRxReq(Ifx_QSPI *qspi);
276 
277 /** \brief Clear TX service requests
278  * \param qspi Pointer to QSPI module registers
279  * \return None
280  */
281 IFX_INLINE void IfxQspi_clearTxReq(Ifx_QSPI *qspi);
282 
283 /** \brief Configure PT1 event (also USR event depending if USREN=1 )
284  * \param qspi Pointer to QSPI module registers
285  * \param pt1Config Phase Transition1 Event Config
286  * \return None
287  */
288 IFX_INLINE void IfxQspi_configPT1Event(Ifx_QSPI *qspi, IfxQspi_PhaseTransitionEvent pt1Config);
289 
290 /** \brief Configure PT2 event
291  * \param qspi Pointer to QSPI module registers
292  * \param pt2Config Phase Transition2 Event Config
293  * \return None
294  */
295 IFX_INLINE void IfxQspi_configPT2Event(Ifx_QSPI *qspi, IfxQspi_PhaseTransitionEvent pt2Config);
296 
297 /** \brief Enable/Disable Loopback mode.
298  * \param qspi Pointer to QSPI module registers
299  * \param enable Enable / Disable loopback
300  * \return None
301  */
302 IFX_INLINE void IfxQspi_enableLoopbackMode(Ifx_QSPI *qspi, boolean enable);
303 
304 /** \brief enable Hard/Soft Module suspend
305  * Note: The api works only when the OCDS is enabled and in Supervisor Mode. When OCDS is disabled the OCS suspend control is ineffective.
306  * \param qspi Pointer to QSPI module registers
307  * \param suspend Module suspend
308  * \return None
309  */
310 IFX_INLINE void IfxQspi_enableModuleSuspend(Ifx_QSPI *qspi, IfxQspi_Suspend suspend);
311 
312 /** \brief enable Phase Transition1 Event
313  * \param qspi Pointer to QSPI module registers
314  * \param enable Enable (1) / Disable (0)
315  * \return None
316  */
317 IFX_INLINE void IfxQspi_enablePT1Event(Ifx_QSPI *qspi, boolean enable);
318 
319 /** \brief enable Phase Transition2 Event
320  * \param qspi Pointer to QSPI module registers
321  * \param enable Enable (1) / Disable (0)
322  * \return None
323  */
324 IFX_INLINE void IfxQspi_enablePT2Event(Ifx_QSPI *qspi, boolean enable);
325 
326 /** \brief enable User Event (Event selected by PT1)
327  * \param qspi Pointer to QSPI module registers
328  * \param enable Enable (1) / Disable (0)
329  * \return None
330  */
331 IFX_INLINE void IfxQspi_enableUsrEvent(Ifx_QSPI *qspi, boolean enable);
332 
333 /**
334  * \param qspi Pointer to QSPI module registers
335  * \return Error Flags
336  */
337 IFX_INLINE uint16 IfxQspi_getErrorFlags(Ifx_QSPI *qspi);
338 
339 /** \brief Request for Module in Pause state
340  * no interrupts
341  * no communication
342  * \param qspi Pointer to QSPI module registers
343  * \return None
344  */
345 IFX_INLINE void IfxQspi_pause(Ifx_QSPI *qspi);
346 
347 /** \brief Read the oldest data from RXFIFO
348  * \param qspi Pointer to QSPI module registers
349  */
351 
352 /** \brief Request reset (State Machine & FIFO / Register / Module)
353  * \param qspi Pointer to QSPI module registers
354  * \param reset reset type (GLOBALCON.RESETS)
355  * \return None
356  */
357 IFX_INLINE void IfxQspi_requestReset(Ifx_QSPI *qspi, IfxQspi_Reset reset);
358 
359 /** \brief Request for QSPI in Run state
360  * \param qspi Pointer to QSPI module registers
361  * \return None
362  */
363 IFX_INLINE void IfxQspi_run(Ifx_QSPI *qspi);
364 
365 /** \brief Set the threshold of RXFIFO for service request generation
366  * \param qspi Pointer to QSPI module registers
367  * \param rxFifoInt RxFIFO Interrupt threshold to set
368  * \return None
369  */
371 
372 /** \brief Write Data into DATAENTRY register
373  * \param qspi Pointer to QSPI module registers
374  * \param data Data to be entered into TxFIFO
375  * \return None
376  */
377 IFX_INLINE void IfxQspi_writeTransmitFifo(Ifx_QSPI *qspi, uint32 data);
378 
379 /******************************************************************************/
380 /*-------------------------Global Function Prototypes-------------------------*/
381 /******************************************************************************/
382 
383 /** \brief Reads 16bit data from the Rx FIFO
384  * \param qspi Pointer to QSPI module registers
385  * \param data Received data will be copied into this array
386  * \param count Number of items to be received
387  * \return None
388  */
389 IFX_EXTERN void IfxQspi_read16(Ifx_QSPI *qspi, uint16 *data, Ifx_SizeT count);
390 
391 /** \brief Reads 32bit data from the Rx FIFO
392  * \param qspi Pointer to QSPI module registers
393  * \param data Received data will be copied into this array
394  * \param count Number of items to be received
395  * \return None
396  */
397 IFX_EXTERN void IfxQspi_read32(Ifx_QSPI *qspi, uint32 *data, Ifx_SizeT count);
398 
399 /** \brief Reads 8bit data from the Rx FIFO
400  * \param qspi Pointer to QSPI module registers
401  * \param data Received data will be copied into this array
402  * \param count Number of items to be received
403  * \return None
404  */
405 IFX_EXTERN void IfxQspi_read8(Ifx_QSPI *qspi, uint8 *data, Ifx_SizeT count);
406 
407 /** \brief resets QSPI kernel
408  * \param qspi pointer to QSPI registers
409  * \return None
410  */
411 IFX_EXTERN void IfxQspi_resetModule(Ifx_QSPI *qspi);
412 
413 /** \brief Writes 16bit data into the Tx FIFO
414  * \param qspi Pointer to QSPI module registers
415  * \param channelId Channel number to which econ val belongs
416  * \param data Array of data to be sent
417  * \param count Number of items to be sent
418  * \return None
419  */
420 IFX_EXTERN void IfxQspi_write16(Ifx_QSPI *qspi, IfxQspi_ChannelId channelId, uint16 *data, Ifx_SizeT count);
421 
422 /** \brief Writes 32bit data into the Tx FIFO
423  * \param qspi Pointer to QSPI module registers
424  * \param channelId Channel number to which econ val belongs
425  * \param data Array of data to be sent
426  * \param count Number of items to be sent
427  * \return None
428  */
429 IFX_EXTERN void IfxQspi_write32(Ifx_QSPI *qspi, IfxQspi_ChannelId channelId, uint32 *data, Ifx_SizeT count);
430 
431 /** \brief Writes 8bit data into the Tx FIFO
432  * \param qspi Pointer to QSPI module registers
433  * \param channelId Channel number to which econ val belongs
434  * \param data Array of data to be sent
435  * \param count Number of items to be sent
436  * \return None
437  */
438 IFX_EXTERN void IfxQspi_write8(Ifx_QSPI *qspi, IfxQspi_ChannelId channelId, uint8 *data, Ifx_SizeT count);
439 
440 /** \} */
441 
442 /** \addtogroup IfxLld_Qspi_Std_Support
443  * \{ */
444 
445 /******************************************************************************/
446 /*-------------------------Inline Function Prototypes-------------------------*/
447 /******************************************************************************/
448 
449 /** \brief flush the receive FIFO
450  * \param qspi Pointer to QSPI module registers
451  * \return None
452  */
453 IFX_INLINE void IfxQspi_flushReceiveFifo(Ifx_QSPI *qspi);
454 
455 /** \brief flush the transmit FIFO
456  * \param qspi Pointer to QSPI module registers
457  * \return None
458  */
459 IFX_INLINE void IfxQspi_flushTransmitFifo(Ifx_QSPI *qspi);
460 
461 /** \brief Gets the current mode of QSPI
462  * \param qspi Pointer to QSPI module registers
463  * \return The current mode
464  */
465 IFX_INLINE IfxQspi_Mode IfxQspi_getMode(Ifx_QSPI *qspi);
466 
467 /** \brief Specifies function to get module frequency
468  * \param qspi Pointer to QSPI module registers
469  * \return Module frequency in Float value
470  */
471 IFX_INLINE float IfxQspi_getModuleFrequency(Ifx_QSPI *qspi);
472 
473 /** \brief Gets actual transmission phase
474  * \param qspi Pointer to QSPI module registers
475  * \return Actual transmission phase
476  */
478 
479 /** \brief Gets the filling level of RXFIFO
480  * \param qspi Pointer to QSPI module registers
481  * \return RxFIFO level
482  */
484 
485 /** \brief Gets Time Quanta frequency
486  * \param qspi Pointer to QSPI module registers
487  * \return TQ frequency in float
488  */
489 IFX_INLINE float IfxQspi_getTimeQuantaFrequency(Ifx_QSPI *qspi);
490 
491 /** \brief Gets the filling level of TXFIFO
492  * \param qspi Pointer to QSPI module registers
493  * \return TxFIFO level
494  */
496 
497 /** \brief Specifies the Module enable or disable status
498  * \param qspi Pointer to QSPI module registers
499  * \return TRUE if module is enabled otherwise FALSE
500  */
501 IFX_INLINE boolean IfxQspi_isModuleEnabled(Ifx_QSPI *qspi);
502 
503 /** \brief Sets the disable module request
504  * \param qspi Pointer to QSPI module registers
505  * \return None
506  */
507 IFX_INLINE void IfxQspi_setDisableModuleRequest(Ifx_QSPI *qspi);
508 
509 /** \brief Sets the enable module request
510  * \param qspi Pointer to QSPI module registers
511  * \return None
512  */
513 IFX_INLINE void IfxQspi_setEnableModuleRequest(Ifx_QSPI *qspi);
514 
515 /** \brief Sets the disable module request
516  * \param qspi Pointer to QSPI module registers
517  * \param mode Sleep mode selection
518  * \return None
519  */
520 IFX_INLINE void IfxQspi_setSleepMode(Ifx_QSPI *qspi, IfxQspi_SleepMode mode);
521 
522 /** \brief Set the threshold of TXFIFO for service request generation
523  * \param qspi Pointer to QSPI module registers
524  * \param txFifoInt TxFifo Interrupt threshold to set
525  * \return None
526  */
528 
529 /** \brief Write configuration into BACON register
530  * \param qspi Pointer to QSPI module registers
531  * \param baconVal baconVal Value to be entered in BACON register
532  * \return None
533  */
534 IFX_INLINE void IfxQspi_writeBasicConfiguration(Ifx_QSPI *qspi, uint32 baconVal);
535 
536 /** \brief Write configuration into BACON register with .LAST flag set to 0
537  * \param qspi Pointer to QSPI module registers
538  * \param baconVal baconVal Value to be entered in BACON register
539  * \return None
540  */
541 IFX_INLINE void IfxQspi_writeBasicConfigurationBeginStream(Ifx_QSPI *qspi, uint32 baconVal);
542 
543 /** \brief Write configuration into BACON register with .LAST flag set to 1
544  * \param qspi Pointer to QSPI module registers
545  * \param baconVal baconVal Value to be entered in BACON register
546  * \return None
547  */
548 IFX_INLINE void IfxQspi_writeBasicConfigurationEndStream(Ifx_QSPI *qspi, uint32 baconVal);
549 
550 /** \brief Writes channel timing configuration into ECON register
551  * \param qspi Pointer to QSPI module registers
552  * \param channelId Channel number to which econ val belongs
553  * \param econVal Extended configuration value
554  * \return None
555  */
556 IFX_INLINE void IfxQspi_writeExtendedConfiguration(Ifx_QSPI *qspi, IfxQspi_ChannelId channelId, uint32 econVal);
557 
558 /** \brief Writes Data and Configuration into MIXEDENTRY register
559  * \param qspi Pointer to QSPI module registers
560  * \param mixEntryVal Data and configuration in mixed
561  * \return None
562  */
563 IFX_INLINE void IfxQspi_writeMixedDataTransmitFifo(Ifx_QSPI *qspi, uint32 mixEntryVal);
564 
565 /******************************************************************************/
566 /*-------------------------Global Function Prototypes-------------------------*/
567 /******************************************************************************/
568 
569 /** \brief Function to calculate baudrate of specified channel
570  * \param qspi Pointer to QSPI module registers
571  * \param channelId QSPI channel number
572  * \return Actual baudrate in float
573  */
574 IFX_EXTERN float IfxQspi_calcRealBaudrate(Ifx_QSPI *qspi, IfxQspi_ChannelId channelId);
575 
576 /** \brief Function to calculate BACON register values
577  * \param qspi Pointer to QSPI module registers
578  * \param channelId QSPI Channel Number
579  * \param chMode Frame configuration
580  * \param baudrate The desired baudrate
581  * \return Calculated BACON value
582  */
583 IFX_EXTERN uint32 IfxQspi_calculateBasicConfigurationValue(Ifx_QSPI *qspi, const IfxQspi_ChannelId channelId, const SpiIf_ChMode *chMode, const float baudrate);
584 
585 /** \brief Function to calculate ECON register values
586  * \param qspi Pointer to QSPI module registers
587  * \param cs QSPI channel Number : 8->0,9->1,.......
588  * \param chConfig SPI Channel Configuration
589  * \return Calculated ECON[CS] value
590  */
591 IFX_EXTERN uint32 IfxQspi_calculateExtendedConfigurationValue(Ifx_QSPI *qspi, const uint8 cs, const SpiIf_ChConfig *chConfig);
592 
593 /** \brief Function to calculate prescaler
594  * \param qspi Pointer to QSPI module registers
595  * \param baudrate Maximum baudrate in Float
596  * \return Prescaler in integer
597  */
598 IFX_EXTERN uint32 IfxQspi_calculatePrescaler(Ifx_QSPI *qspi, float baudrate);
599 
600 /** \brief Specifies the function to calculate Time quantum length
601  * \param qspi Pointer to QSPI module registers
602  * \param maxBaudrate Maximum baudrate in Float
603  * \return Time quantum length in integer
604  */
605 IFX_EXTERN uint32 IfxQspi_calculateTimeQuantumLength(Ifx_QSPI *qspi, float maxBaudrate);
606 
607 /** \brief Re-calculated BACON from the oldBACON
608  * \param oldBACON Old BACON value
609  * \param numOfData numOfData in LONG or CONTINUOUS mode
610  * \param shortData Specifies SHORT mode (TRUE) or other modes (FALSE)
611  * \param lastData Specifies last data in LONG or CONTINUOUS
612  * \return Re-calculated BACON
613  */
614 IFX_EXTERN uint32 IfxQspi_recalcBasicConfiguration(uint32 oldBACON, Ifx_SizeT numOfData, boolean shortData, boolean lastData);
615 
616 /** \brief Configures a Slave Select Output
617  * \param qspi Pointer to QSPI module registers
618  * \param channelId Channel number to which econ val belongs
619  * \param outputEnable chip select output will be enabled during transaction
620  * \param activeLevel TRUE: active-high, FALSE: active-low
621  * \return None
622  */
623 IFX_EXTERN void IfxQspi_setSlaveSelectOutputControl(Ifx_QSPI *qspi, IfxQspi_ChannelId channelId, boolean outputEnable, boolean activeLevel);
624 
625 /** \} */
626 
627 /** \addtogroup IfxLld_Qspi_Std_Interrupt
628  * \{ */
629 
630 /******************************************************************************/
631 /*-------------------------Inline Function Prototypes-------------------------*/
632 /******************************************************************************/
633 
634 /** \brief Gets the Error request value
635  * \param qspi Pointer to QSPI module registers
636  * \return Error request value
637  */
638 IFX_INLINE volatile Ifx_SRC_SRCR *IfxQspi_getErrorSrc(Ifx_QSPI *qspi);
639 
640 /** \brief Specifies the function to get Index
641  * \param qspi Pointer to QSPI module registers
642  * \return Index in Integer
643  */
644 IFX_INLINE uint32 IfxQspi_getIndex(Ifx_QSPI *qspi);
645 
646 /** \brief Gets the RXFIFO service request
647  * \param qspi Pointer to QSPI module registers
648  * \return Receive service request value
649  */
650 IFX_INLINE volatile Ifx_SRC_SRCR *IfxQspi_getReceiveSrc(Ifx_QSPI *qspi);
651 
652 /** \brief Gets the TXFIFO service request
653  * \param qspi Pointer to QSPI module registers
654  * \return Transmission service request value
655  */
656 IFX_INLINE volatile Ifx_SRC_SRCR *IfxQspi_getTransmitSrc(Ifx_QSPI *qspi);
657 
658 /** \} */
659 
660 /** \addtogroup IfxLld_Qspi_Std_IO
661  * \{ */
662 
663 /******************************************************************************/
664 /*-------------------------Inline Function Prototypes-------------------------*/
665 /******************************************************************************/
666 
667 /** \brief Initializes a MRST input
668  * \param mrstIn the MRST Pin which should be configured
669  * \param mrstInMode the pin input mode which should be configured
670  * \return None
671  */
672 IFX_INLINE void IfxQspi_initMrstInPin(const IfxQspi_Mrst_In *mrstIn, IfxPort_InputMode mrstInMode);
673 
674 /** \brief Initializes a MRST output
675  * \param mrstOut the MRST Pin which should be configured
676  * \param mrstOutMode the pin output mode which should be configured
677  * \param padDriver the pad driver mode which should be configured
678  * \return None
679  */
680 IFX_INLINE void IfxQspi_initMrstOutPin(const IfxQspi_Mrst_Out *mrstOut, IfxPort_OutputMode mrstOutMode, IfxPort_PadDriver padDriver);
681 
682 /** \brief Initializes a MTSR input
683  * \param mtsrIn the MTSR Pin which should be configured
684  * \param mtsrInMode the pin input mode which should be configured
685  * \return None
686  */
687 IFX_INLINE void IfxQspi_initMtsrInPin(const IfxQspi_Mtsr_In *mtsrIn, IfxPort_InputMode mtsrInMode);
688 
689 /** \brief Initializes a MTSR output
690  * \param mtsrOut the MTSR Pin which should be configured
691  * \param mtsrOutMode the pin output mode which should be configured
692  * \param padDriver the pad driver mode which should be configured
693  * \return None
694  */
695 IFX_INLINE void IfxQspi_initMtsrOutPin(const IfxQspi_Mtsr_Out *mtsrOut, IfxPort_OutputMode mtsrOutMode, IfxPort_PadDriver padDriver);
696 
697 /** \brief Initializes a SCLK input
698  * \param sclkIn the SCLK Pin which should be configured
699  * \param sclkInMode the pin input mode which should be configured
700  * \return None
701  */
702 IFX_INLINE void IfxQspi_initSclkInPin(const IfxQspi_Sclk_In *sclkIn, IfxPort_InputMode sclkInMode);
703 
704 /** \brief Initializes a SCLK output
705  * \param sclkOut the SCLK Pin which should be configured
706  * \param sclkOutMode the pin output mode which should be configured
707  * \param padDriver the pad driver mode which should be configured
708  * \return None
709  */
710 IFX_INLINE void IfxQspi_initSclkOutPin(const IfxQspi_Sclk_Out *sclkOut, IfxPort_OutputMode sclkOutMode, IfxPort_PadDriver padDriver);
711 
712 /** \brief Initializes a SLSI input
713  * \param slsi the SLSI Pin which should be configured
714  * \param slsiMode the pin input mode which should be configured
715  * \return None
716  */
718 
719 /** \brief Initializes a SLSO output
720  * \param slso the SLSO Pin which should be configured
721  * \param slsoMode the pin output mode which should be configured
722  * \param padDriver the pad driver mode which should be configured
723  * \param outIndex Pin Pad driver index
724  * \return None
725  */
727 
728 /** \} */
729 
730 /******************************************************************************/
731 /*---------------------Inline Function Implementations------------------------*/
732 /******************************************************************************/
733 
735 {
736  qspi->FLAGSCLEAR.U = 0xFFFFU;
737 }
738 
739 
740 IFX_INLINE void IfxQspi_clearRxReq(Ifx_QSPI *qspi)
741 {
742  qspi->FLAGSCLEAR.B.RXC = 1U;
743 }
744 
745 
746 IFX_INLINE void IfxQspi_clearTxReq(Ifx_QSPI *qspi)
747 {
748  qspi->FLAGSCLEAR.B.TXC = 1U;
749 }
750 
751 
753 {
754  qspi->GLOBALCON1.B.PT1 = pt1Config;
755 }
756 
757 
759 {
760  qspi->GLOBALCON1.B.PT2 = pt2Config;
761 }
762 
763 
764 IFX_INLINE void IfxQspi_enableLoopbackMode(Ifx_QSPI *qspi, boolean enable)
765 {
766  qspi->GLOBALCON.B.LB = 1;
767 }
768 
769 
771 {
772  Ifx_QSPI_OCS ocs;
773  ocs.U = qspi->OCS.U;
774 
775  // remove protection ie SUS_P to 0 (32 bit write only.)
776  ocs.B.SUS_P = 0;
777  qspi->OCS.U = ocs.U;
778  ocs.U = qspi->OCS.U;
779 
780  ocs.B.SUS = suspend;
781  // enable protection bit?
782  qspi->OCS.U = ocs.U;
783 }
784 
785 
786 IFX_INLINE void IfxQspi_enablePT1Event(Ifx_QSPI *qspi, boolean enable)
787 {
788  qspi->GLOBALCON1.B.PT1EN = enable;
789 }
790 
791 
792 IFX_INLINE void IfxQspi_enablePT2Event(Ifx_QSPI *qspi, boolean enable)
793 {
794  qspi->GLOBALCON1.B.PT2EN = enable;
795 }
796 
797 
798 IFX_INLINE void IfxQspi_enableUsrEvent(Ifx_QSPI *qspi, boolean enable)
799 {
800  qspi->GLOBALCON1.B.USREN = enable;
801 }
802 
803 
805 {
806  // Flush RXFIFO
807  qspi->GLOBALCON.B.RESETS = 4;
808 }
809 
810 
812 {
813  // Flush TXFIFO
814  qspi->GLOBALCON.B.RESETS = 2;
815 }
816 
817 
819 {
820  return qspi->STATUS.B.ERRORFLAGS;
821 }
822 
823 
824 IFX_INLINE volatile Ifx_SRC_SRCR *IfxQspi_getErrorSrc(Ifx_QSPI *qspi)
825 {
826  uint32 index = IfxQspi_getIndex(qspi);
827  return &MODULE_SRC.QSPI.QSPI[index].ERR;
828 }
829 
830 
832 {
833  uint32 base = (uint32)&MODULE_QSPI0;
834  uint32 singleDistance = ((uint32)&MODULE_QSPI1) - base;
835  uint32 distance = ((uint32)qspi) - base;
836  uint32 index = distance / singleDistance;
837  return index;
838 }
839 
840 
842 {
843  return (IfxQspi_Mode)qspi->GLOBALCON.B.MS;
844 }
845 
846 
848 {
849  return IfxScuCcu_getMaxFrequency();
850 }
851 
852 
854 {
855  return (IfxQspi_Phase)qspi->STATUS.B.PHASE;
856 }
857 
858 
860 {
861  return qspi->STATUS.B.RXFIFOLEVEL;
862 }
863 
864 
865 IFX_INLINE volatile Ifx_SRC_SRCR *IfxQspi_getReceiveSrc(Ifx_QSPI *qspi)
866 {
867  uint32 index = IfxQspi_getIndex(qspi);
868  return &MODULE_SRC.QSPI.QSPI[index].RX;
869 }
870 
871 
873 {
874  return IfxQspi_getModuleFrequency(qspi) / (qspi->GLOBALCON.B.TQ + 1);
875 }
876 
877 
879 {
880  return qspi->STATUS.B.TXFIFOLEVEL;
881 }
882 
883 
884 IFX_INLINE volatile Ifx_SRC_SRCR *IfxQspi_getTransmitSrc(Ifx_QSPI *qspi)
885 {
886  uint32 index = IfxQspi_getIndex(qspi);
887  return &MODULE_SRC.QSPI.QSPI[index].TX;
888 }
889 
890 
892 {
893  IfxPort_setPinModeInput(mrstIn->pin.port, mrstIn->pin.pinIndex, mrstInMode);
894  mrstIn->module->PISEL.B.MRIS = mrstIn->select;
895 }
896 
897 
899 {
900  IfxPort_setPinModeOutput(mrstOut->pin.port, mrstOut->pin.pinIndex, mrstOutMode, mrstOut->select);
901  IfxPort_setPinPadDriver(mrstOut->pin.port, mrstOut->pin.pinIndex, padDriver);
902 }
903 
904 
906 {
907  IfxPort_setPinModeInput(mtsrIn->pin.port, mtsrIn->pin.pinIndex, mtsrInMode);
908  mtsrIn->module->PISEL.B.SRIS = mtsrIn->select;
909 }
910 
911 
913 {
914  IfxPort_setPinModeOutput(mtsrOut->pin.port, mtsrOut->pin.pinIndex, mtsrOutMode, mtsrOut->select);
915  IfxPort_setPinPadDriver(mtsrOut->pin.port, mtsrOut->pin.pinIndex, padDriver);
916 }
917 
918 
920 {
921  IfxPort_setPinModeInput(sclkIn->pin.port, sclkIn->pin.pinIndex, sclkInMode);
922  sclkIn->module->PISEL.B.SCIS = sclkIn->select;
923 }
924 
925 
927 {
928  IfxPort_setPinModeOutput(sclkOut->pin.port, sclkOut->pin.pinIndex, sclkOutMode, sclkOut->select);
929  IfxPort_setPinPadDriver(sclkOut->pin.port, sclkOut->pin.pinIndex, padDriver);
930 }
931 
932 
934 {
935  IfxPort_setPinModeInput(slsi->pin.port, slsi->pin.pinIndex, slsiMode);
936  /* PISEL */
937  slsi->module->PISEL.B.SLSIS = slsi->select + 1;
938 }
939 
940 
942 {
943  IfxPort_setPinModeOutput(slso->pin.port, slso->pin.pinIndex, slsoMode, outIndex);
944  IfxPort_setPinPadDriver(slso->pin.port, slso->pin.pinIndex, padDriver);
945 }
946 
947 
948 IFX_INLINE boolean IfxQspi_isModuleEnabled(Ifx_QSPI *qspi)
949 {
950  return (qspi->CLC.B.DISS == 0) ? TRUE : FALSE;
951 }
952 
953 
954 IFX_INLINE void IfxQspi_pause(Ifx_QSPI *qspi)
955 {
956  qspi->GLOBALCON.B.EN = 0;
957 
958  while (IfxQspi_getPhase(qspi) != IfxQspi_Phase_wait)
959  {}
960 }
961 
962 
964 {
965  return qspi->RXEXIT.U;
966 }
967 
968 
969 IFX_INLINE void IfxQspi_requestReset(Ifx_QSPI *qspi, IfxQspi_Reset reset)
970 {
971  qspi->GLOBALCON.B.RESETS = reset;
972 }
973 
974 
975 IFX_INLINE void IfxQspi_run(Ifx_QSPI *qspi)
976 {
977  qspi->GLOBALCON.B.EN = 1;
978 }
979 
980 
982 {
983  qspi->CLC.B.DISR = 1;
984 }
985 
986 
988 {
989  qspi->CLC.B.DISR = 0;
990 }
991 
992 
994 {
995  qspi->GLOBALCON1.B.RXFIFOINT = rxFifoInt;
996 }
997 
998 
1000 {
1001  qspi->CLC.B.EDIS = mode;
1002 }
1003 
1004 
1006 {
1007  qspi->GLOBALCON1.B.TXFIFOINT = txFifoInt;
1008 }
1009 
1010 
1011 IFX_INLINE void IfxQspi_writeBasicConfiguration(Ifx_QSPI *qspi, uint32 baconVal)
1012 {
1013  qspi->BACONENTRY.U = baconVal;
1014 }
1015 
1016 
1018 {
1019  Ifx_QSPI_BACON bacon;
1020  bacon.U = baconVal;
1021  bacon.B.LAST = 0;
1022 
1023  qspi->BACONENTRY.U = bacon.U;
1024 }
1025 
1026 
1028 {
1029  Ifx_QSPI_BACON bacon;
1030  bacon.U = baconVal;
1031  bacon.B.LAST = 1;
1032 
1033  qspi->BACONENTRY.U = bacon.U;
1034 }
1035 
1036 
1038 {
1039  int cs = channelId % 8;
1040  qspi->ECON[cs].U = econVal;
1041 }
1042 
1043 
1044 IFX_INLINE void IfxQspi_writeMixedDataTransmitFifo(Ifx_QSPI *qspi, uint32 mixEntryVal)
1045 {
1046  qspi->MIXENTRY.U = mixEntryVal;
1047 }
1048 
1049 
1050 IFX_INLINE void IfxQspi_writeTransmitFifo(Ifx_QSPI *qspi, uint32 data)
1051 {
1052  qspi->DATAENTRY[0].U = data;
1053 }
1054 
1055 
1056 #endif /* IFXQSPI_H */