1 /*******************************************************************************
2  * Copyright 2019-2020 Microchip FPGA Embedded Systems Solutions.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  *
24  *
25  * PolarFire SoC (MPFS) Microprocessor SubSystem QSPI bare metal software
26  * driver public API.
27  *
28  */
29 /*=========================================================================*//**
30   @mainpage PolarFire SoC MSS QSPI Bare Metal Driver
31 
32   ==============================================================================
33   Introduction
34   ==============================================================================
35   The PolarFire SoC Microprocessor SubSystem (MSS) includes a QSPI controller
36   for fast SPI transfers. The MSS QSPI is designed as a SPI master to work
37   specifically with the (Q)SPI memory devices. The PolarFire SoC MSS QSPI driver
38   provides a set of functions for controlling the MSS QSPI as part of a bare
39   metal system, where no operating system is available. This driver can be
40   adapted for use as part of an operating system, but the implementation of the
41   adaptation layer between this driver and the operating system's driver model
42   is outside the scope of this driver.
43 
44   --------------------------------
45   Features
46   --------------------------------
47   The PolarFire SoC MSS QSPI driver provides the following features:
48        - QSPI Master operations in 1-bit, 2-bit, 4-bit formats and extended
49          operations
50        - XIP operations
51        - Configurable SPI mode0 and mode3
52        - Programmable SPI clock
53 
54   ==============================================================================
55   Hardware Flow Dependencies
56   ==============================================================================
57   The configuration of all the features of the MSS QSPI peripheral is covered by
58   this driver, with the exception of the PolarFire SoC IOMUX configuration.
59   The PolarFire SoC allows multiple non-concurrent uses of few external pins
60   through IOMUX configuration. This feature allows optimization of external pin
61   usage by assigning external pins for use by either the microprocessor
62   subsystem or the FPGA fabric. The MSS QSPI serial signals are routed through
63   IOMUXs to the PolarFire SoC device external pins. The MSS QSPI serial
64   signals can also be routed through IOMUXs to the PolarFire SoC FPGA fabric.
65   For more information on IOMUX, see the IOMUX section of the PolarFire SoC
66   Microprocessor Subsystem (MSS) User's Guide.
67 
68   The IOMUXs are configured using the PolarFire SoC MSS configurator tool. You
69   must ensure that the MSS QSPI peripherals are enabled and configured in the
70   PolarFire SoC MSS configurator if you wish to use them. For more information
71   on IOMUXs, refer to the IOMUX section of the PolarFire SoC microprocessor
72   Subsystem (MSS) User's Guide.
73 
74   The base address and the register addresses are defined in this driver as
75   constants. The interrupt number assignment for the MSS QSPI peripherals is
76   defined as constants in the MPFS HAL. You must ensure that the latest MPFS HAL
77   is included in the project settings of the SoftConsole toolchain and that it
78   is generated into your project.
79 
80   ==============================================================================
81   Theory of Operation
82   ==============================================================================
83   The MSS QSPI driver functions are grouped into the following categories.
84     - Initialization and configuration functions
85     - Polled transmit and receive functions
86     - Interrupt driven transmit and receive functions
87 
88   --------------------------------
89   Initialization and Configuration
90   --------------------------------
91   The MSS QSPI supports the following operations.
92     - Normal SPI operations (1 bit)
93     - Dual SPI operations   (2 bit)
94     - Quad SPI operations   (4 bit)
95 
96   The MSS QSPI driver provides the MSS_QSPI_init() function to initialize the
97   MSS QSPI hardware block. This initialization function must be called before
98   any other MSS QSPI driver functions can be called.
99 
100   The MSS QSPI driver provides the MSS_QSPI_config() function to configure the
101   MSS QSPI with desired configuration values. It also provides the
102   MSS_QSPI_get_config() function to read back the current configurations of the
103   MSS QSPI. You can use this function to retrieve the current configurations and
104   then overwrite them with the application specific values, such as SPI mode,
105   SPI clock rate, SDI sampling, QSPI operation, XIP mode and XIP address bits.
106   All these configuration options are explained in detail in the API function
107   description of the respective function.
108 
109   --------------------------------------
110   SPI master block transfer control
111   --------------------------------------
112   The driver can transmit and receive data when initialized and configured with
113   the desired configuration values. The MSS QSPI is designed to specifically
114   work with SPI flash memories. It supports a single, active-low slave-select
115   output. Block transfers can be accomplished in the following ways.
116     - Polled block transfer
117     - Interrupt driven block transfer
118 
119   ---------------------------
120   Polled block transfer
121   ---------------------------
122   The MSS_QSPI_polled_transfer_block() is provided to accomplish data transfers
123   where no interrupt is used. This function polls the status register to know
124   the current status of the on-going transfer. This is a blocking
125   function. A MSS QSPI block transfer always has some amount of data to be
126   transmitted (at least one command byte) but receiving useful data from target
127   memory device is optional. So, if the scheduled block transfer
128   is only transferring data (and not receiving any data), then this function
129   will exit after transmitting the required bytes. In a given transfer, if
130   there is data to be received from the target memory device, then this function
131   will exit when the expected data is received from the target memory device.
132 
133   --------------------------------
134   Interrupt driven block transfer
135   --------------------------------
136   This block transfer can be accomplished using interrupts instead of polling
137   the status register. The Following functions are provided to support interrupt
138   driven block transfers.
139             - MSS_QSPI_irq_transfer_block()
140             - MSS_QSPI_set_status_handler()
141 
142   The MSS_QSPI_set_status_handler() function must be used to set a status handler
143   call-back function with the driver. This function will be called-back by the
144   driver at two different stages of the transfer. At the first stage, it will
145   be called when the required number of bytes are transmitted. At the second
146   stage, if there is data to be received from the target memory device then it
147   will be called again when the desired data is received. Appropriate status
148   value is passed by the driver as a parameter of this call-back function, so
149   that the application can infer the event occurred.
150 
151   -----------
152   QSPI Status
153   -----------
154   The MSS_QSPI_read_status() function reads the current status of the MSS QSPI.
155   This function can typically be used to know the status of the ongoing transfer.
156   This function returns the status register value and can be called at any time
157   after the MSS QSPI is initialized and configured.
158 
159   -------------
160   Direct Access
161   -------------
162   MSS QSPI allows direct access to the QSPI interface pins to support access to
163   non-standard SPI devices via direct CPU control.
164 
165   This driver provides following functions to read and write the direct access
166   register of the MSS QSPI.
167                   - MSS_QSPI_read_direct_access_reg()
168                   - MSS_QSPI_write_direct_access_reg()
169 
170   Using these functions, you can generate any sequence of binary transitions on
171   the QSPI pins which might be needed to communicate with non-standard target
172   devices.
173 
174  *//*=========================================================================*/
175 
176 #ifndef MSS_QSPI_H_
177 #define MSS_QSPI_H_             1
178 
179 #include "drivers/mss_qspi/mss_qspi_regs.h"
180 
181 #ifdef __cplusplus
182 extern "C" {
183 #endif
184 
185 /* The following constants can be used as input parameter value to configure the
186  * event on which the SDI pin is sampled as shown below:
187  *  qspi_config.sample = MSS_QSPI_SAMPLE_POSAGE_SPICLK;
188  *  MSS_QSPI_configure(&qspi_config);
189  *
190  * */
191 /* The SDI pin is sampled at the rising edge off SPI CLOCK */
192 #define MSS_QSPI_SAMPLE_POSAGE_SPICLK       0x00u
193 
194 /* The SDI pin is sampled on the last falling HCLK edge in the SPI clock period */
195 #define MSS_QSPI_SAMPLE_ACTIVE_SPICLK       0x01u
196 
197 /* The SDI pin is sampled at the rising HCLK edge as SPICLK falls */
198 #define MSS_QSPI_SAMPLE_NEGAGE_SPICLK       0x02u
199 
200 /* Public constant definitions
201  * The following constants can be used to configure the MSS QSPI where a zero
202  * or non-zero value such as enable or disable is to be provided as input
203  * parameter as shown below:
204  *      qspi_config.xip = MSS_QSPI_DISABLE;
205  *      MSS_QSPI_configure(&qspi_config);
206  *
207  * */
208 #define MSS_QSPI_ENABLE                     0x01u
209 #define MSS_QSPI_DISABLE                    0x00u
210 
211 /***************************************************************************//**
212  These values are used to program the io_format parameter of the configuration
213  structure of this driver as shown below:
214      qspi_config.io_format = MSS_QSPI_QUAD_FULL;
215      MSS_QSPI_configure(&qspi_config);
216 
217 |   Value            |                   Description                            |
218 |--------------------|----------------------------------------------------------|
219 |MSS_QSPI_NORMAL     |  1 bit Normal SPI operations                             |
220 |                    |  (single DQ0 TX and single  DQ1 RX lines)                |
221 |                    |                                                          |
222 |MSS_QSPI_DUAL_EX_RO |  2 bit SPI operations                                    |
223 |                    |  (command and address bytes on DQ0 only. Data on DQ[1:0])|
224 |                       |                                                       |
225 |MSS_QSPI_QUAD_EX_RO |  4 bit SPI operations                                    |
226 |                    |  (command and address bytes on DQ0 only. Data on DQ[3:0])|
227 |                    |                                                          |
228 |MSS_QSPI_DUAL_EX_RW |  2 bit SPI operations                                    |
229 |                    |  (command byte on DQ0 only. Address and Data on DQ[1:0]) |
230 |                    |                                                          |
231 |MSS_QSPI_QUAD_EX_RW |  4 bit SPI operations                                    |
232 |                    |  (command byte on DQ0 only. Address and Data on DQ[3:0]) |
233 |                    |                                                          |
234 |MSS_QSPI_DUAL_FULL  |  2 bit SPI operations                                    |
235 |                    |  (command, address and Data on DQ[1:0])                  |
236 |                    |                                                          |
237 |MSS_QSPI_QUAD_FULL  |  4 bit SPI operations                                    |
238 |                    |  (command, address and Data on DQ[3:0])                  |
239 |                    |                                                          |
240 
241 */
242 typedef enum mss_qspi_io_format_t
243 {
244     MSS_QSPI_NORMAL      = 0u,
245     MSS_QSPI_DUAL_EX_RO  = 2u,
246     MSS_QSPI_QUAD_EX_RO  = 3u,
247     MSS_QSPI_DUAL_EX_RW  = 4u,
248     MSS_QSPI_QUAD_EX_RW  = 5u,
249     MSS_QSPI_DUAL_FULL   = 6u,
250     MSS_QSPI_QUAD_FULL   = 7u
251 
252 } mss_qspi_io_format;
253 
254 /***************************************************************************//**
255  These values are used to program the spi_mode parameter of the configuration
256  structure of this driver as shown below:
257      qspi_config.spi_mode = MSS_QSPI_MODE0;
258      MSS_QSPI_configure(&qspi_config);
259 
260 |   Value           |                   Description                            |
261 |-------------------|----------------------------------------------------------|
262 |   MSS_QSPI_MODE0  | Set clock IDLE to low   (0)                              |
263 |   MSS_QSPI_MODE0  | Set clock IDLE to high  (1)                              |
264 
265 */
266 typedef enum mss_qspi_protocol_mode_t
267 {
268     MSS_QSPI_MODE0    = 0x0u,
269     MSS_QSPI_MODE3    = 0x1u
270 
271 } mss_qspi_protocol_mode;
272 
273 /***************************************************************************//**
274  These values are used to program the spi_mode parameter of the configuration
275  structure of this driver as shown below:
276      qspi_config.clk_div =  MSS_QSPI_CLK_DIV_2;
277      MSS_QSPI_configure(&qspi_config);
278 
279 |        Value          |        Description        |
280 |-----------------------|---------------------------|
281 |   MSS_QSPI_CLK_DIV_2  |  Set SPI clock to HCLK/2  |
282 |   MSS_QSPI_CLK_DIV_4  |  Set SPI clock to HCLK/4  |
283 |   MSS_QSPI_CLK_DIV_6  |  Set SPI clock to HCLK/6  |
284 |   MSS_QSPI_CLK_DIV_8  |  Set SPI clock to HCLK/8  |
285 |   MSS_QSPI_CLK_DIV_10 |  Set SPI clock to HCLK/10 |
286 |   MSS_QSPI_CLK_DIV_12 |  Set SPI clock to HCLK/12 |
287 |   MSS_QSPI_CLK_DIV_14 |  Set SPI clock to HCLK/14 |
288 |   MSS_QSPI_CLK_DIV_16 |  Set SPI clock to HCLK/16 |
289 |   MSS_QSPI_CLK_DIV_18 |  Set SPI clock to HCLK/18 |
290 |   MSS_QSPI_CLK_DIV_20 |  Set SPI clock to HCLK/20 |
291 |   MSS_QSPI_CLK_DIV_22 |  Set SPI clock to HCLK/22 |
292 |   MSS_QSPI_CLK_DIV_24 |  Set SPI clock to HCLK/24 |
293 |   MSS_QSPI_CLK_DIV_26 |  Set SPI clock to HCLK/26 |
294 |   MSS_QSPI_CLK_DIV_28 |  Set SPI clock to HCLK/28 |
295 |   MSS_QSPI_CLK_DIV_30 |  Set SPI clock to HCLK/30 |
296 
297 */
298 typedef enum mss_qspi_clk_div_t
299 {
300     MSS_QSPI_CLK_DIV_2     = 0x1u,
301     MSS_QSPI_CLK_DIV_4     = 0x2u,
302     MSS_QSPI_CLK_DIV_6     = 0x3u,
303     MSS_QSPI_CLK_DIV_8     = 0x4u,
304     MSS_QSPI_CLK_DIV_10    = 0x5u,
305     MSS_QSPI_CLK_DIV_12    = 0x6u,
306     MSS_QSPI_CLK_DIV_14    = 0x7u,
307     MSS_QSPI_CLK_DIV_16    = 0x8u,
308     MSS_QSPI_CLK_DIV_18    = 0x9u,
309     MSS_QSPI_CLK_DIV_20    = 0xAu,
310     MSS_QSPI_CLK_DIV_22    = 0xBu,
311     MSS_QSPI_CLK_DIV_24    = 0xCu,
312     MSS_QSPI_CLK_DIV_26    = 0xDu,
313     MSS_QSPI_CLK_DIV_28    = 0xEu,
314     MSS_QSPI_CLK_DIV_30    = 0xFu
315 
316 } mss_qspi_clk_div;
317 
318 /***************************************************************************//**
319  This prototype defines the function prototype that must be followed by MSS QSPI
320  status handler functions. This function is registered with the MSS QSPI driver
321  through a call to the MSS_QSPI_set_status_handler() function.
322 
323  Declaring and Implementing Status Handler Function:
324  Slave frame receive handler functions should follow the following prototype.
325         void transfer_status_handler(uint32_t status);
326 
327  The actual name of the status handler is unimportant. You can use any name
328  of your choice. The status parameter will contain a value indicating which
329  of the TX-DONE, RX-DONE event has caused the interrupt.
330 */
331 typedef void (*mss_qspi_status_handler_t)(uint32_t status);
332 
333 
334 /***************************************************************************//**
335   MSS QSPI configuration structure.
336   This is structure definition for MSS QSPI configuration instance. It defines
337   the configuration data to be exchanged by the application with the driver.
338 
339   Configuration options for MSS QSPI
340 
341 |  Parameter  |                         Description                            |
342 |-------------|----------------------------------------------------------------|
343 |   xip       |  Enable or disable XIP mode                                    |
344 |   xip_addr  |  Number of address bytes used in XIP mode                      |
345 |   spi_mode  |  Select either Motorola mode0 or mode3                         |
346 |   clk_div   |  HCLK Clock divider for generating SPI clock                   |
347 |   io_format |  QSPI transfer format, extended,dual,quad etc.                 |
348 |   sample    |  Select the event on which the QSPI samples the incoming data  |
349 
350 */
351 typedef struct mss_qspi_config{
352     uint8_t                 xip;
353     uint8_t                 xip_addr;
354     mss_qspi_protocol_mode  spi_mode;   /*clkidl mode0 or mode3*/
355     mss_qspi_clk_div        clk_div;
356     mss_qspi_io_format      io_format;
357     uint8_t                 sample;
358 }mss_qspi_config_t;
359 
360 
361 /*----------------------------------------------------------------------------*/
362 /*------------------------MSS QSPI internal structures   ---------------------*/
363 /*----------------------------------------------------------------------------*/
364 
365 /*Register map of the PolarFire SoC MSS QSPI*/
366 typedef struct
367 {
368     volatile uint32_t CONTROL;
369     volatile uint32_t FRAMES;
370     volatile uint32_t RESERVED1;
371     volatile uint32_t INTENABLE;
372     volatile uint32_t STATUS;
373     volatile uint32_t DIRECT;
374     volatile uint8_t ADDRUP;
375     volatile uint8_t ADDRUP_R1;
376     volatile uint8_t ADDRUP_R2;
377     volatile uint8_t ADDRUP_R3;
378     volatile uint32_t RESERVED2[9];
379     volatile uint8_t RXDATAX1;
380     volatile uint8_t RXDATAX1_R1;
381     volatile uint8_t RXDATAX1_R2;
382     volatile uint8_t RXDATAX1_R3;
383     volatile uint8_t TXDATAX1;
384     volatile uint8_t TXDATAX1_R1;
385     volatile uint8_t TXDATAX1_R2;
386     volatile uint8_t TXDATAX1_R3;
387     volatile uint32_t RXDATAX4;
388     volatile uint32_t TXDATAX4;
389     volatile uint32_t FRAMESUP;
390 
391 } QSPI_TypeDef;
392 
393 /*PolarFire SoC MSS QSPI base memory address*/
394 #define QSPI_BASE               0x21000000u
395 
396 /*PolarFire SoC MSS QSPI hardware instance*/
397 #define QSPI                    ((QSPI_TypeDef *) QSPI_BASE)
398 
399 
400 
401 /*----------------------------------------------------------------------------*/
402 /*------------------------MSS QSPI Public APIs--------------------------------*/
403 /*----------------------------------------------------------------------------*/
404 
405 
406 
407 /***************************************************************************//**
408   The MSS_QSPI_init() function initializes and enables the PolarFireSoC MSS QSPI.
409 
410   It enables the MSS QSPI hardware block, and configures it with the default
411   values.
412 
413   @param
414     This function takes no function parameters.
415 
416   @return
417     This function does not return a value.
418 
419   Example:
420   @code
421    @endcode
422  */
423 void MSS_QSPI_init
424 (
425     void
426 );
427 
428 /***************************************************************************//**
429   The MSS_QSPI_enable() function enables the MSS QSPI hardware block.
430 
431   @param
432     This function takes no function parameters.
433 
434   @return
435     This function does not return a value.
436 
437   Example:
438   @code
439   @endcode
440  */
MSS_QSPI_enable(void)441 static inline void MSS_QSPI_enable(void)
442 {
443     QSPI->CONTROL |= CTRL_EN_MASK;
444 }
445 
446 /***************************************************************************//**
447   The MSS_QSPI_disable() function disables the MSS QSPI hardware block.
448 
449   @param
450     This function takes no function parameters.
451 
452   @return
453     This function does not return a value.
454 
455   Example:
456   @code
457   @endcode
458  */
MSS_QSPI_disable(void)459 static inline void MSS_QSPI_disable(void)
460 {
461     QSPI->CONTROL &= ~CTRL_EN_MASK;
462 }
463 
464 /***************************************************************************//**
465   The MSS_QSPI_configure() function configures the MSS QSPI to desired
466   configuration values.
467 
468   @param config
469     The config parameter is a pointer to the mss_qspi_config_t structure, which
470     provides new configuration values. See the mss_qspi_config_t section for
471     details.
472 
473   @return
474     This function does not return a value.
475 
476   Example:
477   @code
478   @endcode
479  */
480 void MSS_QSPI_configure
481 (
482     const mss_qspi_config_t* config
483 );
484 
485 /***************************************************************************//**
486   The MSS_QSPI_get_config() function reads-back the current configurations of
487   the MSS QSPI. This function can be used when you want to read the current
488   configurations, modify the configuration values of your choice and reconfigure
489   the MSS QSPI hardware, using MSS_QSPI_configure() function.
490 
491   @param config
492     The config parameter is a pointer to an mss_qspi_config_t structure in which
493     the current configuration values of the MSS QSPI are returned.
494 
495     Please see description of mss_qspi_config_t for more details.
496 
497   @return
498     This function does not return a value.
499 
500   Example:
501   @code
502   @endcode
503  */
504 void MSS_QSPI_get_config
505 (
506     mss_qspi_config_t* config
507 );
508 
509 /***************************************************************************//**
510   The MSS_QSPI_polled_transfer_block() function is used to carry out a QSPI
511   transfer with the target memory device using polling method of data transfer.
512   The QSPI transfer characteristics are configured every time a new transfer is
513   initiated. This is a blocking function.
514 
515   @param num_addr_bytes
516     The num_addr_bytes parameter indicates the number of address bytes to be
517     used while transacting with the target memory device. Depending on the
518     target memory device, the address within the target memory device can be
519     either 3 or 4 bytes long. You must make sure that you provide the exact same
520     number with which the target memory device is configured.
521 
522     Note: Few command opcodes do not require specified addresses. For example
523     READ_ID. For such commands the num_addr_bytes parameter must be set to 0x0.
524 
525   @param target_mem_addr
526     The target_mem_addr parameter is the memory address in the target memory
527     device on which the read/write operation is to be carried out.
528 
529   @param tx_buffer
530     The tx_buffer parameter is the pointer to the buffer from which the data
531     needs to transmitted to the target memory device.
532 
533   @param tx_byte_size
534     The tx_byte_size parameter is the exact number of bytes that needs to be
535     transmitted to the target memory device.
536 
537     Note: This parameter must not consider the command opcode and address bytes
538     as part of the data that needs to be transmitted.
539 
540   @param rd_buffer
541     The rd_buffer parameter is the pointer to the buffer where the data returned
542     by the target memory device is to be stored.
543 
544   @param rd_byte_size
545     The rd_byte_size parameter is the exact number of bytes that needs to be
546     received from the target memory device.
547 
548   @param num_idle_cycles
549     The num_idle_cycles parameter indicates the number of Idle cycles/dummy clock
550     edges that must be generated after the address bytes are transmitted and
551     before target memory device starts sending data. This must be correctly set
552     based on the target memory device and the SPI command being used – this may
553     also vary based on SPI clock and the way the target memory device is
554     configured.
555 
556   @return
557     This function does not return a value.
558 
559   Example:
560   @code
561   @endcode
562  */
563 void MSS_QSPI_polled_transfer_block
564 (
565     uint8_t num_addr_bytes,
566     const void * const tx_buffer,
567     uint32_t tx_byte_size,
568     const void * const rd_buffer,
569     uint32_t rd_byte_size,
570     uint8_t num_idle_cycles
571 );
572 
573 /***************************************************************************//**
574   The MSS_QSPI_irq_transfer_block() function is used to carry out a QSPI transfer
575   with the target memory device using interrupt method of data transfers.
576   The QSPI transfer characteristics are configured every time a new transfer is
577   initiated. This is non-blocking function. You must configure the interrupt
578   handler function, before calling this function.It will enable the interrupts
579   and start transmitting as many bytes as requested. You will get an indication
580   when the actual SPI transmit operation is complete when The transmit-done
581   interrupt event occurs and this driver calls-back the interrupt handler
582   function that you previously provided. If the transfer includes receiving
583   data from the target memory device then the receive-available and receive-done
584   interrupts are also enabled by this function. The data will be received in the
585   interrupt routine. The interrupt handler provided by you will be called-back
586   again when the receive-done interrupt event occurs.
587 
588   @param num_addr_bytes
589     The num_addr_bytes parameter indicates the number of address bytes to be
590     used while transacting with the target memory device. Depending on the the
591     target memory device, the address within the target memory device can be
592     either 3 or 4 bytes long.  You must make sure that you provide the exact
593     same number with which the target memory device is configured.
594 
595     Note: There will be some command opcodes for which no address needs to be
596     specified. e.g. READ_ID. For such commands the num_addr_bytes parameter
597     must be set to 0x0.
598 
599   @param target_mem_addr
600     The target_mem_addr parameter is the memory address in the target memory
601     device on which the read/write operation is to be carried out.
602 
603   @param tx_buffer
604     The tx_buffer parameter is the pointer to the buffer from which the data
605     needs to transmitted to the target QSPI memory.
606 
607   @param tx_byte_size
608     The tx_byte_size parameter is the exact number of bytes that needs to be
609     transmitted to target memory device.
610 
611     Note: This parameter must not consider the command opcode and address bytes
612     as part of the data that needs to be transmitted.
613 
614   @param rd_buffer
615     The rd_buffer parameter is the pointer to the buffer where the data returned
616     by the target memory device is to be stored.
617 
618   @param rd_byte_size
619     The rd_byte_size parameter is the exact number of bytes that needs to be
620     received from the target memory device.
621 
622   @param num_idle_cycles
623     The num_idle_cycles parameter indicates the The number of IDLE/dummy clock
624     edges that must be generated after the address bytes are transmitted and
625     before target memory device starts sending data. This must be correctly set
626     based on the target memory device and the SPI command being used – this may
627     also vary based on SPI clock and the way the target memory device is
628     configured.
629 
630   @return
631     This function a non-zero value if the MSS QSPI is busy completing the
632     previous transfer and can not accept a new transfer. A zero return value
633     indicates successful execution of this function.
634 
635   Example:
636   @code
637   @endcode
638  */
639 uint8_t MSS_QSPI_irq_transfer_block
640 (
641     uint8_t num_addr_bytes,
642     const void * const tx_buffer,
643     uint32_t tx_byte_size,
644     const void * const rd_buffer,
645     uint32_t rd_byte_size,
646     uint8_t num_idle_cycles
647 );
648 
649 /***************************************************************************//**
650   The MSS_QSPI_set_status_handler() function registers an interrupt handler
651   function with this driver which is used to indicate the interrupt status back
652   to the application. This status handler function is called by this driver in
653   two events. First, when the transmission of required bytes is completed
654   (Transmit-Done). Second, if data is to be received from the target memory
655   device then this function is called again when required data is received
656   (Receive-Done).
657 
658   @param handler
659   The handler parameter is the interrupt handler function of the type
660   mss_qspi_status_handler_t which needs to be registered.
661 
662   @return
663     This function does not return a value.
664 
665   Example:
666   @code
667   @endcode
668  */
669 void MSS_QSPI_set_status_handler
670 (
671    mss_qspi_status_handler_t handler
672 );
673 
674 /***************************************************************************//**
675   The MSS_QSPI_read_direct_access_reg() reads the current value of the direct
676   access register(DAR) of the MSS QSPI. DAR allows direct access to the QSPI
677   interface pins to support access to non-standard SPI devices through direct
678   CPU control.
679 
680   @param
681     This function takes no function parameters.
682 
683   @return
684     This function returns the current value of the DAR of the MSS QSPI.
685 
686   Example:
687   @code
688   @endcode
689  */
MSS_QSPI_read_direct_access_reg(void)690 static inline uint32_t MSS_QSPI_read_direct_access_reg(void)
691 {
692     return(QSPI->DIRECT);
693 }
694 
695 /***************************************************************************//**
696   The MSS_QSPI_write_direct_access_reg() to write a value of the DAR of the MSS
697   QSPI. DAR allows direct access to the QSPI interface pins, to support access
698   to non-standard SPI devices through direct CPU control.
699 
700   @param value
701   The value parameter is the value that needs to be set into the direct access
702   register of the MSS QSPI.
703 
704   @return
705     This function does not return a value.
706 
707   Example:
708   @code
709   @endcode
710  */
MSS_QSPI_write_direct_access_reg(uint32_t value)711 static inline void MSS_QSPI_write_direct_access_reg(uint32_t value)
712 {
713     QSPI->DIRECT = value;
714 }
715 
716 /***************************************************************************//**
717   The function MSS_QSPI_read_status() is used to read the status of the MSS QSPI.
718   This function returns the status register value and can be called any time
719   after the MSS QSPI is initialized and configured.
720 
721   @param
722     This function takes no function parameters.
723 
724   @return
725     This function returns the the current value of the status register of the
726     MSS QSPI.
727 
728   Example:
729   @code
730   @endcode
731  */
MSS_QSPI_read_status(void)732 static inline uint32_t MSS_QSPI_read_status(void)
733 {
734     return(QSPI->STATUS);
735 }
736 
737 #ifdef __cplusplus
738 }
739 #endif
740 
741 #endif /* MSS_QSPI_H_*/
742