/* * Copyright 2013-2016 Freescale Semiconductor, Inc. * Copyright 2016-2020 NXP * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * */ #ifndef FSL_FTFX_CONTROLLER_H #define FSL_FTFX_CONTROLLER_H #include "fsl_ftfx_features.h" #include "fsl_ftfx_utilities.h" /*! * @addtogroup ftfx_controller * @{ */ /******************************************************************************* * Definitions ******************************************************************************/ /*! * @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 { 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.*/ kStatus_FTFx_CommandOperationInProgress = MAKE_STATUS(kStatusGroupFtfxDriver, 21), /*!< The option of flash command is processing.*/ }; /*@}*/ /*! * @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 = (int)0xc33cc33cu, /*!< Flash is not secure.*/ kFTFx_SecurityStateBackdoorEnabled = (int)0x5aa55aa5u, /*!< Flash backdoor is enabled.*/ kFTFx_SecurityStateBackdoorDisabled = (int)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 acceleration ram property. */ enum _flash_acceleration_ram_property { kFLASH_AccelerationRamSize = 0x400U }; #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD /*! * @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; #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */ /*! * @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; #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD /*! * @brief 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; /*!