AM64x MCU+ SDK  08.03.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 
42 #include <stdint.h>
43 #include <kernel/dpl/SystemP.h>
44 #include <drivers/hw_include/soc_config.h>
45 
60 typedef void *Flash_Handle;
61 
65 typedef struct Flash_Config_s Flash_Config;
66 
70 typedef struct Flash_Params_s Flash_Params;
71 
72 
90 typedef int32_t (*Flash_OpenFxn)(Flash_Config *config, Flash_Params *params);
91 
102 typedef void (*Flash_CloseFxn)(Flash_Config *config);
103 
117 typedef int32_t (*Flash_ReadFxn)(Flash_Config *config, uint32_t offset,
118  uint8_t *buf, uint32_t len) ;
119 
133 typedef int32_t (*Flash_WriteFxn)(Flash_Config *config, uint32_t offset,
134  uint8_t *buf, uint32_t len) ;
135 
147 typedef int32_t (*Flash_EraseFxn)(Flash_Config *config, uint32_t blockNum);
148 
155 typedef struct Flash_Params_s {
156 
157  uint32_t rsv;
159 } Flash_Params;
160 
164 typedef struct Flash_Fxns_s
165 {
172 } Flash_Fxns;
173 
177 typedef struct Flash_Attrs_s {
178 
179  uint32_t deviceId;
180  uint32_t manufacturerId;
181  uint32_t driverInstance;
182  uint32_t flashSize;
183  uint32_t blockCount;
184  uint32_t blockSize;
185  uint32_t pageCount;
186  uint32_t pageSize;
187  uint32_t sectorCount;
188  uint32_t sectorSize;
190 } Flash_Attrs;
191 
195 typedef struct Flash_Config_s
196 {
199  void *devDefines;
200  void *object;
202 } Flash_Config;
203 
204 /* Flash specific includes */
205 #if defined (DRV_VERSION_FLASH_V0)
206 #include <board/flash/flash_nor_xspi.h>
207 #include <board/flash/flash_nor_ospi.h>
208 #include <board/flash/flash_nor_ospi_quad.h>
209 #endif
210 
211 #if defined (DRV_VERSION_FLASH_V1)
212 #include <board/flash/flash_nor_qspi.h>
213 #endif
214 
223 
242 Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params);
243 
250 
259 Flash_Handle Flash_getHandle(uint32_t instanceId);
260 
273 int32_t Flash_read(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
274 
287 int32_t Flash_write(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
288 
299 int32_t Flash_blkPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t block, uint32_t page);
300 
311 int32_t Flash_offsetToBlkPage(Flash_Handle handle, uint32_t offset, uint32_t *block, uint32_t *page);
312 
323 int32_t Flash_eraseBlk(Flash_Handle handle, uint32_t blockNum);
324 
333 
341 Flash_Attrs *Flash_getAttrs(uint32_t instanceId);
342 
346 #ifdef __cplusplus
347 }
348 #endif
349 
350 #endif /* FLASH_H_ */
Flash_close
void Flash_close(Flash_Handle handle)
Close flash driver.
Flash_Config::attrs
Flash_Attrs * attrs
Definition: flash.h:197
Flash_Attrs::flashSize
uint32_t flashSize
Definition: flash.h:182
Flash_Fxns::openFxn
Flash_OpenFxn openFxn
Definition: flash.h:166
Flash_Attrs::blockCount
uint32_t blockCount
Definition: flash.h:183
Flash_CloseFxn
void(* Flash_CloseFxn)(Flash_Config *config)
Driver implementation to close a specific flash driver.
Definition: flash.h:102
SystemP.h
Flash_Attrs::driverInstance
uint32_t driverInstance
Definition: flash.h:181
Flash_Config
Flash driver configuration, these are filled by SysCfg based on the flash device that is selected.
Definition: flash.h:196
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_Attrs::sectorSize
uint32_t sectorSize
Definition: flash.h:188
Flash_Config::fxns
Flash_Fxns * fxns
Definition: flash.h:198
Flash_Attrs::pageSize
uint32_t pageSize
Definition: flash.h:186
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:117
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:177
Flash_Fxns::eraseFxn
Flash_EraseFxn eraseFxn
Definition: flash.h:170
Flash_getHandle
Flash_Handle Flash_getHandle(uint32_t instanceId)
Get handle to flash driver.
Flash_Fxns
Driver implementation callbacks.
Definition: flash.h:165
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:147
Flash_getPhyTuningOffset
uint32_t Flash_getPhyTuningOffset(Flash_Handle handle)
Return flash offset to write PHY tuning data.
Flash_Params::rsv
uint32_t rsv
Definition: flash.h:157
Flash_Config
struct Flash_Config_s Flash_Config
Forward declaration of Flash_Config.
Definition: flash.h:65
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:133
Flash_Fxns::closeFxn
Flash_CloseFxn closeFxn
Definition: flash.h:167
Flash_Params_init
void Flash_Params_init(Flash_Params *params)
Set default parameters in the Flash_Params structure.
Flash_Attrs::pageCount
uint32_t pageCount
Definition: flash.h:185
Flash_Params
struct Flash_Params_s Flash_Params
Forward declaration of Flash_Params.
Definition: flash.h:70
Flash_getAttrs
Flash_Attrs * Flash_getAttrs(uint32_t instanceId)
Return flash attributes.
Flash_Attrs::blockSize
uint32_t blockSize
Definition: flash.h:184
Flash_Attrs::deviceId
uint32_t deviceId
Definition: flash.h:179
Flash_Fxns::readFxn
Flash_ReadFxn readFxn
Definition: flash.h:168
Flash_Fxns::writeFxn
Flash_WriteFxn writeFxn
Definition: flash.h:169
Flash_OpenFxn
int32_t(* Flash_OpenFxn)(Flash_Config *config, Flash_Params *params)
Driver implementation to open a specific flash driver.
Definition: flash.h:90
Flash_open
Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params)
Open flash driver.
Flash_Attrs::manufacturerId
uint32_t manufacturerId
Definition: flash.h:180
Flash_Config::devDefines
void * devDefines
Definition: flash.h:199
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_Attrs::sectorCount
uint32_t sectorCount
Definition: flash.h:187
Flash_Params
Parameters passed during Flash_open()
Definition: flash.h:155
Flash_Handle
void * Flash_Handle
Handle to the FLash driver returned by Flash_opem()
Definition: flash.h:60
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:200