AM64x MCU+ SDK  07.03.00
ospi/v0/ospi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 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 OSPI_H_
51 #define OSPI_H_
52 
53 /* ========================================================================== */
54 /* Include Files */
55 /* ========================================================================== */
56 
57 #include <stdint.h>
58 #include <kernel/dpl/SystemP.h>
59 #include <kernel/dpl/HwiP.h>
60 #include <kernel/dpl/SemaphoreP.h>
61 #include <drivers/hw_include/csl_types.h>
62 #include <drivers/hw_include/cslr_ospi.h>
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 /* ========================================================================== */
69 /* Macros & Typedefs */
70 /* ========================================================================== */
71 
73 typedef void *OSPI_Handle;
74 
83 #define OSPI_TRANSFER_COMPLETED (0U)
84 #define OSPI_TRANSFER_STARTED (1U)
85 #define OSPI_TRANSFER_CANCELLED (2U)
86 #define OSPI_TRANSFER_FAILED (3U)
87 #define OSPI_TRANSFER_CSN_DEASSERT (4U)
88 #define OSPI_TRANSFER_TIMEOUT (5U)
89 
110 #define OSPI_TRANSFER_MODE_BLOCKING (0U)
111 
115 #define OSPI_TRANSFER_MODE_CALLBACK (1U)
116 
120 #define OSPI_TRANSFER_MODE_POLLING (2U)
121 
137 #define OSPI_FF_POL0_PHA0 (0U)
138 #define OSPI_FF_POL0_PHA1 (CSL_OSPI_FLASH_CFG_CONFIG_REG_SEL_CLK_PHASE_FLD_MASK | 0U)
139 #define OSPI_FF_POL1_PHA0 (0U | CSL_OSPI_FLASH_CFG_CONFIG_REG_SEL_CLK_POL_FLD_MASK)
140 #define OSPI_FF_POL1_PHA1 (CSL_OSPI_FLASH_CFG_CONFIG_REG_SEL_CLK_PHASE_FLD_MASK | \
141  CSL_OSPI_FLASH_CFG_CONFIG_REG_SEL_CLK_POL_FLD_MASK)
142 
152 #define OSPI_XFER_LINES_SINGLE (0U)
153 #define OSPI_XFER_LINES_DUAL (1U)
154 #define OSPI_XFER_LINES_QUAD (2U)
155 #define OSPI_XFER_LINES_OCTAL (3U)
156 
166 #define OSPI_CS0 (0U)
167 #define OSPI_CS1 (1U)
168 #define OSPI_CS2 (2U)
169 #define OSPI_CS3 (3U)
170 
171 #define OSPI_CHIP_SELECT(x) ((~((1U) << (x))) & 0xFU)
172 
182 #define OSPI_DECODER_SELECT4 ((uint32_t) 0U)
183 #define OSPI_DECODER_SELECT16 ((uint32_t) 1U)
184 
186 /* ========================================================================== */
187 /* Structure Declarations */
188 /* ========================================================================== */
196 typedef struct
197 {
198  uint32_t count;
200  void *buf;
202  uint32_t addrOffset;
204  uint32_t status;
206  uint32_t transferTimeout;
209 
210 typedef struct
211 {
212  void *cmd;
214  uint32_t cmdLen;
216  void *txDataBuf;
218  uint32_t txDataLen;
221 
222 typedef struct
223 {
224  void *cmd;
226  uint32_t cmdLen;
228  void *rxDataBuf;
230  uint32_t rxDataLen;
233 
244 typedef struct
245 {
246  int32_t ospiDmaChIndex;
247  /* Index of Channel used by OSPI DMA Driver. This index will be set by SysCfg according to the DMA driver chosen.
248  * The OSPI driver uses this index to do an \ref OSPI_dmaOpen inside the \ref OSPI_open if the DMA mode is enabled
249  */
250 } OSPI_Params;
251 
253 typedef struct
254 {
255  /*
256  * SOC configuration
257  */
258  uint32_t baseAddr;
260  uint32_t dataBaseAddr;
262  uint32_t inputClkFreq;
265  /*
266  * Driver configuration
267  */
268  uint32_t intrNum;
270  uint32_t intrEnable;
272  uint8_t intrPriority;
274  uint32_t xipEnable;
276  uint32_t dtrEnable;
278  uint32_t dmaEnable;
280  uint32_t phyEnable;
282  uint32_t dacEnable;
284  uint32_t pageSize;
286  uint32_t blkSize;
288  uint32_t xferLines;
290  uint32_t frmFmt;
292  uint32_t devDelays[4];
294  uint32_t rdDummyClks;
296  uint32_t extRdDummyClks;
298  uint32_t chipSelect;
300  uint32_t decChipSelect;
302  uint32_t baudRateDiv;
304 } OSPI_Attrs;
305 
310 typedef struct
311 {
312  /*
313  * User params
314  */
317  uint32_t transferMode;
319  uint32_t xferLines;
321  uint32_t rdDummyClks;
323  uint32_t extRdDummyClks;
325  /*
326  * State variables
327  */
328  uint32_t isOpen;
339  uint32_t rdStatusCmd;
342 } OSPI_Object;
343 
344 typedef struct
345 {
350 } OSPI_Config;
351 
353 extern OSPI_Config gOspiConfig[];
355 extern uint32_t gOspiConfigNum;
356 
357 /* ========================================================================== */
358 /* Internal/Private Structure Declarations */
359 /* ========================================================================== */
360 
361 /* ========================================================================== */
362 /* Function Declarations */
363 /* ========================================================================== */
364 
368 void OSPI_init(void);
369 
373 void OSPI_deinit(void);
374 
375 
381 void OSPI_Params_init( OSPI_Params *ospiParams);
382 
397 OSPI_Handle OSPI_open(uint32_t index, const OSPI_Params *openParams);
398 
408 void OSPI_close(OSPI_Handle handle);
409 
423 
442 
455 
468 
481 
494 int32_t OSPI_readCmd(OSPI_Handle handle, OSPI_ReadCmdParams *rdParams);
495 
507 int32_t OSPI_writeCmd(OSPI_Handle handle, OSPI_WriteCmdParams *wrParams);
508 
517 
526 
535 
545 uint32_t OSPI_isDacEnable(OSPI_Handle handle);
546 
556 uint32_t OSPI_isDmaEnable(OSPI_Handle handle);
557 
568 
578 uint32_t OSPI_isPhyEnable(OSPI_Handle handle);
579 
590 uint32_t OSPI_isDtrEnable(OSPI_Handle handle);
591 
601 uint32_t OSPI_isXipEnable(OSPI_Handle handle);
602 
613 
626 int32_t OSPI_enableModeDDR(OSPI_Handle handle, uint32_t cmd, uint32_t addr, uint32_t data);
627 
640 int32_t OSPI_enableModeSDR(OSPI_Handle handle, uint32_t cmd, uint32_t addr, uint32_t data);
641 
654 int32_t OSPI_enableModeXIP(OSPI_Handle handle, uint32_t cmd, uint32_t addr, uint32_t data);
655 
668 int32_t OSPI_setDummyCycle(OSPI_Handle handle, uint32_t cmd, uint32_t addr, uint32_t data);
669 
679 void OSPI_setReadDummyCycles(OSPI_Handle handle, uint32_t dummyCycles);
680 
690 void OSPI_setExtReadDummyCycles(OSPI_Handle handle, uint32_t dummyCycles);
691 
701 void OSPI_setXferLines(OSPI_Handle handle, uint32_t xferLines);
702 
714 void OSPI_setXferOpCode(OSPI_Handle handle, uint32_t readCmd, uint32_t pageProgCmd, uint32_t readStatusCmd);
715 
727 void OSPI_setXferOpCodeExt(OSPI_Handle handle, uint32_t *cmd, uint32_t cmdLen);
728 
739 
750 
761 
764 #ifdef __cplusplus
765 }
766 #endif
767 
768 #endif /* #ifndef OSPI_H_ */
769 
770 
OSPI_isDacEnable
uint32_t OSPI_isDacEnable(OSPI_Handle handle)
This function checks if the Direct Access Controller is enabled.
OSPI_Attrs::pageSize
uint32_t pageSize
Definition: ospi/v0/ospi.h:284
OSPI_Transaction::status
uint32_t status
Definition: ospi/v0/ospi.h:204
OSPI_ReadCmdParams
Definition: ospi/v0/ospi.h:223
OSPI_enableModeSDR
int32_t OSPI_enableModeSDR(OSPI_Handle handle, uint32_t cmd, uint32_t addr, uint32_t data)
This function enables the Single Data Rate (DDR)
OSPI_Transaction_init
void OSPI_Transaction_init(OSPI_Transaction *trans)
Function to initialize the OSPI_Transaction structure.
OSPI_WriteCmdParams
Definition: ospi/v0/ospi.h:211
OSPI_ReadCmdParams_init
void OSPI_ReadCmdParams_init(OSPI_ReadCmdParams *rdParams)
Function to initialize the OSPI_Transaction structure.
OSPI_Attrs::xipEnable
uint32_t xipEnable
Definition: ospi/v0/ospi.h:274
OSPI_Transaction::transferTimeout
uint32_t transferTimeout
Definition: ospi/v0/ospi.h:206
OSPI_Attrs::dacEnable
uint32_t dacEnable
Definition: ospi/v0/ospi.h:282
OSPI_Attrs::xferLines
uint32_t xferLines
Definition: ospi/v0/ospi.h:288
OSPI_Transaction
Data structure used with OSPI_Transfers - OSPI_readDirect, OSPI_writeDirect, OSPI_readIndirect,...
Definition: ospi/v0/ospi.h:197
OSPI_Attrs::intrPriority
uint8_t intrPriority
Definition: ospi/v0/ospi.h:272
index
uint16_t index
Definition: tisci_rm_proxy.h:3
SystemP.h
OSPI_init
void OSPI_init(void)
This function initializes the OSPI module.
OSPI_setXferLines
void OSPI_setXferLines(OSPI_Handle handle, uint32_t xferLines)
This function sets the number of transfer lines to the flash device configuration registers.
OSPI_deinit
void OSPI_deinit(void)
This function de-initializes the OSPI module.
OSPI_Object::rdStatusCmd
uint32_t rdStatusCmd
Definition: ospi/v0/ospi.h:339
OSPI_Params_init
void OSPI_Params_init(OSPI_Params *ospiParams)
Initialize data structure with defaults.
OSPI_getXferLines
uint32_t OSPI_getXferLines(OSPI_Handle handle)
This function returns the number of transfer lines enabled for the OSPI communication.
OSPI_isDtrEnable
uint32_t OSPI_isDtrEnable(OSPI_Handle handle)
This function checks if the Dual Transfer Rate (Sampling on both rising and falling edge of the clock...
OSPI_Object::handle
OSPI_Handle handle
Definition: ospi/v0/ospi.h:315
OSPI_Attrs::dataBaseAddr
uint32_t dataBaseAddr
Definition: ospi/v0/ospi.h:260
OSPI_Transaction::count
uint32_t count
Definition: ospi/v0/ospi.h:198
OSPI_Attrs::dtrEnable
uint32_t dtrEnable
Definition: ospi/v0/ospi.h:276
OSPI_isXipEnable
uint32_t OSPI_isXipEnable(OSPI_Handle handle)
This function checks if the eXecute In Place (XIP) mode is enabled.
OSPI_Attrs::baudRateDiv
uint32_t baudRateDiv
Definition: ospi/v0/ospi.h:302
OSPI_Params
OSPI Parameters.
Definition: ospi/v0/ospi.h:245
data
uint32_t data
Definition: tisci_rm_psil.h:1
OSPI_getHandle
OSPI_Handle OSPI_getHandle(uint32_t index)
This function returns the handle of an open OSPI Instance from the instance index.
SemaphoreP.h
OSPI_Object::transferMode
uint32_t transferMode
Definition: ospi/v0/ospi.h:317
OSPI_WriteCmdParams::txDataLen
uint32_t txDataLen
Definition: ospi/v0/ospi.h:218
OSPI_WriteCmdParams::txDataBuf
void * txDataBuf
Definition: ospi/v0/ospi.h:216
addr
uint64_t addr
Definition: csl_udmap_tr.h:3
OSPI_disableDacMode
int32_t OSPI_disableDacMode(OSPI_Handle handle)
This function disables the Direct Access Mode.
OSPI_Attrs::inputClkFreq
uint32_t inputClkFreq
Definition: ospi/v0/ospi.h:262
OSPI_setExtReadDummyCycles
void OSPI_setExtReadDummyCycles(OSPI_Handle handle, uint32_t dummyCycles)
This function sets appropriate dummy cycles to the OSPI object to be used for flash extended read.
OSPI_Attrs
OSPI instance attributes - used during init time.
Definition: ospi/v0/ospi.h:254
OSPI_getFlashDataBaseAddr
uint32_t OSPI_getFlashDataBaseAddr(OSPI_Handle handle)
This function gets the SOC mapped data base address of the flash.
OSPI_Object
OSPI driver object.
Definition: ospi/v0/ospi.h:311
OSPI_readDirect
int32_t OSPI_readDirect(OSPI_Handle handle, OSPI_Transaction *trans)
Function to perform direct reads from the flash using DAC controller.
OSPI_Attrs::chipSelect
uint32_t chipSelect
Definition: ospi/v0/ospi.h:298
OSPI_Object::isOpen
uint32_t isOpen
Definition: ospi/v0/ospi.h:328
OSPI_ReadCmdParams::rxDataBuf
void * rxDataBuf
Definition: ospi/v0/ospi.h:228
OSPI_writeIndirect
int32_t OSPI_writeIndirect(OSPI_Handle handle, OSPI_Transaction *trans)
Function to perform indirect writes to the flash using INDAC controller.
OSPI_Attrs::blkSize
uint32_t blkSize
Definition: ospi/v0/ospi.h:286
OSPI_isPhyEnable
uint32_t OSPI_isPhyEnable(OSPI_Handle handle)
This function checks if the OSPI PHY controller is enabled.
OSPI_Attrs::extRdDummyClks
uint32_t extRdDummyClks
Definition: ospi/v0/ospi.h:296
HwiP.h
OSPI_Object::extRdDummyClks
uint32_t extRdDummyClks
Definition: ospi/v0/ospi.h:323
OSPI_writeCmd
int32_t OSPI_writeCmd(OSPI_Handle handle, OSPI_WriteCmdParams *wrParams)
Function to send specific commands and related data to flash.
OSPI_setDummyCycle
int32_t OSPI_setDummyCycle(OSPI_Handle handle, uint32_t cmd, uint32_t addr, uint32_t data)
This function sets appropriate dummy cycles to the flash controller.
OSPI_Params::ospiDmaChIndex
int32_t ospiDmaChIndex
Definition: ospi/v0/ospi.h:246
OSPI_Transaction::buf
void * buf
Definition: ospi/v0/ospi.h:200
OSPI_setXferOpCode
void OSPI_setXferOpCode(OSPI_Handle handle, uint32_t readCmd, uint32_t pageProgCmd, uint32_t readStatusCmd)
This function sets the transfer opcodes required for correct read and write operations to the flash.
OSPI_Config
Definition: ospi/v0/ospi.h:345
OSPI_ReadCmdParams::cmdLen
uint32_t cmdLen
Definition: ospi/v0/ospi.h:226
OSPI_Attrs::intrNum
uint32_t intrNum
Definition: ospi/v0/ospi.h:268
OSPI_close
void OSPI_close(OSPI_Handle handle)
Function to close a OSPI peripheral specified by the OSPI handle.
OSPI_Object::lockObj
SemaphoreP_Object lockObj
Definition: ospi/v0/ospi.h:330
OSPI_setXferOpCodeExt
void OSPI_setXferOpCodeExt(OSPI_Handle handle, uint32_t *cmd, uint32_t cmdLen)
This function sets the transfer opcodes required for correct read and write operations to the flash f...
OSPI_enableModeXIP
int32_t OSPI_enableModeXIP(OSPI_Handle handle, uint32_t cmd, uint32_t addr, uint32_t data)
This function enables the eXecute In Place (XIP) mode.
OSPI_Object::xferLines
uint32_t xferLines
Definition: ospi/v0/ospi.h:319
OSPI_isDmaEnable
uint32_t OSPI_isDmaEnable(OSPI_Handle handle)
This function checks if DMA is enabled for reads.
OSPI_Attrs::rdDummyClks
uint32_t rdDummyClks
Definition: ospi/v0/ospi.h:294
HwiP_Object
Opaque Hwi object used with the Hwi APIs.
Definition: HwiP.h:91
OSPI_Object::hwiObj
HwiP_Object hwiObj
Definition: ospi/v0/ospi.h:334
OSPI_Object::rdDummyClks
uint32_t rdDummyClks
Definition: ospi/v0/ospi.h:321
OSPI_setReadDummyCycles
void OSPI_setReadDummyCycles(OSPI_Handle handle, uint32_t dummyCycles)
This function sets appropriate dummy cycles to the OSPI object to be used for flash read.
OSPI_Object::ospiDmaHandle
void * ospiDmaHandle
Definition: ospi/v0/ospi.h:341
gOspiConfig
OSPI_Config gOspiConfig[]
Externally defined driver configuration array.
OSPI_isIntrEnable
uint32_t OSPI_isIntrEnable(OSPI_Handle handle)
This function checks if interrupts are enabled.
OSPI_Transaction::addrOffset
uint32_t addrOffset
Definition: ospi/v0/ospi.h:202
OSPI_Attrs::dmaEnable
uint32_t dmaEnable
Definition: ospi/v0/ospi.h:278
OSPI_Attrs::phyEnable
uint32_t phyEnable
Definition: ospi/v0/ospi.h:280
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
OSPI_ReadCmdParams::rxDataLen
uint32_t rxDataLen
Definition: ospi/v0/ospi.h:230
OSPI_enableModeDDR
int32_t OSPI_enableModeDDR(OSPI_Handle handle, uint32_t cmd, uint32_t addr, uint32_t data)
This function enables the Dual Data Rate (DDR)
OSPI_ReadCmdParams::cmd
void * cmd
Definition: ospi/v0/ospi.h:224
OSPI_WriteCmdParams_init
void OSPI_WriteCmdParams_init(OSPI_WriteCmdParams *wrParams)
Function to initialize the OSPI_Transaction structure.
OSPI_open
OSPI_Handle OSPI_open(uint32_t index, const OSPI_Params *openParams)
This function opens a given OSPI peripheral.
OSPI_Object::currTrans
OSPI_Transaction * currTrans
Definition: ospi/v0/ospi.h:337
OSPI_Attrs::intrEnable
uint32_t intrEnable
Definition: ospi/v0/ospi.h:270
OSPI_enableDacMode
int32_t OSPI_enableDacMode(OSPI_Handle handle)
This function enables the Direct Access Mode.
OSPI_Handle
void * OSPI_Handle
A handle that is returned from a OSPI_open() call.
Definition: ospi/v0/ospi.h:73
OSPI_Attrs::baseAddr
uint32_t baseAddr
Definition: ospi/v0/ospi.h:258
OSPI_Attrs::frmFmt
uint32_t frmFmt
Definition: ospi/v0/ospi.h:290
gOspiConfigNum
uint32_t gOspiConfigNum
Externally defined driver configuration array size.
OSPI_WriteCmdParams::cmd
void * cmd
Definition: ospi/v0/ospi.h:212
OSPI_writeDirect
int32_t OSPI_writeDirect(OSPI_Handle handle, OSPI_Transaction *trans)
Function to perform direct writes to the flash using DAC controller.
OSPI_Config::attrs
const OSPI_Attrs * attrs
Definition: ospi/v0/ospi.h:346
OSPI_WriteCmdParams::cmdLen
uint32_t cmdLen
Definition: ospi/v0/ospi.h:214
OSPI_readCmd
int32_t OSPI_readCmd(OSPI_Handle handle, OSPI_ReadCmdParams *rdParams)
Function to send specific commands and receive related data from flash.
OSPI_Config::object
OSPI_Object * object
Definition: ospi/v0/ospi.h:348
OSPI_readIndirect
int32_t OSPI_readIndirect(OSPI_Handle handle, OSPI_Transaction *trans)
Function to perform indirect reads from the flash using INDAC controller.
OSPI_Attrs::decChipSelect
uint32_t decChipSelect
Definition: ospi/v0/ospi.h:300
OSPI_Object::transferSemObj
SemaphoreP_Object transferSemObj
Definition: ospi/v0/ospi.h:332