AM243x MCU+ SDK  08.04.00
flash.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 
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 
46 #define FLASH_INVALID_VALUE (0xFFFFFFFFU)
47 
62 typedef void *Flash_Handle;
63 
67 typedef struct Flash_Config_s Flash_Config;
68 
72 typedef struct Flash_Params_s Flash_Params;
73 
79 typedef struct Flash_DevConfig_s {
80 
81  uint8_t cmdExtType;
82  uint8_t byteOrder;
83  uint8_t enable4BAddr;
84  uint8_t addrByteSupport;
85 
87  uint8_t cmdWren;
88  uint8_t cmdRdsr;
89  uint8_t srWip;
90 
91  uint8_t srWel;
92  uint8_t resetType;
93  uint8_t deviceBusyType;
94  uint8_t xspiWipRdCmd;
95 
96  uint32_t xspiWipReg;
97  uint32_t xspiWipBit;
99  uint32_t flashBusyTimeout;
100 
101  FlashCfg_EraseConfig eraseCfg;
102  FlashCfg_ReadIDConfig idCfg;
103  FlashCfg_ProtoEnConfig protocolCfg;
104 
106 
124 typedef int32_t (*Flash_OpenFxn)(Flash_Config *config, Flash_Params *params);
125 
136 typedef void (*Flash_CloseFxn)(Flash_Config *config);
137 
151 typedef int32_t (*Flash_ReadFxn)(Flash_Config *config, uint32_t offset,
152  uint8_t *buf, uint32_t len) ;
153 
167 typedef int32_t (*Flash_WriteFxn)(Flash_Config *config, uint32_t offset,
168  uint8_t *buf, uint32_t len) ;
169 
181 typedef int32_t (*Flash_EraseFxn)(Flash_Config *config, uint32_t blockNum);
182 
194 typedef int32_t (*Flash_EraseSectorFxn)(Flash_Config *config, uint32_t sectorNum);
195 
207 typedef int32_t (*Flash_ResetFxn)(Flash_Config *config);
208 
219 typedef int32_t (*Flash_quirksFxn)(Flash_Config *config);
220 
228 typedef int32_t (*Flash_custProtocolFxn)(Flash_Config *config);
229 
236 typedef struct Flash_Params_s {
237 
240 
241 } Flash_Params;
242 
246 typedef struct Flash_Fxns_s
247 {
256 } Flash_Fxns;
257 
261 typedef struct Flash_Attrs_s {
262 
263  uint32_t flashType;
264  char *flashName;
265  uint32_t deviceId;
266  uint32_t manufacturerId;
267  uint32_t driverInstance;
268  uint32_t flashSize;
269  uint32_t blockCount;
270  uint32_t blockSize;
271  uint32_t pageCount;
272  uint32_t pageSize;
273  uint32_t sectorCount;
274  uint32_t sectorSize;
276 } Flash_Attrs;
277 
281 typedef struct Flash_Config_s
282 {
286  void *object;
288 } Flash_Config;
289 
290 /* Flash specific includes */
291 #if defined (DRV_VERSION_FLASH_V0)
292 #include <board/flash/ospi/flash_nor_ospi.h>
293 #endif
294 
295 #if defined (DRV_VERSION_FLASH_V1)
296 #include <board/flash/qspi/flash_nor_qspi.h>
297 #endif
298 
307 
326 Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params);
327 
334 
343 Flash_Handle Flash_getHandle(uint32_t instanceId);
344 
357 int32_t Flash_read(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
358 
371 int32_t Flash_write(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
372 
383 int32_t Flash_blkPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t block, uint32_t page);
384 
395 int32_t Flash_offsetToBlkPage(Flash_Handle handle, uint32_t offset, uint32_t *block, uint32_t *page);
396 
407 int32_t Flash_SectorPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t sector, uint32_t page);
408 
419 int32_t Flash_offsetToSectorPage(Flash_Handle handle, uint32_t offset, uint32_t *sector, uint32_t *page);
420 
431 int32_t Flash_eraseBlk(Flash_Handle handle, uint32_t blockNum);
432 
443 int32_t Flash_eraseSector(Flash_Handle handle, uint32_t sectorNum);
444 
452 int32_t Flash_reset(Flash_Handle handle);
453 
462 
470 Flash_Attrs *Flash_getAttrs(uint32_t instanceId);
471 
475 #ifdef __cplusplus
476 }
477 #endif
478 
479 #endif /* FLASH_H_ */
Flash_Attrs::flashType
uint32_t flashType
Definition: flash.h:263
Flash_close
void Flash_close(Flash_Handle handle)
Close flash driver.
Flash_Config::attrs
Flash_Attrs * attrs
Definition: flash.h:283
Flash_Attrs::flashSize
uint32_t flashSize
Definition: flash.h:268
Flash_Fxns::openFxn
Flash_OpenFxn openFxn
Definition: flash.h:248
Flash_DevConfig::eraseCfg
FlashCfg_EraseConfig eraseCfg
Definition: flash.h:101
Flash_Attrs::blockCount
uint32_t blockCount
Definition: flash.h:269
Flash_DevConfig::protocolCfg
FlashCfg_ProtoEnConfig protocolCfg
Definition: flash.h:103
Flash_DevConfig::cmdExtType
uint8_t cmdExtType
Definition: flash.h:81
Flash_CloseFxn
void(* Flash_CloseFxn)(Flash_Config *config)
Driver implementation to close a specific flash driver.
Definition: flash.h:136
SystemP.h
Flash_DevConfig::cmdWren
uint8_t cmdWren
Definition: flash.h:87
Flash_Config::devConfig
Flash_DevConfig * devConfig
Definition: flash.h:285
Flash_Attrs::driverInstance
uint32_t driverInstance
Definition: flash.h:267
Flash_Config
Flash driver configuration, these are filled by SysCfg based on the flash device that is selected.
Definition: flash.h:282
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_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:93
Flash_DevConfig::cmdRdsr
uint8_t cmdRdsr
Definition: flash.h:88
Flash_DevConfig::xspiWipReg
uint32_t xspiWipReg
Definition: flash.h:96
Flash_Fxns::eraseSectorFxn
Flash_EraseSectorFxn eraseSectorFxn
Definition: flash.h:253
Flash_DevConfig::flashBusyTimeout
uint32_t flashBusyTimeout
Definition: flash.h:99
Flash_Attrs::sectorSize
uint32_t sectorSize
Definition: flash.h:274
Flash_Config::fxns
Flash_Fxns * fxns
Definition: flash.h:284
Flash_Attrs::pageSize
uint32_t pageSize
Definition: flash.h:272
Flash_DevConfig::addrByteSupport
uint8_t addrByteSupport
Definition: flash.h:84
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:151
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.
Flash_Attrs
Flash device attributes, these are filled by SysCfg based on the flash device that is selected.
Definition: flash.h:261
Flash_Attrs::flashName
char * flashName
Definition: flash.h:264
Flash_DevConfig::xspiWipBit
uint32_t xspiWipBit
Definition: flash.h:97
Flash_Fxns::eraseFxn
Flash_EraseFxn eraseFxn
Definition: flash.h:252
Flash_getHandle
Flash_Handle Flash_getHandle(uint32_t instanceId)
Get handle to flash driver.
Flash_Fxns
Driver implementation callbacks.
Definition: flash.h:247
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:181
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:86
Flash_DevConfig::srWip
uint8_t srWip
Definition: flash.h:89
Flash_DevConfig::srWel
uint8_t srWel
Definition: flash.h:91
Flash_Config
struct Flash_Config_s Flash_Config
Forward declaration of Flash_Config.
Definition: flash.h:67
Flash_DevConfig::resetType
uint8_t resetType
Definition: flash.h:92
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:167
Flash_Fxns::closeFxn
Flash_CloseFxn closeFxn
Definition: flash.h:249
Flash_DevConfig::flashWriteTimeout
uint32_t flashWriteTimeout
Definition: flash.h:98
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:207
Flash_Attrs::pageCount
uint32_t pageCount
Definition: flash.h:271
Flash_Params
struct Flash_Params_s Flash_Params
Forward declaration of Flash_Params.
Definition: flash.h:72
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:228
Flash_getAttrs
Flash_Attrs * Flash_getAttrs(uint32_t instanceId)
Return flash attributes.
Flash_DevConfig::xspiWipRdCmd
uint8_t xspiWipRdCmd
Definition: flash.h:94
Flash_Attrs::blockSize
uint32_t blockSize
Definition: flash.h:270
Flash_DevConfig::idCfg
FlashCfg_ReadIDConfig idCfg
Definition: flash.h:102
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_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:265
Flash_Fxns::readFxn
Flash_ReadFxn readFxn
Definition: flash.h:250
Flash_DevConfig::enable4BAddr
uint8_t enable4BAddr
Definition: flash.h:83
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:194
Flash_Fxns::writeFxn
Flash_WriteFxn writeFxn
Definition: flash.h:251
Flash_OpenFxn
int32_t(* Flash_OpenFxn)(Flash_Config *config, Flash_Params *params)
Driver implementation to open a specific flash driver.
Definition: flash.h:124
Flash_open
Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params)
Open flash driver.
Flash_DevConfig::byteOrder
uint8_t byteOrder
Definition: flash.h:82
Flash_Attrs::manufacturerId
uint32_t manufacturerId
Definition: flash.h:266
Flash_Fxns::resetFxn
Flash_ResetFxn resetFxn
Definition: flash.h:254
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_quirksFxn
int32_t(* Flash_quirksFxn)(Flash_Config *config)
User implementation of a custom function to handle vendor specific quirks.
Definition: flash.h:219
Flash_Attrs::sectorCount
uint32_t sectorCount
Definition: flash.h:273
Flash_Params
Parameters passed during Flash_open()
Definition: flash.h:236
Flash_Handle
void * Flash_Handle
Handle to the FLash driver returned by Flash_opem()
Definition: flash.h:62
Flash_Params::quirksFxn
Flash_quirksFxn quirksFxn
Definition: flash.h:238
Flash_Params::custProtoFxn
Flash_custProtocolFxn custProtoFxn
Definition: flash.h:239
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:79
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:286