AM62Ax MCU+ SDK  10.01.00
flash.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021-2023 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 
33 #ifndef FLASH_H_
34 #define FLASH_H_
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
41 #include <stdint.h>
42 #include <kernel/dpl/SystemP.h>
43 #include <drivers/hw_include/soc_config.h>
44 #include <board/flash/flash_config.h>
45 #include <kernel/dpl/SemaphoreP.h>
46 
47 #define FLASH_INVALID_VALUE (0xFFFFFFFFU)
48 
49 #define CONFIG_FLASH_TYPE_SERIAL ((uint32_t)0x1)
50 #define CONFIG_FLASH_TYPE_PARALLEL ((uint32_t)0x2)
51 
55 #define CONFIG_FLASH_TYPE_SERIAL_NOR (0x00U)
56 #define CONFIG_FLASH_TYPE_SERIAL_NAND (0x01U)
57 #define CONFIG_FLASH_TYPE_PARALLEL_NOR (0x02U)
58 #define CONFIG_FLASH_TYPE_PARALLEL_NAND (0x03U)
59 #define CONFIG_FLASH_TYPE_INVALID (0xFFU)
60 
61 #define FLASH_NOR_UPDATE_RD_DUMMY_VALUE (1U)
62 #define FLASH_NAND_UPDATE_RD_DUMMY_VALUE (0U)
63 
78 typedef void *Flash_Handle;
79 
83 typedef struct Flash_Config_s Flash_Config;
84 
88 typedef struct Flash_Params_s Flash_Params;
89 
95 typedef struct Flash_DevConfig_s {
96 
97  uint8_t cmdExtType;
98  uint8_t byteOrder;
99  uint8_t enable4BAddr;
101 
103  uint8_t cmdWren;
104  uint8_t cmdRdsr;
105  uint8_t cmdWrsr;
106  uint8_t cmdPageLoad;
107  uint8_t cmdPageProg;
108  uint8_t srWip;
109 
114  uint8_t cmdRandomInput;
117  uint8_t pageColAddrCyc;
118  uint8_t pageRowAddrCyc;
119  uint8_t cmdReadStatus;
120  uint8_t cmdReset;
121 
122 
123  uint8_t srWel;
124  uint8_t resetType;
125  uint8_t deviceBusyType;
126  uint8_t xspiWipRdCmd;
127 
128  uint32_t srWipReg;
129  uint32_t xspiWipReg;
130  uint32_t xspiWipBit;
131  uint32_t xspiRdsrDummy;
134 
135  FlashCfg_EraseConfig eraseCfg;
136  FlashCfg_ReadIDConfig idCfg;
137  FlashCfg_ProtoEnConfig protocolCfg;
138 
139  uint32_t progStatusReg;
141  uint32_t eraseStatusReg;
143  uint8_t srProgStatus;
144  uint8_t srEraseStatus;
147 
149 
167 typedef int32_t (*Flash_OpenFxn)(Flash_Config *config, Flash_Params *params);
168 
179 typedef void (*Flash_CloseFxn)(Flash_Config *config);
180 
194 typedef int32_t (*Flash_ReadFxn)(Flash_Config *config, uint32_t offset,
195  uint8_t *buf, uint32_t len) ;
196 
210 typedef int32_t (*Flash_WriteFxn)(Flash_Config *config, uint32_t offset,
211  uint8_t *buf, uint32_t len) ;
212 
224 typedef int32_t (*Flash_EraseFxn)(Flash_Config *config, uint32_t blockNum);
225 
237 typedef int32_t (*Flash_EraseSectorFxn)(Flash_Config *config, uint32_t sectorNum);
238 
250 typedef int32_t (*Flash_ResetFxn)(Flash_Config *config);
251 
262 typedef int32_t (*Flash_EnablePhyPipelineFxn)(Flash_Config *config);
263 
274 typedef int32_t (*Flash_DisablePhyPipelineFxn)(Flash_Config *config);
275 
286 typedef int32_t (*Flash_quirksFxn)(Flash_Config *config);
287 
295 typedef int32_t (*Flash_custProtocolFxn)(Flash_Config *config);
296 
303 typedef struct Flash_Params_s {
304 
307 
308 } Flash_Params;
309 
313 typedef struct Flash_Fxns_s
314 {
325 } Flash_Fxns;
326 
330 typedef struct Flash_Attrs_s {
331 
332  uint32_t flashType;
333  char *flashName;
334  uint32_t deviceId;
335  uint32_t manufacturerId;
336  uint32_t driverInstance;
337  uint32_t flashSize;
338  uint32_t blockCount;
339  uint32_t blockSize;
340  uint32_t pageCount;
341  uint32_t pageSize;
342  uint32_t sectorCount;
343  uint32_t sectorSize;
344  uint32_t spareAreaSize;
346 } Flash_Attrs;
347 
351 typedef struct Flash_Config_s
352 {
356  void *object;
359 } Flash_Config;
360 
361 /* Flash specific includes */
362 #if defined (DRV_VERSION_SERIAL_FLASH_V0)
363 #include <board/flash/ospi/flash_nor_ospi.h>
364 #include <board/flash/ospi/flash_nand_ospi.h>
365 #endif
366 
367 #if defined (DRV_VERSION_SERIAL_FLASH_V1)
368 #include <board/flash/qspi/flash_nor_qspi.h>
369 #endif
370 
371 #if defined (DRV_VERSION_PARALLEL_FLASH_V0)
372 #include <board/flash/gpmc/flash_nand_gpmc.h>
373 #endif
374 
383 
402 Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params);
403 
410 
419 Flash_Handle Flash_getHandle(uint32_t instanceId);
420 
433 int32_t Flash_read(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
434 
447 int32_t Flash_write(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
448 
459 int32_t Flash_blkPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t block, uint32_t page);
460 
471 int32_t Flash_offsetToBlkPage(Flash_Handle handle, uint32_t offset, uint32_t *block, uint32_t *page);
472 
483 int32_t Flash_SectorPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t sector, uint32_t page);
484 
495 int32_t Flash_offsetToSectorPage(Flash_Handle handle, uint32_t offset, uint32_t *sector, uint32_t *page);
496 
507 int32_t Flash_eraseBlk(Flash_Handle handle, uint32_t blockNum);
508 
519 int32_t Flash_eraseSector(Flash_Handle handle, uint32_t sectorNum);
520 
528 int32_t Flash_reset(Flash_Handle handle);
529 
538 
547 
556 
564 Flash_Attrs *Flash_getAttrs(uint32_t instanceId);
565 
573 uint32_t Flash_getFlashInterfaceIndex(uint32_t flashType);
574 
578 void Flash_init(void);
579 
583 void Flash_deinit(void);
584 
588 #ifdef __cplusplus
589 }
590 #endif
591 
592 #endif /* FLASH_H_ */
Flash_DevConfig::cmdPageLoadCyc1
uint8_t cmdPageLoadCyc1
Definition: flash.h:110
Flash_Attrs::flashType
uint32_t flashType
Definition: flash.h:332
Flash_DevConfig::cmdPageProgCyc1
uint8_t cmdPageProgCyc1
Definition: flash.h:115
Flash_close
void Flash_close(Flash_Handle handle)
Close flash driver.
Flash_DevConfig::cmdReadStatus
uint8_t cmdReadStatus
Definition: flash.h:119
Flash_Config::lockSem
SemaphoreP_Object lockSem
Definition: flash.h:357
Flash_DevConfig::xspiRdsrDummy
uint32_t xspiRdsrDummy
Definition: flash.h:131
Flash_Config::attrs
Flash_Attrs * attrs
Definition: flash.h:353
Flash_Attrs::flashSize
uint32_t flashSize
Definition: flash.h:337
Flash_DevConfig::progStatusReg
uint32_t progStatusReg
Definition: flash.h:139
Flash_Fxns::openFxn
Flash_OpenFxn openFxn
Definition: flash.h:315
Flash_DisablePhyPipelineFxn
int32_t(* Flash_DisablePhyPipelineFxn)(Flash_Config *config)
Driver implementation to disable PHY pipeline mode in Flash.
Definition: flash.h:274
Flash_deinit
void Flash_deinit(void)
This function de-initializes the Flash module.
Flash_DevConfig::eraseCfg
FlashCfg_EraseConfig eraseCfg
Definition: flash.h:135
Flash_DevConfig::cmdWrsr
uint8_t cmdWrsr
Definition: flash.h:105
Flash_Attrs::blockCount
uint32_t blockCount
Definition: flash.h:338
Flash_DevConfig::protocolCfg
FlashCfg_ProtoEnConfig protocolCfg
Definition: flash.h:137
Flash_DevConfig::cmdExtType
uint8_t cmdExtType
Definition: flash.h:97
Flash_CloseFxn
void(* Flash_CloseFxn)(Flash_Config *config)
Driver implementation to close a specific flash driver.
Definition: flash.h:179
SystemP.h
Flash_DevConfig::cmdWren
uint8_t cmdWren
Definition: flash.h:103
Flash_Config::devConfig
Flash_DevConfig * devConfig
Definition: flash.h:355
Flash_Attrs::driverInstance
uint32_t driverInstance
Definition: flash.h:336
Flash_Config
Flash driver configuration, these are filled by SysCfg based on the flash device that is selected.
Definition: flash.h:352
Flash_offsetToBlkPage
int32_t Flash_offsetToBlkPage(Flash_Handle handle, uint32_t offset, uint32_t *block, uint32_t *page)
Utility API to convert offset in bytes to (Block Num, Page Num)
Flash_DevConfig::cmdPageProg
uint8_t cmdPageProg
Definition: flash.h:107
Flash_DevConfig::srWipReg
uint32_t srWipReg
Definition: flash.h:128
Flash_SectorPageToOffset
int32_t Flash_SectorPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t sector, uint32_t page)
Utility API to convert (Sector Num, Page Num) to offset in bytes.
Flash_DevConfig::deviceBusyType
uint8_t deviceBusyType
Definition: flash.h:125
Flash_DevConfig::cmdRdsr
uint8_t cmdRdsr
Definition: flash.h:104
Flash_DevConfig::xspiWipReg
uint32_t xspiWipReg
Definition: flash.h:129
Flash_DevConfig::cmdPageProgCyc2
uint8_t cmdPageProgCyc2
Definition: flash.h:116
Flash_Fxns::eraseSectorFxn
Flash_EraseSectorFxn eraseSectorFxn
Definition: flash.h:320
Flash_DevConfig::flashBusyTimeout
uint32_t flashBusyTimeout
Definition: flash.h:133
Flash_Attrs::sectorSize
uint32_t sectorSize
Definition: flash.h:343
Flash_Config::fxns
Flash_Fxns * fxns
Definition: flash.h:354
Flash_Attrs::pageSize
uint32_t pageSize
Definition: flash.h:341
Flash_DevConfig::addrByteSupport
uint8_t addrByteSupport
Definition: flash.h:100
Flash_ReadFxn
int32_t(* Flash_ReadFxn)(Flash_Config *config, uint32_t offset, uint8_t *buf, uint32_t len)
Driver implementation to read from flash using a specific flash driver.
Definition: flash.h:194
Flash_blkPageToOffset
int32_t Flash_blkPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t block, uint32_t page)
Utility API to convert (Block Num, Page Num) to offset in bytes.
SemaphoreP.h
Flash_Attrs
Flash device attributes, these are filled by SysCfg based on the flash device that is selected.
Definition: flash.h:330
Flash_Attrs::flashName
char * flashName
Definition: flash.h:333
Flash_DevConfig::cmdRandomReadCyc2
uint8_t cmdRandomReadCyc2
Definition: flash.h:113
Flash_DevConfig::xspiWipBit
uint32_t xspiWipBit
Definition: flash.h:130
Flash_Fxns::eraseFxn
Flash_EraseFxn eraseFxn
Definition: flash.h:319
Flash_getHandle
Flash_Handle Flash_getHandle(uint32_t instanceId)
Get handle to flash driver.
Flash_Fxns
Driver implementation callbacks.
Definition: flash.h:314
Flash_EraseFxn
int32_t(* Flash_EraseFxn)(Flash_Config *config, uint32_t blockNum)
Driver implementation to erase a block using a specific flash driver.
Definition: flash.h:224
Flash_getPhyTuningOffset
uint32_t Flash_getPhyTuningOffset(Flash_Handle handle)
Return flash offset to write PHY tuning data.
Flash_DevConfig::fourByteAddrEnSeq
uint8_t fourByteAddrEnSeq
Definition: flash.h:102
Flash_DevConfig::srWip
uint8_t srWip
Definition: flash.h:108
Flash_DevConfig::srWel
uint8_t srWel
Definition: flash.h:123
Flash_Config
struct Flash_Config_s Flash_Config
Forward declaration of Flash_Config.
Definition: flash.h:83
Flash_DevConfig::resetType
uint8_t resetType
Definition: flash.h:124
Flash_WriteFxn
int32_t(* Flash_WriteFxn)(Flash_Config *config, uint32_t offset, uint8_t *buf, uint32_t len)
Driver implementation to write to flash using specific flash driver.
Definition: flash.h:210
Flash_Fxns::closeFxn
Flash_CloseFxn closeFxn
Definition: flash.h:316
Flash_DevConfig::cmdPageLoadCyc2
uint8_t cmdPageLoadCyc2
Definition: flash.h:111
Flash_DevConfig::flashWriteTimeout
uint32_t flashWriteTimeout
Definition: flash.h:132
Flash_Params_init
void Flash_Params_init(Flash_Params *params)
Set default parameters in the Flash_Params structure.
Flash_ResetFxn
int32_t(* Flash_ResetFxn)(Flash_Config *config)
Driver implementation to soft reset the flash.
Definition: flash.h:250
Flash_Attrs::pageCount
uint32_t pageCount
Definition: flash.h:340
Flash_Params
struct Flash_Params_s Flash_Params
Forward declaration of Flash_Params.
Definition: flash.h:88
Flash_Attrs::spareAreaSize
uint32_t spareAreaSize
Definition: flash.h:344
Flash_DevConfig::pageRowAddrCyc
uint8_t pageRowAddrCyc
Definition: flash.h:118
Flash_custProtocolFxn
int32_t(* Flash_custProtocolFxn)(Flash_Config *config)
User implementation of a custom function to configure flash to operate in a specific protocol.
Definition: flash.h:295
Flash_EnablePhyPipelineFxn
int32_t(* Flash_EnablePhyPipelineFxn)(Flash_Config *config)
Driver implementation to enable PHY pipeline mode in Flash.
Definition: flash.h:262
Flash_Fxns::enablePhyPipelineFxn
Flash_EnablePhyPipelineFxn enablePhyPipelineFxn
Definition: flash.h:322
Flash_getAttrs
Flash_Attrs * Flash_getAttrs(uint32_t instanceId)
Return flash attributes.
Flash_DevConfig::xspiWipRdCmd
uint8_t xspiWipRdCmd
Definition: flash.h:126
Flash_Attrs::blockSize
uint32_t blockSize
Definition: flash.h:339
Flash_DevConfig::idCfg
FlashCfg_ReadIDConfig idCfg
Definition: flash.h:136
Flash_disablePhyPipeline
int32_t Flash_disablePhyPipeline(Flash_Handle handle)
Disable PHY mode in flash.
Flash_offsetToSectorPage
int32_t Flash_offsetToSectorPage(Flash_Handle handle, uint32_t offset, uint32_t *sector, uint32_t *page)
Utility API to convert offset in bytes to (Sector Num, Page Num)
Flash_DevConfig::xspiEraseStatusReg
uint32_t xspiEraseStatusReg
Definition: flash.h:142
Flash_enablePhyPipeline
int32_t Flash_enablePhyPipeline(Flash_Handle handle)
Enables PHY mode in flash.
Flash_DevConfig::srWriteProtectMask
uint8_t srWriteProtectMask
Definition: flash.h:146
Flash_Fxns::disablePhyPipelineFxn
Flash_DisablePhyPipelineFxn disablePhyPipelineFxn
Definition: flash.h:323
Flash_eraseSector
int32_t Flash_eraseSector(Flash_Handle handle, uint32_t sectorNum)
Erase a sector from flash.
Flash_Attrs::deviceId
uint32_t deviceId
Definition: flash.h:334
Flash_Fxns::readFxn
Flash_ReadFxn readFxn
Definition: flash.h:317
Flash_DevConfig::enable4BAddr
uint8_t enable4BAddr
Definition: flash.h:99
Flash_reset
int32_t Flash_reset(Flash_Handle handle)
Do a soft reset of the flash.
Flash_EraseSectorFxn
int32_t(* Flash_EraseSectorFxn)(Flash_Config *config, uint32_t sectorNum)
Driver implementation to erase a sector using a specific flash driver.
Definition: flash.h:237
Flash_Fxns::writeFxn
Flash_WriteFxn writeFxn
Definition: flash.h:318
Flash_OpenFxn
int32_t(* Flash_OpenFxn)(Flash_Config *config, Flash_Params *params)
Driver implementation to open a specific flash driver.
Definition: flash.h:167
Flash_DevConfig::cmdReset
uint8_t cmdReset
Definition: flash.h:120
Flash_open
Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params)
Open flash driver.
Flash_DevConfig::cmdRandomInput
uint8_t cmdRandomInput
Definition: flash.h:114
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
Flash_DevConfig::cmdRandomReadCyc1
uint8_t cmdRandomReadCyc1
Definition: flash.h:112
Flash_init
void Flash_init(void)
This function initializes the Flash module.
Flash_DevConfig::byteOrder
uint8_t byteOrder
Definition: flash.h:98
Flash_DevConfig::srWriteProtectReg
uint8_t srWriteProtectReg
Definition: flash.h:145
Flash_Attrs::manufacturerId
uint32_t manufacturerId
Definition: flash.h:335
Flash_DevConfig::cmdPageLoad
uint8_t cmdPageLoad
Definition: flash.h:106
Flash_Fxns::resetFxn
Flash_ResetFxn resetFxn
Definition: flash.h:321
Flash_DevConfig::pageColAddrCyc
uint8_t pageColAddrCyc
Definition: flash.h:117
Flash_eraseBlk
int32_t Flash_eraseBlk(Flash_Handle handle, uint32_t blockNum)
Erase a block from flash.
Flash_write
int32_t Flash_write(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len)
Write to flash.
Flash_DevConfig::srEraseStatus
uint8_t srEraseStatus
Definition: flash.h:144
Flash_DevConfig::eraseStatusReg
uint32_t eraseStatusReg
Definition: flash.h:141
Flash_quirksFxn
int32_t(* Flash_quirksFxn)(Flash_Config *config)
User implementation of a custom function to handle vendor specific quirks.
Definition: flash.h:286
Flash_Attrs::sectorCount
uint32_t sectorCount
Definition: flash.h:342
Flash_DevConfig::xspiProgStatusReg
uint32_t xspiProgStatusReg
Definition: flash.h:140
Flash_Params
Parameters passed during Flash_open()
Definition: flash.h:303
Flash_Handle
void * Flash_Handle
Handle to the FLash driver returned by Flash_opem()
Definition: flash.h:78
Flash_DevConfig::srProgStatus
uint8_t srProgStatus
Definition: flash.h:143
Flash_getFlashInterfaceIndex
uint32_t Flash_getFlashInterfaceIndex(uint32_t flashType)
Return flash index based on type of flash.
Flash_Params::quirksFxn
Flash_quirksFxn quirksFxn
Definition: flash.h:305
Flash_Params::custProtoFxn
Flash_custProtocolFxn custProtoFxn
Definition: flash.h:306
Flash_DevConfig
Flash device config. This will be part of the flash config, so has to be filled by sysconfig or other...
Definition: flash.h:95
Flash_read
int32_t Flash_read(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len)
Read data from flash.
Flash_Config::object
void * object
Definition: flash.h:356