1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2022 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef __FSL_FLEXSPI_H_
10 #define __FSL_FLEXSPI_H_
11 
12 #include <stddef.h>
13 #include "fsl_device_registers.h"
14 #include "fsl_common.h"
15 
16 /*!
17  * @addtogroup flexspi
18  * @{
19  */
20 
21 /*******************************************************************************
22  * Definitions
23  ******************************************************************************/
24 
25 /*! @name Driver version */
26 /*@{*/
27 /*! @brief FLEXSPI driver version. */
28 #define FSL_FLEXSPI_DRIVER_VERSION (MAKE_VERSION(2, 5, 1))
29 /*@}*/
30 
31 #define FSL_FEATURE_FLEXSPI_AHB_BUFFER_COUNT FSL_FEATURE_FLEXSPI_AHB_BUFFER_COUNTn(0)
32 
33 /*! @brief Formula to form FLEXSPI instructions in LUT table. */
34 #define FLEXSPI_LUT_SEQ(cmd0, pad0, op0, cmd1, pad1, op1)                                                              \
35     (FLEXSPI_LUT_OPERAND0(op0) | FLEXSPI_LUT_NUM_PADS0(pad0) | FLEXSPI_LUT_OPCODE0(cmd0) | FLEXSPI_LUT_OPERAND1(op1) | \
36      FLEXSPI_LUT_NUM_PADS1(pad1) | FLEXSPI_LUT_OPCODE1(cmd1))
37 
38 /*! @brief Status structure of FLEXSPI.*/
39 enum
40 {
41     kStatus_FLEXSPI_Busy                     = MAKE_STATUS(kStatusGroup_FLEXSPI, 0), /*!< FLEXSPI is busy */
42     kStatus_FLEXSPI_SequenceExecutionTimeout = MAKE_STATUS(kStatusGroup_FLEXSPI, 1), /*!< Sequence execution timeout
43                                                                             error occurred during FLEXSPI transfer. */
44     kStatus_FLEXSPI_IpCommandSequenceError = MAKE_STATUS(kStatusGroup_FLEXSPI, 2),   /*!< IP command Sequence execution
45                                                                      timeout error occurred during FLEXSPI transfer. */
46     kStatus_FLEXSPI_IpCommandGrantTimeout = MAKE_STATUS(kStatusGroup_FLEXSPI, 3),    /*!< IP command grant timeout error
47                                                                                     occurred during FLEXSPI transfer. */
48 };
49 
50 /*! @brief CMD definition of FLEXSPI, use to form LUT instruction, _flexspi_command. */
51 enum
52 {
53     kFLEXSPI_Command_STOP           = 0x00U, /*!< Stop execution, deassert CS. */
54     kFLEXSPI_Command_SDR            = 0x01U, /*!< Transmit Command code to Flash, using SDR mode. */
55     kFLEXSPI_Command_RADDR_SDR      = 0x02U, /*!< Transmit Row Address to Flash, using SDR mode. */
56     kFLEXSPI_Command_CADDR_SDR      = 0x03U, /*!< Transmit Column Address to Flash, using SDR mode. */
57     kFLEXSPI_Command_MODE1_SDR      = 0x04U, /*!< Transmit 1-bit Mode bits to Flash, using SDR mode. */
58     kFLEXSPI_Command_MODE2_SDR      = 0x05U, /*!< Transmit 2-bit Mode bits to Flash, using SDR mode. */
59     kFLEXSPI_Command_MODE4_SDR      = 0x06U, /*!< Transmit 4-bit Mode bits to Flash, using SDR mode. */
60     kFLEXSPI_Command_MODE8_SDR      = 0x07U, /*!< Transmit 8-bit Mode bits to Flash, using SDR mode. */
61     kFLEXSPI_Command_WRITE_SDR      = 0x08U, /*!< Transmit Programming Data to Flash, using SDR mode. */
62     kFLEXSPI_Command_READ_SDR       = 0x09U, /*!< Receive Read Data from Flash, using SDR mode. */
63     kFLEXSPI_Command_LEARN_SDR      = 0x0AU, /*!< Receive Read Data or Preamble bit from Flash, SDR mode. */
64     kFLEXSPI_Command_DATSZ_SDR      = 0x0BU, /*!< Transmit Read/Program Data size (byte) to Flash, SDR mode. */
65     kFLEXSPI_Command_DUMMY_SDR      = 0x0CU, /*!< Leave data lines undriven by FlexSPI controller.*/
66     kFLEXSPI_Command_DUMMY_RWDS_SDR = 0x0DU, /*!< Leave data lines undriven by FlexSPI controller,
67                                                   dummy cycles decided by RWDS. */
68     kFLEXSPI_Command_DDR            = 0x21U, /*!< Transmit Command code to Flash, using DDR mode. */
69     kFLEXSPI_Command_RADDR_DDR      = 0x22U, /*!< Transmit Row Address to Flash, using DDR mode. */
70     kFLEXSPI_Command_CADDR_DDR      = 0x23U, /*!< Transmit Column Address to Flash, using DDR mode. */
71     kFLEXSPI_Command_MODE1_DDR      = 0x24U, /*!< Transmit 1-bit Mode bits to Flash, using DDR mode. */
72     kFLEXSPI_Command_MODE2_DDR      = 0x25U, /*!< Transmit 2-bit Mode bits to Flash, using DDR mode. */
73     kFLEXSPI_Command_MODE4_DDR      = 0x26U, /*!< Transmit 4-bit Mode bits to Flash, using DDR mode. */
74     kFLEXSPI_Command_MODE8_DDR      = 0x27U, /*!< Transmit 8-bit Mode bits to Flash, using DDR mode. */
75     kFLEXSPI_Command_WRITE_DDR      = 0x28U, /*!< Transmit Programming Data to Flash, using DDR mode. */
76     kFLEXSPI_Command_READ_DDR       = 0x29U, /*!< Receive Read Data from Flash, using DDR mode. */
77     kFLEXSPI_Command_LEARN_DDR      = 0x2AU, /*!< Receive Read Data or Preamble bit from Flash, DDR mode. */
78     kFLEXSPI_Command_DATSZ_DDR      = 0x2BU, /*!< Transmit Read/Program Data size (byte) to Flash, DDR mode. */
79     kFLEXSPI_Command_DUMMY_DDR      = 0x2CU, /*!< Leave data lines undriven by FlexSPI controller.*/
80     kFLEXSPI_Command_DUMMY_RWDS_DDR = 0x2DU, /*!< Leave data lines undriven by FlexSPI controller,
81                                                dummy cycles decided by RWDS. */
82     kFLEXSPI_Command_JUMP_ON_CS = 0x1FU,     /*!< Stop execution, deassert CS and save operand[7:0] as the
83                                                instruction start pointer for next sequence */
84 };
85 
86 /*! @brief pad definition of FLEXSPI, use to form LUT instruction. */
87 typedef enum _flexspi_pad
88 {
89     kFLEXSPI_1PAD = 0x00U, /*!< Transmit command/address and transmit/receive data only through DATA0/DATA1. */
90     kFLEXSPI_2PAD = 0x01U, /*!< Transmit command/address and transmit/receive data only through DATA[1:0]. */
91     kFLEXSPI_4PAD = 0x02U, /*!< Transmit command/address and transmit/receive data only through DATA[3:0]. */
92     kFLEXSPI_8PAD = 0x03U, /*!< Transmit command/address and transmit/receive data only through DATA[7:0]. */
93 } flexspi_pad_t;
94 
95 /*! @brief FLEXSPI interrupt status flags.*/
96 typedef enum _flexspi_flags
97 {
98     kFLEXSPI_SequenceExecutionTimeoutFlag = FLEXSPI_INTEN_SEQTIMEOUTEN_MASK, /*!< Sequence execution timeout. */
99 #if defined(FSL_FEATURE_FLEXSPI_HAS_INTEN_AHBBUSERROREN) && FSL_FEATURE_FLEXSPI_HAS_INTEN_AHBBUSERROREN
100     kFLEXSPI_AhbBusErrorFlag = FLEXSPI_INTEN_AHBBUSERROREN_MASK, /*!< AHB Bus error flag. */
101 #else
102     kFLEXSPI_AhbBusTimeoutFlag = FLEXSPI_INTEN_AHBBUSTIMEOUTEN_MASK, /*!< AHB Bus timeout. */
103 #endif
104     kFLEXSPI_SckStoppedBecauseTxEmptyFlag =
105         FLEXSPI_INTEN_SCKSTOPBYWREN_MASK, /*!< SCK is stopped during command
106                                                sequence because Async TX FIFO empty. */
107     kFLEXSPI_SckStoppedBecauseRxFullFlag =
108         FLEXSPI_INTEN_SCKSTOPBYRDEN_MASK, /*!< SCK is stopped during command
109                                                sequence because Async RX FIFO full. */
110 #if !((defined(FSL_FEATURE_FLEXSPI_HAS_NO_DATA_LEARN)) && (FSL_FEATURE_FLEXSPI_HAS_NO_DATA_LEARN))
111     kFLEXSPI_DataLearningFailedFlag = FLEXSPI_INTEN_DATALEARNFAILEN_MASK, /*!< Data learning failed. */
112 #endif
113     kFLEXSPI_IpTxFifoWatermarkEmptyFlag     = FLEXSPI_INTEN_IPTXWEEN_MASK, /*!< IP TX FIFO WaterMark empty. */
114     kFLEXSPI_IpRxFifoWatermarkAvailableFlag = FLEXSPI_INTEN_IPRXWAEN_MASK, /*!< IP RX FIFO WaterMark available. */
115     kFLEXSPI_AhbCommandSequenceErrorFlag =
116         FLEXSPI_INTEN_AHBCMDERREN_MASK,                                  /*!< AHB triggered Command Sequences Error. */
117     kFLEXSPI_IpCommandSequenceErrorFlag = FLEXSPI_INTEN_IPCMDERREN_MASK, /*!< IP triggered Command Sequences Error. */
118     kFLEXSPI_AhbCommandGrantTimeoutFlag =
119         FLEXSPI_INTEN_AHBCMDGEEN_MASK, /*!< AHB triggered Command Sequences Grant Timeout. */
120     kFLEXSPI_IpCommandGrantTimeoutFlag =
121         FLEXSPI_INTEN_IPCMDGEEN_MASK, /*!< IP triggered Command Sequences Grant Timeout. */
122     kFLEXSPI_IpCommandExecutionDoneFlag =
123         FLEXSPI_INTEN_IPCMDDONEEN_MASK,  /*!< IP triggered Command Sequences Execution finished. */
124     kFLEXSPI_AllInterruptFlags = 0xFFFU, /*!< All flags. */
125 } flexspi_flags_t;
126 
127 /*! @brief FLEXSPI sample clock source selection for Flash Reading.*/
128 typedef enum _flexspi_read_sample_clock
129 {
130     kFLEXSPI_ReadSampleClkLoopbackInternally = 0x0U,      /*!< Dummy Read strobe generated by FlexSPI Controller
131                                                                and loopback internally. */
132     kFLEXSPI_ReadSampleClkLoopbackFromDqsPad = 0x1U,      /*!< Dummy Read strobe generated by FlexSPI Controller
133                                                                and loopback from DQS pad. */
134     kFLEXSPI_ReadSampleClkLoopbackFromSckPad      = 0x2U, /*!< SCK output clock and loopback from SCK pad. */
135     kFLEXSPI_ReadSampleClkExternalInputFromDqsPad = 0x3U, /*!< Flash provided Read strobe and input from DQS pad. */
136 } flexspi_read_sample_clock_t;
137 
138 /*! @brief FLEXSPI interval unit for flash device select.*/
139 typedef enum _flexspi_cs_interval_cycle_unit
140 {
141     kFLEXSPI_CsIntervalUnit1SckCycle   = 0x0U, /*!< Chip selection interval: CSINTERVAL * 1 serial clock cycle. */
142     kFLEXSPI_CsIntervalUnit256SckCycle = 0x1U, /*!< Chip selection interval: CSINTERVAL * 256 serial clock cycle. */
143 } flexspi_cs_interval_cycle_unit_t;
144 
145 /*! @brief FLEXSPI AHB wait interval unit for writing.*/
146 typedef enum _flexspi_ahb_write_wait_unit
147 {
148     kFLEXSPI_AhbWriteWaitUnit2AhbCycle     = 0x0U, /*!< AWRWAIT unit is 2 ahb clock cycle. */
149     kFLEXSPI_AhbWriteWaitUnit8AhbCycle     = 0x1U, /*!< AWRWAIT unit is 8 ahb clock cycle. */
150     kFLEXSPI_AhbWriteWaitUnit32AhbCycle    = 0x2U, /*!< AWRWAIT unit is 32 ahb clock cycle. */
151     kFLEXSPI_AhbWriteWaitUnit128AhbCycle   = 0x3U, /*!< AWRWAIT unit is 128 ahb clock cycle. */
152     kFLEXSPI_AhbWriteWaitUnit512AhbCycle   = 0x4U, /*!< AWRWAIT unit is 512 ahb clock cycle. */
153     kFLEXSPI_AhbWriteWaitUnit2048AhbCycle  = 0x5U, /*!< AWRWAIT unit is 2048 ahb clock cycle. */
154     kFLEXSPI_AhbWriteWaitUnit8192AhbCycle  = 0x6U, /*!< AWRWAIT unit is 8192 ahb clock cycle. */
155     kFLEXSPI_AhbWriteWaitUnit32768AhbCycle = 0x7U, /*!< AWRWAIT unit is 32768 ahb clock cycle. */
156 } flexspi_ahb_write_wait_unit_t;
157 
158 /*! @brief Error Code when IP command Error detected.*/
159 typedef enum _flexspi_ip_error_code
160 {
161     kFLEXSPI_IpCmdErrorNoError               = 0x0U,    /*!< No error. */
162     kFLEXSPI_IpCmdErrorJumpOnCsInIpCmd       = 0x2U,    /*!< IP command with JMP_ON_CS instruction used. */
163     kFLEXSPI_IpCmdErrorUnknownOpCode         = 0x3U,    /*!< Unknown instruction opcode in the sequence. */
164     kFLEXSPI_IpCmdErrorSdrDummyInDdrSequence = 0x4U,    /*!< Instruction DUMMY_SDR/DUMMY_RWDS_SDR
165                                                              used in DDR sequence. */
166     kFLEXSPI_IpCmdErrorDdrDummyInSdrSequence = 0x5U,    /*!< Instruction DUMMY_DDR/DUMMY_RWDS_DDR
167                                                              used in SDR sequence. */
168     kFLEXSPI_IpCmdErrorInvalidAddress = 0x6U,           /*!< Flash access start address exceed the whole
169                                                             flash address range (A1/A2/B1/B2). */
170     kFLEXSPI_IpCmdErrorSequenceExecutionTimeout = 0xEU, /*!< Sequence execution timeout. */
171     kFLEXSPI_IpCmdErrorFlashBoundaryAcrosss     = 0xFU, /*!< Flash boundary crossed. */
172 } flexspi_ip_error_code_t;
173 
174 /*! @brief Error Code when AHB command Error detected.*/
175 typedef enum _flexspi_ahb_error_code
176 {
177     kFLEXSPI_AhbCmdErrorNoError            = 0x0U,    /*!< No error. */
178     kFLEXSPI_AhbCmdErrorJumpOnCsInWriteCmd = 0x2U,    /*!< AHB Write command with JMP_ON_CS instruction
179                                                            used in the sequence. */
180     kFLEXSPI_AhbCmdErrorUnknownOpCode         = 0x3U, /*!< Unknown instruction opcode in the sequence. */
181     kFLEXSPI_AhbCmdErrorSdrDummyInDdrSequence = 0x4U, /*!< Instruction DUMMY_SDR/DUMMY_RWDS_SDR used
182                                                            in DDR sequence. */
183     kFLEXSPI_AhbCmdErrorDdrDummyInSdrSequence = 0x5U, /*!< Instruction DUMMY_DDR/DUMMY_RWDS_DDR
184                                                            used in SDR sequence. */
185     kFLEXSPI_AhbCmdSequenceExecutionTimeout = 0x6U,   /*!< Sequence execution timeout. */
186 } flexspi_ahb_error_code_t;
187 
188 /*! @brief FLEXSPI operation port select.*/
189 typedef enum _flexspi_port
190 {
191     kFLEXSPI_PortA1 = 0x0U, /*!< Access flash on A1 port. */
192     kFLEXSPI_PortA2,        /*!< Access flash on A2 port. */
193 #if !((defined(FSL_FEATURE_FLEXSPI_NO_SUPPORT_PORTB)) && (FSL_FEATURE_FLEXSPI_NO_SUPPORT_PORTB))
194     kFLEXSPI_PortB1, /*!< Access flash on B1 port. */
195     kFLEXSPI_PortB2, /*!< Access flash on B2 port. */
196 #endif
197     kFLEXSPI_PortCount
198 } flexspi_port_t;
199 
200 /*! @brief Trigger source of current command sequence granted by arbitrator.*/
201 typedef enum _flexspi_arb_command_source
202 {
203     kFLEXSPI_AhbReadCommand   = 0x0U,
204     kFLEXSPI_AhbWriteCommand  = 0x1U,
205     kFLEXSPI_IpCommand        = 0x2U,
206     kFLEXSPI_SuspendedCommand = 0x3U,
207 } flexspi_arb_command_source_t;
208 
209 /*! @brief Command type. */
210 typedef enum _flexspi_command_type
211 {
212     kFLEXSPI_Command, /*!< FlexSPI operation: Only command, both TX and Rx buffer are ignored. */
213     kFLEXSPI_Config,  /*!< FlexSPI operation: Configure device mode, the TX fifo size is fixed in LUT. */
214     kFLEXSPI_Read,    /* /!< FlexSPI operation: Read, only Rx Buffer is effective. */
215     kFLEXSPI_Write,   /* /!< FlexSPI operation: Read, only Tx Buffer is effective. */
216 } flexspi_command_type_t;
217 
218 typedef struct _flexspi_ahbBuffer_config
219 {
220     uint8_t priority;    /*!< This priority for AHB Master Read which this AHB RX Buffer is assigned. */
221     uint8_t masterIndex; /*!< AHB Master ID the AHB RX Buffer is assigned. */
222     uint16_t bufferSize; /*!< AHB buffer size in byte. */
223     bool enablePrefetch; /*!< AHB Read Prefetch Enable for current AHB RX Buffer corresponding Master, allows
224                           prefetch disable/enable separately for each master. */
225 } flexspi_ahbBuffer_config_t;
226 
227 /*! @brief FLEXSPI configuration structure. */
228 typedef struct _flexspi_config
229 {
230     flexspi_read_sample_clock_t rxSampleClock; /*!< Sample Clock source selection for Flash Reading. */
231     bool enableSckFreeRunning;                 /*!< Enable/disable SCK output free-running. */
232 #if !(defined(FSL_FEATURE_FLEXSPI_HAS_NO_MCR0_COMBINATIONEN) && FSL_FEATURE_FLEXSPI_HAS_NO_MCR0_COMBINATIONEN)
233     bool enableCombination; /*!< Enable/disable combining PORT A and B Data Pins
234                             (SIOA[3:0] and SIOB[3:0]) to support Flash Octal mode. */
235 #endif
236     bool enableDoze;            /*!< Enable/disable doze mode support. */
237     bool enableHalfSpeedAccess; /*!< Enable/disable divide by 2 of the clock for half
238                                  speed commands. */
239 #if defined(FSL_FEATURE_FLEXSPI_SUPPORT_SEPERATE_RXCLKSRC_PORTB) && FSL_FEATURE_FLEXSPI_SUPPORT_SEPERATE_RXCLKSRC_PORTB
240     flexspi_read_sample_clock_t rxSampleClockPortB; /*!< Sample Clock source_b selection for Flash Reading. */
241 #endif
242 #if defined(FSL_FEATURE_FLEXSPI_SUPPORT_RXCLKSRC_DIFF) && FSL_FEATURE_FLEXSPI_SUPPORT_RXCLKSRC_DIFF
243     bool rxSampleClockDiff; /*!< Sample Clock source or source_b selection for Flash Reading. */
244 #endif
245 #if !(defined(FSL_FEATURE_FLEXSPI_HAS_NO_MCR2_SCKBDIFFOPT) && FSL_FEATURE_FLEXSPI_HAS_NO_MCR2_SCKBDIFFOPT)
246     bool enableSckBDiffOpt; /*!< Enable/disable SCKB pad use as SCKA differential clock
247                              output, when enable, Port B flash access is not available. */
248 #endif
249     bool enableSameConfigForAll; /*!< Enable/disable same configuration for all connected devices
250                                   when enabled, same configuration in FLASHA1CRx is applied to all. */
251     uint16_t seqTimeoutCycle;    /*!< Timeout wait cycle for command sequence execution,
252                                  timeout after ahbGrantTimeoutCyle*1024 serial root clock cycles. */
253     uint8_t ipGrantTimeoutCycle; /*!< Timeout wait cycle for IP command grant, timeout after
254                                   ipGrantTimeoutCycle*1024 AHB clock cycles. */
255     uint8_t txWatermark;         /*!< FLEXSPI IP transmit watermark value. */
256     uint8_t rxWatermark;         /*!< FLEXSPI receive watermark value. */
257     struct
258     {
259 #if !(defined(FSL_FEATURE_FLEXSPI_HAS_NO_MCR0_ATDFEN) && FSL_FEATURE_FLEXSPI_HAS_NO_MCR0_ATDFEN)
260         bool enableAHBWriteIpTxFifo; /*!< Enable AHB bus write access to IP TX FIFO. */
261 #endif
262 #if !(defined(FSL_FEATURE_FLEXSPI_HAS_NO_MCR0_ARDFEN) && FSL_FEATURE_FLEXSPI_HAS_NO_MCR0_ARDFEN)
263         bool enableAHBWriteIpRxFifo; /*!< Enable AHB bus write access to IP RX FIFO. */
264 #endif
265         uint8_t ahbGrantTimeoutCycle; /*!< Timeout wait cycle for AHB command grant,
266                                        timeout after ahbGrantTimeoutCyle*1024 AHB clock cycles. */
267         uint16_t ahbBusTimeoutCycle;  /*!< Timeout wait cycle for AHB read/write access,
268                                       timeout after ahbBusTimeoutCycle*1024 AHB clock cycles. */
269         uint8_t resumeWaitCycle;      /*!< Wait cycle for idle state before suspended command sequence
270                                        resume, timeout after ahbBusTimeoutCycle AHB clock cycles. */
271         flexspi_ahbBuffer_config_t buffer[FSL_FEATURE_FLEXSPI_AHB_BUFFER_COUNT]; /*!< AHB buffer size. */
272         bool enableClearAHBBufferOpt; /*!< Enable/disable automatically clean AHB RX Buffer and TX Buffer
273                                        when FLEXSPI returns STOP mode ACK. */
274         bool enableReadAddressOpt;    /*!< Enable/disable remove AHB read burst start address alignment limitation.
275                                        when enable, there is no AHB read burst start address alignment limitation. */
276         bool enableAHBPrefetch;       /*!< Enable/disable AHB read prefetch feature, when enabled, FLEXSPI
277                                        will fetch more data than current AHB burst. */
278         bool enableAHBBufferable;     /*!< Enable/disable AHB bufferable write access support, when enabled,
279                                        FLEXSPI return before waiting for command execution finished. */
280         bool enableAHBCachable;       /*!< Enable AHB bus cachable read access support. */
281     } ahbConfig;
282 } flexspi_config_t;
283 
284 /*! @brief External device configuration items. */
285 typedef struct _flexspi_device_config
286 {
287     uint32_t flexspiRootClk; /*!< FLEXSPI serial root clock. */
288     bool isSck2Enabled;      /*!< FLEXSPI use SCK2. */
289     uint32_t flashSize;      /*!< Flash size in KByte. */
290 #if defined(FSL_FEATURE_FLEXSPI_SUPPORT_ADDRESS_SHIFT) && (FSL_FEATURE_FLEXSPI_SUPPORT_ADDRESS_SHIFT)
291     bool addressShift;                               /*!< Address shift. */
292 #endif                                               /* FSL_FEATURE_FLEXSPI_SUPPORT_ADDRESS_SHIFT */
293     flexspi_cs_interval_cycle_unit_t CSIntervalUnit; /*!< CS interval unit, 1 or 256 cycle. */
294     uint16_t CSInterval;                             /*!< CS line assert interval, multiply CS interval unit to
295                                                       get the CS line assert interval cycles. */
296     uint8_t CSHoldTime;                              /*!< CS line hold time. */
297     uint8_t CSSetupTime;                             /*!< CS line setup time. */
298     uint8_t dataValidTime;                           /*!< Data valid time for external device. */
299     uint8_t columnspace;                             /*!< Column space size. */
300     bool enableWordAddress;                          /*!< If enable word address.*/
301     uint8_t AWRSeqIndex;                             /*!< Sequence ID for AHB write command. */
302     uint8_t AWRSeqNumber;                            /*!< Sequence number for AHB write command. */
303     uint8_t ARDSeqIndex;                             /*!< Sequence ID for AHB read command. */
304     uint8_t ARDSeqNumber;                            /*!< Sequence number for AHB read command. */
305     flexspi_ahb_write_wait_unit_t AHBWriteWaitUnit;  /*!< AHB write wait unit. */
306     uint16_t AHBWriteWaitInterval;                   /*!< AHB write wait interval, multiply AHB write interval
307                                                       unit to get the AHB write wait cycles. */
308     bool enableWriteMask;                            /*!< Enable/Disable FLEXSPI drive DQS pin as write mask
309                                                       when writing to external device. */
310 #if defined(FSL_FEATURE_FLEXSPI_HAS_ERRATA_051426) && (FSL_FEATURE_FLEXSPI_HAS_ERRATA_051426)
311     bool isFroClockSource; /*!< Is FRO clock source or not. */
312 #endif
313 } flexspi_device_config_t;
314 
315 /*! @brief Transfer structure for FLEXSPI. */
316 typedef struct _flexspi_transfer
317 {
318     uint32_t deviceAddress;         /*!< Operation device address. */
319     flexspi_port_t port;            /*!< Operation port. */
320     flexspi_command_type_t cmdType; /*!< Execution command type. */
321     uint8_t seqIndex;               /*!< Sequence ID for command. */
322     uint8_t SeqNumber;              /*!< Sequence number for command. */
323     uint32_t *data;                 /*!< Data buffer. */
324     size_t dataSize;                /*!< Data size in bytes. */
325 } flexspi_transfer_t;
326 
327 /* Forward declaration of the handle typedef. */
328 typedef struct _flexspi_handle flexspi_handle_t;
329 
330 /*! @brief FLEXSPI transfer callback function. */
331 typedef void (*flexspi_transfer_callback_t)(FLEXSPI_Type *base,
332                                             flexspi_handle_t *handle,
333                                             status_t status,
334                                             void *userData);
335 
336 /*! @brief Transfer handle structure for FLEXSPI. */
337 struct _flexspi_handle
338 {
339     uint32_t state;                                 /*!< Internal state for FLEXSPI transfer */
340     uint8_t *data;                                  /*!< Data buffer. */
341     size_t dataSize;                                /*!< Remaining Data size in bytes. */
342     size_t transferTotalSize;                       /*!< Total Data size in bytes. */
343     flexspi_transfer_callback_t completionCallback; /*!< Callback for users while transfer finish or error occurred */
344     void *userData;                                 /*!< FLEXSPI callback function parameter.*/
345 };
346 
347 /*******************************************************************************
348  * API
349  ******************************************************************************/
350 
351 #if defined(__cplusplus)
352 extern "C" {
353 #endif /*_cplusplus. */
354 
355 /*!
356  * @name Initialization and deinitialization
357  * @{
358  */
359 
360 /*!
361  * @brief Get the instance number for FLEXSPI.
362  *
363  * @param base FLEXSPI base pointer.
364  */
365 uint32_t FLEXSPI_GetInstance(FLEXSPI_Type *base);
366 
367 /*!
368  * @brief Check and clear IP command execution errors.
369  *
370  * @param base FLEXSPI base pointer.
371  * @param status interrupt status.
372  */
373 status_t FLEXSPI_CheckAndClearError(FLEXSPI_Type *base, uint32_t status);
374 
375 /*!
376  * @brief Initializes the FLEXSPI module and internal state.
377  *
378  * This function enables the clock for FLEXSPI and also configures the FLEXSPI with the
379  * input configure parameters. Users should call this function before any FLEXSPI operations.
380  *
381  * @param base FLEXSPI peripheral base address.
382  * @param config FLEXSPI configure structure.
383  */
384 void FLEXSPI_Init(FLEXSPI_Type *base, const flexspi_config_t *config);
385 
386 /*!
387  * @brief Gets default settings for FLEXSPI.
388  *
389  * @param config FLEXSPI configuration structure.
390  */
391 void FLEXSPI_GetDefaultConfig(flexspi_config_t *config);
392 
393 /*!
394  * @brief Deinitializes the FLEXSPI module.
395  *
396  * Clears the FLEXSPI state and  FLEXSPI module registers.
397  * @param base FLEXSPI peripheral base address.
398  */
399 void FLEXSPI_Deinit(FLEXSPI_Type *base);
400 
401 /*!
402  * @brief Update FLEXSPI DLL value depending on currently flexspi root clock.
403  *
404  * @param base FLEXSPI peripheral base address.
405  * @param config Flash configuration parameters.
406  * @param port FLEXSPI Operation port.
407  */
408 void FLEXSPI_UpdateDllValue(FLEXSPI_Type *base, flexspi_device_config_t *config, flexspi_port_t port);
409 
410 /*!
411  * @brief Configures the connected device parameter.
412  *
413  * This function configures the connected device relevant parameters, such as the size, command, and so on.
414  * The flash configuration value cannot have a default value. The user needs to configure it according to the
415  * connected device.
416  *
417  * @param base FLEXSPI peripheral base address.
418  * @param config Flash configuration parameters.
419  * @param port FLEXSPI Operation port.
420  */
421 void FLEXSPI_SetFlashConfig(FLEXSPI_Type *base, flexspi_device_config_t *config, flexspi_port_t port);
422 
423 /*!
424  * @brief Software reset for the FLEXSPI logic.
425  *
426  * This function sets the software reset flags for both AHB and buffer domain and
427  * resets both AHB buffer and also IP FIFOs.
428  *
429  * @param base FLEXSPI peripheral base address.
430  */
FLEXSPI_SoftwareReset(FLEXSPI_Type * base)431 static inline void FLEXSPI_SoftwareReset(FLEXSPI_Type *base)
432 {
433     base->MCR0 |= FLEXSPI_MCR0_SWRESET_MASK;
434     while (0U != (base->MCR0 & FLEXSPI_MCR0_SWRESET_MASK))
435     {
436     }
437 }
438 
439 /*!
440  * @brief Enables or disables the FLEXSPI module.
441  *
442  * @param base FLEXSPI peripheral base address.
443  * @param enable True means enable FLEXSPI, false means disable.
444  */
FLEXSPI_Enable(FLEXSPI_Type * base,bool enable)445 static inline void FLEXSPI_Enable(FLEXSPI_Type *base, bool enable)
446 {
447     if (enable)
448     {
449         base->MCR0 &= ~FLEXSPI_MCR0_MDIS_MASK;
450     }
451     else
452     {
453         base->MCR0 |= FLEXSPI_MCR0_MDIS_MASK;
454     }
455 }
456 
457 /* @} */
458 
459 /*!
460  * @name Interrupts
461  * @{
462  */
463 /*!
464  * @brief Enables the FLEXSPI interrupts.
465  *
466  * @param base FLEXSPI peripheral base address.
467  * @param mask FLEXSPI interrupt source.
468  */
FLEXSPI_EnableInterrupts(FLEXSPI_Type * base,uint32_t mask)469 static inline void FLEXSPI_EnableInterrupts(FLEXSPI_Type *base, uint32_t mask)
470 {
471     base->INTEN |= mask;
472 }
473 
474 /*!
475  * @brief Disable the FLEXSPI interrupts.
476  *
477  * @param base FLEXSPI peripheral base address.
478  * @param mask FLEXSPI interrupt source.
479  */
FLEXSPI_DisableInterrupts(FLEXSPI_Type * base,uint32_t mask)480 static inline void FLEXSPI_DisableInterrupts(FLEXSPI_Type *base, uint32_t mask)
481 {
482     base->INTEN &= ~mask;
483 }
484 
485 /* @} */
486 
487 /*! @name DMA control */
488 /*@{*/
489 
490 /*!
491  * @brief Enables or disables FLEXSPI IP Tx FIFO DMA requests.
492  *
493  * @param base FLEXSPI peripheral base address.
494  * @param enable Enable flag for transmit DMA request. Pass true for enable, false for disable.
495  */
FLEXSPI_EnableTxDMA(FLEXSPI_Type * base,bool enable)496 static inline void FLEXSPI_EnableTxDMA(FLEXSPI_Type *base, bool enable)
497 {
498     if (enable)
499     {
500         base->IPTXFCR |= FLEXSPI_IPTXFCR_TXDMAEN_MASK;
501     }
502     else
503     {
504         base->IPTXFCR &= ~FLEXSPI_IPTXFCR_TXDMAEN_MASK;
505     }
506 }
507 
508 /*!
509  * @brief Enables or disables FLEXSPI IP Rx FIFO DMA requests.
510  *
511  * @param base FLEXSPI peripheral base address.
512  * @param enable Enable flag for receive DMA request. Pass true for enable, false for disable.
513  */
FLEXSPI_EnableRxDMA(FLEXSPI_Type * base,bool enable)514 static inline void FLEXSPI_EnableRxDMA(FLEXSPI_Type *base, bool enable)
515 {
516     if (enable)
517     {
518         base->IPRXFCR |= FLEXSPI_IPRXFCR_RXDMAEN_MASK;
519     }
520     else
521     {
522         base->IPRXFCR &= ~FLEXSPI_IPRXFCR_RXDMAEN_MASK;
523     }
524 }
525 
526 /*!
527  * @brief Gets FLEXSPI IP tx fifo address for DMA transfer.
528  *
529  * @param base FLEXSPI peripheral base address.
530  * @retval The tx fifo address.
531  */
FLEXSPI_GetTxFifoAddress(FLEXSPI_Type * base)532 static inline uint32_t FLEXSPI_GetTxFifoAddress(FLEXSPI_Type *base)
533 {
534     return (uint32_t)&base->TFDR[0];
535 }
536 
537 /*!
538  * @brief Gets FLEXSPI IP rx fifo address for DMA transfer.
539  *
540  * @param base FLEXSPI peripheral base address.
541  * @retval The rx fifo address.
542  */
FLEXSPI_GetRxFifoAddress(FLEXSPI_Type * base)543 static inline uint32_t FLEXSPI_GetRxFifoAddress(FLEXSPI_Type *base)
544 {
545     return (uint32_t)&base->RFDR[0];
546 }
547 
548 /*@}*/
549 
550 /*! @name FIFO control */
551 /*@{*/
552 
553 /*! @brief Clears the FLEXSPI IP FIFO logic.
554  *
555  * @param base FLEXSPI peripheral base address.
556  * @param txFifo Pass true to reset TX FIFO.
557  * @param rxFifo Pass true to reset RX FIFO.
558  */
FLEXSPI_ResetFifos(FLEXSPI_Type * base,bool txFifo,bool rxFifo)559 static inline void FLEXSPI_ResetFifos(FLEXSPI_Type *base, bool txFifo, bool rxFifo)
560 {
561     if (txFifo)
562     {
563         base->IPTXFCR |= FLEXSPI_IPTXFCR_CLRIPTXF_MASK;
564     }
565     if (rxFifo)
566     {
567         base->IPRXFCR |= FLEXSPI_IPRXFCR_CLRIPRXF_MASK;
568     }
569 }
570 
571 /*!
572  * @brief Gets the valid data entries in the FLEXSPI FIFOs.
573  *
574  * @param base FLEXSPI peripheral base address.
575  * @param[out] txCount Pointer through which the current number of bytes in the transmit FIFO is returned.
576  *      Pass NULL if this value is not required.
577  * @param[out] rxCount Pointer through which the current number of bytes in the receive FIFO is returned.
578  *      Pass NULL if this value is not required.
579  */
FLEXSPI_GetFifoCounts(FLEXSPI_Type * base,size_t * txCount,size_t * rxCount)580 static inline void FLEXSPI_GetFifoCounts(FLEXSPI_Type *base, size_t *txCount, size_t *rxCount)
581 {
582     if (NULL != txCount)
583     {
584         *txCount = (((base->IPTXFSTS) & FLEXSPI_IPTXFSTS_FILL_MASK) >> FLEXSPI_IPTXFSTS_FILL_SHIFT) * 8U;
585     }
586     if (NULL != rxCount)
587     {
588         *rxCount = (((base->IPRXFSTS) & FLEXSPI_IPRXFSTS_FILL_MASK) >> FLEXSPI_IPRXFSTS_FILL_SHIFT) * 8U;
589     }
590 }
591 
592 /*@}*/
593 
594 /*!
595  * @name Status
596  * @{
597  */
598 /*!
599  * @brief Get the FLEXSPI interrupt status flags.
600  *
601  * @param base FLEXSPI peripheral base address.
602  * @retval interrupt status flag, use status flag to AND #flexspi_flags_t could get the related status.
603  */
FLEXSPI_GetInterruptStatusFlags(FLEXSPI_Type * base)604 static inline uint32_t FLEXSPI_GetInterruptStatusFlags(FLEXSPI_Type *base)
605 {
606     return base->INTR;
607 }
608 
609 /*!
610  * @brief Get the FLEXSPI interrupt status flags.
611  *
612  * @param base FLEXSPI peripheral base address.
613  * @param mask FLEXSPI interrupt source.
614  */
FLEXSPI_ClearInterruptStatusFlags(FLEXSPI_Type * base,uint32_t mask)615 static inline void FLEXSPI_ClearInterruptStatusFlags(FLEXSPI_Type *base, uint32_t mask)
616 {
617     base->INTR = mask;
618 }
619 
620 #if !((defined(FSL_FEATURE_FLEXSPI_HAS_NO_DATA_LEARN)) && (FSL_FEATURE_FLEXSPI_HAS_NO_DATA_LEARN))
621 /*! @brief Gets the sampling clock phase selection after Data Learning.
622  *
623  * @param base FLEXSPI peripheral base address.
624  * @param portAPhase Pointer to a uint8_t type variable to receive the selected clock phase on PORTA.
625  * @param portBPhase Pointer to a uint8_t type variable to receive the selected clock phase on PORTB.
626  */
FLEXSPI_GetDataLearningPhase(FLEXSPI_Type * base,uint8_t * portAPhase,uint8_t * portBPhase)627 static inline void FLEXSPI_GetDataLearningPhase(FLEXSPI_Type *base, uint8_t *portAPhase, uint8_t *portBPhase)
628 {
629     if (portAPhase != NULL)
630     {
631         *portAPhase = (uint8_t)((base->STS0 & FLEXSPI_STS0_DATALEARNPHASEA_MASK) >> FLEXSPI_STS0_DATALEARNPHASEA_SHIFT);
632     }
633 
634 #if !((defined(FSL_FEATURE_FLEXSPI_HAS_NO_STS0_DATALEARNPHASEB)) && (FSL_FEATURE_FLEXSPI_HAS_NO_STS0_DATALEARNPHASEB))
635     if (portBPhase != NULL)
636     {
637         *portBPhase = (uint8_t)((base->STS0 & FLEXSPI_STS0_DATALEARNPHASEB_MASK) >> FLEXSPI_STS0_DATALEARNPHASEB_SHIFT);
638     }
639 #endif
640 }
641 #endif
642 
643 /*! @brief Gets the trigger source of current command sequence granted by arbitrator.
644  *
645  * @param base FLEXSPI peripheral base address.
646  * @retval trigger source of current command sequence.
647  */
FLEXSPI_GetArbitratorCommandSource(FLEXSPI_Type * base)648 static inline flexspi_arb_command_source_t FLEXSPI_GetArbitratorCommandSource(FLEXSPI_Type *base)
649 {
650     return (flexspi_arb_command_source_t)(
651         (uint32_t)((base->STS0 & FLEXSPI_STS0_ARBCMDSRC_MASK) >> FLEXSPI_STS0_ARBCMDSRC_SHIFT));
652 }
653 
654 /*! @brief Gets the error code when IP command error detected.
655  *
656  * @param base FLEXSPI peripheral base address.
657  * @param index Pointer to a uint8_t type variable to receive the sequence index when error detected.
658  * @retval error code when IP command error detected.
659  */
FLEXSPI_GetIPCommandErrorCode(FLEXSPI_Type * base,uint8_t * index)660 static inline flexspi_ip_error_code_t FLEXSPI_GetIPCommandErrorCode(FLEXSPI_Type *base, uint8_t *index)
661 {
662     *index = (uint8_t)((base->STS1 & FLEXSPI_STS1_IPCMDERRID_MASK) >> FLEXSPI_STS1_IPCMDERRID_SHIFT);
663     return (flexspi_ip_error_code_t)(
664         (uint32_t)((base->STS1 & FLEXSPI_STS1_IPCMDERRCODE_MASK) >> FLEXSPI_STS1_IPCMDERRCODE_SHIFT));
665 }
666 
667 /*! @brief Gets the error code when AHB command error detected.
668  *
669  * @param base FLEXSPI peripheral base address.
670  * @param index Pointer to a uint8_t type variable to receive the sequence index when error detected.
671  * @retval error code when AHB command error detected.
672  */
FLEXSPI_GetAHBCommandErrorCode(FLEXSPI_Type * base,uint8_t * index)673 static inline flexspi_ahb_error_code_t FLEXSPI_GetAHBCommandErrorCode(FLEXSPI_Type *base, uint8_t *index)
674 {
675     *index = (uint8_t)(base->STS1 & FLEXSPI_STS1_AHBCMDERRID_MASK) >> FLEXSPI_STS1_AHBCMDERRID_SHIFT;
676     return (flexspi_ahb_error_code_t)(
677         (uint32_t)((base->STS1 & FLEXSPI_STS1_AHBCMDERRCODE_MASK) >> FLEXSPI_STS1_AHBCMDERRCODE_SHIFT));
678 }
679 
680 /*! @brief Returns whether the bus is idle.
681  *
682  * @param base FLEXSPI peripheral base address.
683  * @retval true Bus is idle.
684  * @retval false Bus is busy.
685  */
FLEXSPI_GetBusIdleStatus(FLEXSPI_Type * base)686 static inline bool FLEXSPI_GetBusIdleStatus(FLEXSPI_Type *base)
687 {
688     return (0U != (base->STS0 & FLEXSPI_STS0_ARBIDLE_MASK)) && (0U != (base->STS0 & FLEXSPI_STS0_SEQIDLE_MASK));
689 }
690 /*@}*/
691 
692 /*!
693  * @name Bus Operations
694  * @{
695  */
696 
697 /*! @brief Update read sample clock source
698  *
699  * @param base FLEXSPI peripheral base address.
700  * @param clockSource clockSource of type #flexspi_read_sample_clock_t
701  */
702 void FLEXSPI_UpdateRxSampleClock(FLEXSPI_Type *base, flexspi_read_sample_clock_t clockSource);
703 
704 #if !(defined(FSL_FEATURE_FLEXSPI_HAS_NO_IP_PARALLEL_MODE) && FSL_FEATURE_FLEXSPI_HAS_NO_IP_PARALLEL_MODE)
705 /*! @brief Enables/disables the FLEXSPI IP command parallel mode.
706  *
707  * @param base FLEXSPI peripheral base address.
708  * @param enable True means enable parallel mode, false means disable parallel mode.
709  */
FLEXSPI_EnableIPParallelMode(FLEXSPI_Type * base,bool enable)710 static inline void FLEXSPI_EnableIPParallelMode(FLEXSPI_Type *base, bool enable)
711 {
712     if (enable)
713     {
714         base->IPCR1 |= FLEXSPI_IPCR1_IPAREN_MASK;
715     }
716     else
717     {
718         base->IPCR1 &= ~FLEXSPI_IPCR1_IPAREN_MASK;
719     }
720 }
721 #endif
722 
723 #if !(defined(FSL_FEATURE_FLEXSPI_HAS_NO_AHB_PARALLEL_MODE) && FSL_FEATURE_FLEXSPI_HAS_NO_AHB_PARALLEL_MODE)
724 /*! @brief Enables/disables the FLEXSPI AHB command parallel mode.
725  *
726  * @param base FLEXSPI peripheral base address.
727  * @param enable True means enable parallel mode, false means disable parallel mode.
728  */
FLEXSPI_EnableAHBParallelMode(FLEXSPI_Type * base,bool enable)729 static inline void FLEXSPI_EnableAHBParallelMode(FLEXSPI_Type *base, bool enable)
730 {
731     if (enable)
732     {
733         base->AHBCR |= FLEXSPI_AHBCR_APAREN_MASK;
734     }
735     else
736     {
737         base->AHBCR &= ~FLEXSPI_AHBCR_APAREN_MASK;
738     }
739 }
740 #endif
741 
742 /*! @brief Updates the LUT table.
743  *
744  * @param base FLEXSPI peripheral base address.
745  * @param index From which index start to update. It could be any index of the LUT table, which
746  * also allows user to update command content inside a command. Each command consists of up to
747  * 8 instructions and occupy 4*32-bit memory.
748  * @param cmd Command sequence array.
749  * @param count Number of sequences.
750  */
751 void FLEXSPI_UpdateLUT(FLEXSPI_Type *base, uint32_t index, const uint32_t *cmd, uint32_t count);
752 
753 /*!
754  * @brief Writes data into FIFO.
755  *
756  * @param base FLEXSPI peripheral base address
757  * @param data The data bytes to send
758  * @param fifoIndex Destination fifo index.
759  */
FLEXSPI_WriteData(FLEXSPI_Type * base,uint32_t data,uint8_t fifoIndex)760 static inline void FLEXSPI_WriteData(FLEXSPI_Type *base, uint32_t data, uint8_t fifoIndex)
761 {
762     base->TFDR[fifoIndex] = data;
763 }
764 
765 /*!
766  * @brief Receives data from data FIFO.
767  *
768  * @param base FLEXSPI peripheral base address
769  * @param fifoIndex Source fifo index.
770  * @return The data in the FIFO.
771  */
FLEXSPI_ReadData(FLEXSPI_Type * base,uint8_t fifoIndex)772 static inline uint32_t FLEXSPI_ReadData(FLEXSPI_Type *base, uint8_t fifoIndex)
773 {
774     return base->RFDR[fifoIndex];
775 }
776 
777 /*!
778  * @brief Sends a buffer of data bytes using blocking method.
779  * @note This function blocks via polling until all bytes have been sent.
780  * @param base FLEXSPI peripheral base address
781  * @param buffer The data bytes to send
782  * @param size The number of data bytes to send
783  * @retval kStatus_Success write success without error
784  * @retval kStatus_FLEXSPI_SequenceExecutionTimeout sequence execution timeout
785  * @retval kStatus_FLEXSPI_IpCommandSequenceError IP command sequence error detected
786  * @retval kStatus_FLEXSPI_IpCommandGrantTimeout IP command grant timeout detected
787  */
788 status_t FLEXSPI_WriteBlocking(FLEXSPI_Type *base, uint8_t *buffer, size_t size);
789 
790 /*!
791  * @brief Receives a buffer of data bytes using a blocking method.
792  * @note This function blocks via polling until all bytes have been sent.
793  * @param base FLEXSPI peripheral base address
794  * @param buffer The data bytes to send
795  * @param size The number of data bytes to receive
796  * @retval kStatus_Success read success without error
797  * @retval kStatus_FLEXSPI_SequenceExecutionTimeout sequence execution timeout
798  * @retval kStatus_FLEXSPI_IpCommandSequenceError IP command sequencen error detected
799  * @retval kStatus_FLEXSPI_IpCommandGrantTimeout IP command grant timeout detected
800  */
801 status_t FLEXSPI_ReadBlocking(FLEXSPI_Type *base, uint8_t *buffer, size_t size);
802 
803 /*!
804  * @brief Execute command to transfer a buffer data bytes using a blocking method.
805  * @param base FLEXSPI peripheral base address
806  * @param xfer pointer to the transfer structure.
807  * @retval kStatus_Success command transfer success without error
808  * @retval kStatus_FLEXSPI_SequenceExecutionTimeout sequence execution timeout
809  * @retval kStatus_FLEXSPI_IpCommandSequenceError IP command sequence error detected
810  * @retval kStatus_FLEXSPI_IpCommandGrantTimeout IP command grant timeout detected
811  */
812 status_t FLEXSPI_TransferBlocking(FLEXSPI_Type *base, flexspi_transfer_t *xfer);
813 /*! @} */
814 
815 /*!
816  * @name Transactional
817  * @{
818  */
819 
820 /*!
821  * @brief Initializes the FLEXSPI handle which is used in transactional functions.
822  *
823  * @param base FLEXSPI peripheral base address.
824  * @param handle pointer to flexspi_handle_t structure to store the transfer state.
825  * @param callback pointer to user callback function.
826  * @param userData user parameter passed to the callback function.
827  */
828 void FLEXSPI_TransferCreateHandle(FLEXSPI_Type *base,
829                                   flexspi_handle_t *handle,
830                                   flexspi_transfer_callback_t callback,
831                                   void *userData);
832 
833 /*!
834  * @brief Performs a interrupt non-blocking transfer on the FLEXSPI bus.
835  *
836  * @note Calling the API returns immediately after transfer initiates. The user needs
837  * to call FLEXSPI_GetTransferCount to poll the transfer status to check whether
838  * the transfer is finished. If the return status is not kStatus_FLEXSPI_Busy, the transfer
839  * is finished. For FLEXSPI_Read, the dataSize should be multiple of rx watermark level, or
840  * FLEXSPI could not read data properly.
841  *
842  * @param base FLEXSPI peripheral base address.
843  * @param handle pointer to flexspi_handle_t structure which stores the transfer state.
844  * @param xfer pointer to flexspi_transfer_t structure.
845  * @retval kStatus_Success Successfully start the data transmission.
846  * @retval kStatus_FLEXSPI_Busy Previous transmission still not finished.
847  */
848 status_t FLEXSPI_TransferNonBlocking(FLEXSPI_Type *base, flexspi_handle_t *handle, flexspi_transfer_t *xfer);
849 
850 /*!
851  * @brief Gets the master transfer status during a interrupt non-blocking transfer.
852  *
853  * @param base FLEXSPI peripheral base address.
854  * @param handle pointer to flexspi_handle_t structure which stores the transfer state.
855  * @param count Number of bytes transferred so far by the non-blocking transaction.
856  * @retval kStatus_InvalidArgument count is Invalid.
857  * @retval kStatus_Success Successfully return the count.
858  */
859 status_t FLEXSPI_TransferGetCount(FLEXSPI_Type *base, flexspi_handle_t *handle, size_t *count);
860 
861 /*!
862  * @brief Aborts an interrupt non-blocking transfer early.
863  *
864  * @note This API can be called at any time when an interrupt non-blocking transfer initiates
865  * to abort the transfer early.
866  *
867  * @param base FLEXSPI peripheral base address.
868  * @param handle pointer to flexspi_handle_t structure which stores the transfer state
869  */
870 void FLEXSPI_TransferAbort(FLEXSPI_Type *base, flexspi_handle_t *handle);
871 
872 /*!
873  * @brief Master interrupt handler.
874  *
875  * @param base FLEXSPI peripheral base address.
876  * @param handle pointer to flexspi_handle_t structure.
877  */
878 void FLEXSPI_TransferHandleIRQ(FLEXSPI_Type *base, flexspi_handle_t *handle);
879 /*! @} */
880 
881 #if defined(__cplusplus)
882 }
883 #endif /*_cplusplus. */
884 /*@}*/
885 
886 #endif /* __FSL_FLEXSPI_H_ */
887