1 /* 2 * Copyright 2019-2022 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef __FSL_NOR_FLASH_H__ 9 #define __FSL_NOR_FLASH_H__ 10 11 #include "fsl_common.h" 12 13 /*! 14 * @addtogroup nor_flash_component 15 * @{ 16 */ 17 18 /******************************************************************************* 19 * Definitions 20 ******************************************************************************/ 21 22 /*! @brief NOR Flash Config block structure */ 23 typedef struct _nor_config 24 { 25 void *memControlConfig; /*!< memory controller configuration, should be assigned to specific controller 26 configuration structure pointer.*/ 27 void *driverBaseAddr; /*! Driver Base address. */ 28 } nor_config_t; 29 30 /*!@brief NOR Flash handle info*/ 31 typedef struct _nor_handle 32 { 33 /*------------Common parameters used for normal NOR flash controller operation ----------*/ 34 void *driverBaseAddr; /*! Driver Base address. */ 35 uint32_t bytesInPageSize; /*!< Page size in byte of Serial NOR */ 36 uint32_t bytesInSectorSize; /*!< Minimun Sector size in byte supported by Serial NOR */ 37 uint32_t bytesInMemorySize; /*!< Memory size in byte of Serial NOR */ 38 /*------------Specific parameters used for specific NOR flash controller ----------*/ 39 void *deviceSpecific; /*!< Device specific control parameter */ 40 } nor_handle_t; 41 42 /******************************************************************************* 43 * API 44 ******************************************************************************/ 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /*! 51 * @name NOR FLASH Driver 52 * @{ 53 */ 54 55 /*! 56 * @brief Initialize NOR FLASH devices. 57 * 58 * This function initialize NOR Flash controller and NOR Flash. 59 * 60 * @param config NOR flash configuration. 61 * The "memControlConfig" and "driverBaseAddr" are controller specific structure. 62 * please set those two parameter with your Nand controller configuration structure type pointer. 63 * such as for SEMC: 64 * 65 * spifi_mem_nor_config_t spifiNorconfig = 66 * { 67 * ..... 68 * } 69 * nor_config_t config = 70 * { 71 * .memControlConfig = (void *)\&spifiNorconfig; 72 * .driverBaseAddr = (void *)SPIFI0; 73 * } 74 * @param handle The NOR Flash handler. 75 * @retval execution status 76 */ 77 status_t Nor_Flash_Init(nor_config_t *config, nor_handle_t *handle); 78 79 /*! 80 * @brief Read page data from NOR Flash. 81 * 82 * @param handle The NOR Flash handler. 83 * @param address NOR flash start address to read data from. 84 * @param buffer NOR flash buffer to read data to. 85 * @param length NOR flash read length. 86 * @retval execution status 87 */ 88 status_t Nor_Flash_Read(nor_handle_t *handle, uint32_t address, uint8_t *buffer, uint32_t length); 89 90 /*! 91 * @brief Program page data to NOR Flash. 92 * 93 * @param handle The NOR Flash handler. 94 * @param address The address to be programed. 95 * @param buffer The buffer to be programed to the page. 96 * @retval execution status 97 */ 98 status_t Nor_Flash_Page_Program(nor_handle_t *handle, uint32_t address, uint8_t *buffer); 99 100 /*! 101 * @brief Program data to NOR Flash. 102 * 103 * @param handle The NOR Flash handler. 104 * @param address The address to be programed. 105 * @param buffer The buffer to be programed to the page. 106 * @param length The data length to be programed to the page. 107 * @retval execution status 108 */ 109 status_t Nor_Flash_Program(nor_handle_t *handle, uint32_t address, uint8_t *buffer, uint32_t length); 110 111 /*! 112 * @brief Erase sector. 113 * 114 * @param handle The NOR Flash handler. 115 * @param address The start address to be erased. 116 * @retval execution status 117 */ 118 status_t Nor_Flash_Erase_Sector(nor_handle_t *handle, uint32_t address); 119 120 /*! 121 * @brief Erase block. 122 * 123 * @param handle The NOR Flash handler. 124 * @param address The start address to be erased. 125 * @retval execution status 126 */ 127 status_t Nor_Flash_Erase_Block(nor_handle_t *handle, uint32_t address); 128 129 /*! 130 * @brief Erase flash with any size. 131 * 132 * @param handle The NOR Flash handler. 133 * @param address The start address to be erased. 134 * @param size_Byte Erase flash size. 135 * @retval execution status 136 */ 137 status_t Nor_Flash_Erase(nor_handle_t *handle, uint32_t address, uint32_t size_Byte); 138 139 /*! 140 * @brief Erase Chip NOR Flash . 141 * 142 * @param handle The NOR Flash handler. 143 * @retval execution status 144 */ 145 status_t Nor_Flash_Erase_Chip(nor_handle_t *handle); 146 147 /*! 148 * @brief Get the busy status of the NOR Flash. 149 * 150 * @param handle The NOR Flash handler. 151 * @param isBusy Pointer of the variable which has the busy status of the NOR flash. 152 * @retval execution status 153 */ 154 status_t Nor_Flash_Is_Busy(nor_handle_t *handle, bool *isBusy); 155 156 /*! 157 * @brief Deinitialize NOR FLASH devices. 158 * 159 * @param handle The NOR Flash handler. 160 * @retval execution status 161 */ 162 status_t Nor_Flash_DeInit(nor_handle_t *handle); 163 164 /*! @} */ 165 166 #ifdef __cplusplus 167 } 168 #endif 169 /*! @} */ 170 #endif /* __FSL_NOR_FLASH_H__ */ 171