/* * The Clear BSD License * Copyright 2013-2016 Freescale Semiconductor, Inc. * Copyright 2016-2018 NXP * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted (subject to the limitations in the * disclaimer below) provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef _FSL_FTFX_CONTROLLER_H_ #define _FSL_FTFX_CONTROLLER_H_ #include "fsl_ftfx_features.h" #include "fsl_ftfx_utilities.h" /******************************************************************************* * Definitions ******************************************************************************/ /* Component ID definition, used by tools. */ #ifndef FSL_COMPONENT_ID #define FSL_COMPONENT_ID "platform.drivers.flash" #endif /*! * @name FTFx status * @{ */ /*! @brief FTFx driver status group. */ #if defined(kStatusGroup_FlashDriver) #define kStatusGroupGeneric kStatusGroup_Generic #define kStatusGroupFtfxDriver kStatusGroup_FlashDriver #elif defined(kStatusGroup_FLASH) #define kStatusGroupGeneric kStatusGroup_Generic #define kStatusGroupFtfxDriver kStatusGroup_FLASH #else #define kStatusGroupGeneric 0 #define kStatusGroupFtfxDriver 1 #endif /*! * @brief FTFx driver status codes. */ enum _ftfx_status { kStatus_FTFx_Success = MAKE_STATUS(kStatusGroupGeneric, 0), /*!< API is executed successfully*/ kStatus_FTFx_InvalidArgument = MAKE_STATUS(kStatusGroupGeneric, 4), /*!< Invalid argument*/ kStatus_FTFx_SizeError = MAKE_STATUS(kStatusGroupFtfxDriver, 0), /*!< Error size*/ kStatus_FTFx_AlignmentError = MAKE_STATUS(kStatusGroupFtfxDriver, 1), /*!< Parameter is not aligned with the specified baseline*/ kStatus_FTFx_AddressError = MAKE_STATUS(kStatusGroupFtfxDriver, 2), /*!< Address is out of range */ kStatus_FTFx_AccessError = MAKE_STATUS(kStatusGroupFtfxDriver, 3), /*!< Invalid instruction codes and out-of bound addresses */ kStatus_FTFx_ProtectionViolation = MAKE_STATUS( kStatusGroupFtfxDriver, 4), /*!< The program/erase operation is requested to execute on protected areas */ kStatus_FTFx_CommandFailure = MAKE_STATUS(kStatusGroupFtfxDriver, 5), /*!< Run-time error during command execution. */ kStatus_FTFx_UnknownProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 6), /*!< Unknown property.*/ kStatus_FTFx_EraseKeyError = MAKE_STATUS(kStatusGroupFtfxDriver, 7), /*!< API erase key is invalid.*/ kStatus_FTFx_RegionExecuteOnly = MAKE_STATUS(kStatusGroupFtfxDriver, 8), /*!< The current region is execute-only.*/ kStatus_FTFx_ExecuteInRamFunctionNotReady = MAKE_STATUS(kStatusGroupFtfxDriver, 9), /*!< Execute-in-RAM function is not available.*/ kStatus_FTFx_PartitionStatusUpdateFailure = MAKE_STATUS(kStatusGroupFtfxDriver, 10), /*!< Failed to update partition status.*/ kStatus_FTFx_SetFlexramAsEepromError = MAKE_STATUS(kStatusGroupFtfxDriver, 11), /*!< Failed to set FlexRAM as EEPROM.*/ kStatus_FTFx_RecoverFlexramAsRamError = MAKE_STATUS(kStatusGroupFtfxDriver, 12), /*!< Failed to recover FlexRAM as RAM.*/ kStatus_FTFx_SetFlexramAsRamError = MAKE_STATUS(kStatusGroupFtfxDriver, 13), /*!< Failed to set FlexRAM as RAM.*/ kStatus_FTFx_RecoverFlexramAsEepromError = MAKE_STATUS(kStatusGroupFtfxDriver, 14), /*!< Failed to recover FlexRAM as EEPROM.*/ kStatus_FTFx_CommandNotSupported = MAKE_STATUS(kStatusGroupFtfxDriver, 15), /*!< Flash API is not supported.*/ kStatus_FTFx_SwapSystemNotInUninitialized = MAKE_STATUS(kStatusGroupFtfxDriver, 16), /*!< Swap system is not in an uninitialzed state.*/ kStatus_FTFx_SwapIndicatorAddressError = MAKE_STATUS(kStatusGroupFtfxDriver, 17), /*!< The swap indicator address is invalid.*/ kStatus_FTFx_ReadOnlyProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 18), /*!< The flash property is read-only.*/ kStatus_FTFx_InvalidPropertyValue = MAKE_STATUS(kStatusGroupFtfxDriver, 19), /*!< The flash property value is out of range.*/ kStatus_FTFx_InvalidSpeculationOption = MAKE_STATUS(kStatusGroupFtfxDriver, 20), /*!< The option of flash prefetch speculation is invalid.*/ }; /*@}*/ /*! * @name FTFx API key * @{ */ /*! * @brief Enumeration for FTFx driver API keys. * * @note The resulting value is built with a byte order such that the string * being readable in expected order when viewed in a hex editor, if the value * is treated as a 32-bit little endian value. */ enum _ftfx_driver_api_keys { kFTFx_ApiEraseKey = FOUR_CHAR_CODE('k', 'f', 'e', 'k') /*!< Key value used to validate all FTFx erase APIs.*/ }; /*@}*/ /*! * @brief Enumeration for the FlexRAM load during reset option. */ typedef enum _ftfx_partition_flexram_load_option { kFTFx_PartitionFlexramLoadOptLoadedWithValidEepromData = 0x00U, /*!< FlexRAM is loaded with valid EEPROM data during reset sequence.*/ kFTFx_PartitionFlexramLoadOptNotLoaded = 0x01U /*!< FlexRAM is not loaded during reset sequence.*/ } ftfx_partition_flexram_load_opt_t; /*! * @brief Enumeration for the two possible options of flash read resource command. */ typedef enum _ftfx_read_resource_opt { kFTFx_ResourceOptionFlashIfr = 0x00U, /*!< Select code for Program flash 0 IFR, Program flash swap 0 IFR, Data flash 0 IFR */ kFTFx_ResourceOptionVersionId = 0x01U /*!< Select code for the version ID*/ } ftfx_read_resource_opt_t; /*! * @brief Enumeration for supported FTFx margin levels. */ typedef enum _ftfx_margin_value { kFTFx_MarginValueNormal, /*!< Use the 'normal' read level for 1s.*/ kFTFx_MarginValueUser, /*!< Apply the 'User' margin to the normal read-1 level.*/ kFTFx_MarginValueFactory, /*!< Apply the 'Factory' margin to the normal read-1 level.*/ kFTFx_MarginValueInvalid /*!< Not real margin level, Used to determine the range of valid margin level. */ } ftfx_margin_value_t; /*! * @brief Enumeration for the three possible FTFx security states. */ typedef enum _ftfx_security_state { kFTFx_SecurityStateNotSecure = 0xc33cc33cU, /*!< Flash is not secure.*/ kFTFx_SecurityStateBackdoorEnabled = 0x5aa55aa5U, /*!< Flash backdoor is enabled.*/ kFTFx_SecurityStateBackdoorDisabled = 0x5ac33ca5U /*!< Flash backdoor is disabled.*/ } ftfx_security_state_t; /*! * @brief Enumeration for the two possilbe options of set FlexRAM function command. */ typedef enum _ftfx_flexram_function_option { kFTFx_FlexramFuncOptAvailableAsRam = 0xFFU, /*!< An option used to make FlexRAM available as RAM */ kFTFx_FlexramFuncOptAvailableForEeprom = 0x00U /*!< An option used to make FlexRAM available for EEPROM */ } ftfx_flexram_func_opt_t; /*! * @brief Enumeration for the possible options of Swap control commands */ typedef enum _ftfx_swap_control_option { kFTFx_SwapControlOptionIntializeSystem = 0x01U, /*!< An option used to initialize the Swap system */ kFTFx_SwapControlOptionSetInUpdateState = 0x02U, /*!< An option used to set the Swap in an update state */ kFTFx_SwapControlOptionSetInCompleteState = 0x04U, /*!< An option used to set the Swap in a complete state */ kFTFx_SwapControlOptionReportStatus = 0x08U, /*!< An option used to report the Swap status */ kFTFx_SwapControlOptionDisableSystem = 0x10U /*!< An option used to disable the Swap status */ } ftfx_swap_control_opt_t; /*! * @brief Enumeration for the possible flash Swap status. */ typedef enum _ftfx_swap_state { kFTFx_SwapStateUninitialized = 0x00U, /*!< Flash Swap system is in an uninitialized state.*/ kFTFx_SwapStateReady = 0x01U, /*!< Flash Swap system is in a ready state.*/ kFTFx_SwapStateUpdate = 0x02U, /*!< Flash Swap system is in an update state.*/ kFTFx_SwapStateUpdateErased = 0x03U, /*!< Flash Swap system is in an updateErased state.*/ kFTFx_SwapStateComplete = 0x04U, /*!< Flash Swap system is in a complete state.*/ kFTFx_SwapStateDisabled = 0x05U /*!< Flash Swap system is in a disabled state.*/ } ftfx_swap_state_t; /*! * @breif Enumeration for the possible flash Swap block status */ typedef enum _ftfx_swap_block_status { kFTFx_SwapBlockStatusLowerHalfProgramBlocksAtZero = 0x00U, /*!< Swap block status is that lower half program block at zero.*/ kFTFx_SwapBlockStatusUpperHalfProgramBlocksAtZero = 0x01U, /*!< Swap block status is that upper half program block at zero.*/ } ftfx_swap_block_status_t; /*! * @brief Flash Swap information */ typedef struct _ftfx_swap_state_config { ftfx_swap_state_t flashSwapState; /*!