AM263x MCU+ SDK  10.01.00
qspi_lld.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
50 #ifndef QSPI_LLD_H_
51 #define QSPI_LLD_H_
52 
53 /* ========================================================================== */
54 /* Include Files */
55 /* ========================================================================== */
56 
57 #include <drivers/hw_include/cslr_qspi.h>
58 #include <stdbool.h>
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /* ========================================================================== */
65 /* Macros & Typedefs */
66 /* ========================================================================== */
67 
69 typedef void *QSPI_DmaHandle;
70 
72 typedef void *QSPI_DmaChConfig;
73 
82 #define QSPI_CS0 (0U)
83 #define QSPI_CS1 (1U)
84 #define QSPI_CS2 (2U)
85 #define QSPI_CS3 (3U)
86 
91 #define QSPI_NOT_IN_USE(x) (void) 0
92 
98 #define QSPI_LLD_CMD_INVALID_ADDR (0xFFFFFFFFU)
99 
110 #define QSPI_RX_LINES_SINGLE (0U)
111 #define QSPI_RX_LINES_DUAL (1U)
112 #define QSPI_RX_LINES_QUAD (2U)
113 
129 #define QSPI_FF_POL0_PHA0 ((CSL_QSPI_SPI_DC_REG_CKPH0_CKP_0_SHIFT_OUT_FALLING_EDGE \
130  << CSL_QSPI_SPI_DC_REG_CKPH0_SHIFT) | \
131  (CSL_QSPI_SPI_DC_REG_CKP0_DATA_INACTIVE << \
132  CSL_QSPI_SPI_DC_REG_CKP0_SHIFT))
133 #define QSPI_FF_POL0_PHA1 ((CSL_QSPI_SPI_DC_REG_CKPH0_CKP_0_SHIFT_OUT_RISING_EDGE \
134  << CSL_QSPI_SPI_DC_REG_CKPH0_SHIFT) | \
135  (CSL_QSPI_SPI_DC_REG_CKP0_DATA_INACTIVE << \
136  CSL_QSPI_SPI_DC_REG_CKP0_SHIFT))
137 #define QSPI_FF_POL1_PHA0 ((CSL_QSPI_SPI_DC_REG_CKPH0_CKP_1_SHIFT_OUT_RISING_EDGE \
138  << CSL_QSPI_SPI_DC_REG_CKPH0_SHIFT) | \
139  (CSL_QSPI_SPI_DC_REG_CKP0_DATA_ACTIVE << \
140  CSL_QSPI_SPI_DC_REG_CKP0_SHIFT))
141 #define QSPI_FF_POL1_PHA1 ((CSL_QSPI_SPI_DC_REG_CKPH0_CKP_1_SHIFT_OUT_FALLING_EDGE \
142  << CSL_QSPI_SPI_DC_REG_CKPH0_SHIFT) | \
143  (CSL_QSPI_SPI_DC_REG_CKP0_DATA_ACTIVE << \
144  CSL_QSPI_SPI_DC_REG_CKP0_SHIFT))
145 
155 #define QSPI_CS_POL_ACTIVE_LOW (CSL_QSPI_SPI_DC_REG_CSP0_ACTIVE_LOW)
156 #define QSPI_CS_POL_ACTIVE_HIGH (CSL_QSPI_SPI_DC_REG_CSP0_ACTIVE_HIGH)
157 
167 #define QSPI_DATA_DELAY_0 (CSL_QSPI_SPI_DC_REG_DD0_CS_TO_DATA_DELAY_0)
168 #define QSPI_DATA_DELAY_1 (CSL_QSPI_SPI_DC_REG_DD0_CS_TO_DATA_DELAY_1)
169 #define QSPI_DATA_DELAY_2 (CSL_QSPI_SPI_DC_REG_DD0_CS_TO_DATA_DELAY_2)
170 #define QSPI_DATA_DELAY_3 (CSL_QSPI_SPI_DC_REG_DD0_CS_TO_DATA_DELAY_3)
171 
182 #define QSPI_MEM_MAP_PORT_SEL_CFG_PORT \
183  (CSL_QSPI_SPI_SWITCH_REG_MMPT_S_SEL_CFG_PORT)
184 #define QSPI_MEM_MAP_PORT_SEL_MEM_MAP_PORT \
185  (CSL_QSPI_SPI_SWITCH_REG_MMPT_S_SEL_MM_PORT)
186 
189 #define QSPI_MAX_WORD_LENGTH (128U)
190 
197 #define QSPI_SYSTEM_SUCCESS ((int32_t )0)
198 
202 #define QSPI_SYSTEM_FAILURE ((int32_t)-1)
203 
207 #define QSPI_TIMEOUT ((int32_t)-2)
208 
212 #define QSPI_LLD_INVALID_PARAM ((int32_t)-3)
213 
217 #define QSPI_BUSY ((int32_t)-4)
218 
222 #define QSPI_INVALID_STATE ((int32_t)-5)
223 
232 #define QSPI_STATE_RESET (0U)
233 
237 #define QSPI_STATE_READY (1U)
238 
242 #define QSPI_STATE_BUSY (2U)
243 
247 #define QSPI_STATE_ERROR (3U)
248 
257 #define QSPI_STATE_IDLE (0U)
258 
261 #define QSPI_STATE_ADDRESS_WRITE (1U)
262 
265 #define QSPI_STATE_DATA_WRITE (2U)
266 
269 #define QSPI_STATE_DATA_READ (3U)
270 
273 #define QSPI_STATE_BLOCK (4U)
274 
277 #define QSPI_STATE_NON_BLOCK (5U)
278 
281 /* ========================================================================== */
282 /* Function pointers Declarations */
283 /* ========================================================================== */
284 
292 typedef uint32_t (*QSPI_Clock_getTicks)(void);
293 
303 typedef uint32_t (*QSPI_Clock_usecToTicks)(uint64_t usecs);
304 
311 /* Type definition for the callback function*/
312 typedef void (*QSPI_lld_InterruptCallback)(void* args);
313 
321 
330 /* ========================================================================== */
331 /* Structure Definitions */
332 /* ========================================================================== */
336 typedef struct
337 {
338  uint32_t count;
340  uint32_t dataLen;
342  void *buf;
344  uint32_t addrOffset;
346  bool status;
350  uint32_t cmdRegVal;
352  uint32_t currentIndex;
354  uint8_t cmd;
356  uint8_t numAddrBytes;
358  uint32_t wlen;
360  uint32_t state;
363 
367 typedef struct
368 {
369  uint8_t cmd;
371  uint32_t cmdAddr;
374  uint8_t numAddrBytes;
376  void *dataBuf;
378  uint32_t dataLen;
381 
385 typedef struct
386 {
387  uint32_t memMapBaseAddr;
389  uint32_t inputClkFreq;
391  uint32_t qspiClockDiv;
393  uint32_t chipSelect;
395  uint32_t csPol;
397  uint32_t frmFmt;
399  uint32_t dataDelay;
401  uint32_t wrdLen;
403  uint32_t rxLines;
409  uint32_t intrNum;
413  bool wordIntr;
415  bool frameIntr;
417  uint8_t intrPriority;
419  bool dmaEnable;
426 
430 typedef struct
431 {
432  /*
433  * SOC configuration
434  */
435  uint32_t baseAddr;
437  uint8_t readCmd;
439  uint8_t writeCmd;
441  uint32_t frmLength;
443  uint32_t numAddrBytes;
445  uint32_t numDummyBits;
449  uint32_t state;
451  void* args;
458  /* Interrupt Callback to be registered by the application*/
460  /* DMA Readcallback function*/
462 
465 /* ========================================================================== */
466 /* Function Declarations */
467 /* ========================================================================== */
468 
477 
486 
495 
504 
515 
526 
537 
548 
560 int32_t QSPI_lld_read(QSPILLD_Handle hQspi, uint32_t count, void* rxBuf, uint32_t addrOffset, uint32_t timeout);
561 
574 int32_t QSPI_lld_readDma(QSPILLD_Handle hQspi, uint32_t count, void* rxBuf, uint32_t addrOffset, uint32_t timeout);
575 
576 /* API's used by flash driver */
577 
586 int32_t QSPI_lld_setWriteCmd(QSPILLD_Handle hQspi, uint8_t command);
587 
596 int32_t QSPI_lld_setReadCmd(QSPILLD_Handle hQspi, uint8_t command);
597 
609 int32_t QSPI_lld_setAddressByteCount(QSPILLD_Handle hQspi, uint32_t count);
610 
622 int32_t QSPI_lld_setDummyBitCount(QSPILLD_Handle hQspi, uint32_t count);
623 
633 int32_t QSPI_lld_setMemAddrSpace(QSPILLD_Handle hQspi, uint32_t memMappedPortSwitch);
634 
647 int32_t QSPI_lld_setRxLines(QSPILLD_Handle hQspi, uint32_t rxLines);
648 
666 int32_t QSPI_lld_setPreScaler(QSPILLD_Handle hQspi, uint32_t clkDividerVal);
667 
681 int32_t QSPI_lld_getInputClk(QSPILLD_Handle hQspi, uint32_t* inputClk);
682 
693 
700 void QSPI_lld_isr(void* args);
701 
708 
709 
710 #ifdef __cplusplus
711 }
712 #endif
713 
714 #endif /* #ifndef QSPI_LLD_H_ */
715 
QSPI_lld_readCmd
int32_t QSPI_lld_readCmd(QSPILLD_Handle hQspi, QSPILLD_WriteCmdParams *writeMsg)
Function to send specific commands and receive related data from flash in configuration mode.
QSPILLD_WriteCmdParams::dataBuf
void * dataBuf
Definition: qspi_lld.h:376
QSPILLD_InitObject::memMapBaseAddr
uint32_t memMapBaseAddr
Definition: qspi_lld.h:387
QSPILLD_Object::args
void * args
Definition: qspi_lld.h:451
QSPILLD_Transaction::readWriteFlag
bool readWriteFlag
Definition: qspi_lld.h:348
args
void * args
Definition: hsmclient_msg.h:4
QSPILLD_InitObject::inputClkFreq
uint32_t inputClkFreq
Definition: qspi_lld.h:389
QSPILLD_InitObject::wordIntr
bool wordIntr
Definition: qspi_lld.h:413
QSPILLD_Object::readCmd
uint8_t readCmd
Definition: qspi_lld.h:437
QSPI_lld_setRxLines
int32_t QSPI_lld_setRxLines(QSPILLD_Handle hQspi, uint32_t rxLines)
Set QSPI Rx lines in the QSPI object.
QSPILLD_InitObject::Clock_usecToTicks
QSPI_Clock_usecToTicks Clock_usecToTicks
Definition: qspi_lld.h:423
QSPI_lld_readDma
int32_t QSPI_lld_readDma(QSPILLD_Handle hQspi, uint32_t count, void *rxBuf, uint32_t addrOffset, uint32_t timeout)
Function to perform read from the flash in DMA mode.
QSPILLD_Transaction
QSPI Driver Transaction.
Definition: qspi_lld.h:337
QSPILLD_InitObject::intrPriority
uint8_t intrPriority
Definition: qspi_lld.h:417
QSPILLD_TransactionHandle
struct QSPILLD_Transaction * QSPILLD_TransactionHandle
QSPILLD_Transaction::wlen
uint32_t wlen
Definition: qspi_lld.h:358
QSPILLD_InitObject::wrdLen
uint32_t wrdLen
Definition: qspi_lld.h:401
QSPILLD_InitObject::dmaEnable
bool dmaEnable
Definition: qspi_lld.h:419
QSPI_lld_getInputClk
int32_t QSPI_lld_getInputClk(QSPILLD_Handle hQspi, uint32_t *inputClk)
This function returns the input clock at which QSPI was programmed.
QSPILLD_Transaction::cmdRegVal
uint32_t cmdRegVal
Definition: qspi_lld.h:350
QSPI_lld_setReadCmd
int32_t QSPI_lld_setReadCmd(QSPILLD_Handle hQspi, uint8_t command)
Function to set read command to be used.
QSPILLD_Transaction::buf
void * buf
Definition: qspi_lld.h:342
QSPILLD_Object::transaction
QSPILLD_Transaction * transaction
Definition: qspi_lld.h:453
QSPI_lld_read
int32_t QSPI_lld_read(QSPILLD_Handle hQspi, uint32_t count, void *rxBuf, uint32_t addrOffset, uint32_t timeout)
Function to perform reads from the flash in memory map mode.
QSPILLD_Object::baseAddr
uint32_t baseAddr
Definition: qspi_lld.h:435
QSPI_DmaChConfig
void * QSPI_DmaChConfig
A handle that holds DMA configuration parameters for QSPI.
Definition: qspi_lld.h:72
QSPILLD_InitObject
QSPI driver initialization object.
Definition: qspi_lld.h:386
QSPI_lld_InterruptCallback
void(* QSPI_lld_InterruptCallback)(void *args)
The definition of a interrupt completion callback function used by the QSPI driver.
Definition: qspi_lld.h:312
QSPILLD_WriteCmdParams::dataLen
uint32_t dataLen
Definition: qspi_lld.h:378
QSPI_lld_isr
void QSPI_lld_isr(void *args)
QSPI ISR for Read and Write Functionality.
QSPILLD_InitObject::qspiClockDiv
uint32_t qspiClockDiv
Definition: qspi_lld.h:391
QSPILLD_Transaction::status
bool status
Definition: qspi_lld.h:346
QSPILLD_Object::writeCmd
uint8_t writeCmd
Definition: qspi_lld.h:439
QSPILLD_Object::interruptCallback
QSPI_lld_InterruptCallback interruptCallback
Definition: qspi_lld.h:457
QSPILLD_InitObject::intrNum
uint32_t intrNum
Definition: qspi_lld.h:409
QSPILLD_InitObject::csPol
uint32_t csPol
Definition: qspi_lld.h:395
QSPILLD_Handle
struct QSPILLD_Object * QSPILLD_Handle
QSPILLD_WriteCmdParams::cmdAddr
uint32_t cmdAddr
Definition: qspi_lld.h:371
QSPI_lld_dma_readCompleteCallback
void(* QSPI_lld_dma_readCompleteCallback)(void *args)
The definition of a dma read completion callback function used by the QSPI driver.
Definition: qspi_lld.h:320
QSPILLD_Transaction::numAddrBytes
uint8_t numAddrBytes
Definition: qspi_lld.h:356
QSPILLD_InitObject::chipSelect
uint32_t chipSelect
Definition: qspi_lld.h:393
QSPILLD_Object::frmLength
uint32_t frmLength
Definition: qspi_lld.h:441
QSPI_lld_readCmdIntr
int32_t QSPI_lld_readCmdIntr(QSPILLD_Handle hQspi, const QSPILLD_WriteCmdParams *msg)
Function to send specific commands and receive related data from flash in interrupt mode.
QSPILLD_Object
QSPI driver object.
Definition: qspi_lld.h:431
QSPILLD_Object::readCompleteCallback
QSPI_lld_dma_readCompleteCallback readCompleteCallback
Definition: qspi_lld.h:459
QSPI_Clock_usecToTicks
uint32_t(* QSPI_Clock_usecToTicks)(uint64_t usecs)
The definition of a micro seconds to ticks function used by the QSPI driver to get ticks from microse...
Definition: qspi_lld.h:303
QSPILLD_InitObject::qspiDmaHandle
QSPI_DmaHandle qspiDmaHandle
Definition: qspi_lld.h:405
QSPILLD_Transaction::currentIndex
uint32_t currentIndex
Definition: qspi_lld.h:352
QSPILLD_InitObject::intrEnable
bool intrEnable
Definition: qspi_lld.h:411
QSPILLD_WriteCmdParams::cmd
uint8_t cmd
Definition: qspi_lld.h:369
QSPILLD_Object::numDummyBits
uint32_t numDummyBits
Definition: qspi_lld.h:445
QSPI_lld_setDummyBitCount
int32_t QSPI_lld_setDummyBitCount(QSPILLD_Handle hQspi, uint32_t count)
Function to set number of dummy bits to be used.
QSPI_lld_writeCmd
int32_t QSPI_lld_writeCmd(QSPILLD_Handle hQspi, QSPILLD_WriteCmdParams *writeMsg)
Function to send specific commands and write data into flash in configuration mode.
QSPILLD_Transaction::addrOffset
uint32_t addrOffset
Definition: qspi_lld.h:344
QSPI_lld_setWriteCmd
int32_t QSPI_lld_setWriteCmd(QSPILLD_Handle hQspi, uint8_t command)
Function to set write command to be used.
QSPILLD_InitObject::dataDelay
uint32_t dataDelay
Definition: qspi_lld.h:399
QSPI_lld_initDma
int32_t QSPI_lld_initDma(QSPILLD_Handle hQspi)
This function initializes the QSPI module in DMA Mode.
QSPILLD_WriteCmdParams::numAddrBytes
uint8_t numAddrBytes
Definition: qspi_lld.h:374
QSPI_DmaHandle
void * QSPI_DmaHandle
The handle for DMA instance used with QSPI.
Definition: qspi_lld.h:69
QSPILLD_WriteCmdParams
QSPI Transaction Info.
Definition: qspi_lld.h:368
QSPILLD_Transaction::cmd
uint8_t cmd
Definition: qspi_lld.h:354
QSPI_lld_setMemAddrSpace
int32_t QSPI_lld_setMemAddrSpace(QSPILLD_Handle hQspi, uint32_t memMappedPortSwitch)
This function is used to switch between memory mapped and configuration mode.
QSPILLD_InitObject::Clock_getTicks
QSPI_Clock_getTicks Clock_getTicks
Definition: qspi_lld.h:421
QSPI_lld_setPreScaler
int32_t QSPI_lld_setPreScaler(QSPILLD_Handle hQspi, uint32_t clkDividerVal)
Set the QSPI clock register divider value.
QSPILLD_Object::hQspiInit
QSPILLD_InitHandle hQspiInit
Definition: qspi_lld.h:447
QSPILLD_InitObject::frameIntr
bool frameIntr
Definition: qspi_lld.h:415
QSPI_Clock_getTicks
uint32_t(* QSPI_Clock_getTicks)(void)
The definition of a get System Tick function used by the QSPI driver to keep track of time.
Definition: qspi_lld.h:292
QSPI_lld_setAddressByteCount
int32_t QSPI_lld_setAddressByteCount(QSPILLD_Handle hQspi, uint32_t count)
Function to set number of address bytes to be used.
QSPILLD_Transaction::dataLen
uint32_t dataLen
Definition: qspi_lld.h:340
QSPI_lld_deInit
int32_t QSPI_lld_deInit(QSPILLD_Handle hQspi)
This function de-initializes the QSPI module.
QSPI_lld_deInitDma
int32_t QSPI_lld_deInitDma(QSPILLD_Handle hQspi)
This function de-initializes the QSPI module in DMA Mode.
QSPILLD_InitObject::rxLines
uint32_t rxLines
Definition: qspi_lld.h:403
QSPILLD_Transaction::count
uint32_t count
Definition: qspi_lld.h:338
QSPILLD_Object::state
uint32_t state
Definition: qspi_lld.h:449
QSPILLD_InitObject::frmFmt
uint32_t frmFmt
Definition: qspi_lld.h:397
QSPILLD_Object::trans
QSPILLD_Transaction trans
Definition: qspi_lld.h:455
QSPI_lld_readCompleteCallback
void QSPI_lld_readCompleteCallback(void *args)
QSPI Read complete callback for DMA mode.
QSPI_lld_getRxLines
uint32_t QSPI_lld_getRxLines(QSPILLD_Handle hQspi)
Get QSPI Rx lines in the QSPI object.
QSPI_lld_init
int32_t QSPI_lld_init(QSPILLD_Handle hQspi)
This function initializes the QSPI module.
QSPILLD_Object::numAddrBytes
uint32_t numAddrBytes
Definition: qspi_lld.h:443
QSPILLD_Transaction::state
uint32_t state
Definition: qspi_lld.h:360
QSPILLD_InitObject::qspiDmaChConfig
QSPI_DmaChConfig qspiDmaChConfig
Definition: qspi_lld.h:407
QSPI_lld_writeCmdIntr
int32_t QSPI_lld_writeCmdIntr(QSPILLD_Handle hQspi, const QSPILLD_WriteCmdParams *msg)
Function to send specific commands and write data into flash in interrupt mode.
QSPILLD_InitHandle
struct QSPILLD_InitObject * QSPILLD_InitHandle