AM64x MCU+ SDK  08.02.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 #include <stdint.h>
37 #include <kernel/dpl/SystemP.h>
38 #include <drivers/hw_include/soc_config.h>
39 
54 typedef void *Flash_Handle;
55 
59 typedef struct Flash_Config_s Flash_Config;
60 
64 typedef struct Flash_Params_s Flash_Params;
65 
66 
84 typedef int32_t (*Flash_OpenFxn)(Flash_Config *config, Flash_Params *params);
85 
96 typedef void (*Flash_CloseFxn)(Flash_Config *config);
97 
111 typedef int32_t (*Flash_ReadFxn)(Flash_Config *config, uint32_t offset,
112  uint8_t *buf, uint32_t len) ;
113 
127 typedef int32_t (*Flash_WriteFxn)(Flash_Config *config, uint32_t offset,
128  uint8_t *buf, uint32_t len) ;
129 
141 typedef int32_t (*Flash_EraseFxn)(Flash_Config *config, uint32_t blockNum);
142 
149 typedef struct Flash_Params_s {
150 
151  uint32_t rsv;
153 } Flash_Params;
154 
158 typedef struct Flash_Fxns_s
159 {
166 } Flash_Fxns;
167 
171 typedef struct Flash_Attrs_s {
172 
173  uint32_t deviceId;
174  uint32_t manufacturerId;
175  uint32_t driverInstance;
176  uint32_t flashSize;
177  uint32_t blockCount;
178  uint32_t blockSize;
179  uint32_t pageCount;
180  uint32_t pageSize;
181  uint32_t sectorCount;
182  uint32_t sectorSize;
184 } Flash_Attrs;
185 
189 typedef struct Flash_Config_s
190 {
193  void *devDefines;
194  void *object;
196 } Flash_Config;
197 
198 /* Flash specific includes */
199 #if defined (DRV_VERSION_FLASH_V0)
200 #include <board/flash/flash_nor_xspi.h>
201 #include <board/flash/flash_nor_ospi.h>
202 #include <board/flash/flash_nor_ospi_quad.h>
203 #endif
204 
205 #if defined (DRV_VERSION_FLASH_V1)
206 #include <board/flash/flash_nor_qspi.h>
207 #endif
208 
217 
236 Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params);
237 
244 
253 Flash_Handle Flash_getHandle(uint32_t instanceId);
254 
267 int32_t Flash_read(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
268 
281 int32_t Flash_write(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len);
282 
293 int32_t Flash_blkPageToOffset(Flash_Handle handle, uint32_t *offset, uint32_t block, uint32_t page);
294 
305 int32_t Flash_offsetToBlkPage(Flash_Handle handle, uint32_t offset, uint32_t *block, uint32_t *page);
306 
317 int32_t Flash_eraseBlk(Flash_Handle handle, uint32_t blockNum);
318 
327 
335 Flash_Attrs *Flash_getAttrs(uint32_t instanceId);
336 
339 #endif /* FLASH_H_ */
Flash_close
void Flash_close(Flash_Handle handle)
Close flash driver.
Flash_Config::attrs
Flash_Attrs * attrs
Definition: flash.h:191
Flash_Attrs::flashSize
uint32_t flashSize
Definition: flash.h:176
Flash_Fxns::openFxn
Flash_OpenFxn openFxn
Definition: flash.h:160
Flash_Attrs::blockCount
uint32_t blockCount
Definition: flash.h:177
Flash_CloseFxn
void(* Flash_CloseFxn)(Flash_Config *config)
Driver implementation to close a specific flash driver.
Definition: flash.h:96
SystemP.h
Flash_Attrs::driverInstance
uint32_t driverInstance
Definition: flash.h:175
Flash_Config
Flash driver configuration, these are filled by SysCfg based on the flash device that is selected.
Definition: flash.h:190
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:182
Flash_Config::fxns
Flash_Fxns * fxns
Definition: flash.h:192
Flash_Attrs::pageSize
uint32_t pageSize
Definition: flash.h:180
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:111
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:171
Flash_Fxns::eraseFxn
Flash_EraseFxn eraseFxn
Definition: flash.h:164
Flash_getHandle
Flash_Handle Flash_getHandle(uint32_t instanceId)
Get handle to flash driver.
Flash_Fxns
Driver implementation callbacks.
Definition: flash.h:159
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:141
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:151
Flash_Config
struct Flash_Config_s Flash_Config
Forward declaration of Flash_Config.
Definition: flash.h:59
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:127
Flash_Fxns::closeFxn
Flash_CloseFxn closeFxn
Definition: flash.h:161
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:179
Flash_Params
struct Flash_Params_s Flash_Params
Forward declaration of Flash_Params.
Definition: flash.h:64
Flash_getAttrs
Flash_Attrs * Flash_getAttrs(uint32_t instanceId)
Return flash attributes.
Flash_Attrs::blockSize
uint32_t blockSize
Definition: flash.h:178
Flash_Attrs::deviceId
uint32_t deviceId
Definition: flash.h:173
Flash_Fxns::readFxn
Flash_ReadFxn readFxn
Definition: flash.h:162
Flash_Fxns::writeFxn
Flash_WriteFxn writeFxn
Definition: flash.h:163
Flash_OpenFxn
int32_t(* Flash_OpenFxn)(Flash_Config *config, Flash_Params *params)
Driver implementation to open a specific flash driver.
Definition: flash.h:84
Flash_open
Flash_Handle Flash_open(uint32_t instanceId, Flash_Params *params)
Open flash driver.
Flash_Attrs::manufacturerId
uint32_t manufacturerId
Definition: flash.h:174
Flash_Config::devDefines
void * devDefines
Definition: flash.h:193
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:181
Flash_Params
Parameters passed during Flash_open()
Definition: flash.h:149
Flash_Handle
void * Flash_Handle
Handle to the FLash driver returned by Flash_opem()
Definition: flash.h:54
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:194