AM62x MCU+ SDK  09.02.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 
75 typedef void *Flash_Handle;
76 
80 typedef struct Flash_Config_s Flash_Config;
81 
85 typedef struct Flash_Params_s Flash_Params;
86 
92 typedef struct Flash_DevConfig_s {
93 
94  uint8_t cmdExtType;
95  uint8_t byteOrder;
96  uint8_t enable4BAddr;
97  uint8_t addrByteSupport;
98 
100  uint8_t cmdWren;
101  uint8_t cmdRdsr;
102  uint8_t cmdWrsr;
103  uint8_t cmdPageLoad;
104  uint8_t cmdPageProg;
105  uint8_t srWip;
106 
111  uint8_t cmdRandomInput;
114  uint8_t pageColAddrCyc;
115  uint8_t pageRowAddrCyc;
116  uint8_t cmdReadStatus;
117  uint8_t cmdReset;
118 
119 
120  uint8_t srWel;
121  uint8_t resetType;
122  uint8_t deviceBusyType;
123  uint8_t xspiWipRdCmd;
124 
125  uint32_t srWipReg;
126  uint32_t xspiWipReg;
127  uint32_t xspiWipBit;
128  uint32_t xspiRdsrDummy;
131 
132  FlashCfg_EraseConfig eraseCfg;
133  FlashCfg_ReadIDConfig idCfg;
134  FlashCfg_ProtoEnConfig protocolCfg;
135 
136  uint32_t progStatusReg;
138  uint32_t eraseStatusReg;
140  uint8_t srProgStatus;
141  uint8_t srEraseStatus;
144 
146 
164 typedef int32_t (*Flash_OpenFxn)(Flash_Config *config, Flash_Params *params);
165 
176 typedef void (*Flash_CloseFxn)(Flash_Config *config);
177 
191 typedef int32_t (*Flash_ReadFxn)(Flash_Config *config, uint32_t offset,
192  uint8_t *buf, uint32_t len) ;
193 
207 typedef int32_t (*Flash_WriteFxn)(Flash_Config *config, uint32_t offset,
208  uint8_t *buf, uint32_t len) ;
209 
221 typedef int32_t (*Flash_EraseFxn)(Flash_Config *config, uint32_t blockNum);
222 
234 typedef int32_t (*Flash_EraseSectorFxn)(Flash_Config *config, uint32_t sectorNum);
235 
247 typedef int32_t (*Flash_ResetFxn)(Flash_Config *config);
248 
259 typedef int32_t (*Flash_EnablePhyPipelineFxn)(Flash_Config *config);
260 
271 typedef int32_t (*Flash_DisablePhyPipelineFxn)(Flash_Config *config);
272 
283 typedef int32_t (*Flash_quirksFxn)(Flash_Config *config);
284 
292 typedef int32_t (*Flash_custProtocolFxn)(Flash_Config *config);
293 
300 typedef struct Flash_Params_s {
301 
304 
305 } Flash_Params;
306 
310 typedef struct Flash_Fxns_s
311 {
322 } Flash_Fxns;
323 
327 typedef struct Flash_Attrs_s {
328 
329  uint32_t flashType;
330  char *flashName;
331  uint32_t deviceId;
332  uint32_t manufacturerId;
333  uint32_t driverInstance;
334  uint32_t flashSize;
335  uint32_t blockCount;
336  uint32_t blockSize;
337  uint32_t pageCount;
338  uint32_t pageSize;
339  uint32_t sectorCount;
340  uint32_t sectorSize;
341  uint32_t spareAreaSize;
343 } Flash_Attrs;
344 
348 typedef struct Flash_Config_s
349 {
353  void *object;
356 } Flash_Config;
357 
358 /* Flash specific includes */
359 #if defined (DRV_VERSION_SERIAL_FLASH_V0)
360 #include <board/flash/ospi/flash_nor_ospi.h>
361 #include <board/flash/ospi/flash_nand_ospi.h>
362 #endif
363 
364 #if defined (DRV_VERSION_SERIAL_FLASH_V1)
365 #include <board/flash/qspi/flash_nor_qspi.h>
366 #endif
367 
368 #if defined (DRV_VERSION_PARALLEL_FLASH_V0)
369 #include <board/flash/gpmc/flash_nand_gpmc.h>
370 #endif
371 
380 
399 Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params);
400 
407 
416 Flash_Handle Flash_getHandle(uint32_t instanceId);
417 
430 int32_t Flash_read(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
431 
444 int32_t Flash_write(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
445 
456 int32_t Flash_blkPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t block, uint32_t page);
457 
468 int32_t Flash_offsetToBlkPage(Flash_Handle handle, uint32_t offset, uint32_t *block, uint32_t *page);
469 
480 int32_t Flash_SectorPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t sector, uint32_t page);
481 
492 int32_t Flash_offsetToSectorPage(Flash_Handle handle, uint32_t offset, uint32_t *sector, uint32_t *page);
493 
504 int32_t Flash_eraseBlk(Flash_Handle handle, uint32_t blockNum);
505 
516 int32_t Flash_eraseSector(Flash_Handle handle, uint32_t sectorNum);
517 
525 int32_t Flash_reset(Flash_Handle handle);
526 
535 
544 
553 
561 Flash_Attrs *Flash_getAttrs(uint32_t instanceId);
562 
570 uint32_t Flash_getFlashInterfaceIndex(uint32_t flashType);
571 
575 void Flash_init(void);
576 
580 void Flash_deinit(void);
581 
585 #ifdef __cplusplus
586 }
587 #endif
588 
589 #endif /* FLASH_H_ */
Flash_DevConfig::cmdPageLoadCyc1
uint8_t cmdPageLoadCyc1
Definition: flash.h:107
Flash_Attrs::flashType
uint32_t flashType
Definition: flash.h:329
Flash_DevConfig::cmdPageProgCyc1
uint8_t cmdPageProgCyc1
Definition: flash.h:112
Flash_close
void Flash_close(Flash_Handle handle)
Close flash driver.
Flash_DevConfig::cmdReadStatus
uint8_t cmdReadStatus
Definition: flash.h:116
Flash_Config::lockSem
SemaphoreP_Object lockSem
Definition: flash.h:354
Flash_DevConfig::xspiRdsrDummy
uint32_t xspiRdsrDummy
Definition: flash.h:128
Flash_Config::attrs
Flash_Attrs * attrs
Definition: flash.h:350
Flash_Attrs::flashSize
uint32_t flashSize
Definition: flash.h:334
Flash_DevConfig::progStatusReg
uint32_t progStatusReg
Definition: flash.h:136
Flash_Fxns::openFxn
Flash_OpenFxn openFxn
Definition: flash.h:312
Flash_DisablePhyPipelineFxn
int32_t(* Flash_DisablePhyPipelineFxn)(Flash_Config *config)
Driver implementation to disable PHY pipeline mode in Flash.
Definition: flash.h:271
Flash_deinit
void Flash_deinit(void)
This function de-initializes the Flash module.
Flash_DevConfig::eraseCfg
FlashCfg_EraseConfig eraseCfg
Definition: flash.h:132
Flash_DevConfig::cmdWrsr
uint8_t cmdWrsr
Definition: flash.h:102
Flash_Attrs::blockCount
uint32_t blockCount
Definition: flash.h:335
Flash_DevConfig::protocolCfg
FlashCfg_ProtoEnConfig protocolCfg
Definition: flash.h:134
Flash_DevConfig::cmdExtType
uint8_t cmdExtType
Definition: flash.h:94
Flash_CloseFxn
void(* Flash_CloseFxn)(Flash_Config *config)
Driver implementation to close a specific flash driver.
Definition: flash.h:176
SystemP.h
Flash_DevConfig::cmdWren
uint8_t cmdWren
Definition: flash.h:100
Flash_Config::devConfig
Flash_DevConfig * devConfig
Definition: flash.h:352
Flash_Attrs::driverInstance
uint32_t driverInstance
Definition: flash.h:333
Flash_Config
Flash driver configuration, these are filled by SysCfg based on the flash device that is selected.
Definition: flash.h:349
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:104
Flash_DevConfig::srWipReg
uint32_t srWipReg
Definition: flash.h:125
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:122
Flash_DevConfig::cmdRdsr
uint8_t cmdRdsr
Definition: flash.h:101
Flash_DevConfig::xspiWipReg
uint32_t xspiWipReg
Definition: flash.h:126
Flash_DevConfig::cmdPageProgCyc2
uint8_t cmdPageProgCyc2
Definition: flash.h:113
Flash_Fxns::eraseSectorFxn
Flash_EraseSectorFxn eraseSectorFxn
Definition: flash.h:317
Flash_DevConfig::flashBusyTimeout
uint32_t flashBusyTimeout
Definition: flash.h:130
Flash_Attrs::sectorSize
uint32_t sectorSize
Definition: flash.h:340
Flash_Config::fxns
Flash_Fxns * fxns
Definition: flash.h:351
Flash_Attrs::pageSize
uint32_t pageSize
Definition: flash.h:338
Flash_DevConfig::addrByteSupport
uint8_t addrByteSupport
Definition: flash.h:97
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:191
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:327
Flash_Attrs::flashName
char * flashName
Definition: flash.h:330
Flash_DevConfig::cmdRandomReadCyc2
uint8_t cmdRandomReadCyc2
Definition: flash.h:110
Flash_DevConfig::xspiWipBit
uint32_t xspiWipBit
Definition: flash.h:127
Flash_Fxns::eraseFxn
Flash_EraseFxn eraseFxn
Definition: flash.h:316
Flash_getHandle
Flash_Handle Flash_getHandle(uint32_t instanceId)
Get handle to flash driver.
Flash_Fxns
Driver implementation callbacks.
Definition: flash.h:311
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:221
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:99
Flash_DevConfig::srWip
uint8_t srWip
Definition: flash.h:105
Flash_DevConfig::srWel
uint8_t srWel
Definition: flash.h:120
Flash_Config
struct Flash_Config_s Flash_Config
Forward declaration of Flash_Config.
Definition: flash.h:80
Flash_DevConfig::resetType
uint8_t resetType
Definition: flash.h:121
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:207
Flash_Fxns::closeFxn
Flash_CloseFxn closeFxn
Definition: flash.h:313
Flash_DevConfig::cmdPageLoadCyc2
uint8_t cmdPageLoadCyc2
Definition: flash.h:108
Flash_DevConfig::flashWriteTimeout
uint32_t flashWriteTimeout
Definition: flash.h:129
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:247
Flash_Attrs::pageCount
uint32_t pageCount
Definition: flash.h:337
Flash_Params
struct Flash_Params_s Flash_Params
Forward declaration of Flash_Params.
Definition: flash.h:85
Flash_Attrs::spareAreaSize
uint32_t spareAreaSize
Definition: flash.h:341
Flash_DevConfig::pageRowAddrCyc
uint8_t pageRowAddrCyc
Definition: flash.h:115
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:292
Flash_EnablePhyPipelineFxn
int32_t(* Flash_EnablePhyPipelineFxn)(Flash_Config *config)
Driver implementation to enable PHY pipeline mode in Flash.
Definition: flash.h:259
Flash_Fxns::enablePhyPipelineFxn
Flash_EnablePhyPipelineFxn enablePhyPipelineFxn
Definition: flash.h:319
Flash_getAttrs
Flash_Attrs * Flash_getAttrs(uint32_t instanceId)
Return flash attributes.
Flash_DevConfig::xspiWipRdCmd
uint8_t xspiWipRdCmd
Definition: flash.h:123
Flash_Attrs::blockSize
uint32_t blockSize
Definition: flash.h:336
Flash_DevConfig::idCfg
FlashCfg_ReadIDConfig idCfg
Definition: flash.h:133
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:139
Flash_enablePhyPipeline
int32_t Flash_enablePhyPipeline(Flash_Handle handle)
Enables PHY mode in flash.
Flash_DevConfig::srWriteProtectMask
uint8_t srWriteProtectMask
Definition: flash.h:143
Flash_Fxns::disablePhyPipelineFxn
Flash_DisablePhyPipelineFxn disablePhyPipelineFxn
Definition: flash.h:320
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:331
Flash_Fxns::readFxn
Flash_ReadFxn readFxn
Definition: flash.h:314
Flash_DevConfig::enable4BAddr
uint8_t enable4BAddr
Definition: flash.h:96
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:234
Flash_Fxns::writeFxn
Flash_WriteFxn writeFxn
Definition: flash.h:315
Flash_OpenFxn
int32_t(* Flash_OpenFxn)(Flash_Config *config, Flash_Params *params)
Driver implementation to open a specific flash driver.
Definition: flash.h:164
Flash_DevConfig::cmdReset
uint8_t cmdReset
Definition: flash.h:117
Flash_open
Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params)
Open flash driver.
Flash_DevConfig::cmdRandomInput
uint8_t cmdRandomInput
Definition: flash.h:111
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
Flash_DevConfig::cmdRandomReadCyc1
uint8_t cmdRandomReadCyc1
Definition: flash.h:109
Flash_init
void Flash_init(void)
This function initializes the Flash module.
Flash_DevConfig::byteOrder
uint8_t byteOrder
Definition: flash.h:95
Flash_DevConfig::srWriteProtectReg
uint8_t srWriteProtectReg
Definition: flash.h:142
Flash_Attrs::manufacturerId
uint32_t manufacturerId
Definition: flash.h:332
Flash_DevConfig::cmdPageLoad
uint8_t cmdPageLoad
Definition: flash.h:103
Flash_Fxns::resetFxn
Flash_ResetFxn resetFxn
Definition: flash.h:318
Flash_DevConfig::pageColAddrCyc
uint8_t pageColAddrCyc
Definition: flash.h:114
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:141
Flash_DevConfig::eraseStatusReg
uint32_t eraseStatusReg
Definition: flash.h:138
Flash_quirksFxn
int32_t(* Flash_quirksFxn)(Flash_Config *config)
User implementation of a custom function to handle vendor specific quirks.
Definition: flash.h:283
Flash_Attrs::sectorCount
uint32_t sectorCount
Definition: flash.h:339
Flash_DevConfig::xspiProgStatusReg
uint32_t xspiProgStatusReg
Definition: flash.h:137
Flash_Params
Parameters passed during Flash_open()
Definition: flash.h:300
Flash_Handle
void * Flash_Handle
Handle to the FLash driver returned by Flash_opem()
Definition: flash.h:75
Flash_DevConfig::srProgStatus
uint8_t srProgStatus
Definition: flash.h:140
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:302
Flash_Params::custProtoFxn
Flash_custProtocolFxn custProtoFxn
Definition: flash.h:303
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:92
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:353