1 /* 2 * Copyright 2018-2020 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef __MFLASH_COMMON_H__ 8 #define __MFLASH_COMMON_H__ 9 10 #include <stdint.h> 11 #include <stdbool.h> 12 13 #include "fsl_common.h" 14 15 /******************************************************************************* 16 * Common definitions 17 ******************************************************************************/ 18 19 #define MFLASH_INVALID_ADDRESS (UINT32_MAX) 20 21 #define mflash_drv_is_page_aligned(x) (((x) % (MFLASH_PAGE_SIZE)) == 0) 22 #define mflash_drv_is_sector_aligned(x) (((x) % (MFLASH_SECTOR_SIZE)) == 0) 23 24 /* 25 * The addresses of FLASH locations used by APIs below may not correspond with the addresses space, especially when 26 * FLASH remapping is being used. Use mflash_drv_phys2log/log2phys API to obtain actual pointer or physical address. 27 */ 28 29 /******************************************************************************* 30 * APIs provided by low level driver 31 ******************************************************************************/ 32 33 /*! @brief Initializes mflash driver */ 34 int32_t mflash_drv_init(void); 35 36 /*! @brief Erases single sector */ 37 int32_t mflash_drv_sector_erase(uint32_t sector_addr); 38 39 /*! @brief Writes single page */ 40 int32_t mflash_drv_page_program(uint32_t page_addr, uint32_t *data); 41 42 /*! @brief Reads data of arbitrary length */ 43 int32_t mflash_drv_read(uint32_t addr, uint32_t *buffer, uint32_t len); 44 45 /*! @brief Returns pointer to memory area where the specified region of FLASH is mapped, NULL on failure (could not map 46 * continuous block) */ 47 void *mflash_drv_phys2log(uint32_t addr, uint32_t len); 48 49 /*! @brief Returns address of physical memory where the area accessible by given pointer is actually stored, UINT32_MAX 50 * on failure (could not map as continuous block) */ 51 uint32_t mflash_drv_log2phys(void *ptr, uint32_t len); 52 53 #endif 54