/*
 * Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
 * All rights reserved.
 *
 * Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
 * exclusively with CVA's microcontroller products. This file can be freely
 * distributed within development tools that are supporting such microcontroller
 * products.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
 * CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
 * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 */

#ifndef _FTFC_REG_H_
#define _FTFC_REG_H_

/*! \brief Contains public interface to various functions related
 *         to the FTFC Registers
 */

/*******************************************************************************
 * the includes
 ******************************************************************************/

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************
 * the defines
 ******************************************************************************/

/* FSTAT Bit Fields */
#define FTFC_FSTAT_EEEVLD_MASK       (0x20000u)
#define FTFC_FSTAT_EEEVLD_SHIFT      (17u)
#define FTFC_FSTAT_EEEVLD_WIDTH      (1u)
#define FTFC_FSTAT_CCI_CLR_MASK     (0x10000u)
#define FTFC_FSTAT_CCI_CLR_SHIFT    (16u)
#define FTFC_FSTAT_CCI_CLR_WIDTH    (1u)
#define FTFC_FSTAT_EEE_SPERR_MASK   (0x8000u)
#define FTFC_FSTAT_EEE_SPERR_SHIFT  (15u)
#define FTFC_FSTAT_EEE_SPERR_WIDTH  (1u)
#define FTFC_FSTAT_EEE_FLOV_MASK    (0x4000u)
#define FTFC_FSTAT_EEE_FLOV_SHIFT   (14u)
#define FTFC_FSTAT_EEE_FLOV_WIDTH   (1u)
#define FTFC_FSTAT_EEE_TLOV_MASK    (0x2000u)
#define FTFC_FSTAT_EEE_TLOV_SHIFT   (13u)
#define FTFC_FSTAT_EEE_TLOV_WIDTH   (1u)
#define FTFC_FSTAT_RAMRDY_MASK      (0x1000u)
#define FTFC_FSTAT_RAMRDY_SHIFT     (12u)
#define FTFC_FSTAT_RAMRDY_WIDTH     (1u)
#define FTFC_FSTAT_EEERDY_MASK       (0x800u)
#define FTFC_FSTAT_EEERDY_SHIFT      (11u)
#define FTFC_FSTAT_EEERDY_WIDTH      (1u)
#define FTFC_FSTAT_FL_ERRF_MASK     (0x400u)
#define FTFC_FSTAT_FL_ERRF_SHIFT    (10u)
#define FTFC_FSTAT_FL_ERRF_WIDTH    (1u)
#define FTFC_FSTAT_FL_DONE_MASK     (0x200u)
#define FTFC_FSTAT_FL_DONE_SHIFT    (9u)
#define FTFC_FSTAT_FL_DONE_WIDTH    (1u)
#define FTFC_FSTAT_ERSA_REQ_MASK    (0x100u)
#define FTFC_FSTAT_ERSA_REQ_SHIFT   (8u)
#define FTFC_FSTAT_ERSA_REQ_WIDTH   (1u)
#define FTFC_FSTAT_CCIF_MASK        (0x80u)
#define FTFC_FSTAT_CCIF_SHIFT       (7u)
#define FTFC_FSTAT_CCIF_WIDTH       (1u)
#define FTFC_FSTAT_RDCOLERR_MASK    (0x40u)
#define FTFC_FSTAT_RDCOLERR_SHIFT   (6u)
#define FTFC_FSTAT_RDCOLERR_WIDTH   (1u)
#define FTFC_FSTAT_ACCERR_MASK      (0x20u)
#define FTFC_FSTAT_ACCERR_SHIFT     (5u)
#define FTFC_FSTAT_ACCERR_WIDTH     (1u)
#define FTFC_FSTAT_PVIOL_MASK       (0x10u)
#define FTFC_FSTAT_PVIOL_SHIFT      (4u)
#define FTFC_FSTAT_PVIOL_WIDTH      (1u)
#define FTFC_FSTAT_SECF_MASK        (0x8u)
#define FTFC_FSTAT_SECF_SHIFT       (3u)
#define FTFC_FSTAT_SECF_WIDTH       (1u)
#define FTFC_FSTAT_DEDF_MASK        (0x4u)
#define FTFC_FSTAT_DEDF_SHIFT       (2u)
#define FTFC_FSTAT_DEDF_WIDTH       (1u)
#define FTFC_FSTAT_RSPERR_MASK      (0x2u)
#define FTFC_FSTAT_RSPERR_SHIFT     (1u)
#define FTFC_FSTAT_RSPERR_WIDTH     (1u)
#define FTFC_FSTAT_MGSTAT0_MASK     (0x1u)
#define FTFC_FSTAT_MGSTAT0_SHIFT    (0u)
#define FTFC_FSTAT_MGSTAT0_WIDTH    (1u)

/* FCNFG Bit Fields */
#define FTFC_FCNFG_BUSRD_T_MASK     (0xF00u)
#define FTFC_FCNFG_BUSRD_T_SHIFT    (8u)
#define FTFC_FCNFG_BUSRD_T_WIDTH    (4u)
#define FTFC_FCNFG_RSP_ERR_BE_MASK  (0x10u)
#define FTFC_FCNFG_RSP_ERR_BE_SHIFT (4u)
#define FTFC_FCNFG_RSP_ERR_BE_WIDTH (1u)
#define FTFC_FCNFG_ERS_SUS_MASK     (0x8u)
#define FTFC_FCNFG_ERS_SUS_SHIFT    (3u)
#define FTFC_FCNFG_ERS_SUS_WIDTH    (1u)
#define FTFC_FCNFG_RSP_ERR_IE_MASK  (0x4u)
#define FTFC_FCNFG_RSP_ERR_IE_SHIFT (2u)
#define FTFC_FCNFG_RSP_ERR_IE_WIDTH (1u)
#define FTFC_FCNFG_CCIF_IE_MASK     (0x2u)
#define FTFC_FCNFG_CCIF_IE_SHIFT    (1u)
#define FTFC_FCNFG_CCIF_IE_WIDTH    (1u)
#define FTFC_FCNFG_RDCOL_IE_MASK    (0x1u)
#define FTFC_FCNFG_RDCOL_IE_SHIFT   (0u)
#define FTFC_FCNFG_RDCOL_IE_WIDTH   (1u)

/* FSEC Bit Fields */
#define FTFC_FSEC_KEYEN_MASK        (0xC0u)
#define FTFC_FSEC_KEYEN_SHIFT       (6u)
#define FTFC_FSEC_KEYEN_WIDTH       (2u)
#define FTFC_FSEC_MEEN_MASK         (0x30u)
#define FTFC_FSEC_MEEN_SHIFT        (4u)
#define FTFC_FSEC_MEEN_WIDTH        (2u)
#define FTFC_FSEC_SECURE_MASK       (0x3u)
#define FTFC_FSEC_SECURE_SHIFT      (0u)
#define FTFC_FSEC_SECURE_WIDTH      (2u)

/* PFPROT Bit Fields */
#define FTFC_PFPROT_PFPROT_MASK     (0xFFFFFFFu)
#define FTFC_PFPROT_PFPROT_SHIFT    (0u)
#define FTFC_PFPROT_PFPROT_WIDTH    (28u)

/* DFPROT Bit Fields */
#define FTFC_DFPROT_DFPROT_MASK     (0xFFu)
#define FTFC_DFPROT_DFPROT_SHIFT    (0u)
#define FTFC_DFPROT_DFPROT_WIDTH    (8u)

/* EFPROT Bit Fields */
#define FTFC_EFPROT_EFPROT_MASK     (0xFFu)
#define FTFC_EFPROT_EFPROT_SHIFT    (0u)
#define FTFC_EFPROT_EFPROT_WIDTH    (8u)

/*******************************************************************************
 * the typedefs
 ******************************************************************************/

/*! \brief The definition of FTFC registers
 */
typedef struct _FtfcRegType_
{
    volatile uint32_t       FSTAT;        /*!< flash module status, offset: 0x00 */
    volatile uint32_t       FCNFG;        /*!< flash module configuration, offset: 0x04 */
    const volatile uint32_t FSEC;         /*!< flash module secure setting, offset: 0x08 */
    volatile uint32_t       PFPROT;       /*!< flash module program flash protection, offset: 0x0C */
    volatile uint32_t       DFPROT;       /*!< flash module data flash protection, offset: 0x10 */
    volatile uint32_t       EFPROT;       /*!< flash module eee_ram protection, offset: 0x14 */
    uint32_t                RESERVED0[1]; /*!< Reserverd block, offset: 0x18 */
    volatile uint8_t        FCCOB[16];    /*!< flash common command object 0 - 15, offset: 0x1C */
} FtfcRegType;

/*******************************************************************************
 * the globals
 ******************************************************************************/

/*******************************************************************************
 * the function prototypes
 ******************************************************************************/

/*! \brief Gets the flash eee valid flag
 *
 * This function gets the current flash eee valid flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash eee valid flag
 *         - 0b : eee invalid
 *         - 1b : eee valid
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatEeevld(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_EEEVLD_MASK) >> FTFC_FSTAT_EEEVLD_SHIFT);
}

/*! \brief Sets the flash command complete interrupt clear
 *
 * This function sets the flash command complete interrupt clear.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash command complete interrupt clear
 *                    - 0b : invlaid operation
 *                    - 1b : clear the command complete interrupt
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatCcifClr(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_CCI_CLR_SHIFT)) & FTFC_FSTAT_CCI_CLR_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the flash eee state page error flag
 *
 * This function gets the current flash eee state page error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash eee state page error flag
 *         - 0b : eee state pasges ok
 *         - 1b : eee state pasges error
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatEeeStpgErrF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_EEE_SPERR_MASK) >> FTFC_FSTAT_EEE_SPERR_SHIFT);
}

/*! \brief Sets the emulated eeprom full level overflow flag
 *
 * This function sets the emulated eeprom full level overflow flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of emulated eeprom full level overflow flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatEeeFlov(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_EEE_FLOV_SHIFT)) & FTFC_FSTAT_EEE_FLOV_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the emulated eeprom full level overflow flag
 *
 * This function gets the current emulated eeprom full level overflow flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return the emulated eeprom full level overflow flag
 *         - 0b : eee write pointer under full level
 *         - 1b : eee write pointer reach/over full level
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatEeeFlov(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_EEE_FLOV_MASK) >> FTFC_FSTAT_EEE_FLOV_SHIFT);
}

/*! \brief Gets the emulated eeprom threshold level overflow flag
 *
 * This function gets the current emulated eeprom threshold level overflow flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return the emulated eeprom threshold level overflow flag
 *         - 0b : eee write pointer under threshold level
 *         - 1b : eee write pointer reach/over threshold level
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatEeeTlov(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_EEE_TLOV_MASK) >> FTFC_FSTAT_EEE_TLOV_SHIFT);
}

/*! \brief Sets the emulated eeprom threshold level overflow flag
 *
 * This function sets the emulated eeprom threshold level overflow flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of emulated eeprom threshold level overflow flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatEeeTlov(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_EEE_TLOV_SHIFT)) & FTFC_FSTAT_EEE_TLOV_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Sets the flash eee state page error flag
 *
 * This function sets the flash eee state page error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash eee state page error flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatStpgErrF(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_EEE_SPERR_SHIFT)) & FTFC_FSTAT_EEE_SPERR_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the ram ready flag
 *
 * This function gets the current ram ready flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return ram ready flag
 *         - 0b : flexram is not ready for system ram
 *         - 1b : flexram is ready for system ram
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatRamRdy(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_RAMRDY_MASK) >> FTFC_FSTAT_RAMRDY_SHIFT);
}

/*! \brief Gets the eee_ram ready flag
 *
 * This function gets the current eee_ram ready flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return eee_ram ready flag
 *         - 0b : flexram is not ready for eee_ram
 *         - 1b : flexram is ready for eee_ram
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatEeeRamRdy(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_EEERDY_MASK) >> FTFC_FSTAT_EEERDY_SHIFT);
}

/*! \brief Gets the flash loader error flag
 *
 * This function gets the current flash loader error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash loader error flag
 *         - 0b : flash loader no error
 *         - 1b : flash loader error
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatFlErrF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_FL_ERRF_MASK) >> FTFC_FSTAT_FL_ERRF_SHIFT);
}

/*! \brief Gets the flash loader done flag
 *
 * This function gets the current flash loader done flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash loader done flag
 *         - 0b : flash loader is not done
 *         - 1b : flash loader is done
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatFlDone(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_FL_DONE_MASK) >> FTFC_FSTAT_FL_DONE_SHIFT);
}

/*! \brief Gets the flash erase sector flag
 *
 * This function gets the current flash erase sector flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash erase sector flag
 *         - 0b : not erasing sector
 *         - 1b : erasing sector
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatErsSctF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_ERSA_REQ_MASK) >> FTFC_FSTAT_ERSA_REQ_SHIFT);
}

/*! \brief Gets the flash command complete flag
 *
 * This function gets the current flash command complete flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return ftfc command complete flag
 *         - 0b : not completed
 *         - 1b : completed
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatCcif(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_CCIF_MASK) >> FTFC_FSTAT_CCIF_SHIFT);
}

/*! \brief Sets the flash command complete flag
 *
 * This function sets the flash command complete flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash command complete flag
 *             - 0b : no effect
 *             - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatCcif(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_CCIF_SHIFT)) & FTFC_FSTAT_CCIF_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the flash read collide error flag
 *
 * This function gets the current flash read collide error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash read collide error flag
 *         - 0b : not collide
 *         - 1b : collided
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatRdColF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_RDCOLERR_MASK) >> FTFC_FSTAT_RDCOLERR_SHIFT);
}

/*! \brief Sets the flash read collide error flag
 *
 * This function sets the flash read collide error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash read collide error flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatRdColF(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_RDCOLERR_SHIFT)) & FTFC_FSTAT_RDCOLERR_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the flash command configuration error flag
 *
 * This function gets the current flash command configuration error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash command configuration error flag
 *         - 0b : no command configuration error
 *         - 1b : command configuration error has occurred
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatAccErrF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_ACCERR_MASK) >> FTFC_FSTAT_ACCERR_SHIFT);
}

/*! \brief Sets the flash command configuration error flag
 *
 * This function sets the flash command configuration error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash command configuration error flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatAccErrF(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_ACCERR_SHIFT)) & FTFC_FSTAT_ACCERR_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the flash protection violation error flag
 *
 * This function gets the current flash protection violation error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash protection violation error flag
 *         - 0b : not violation
 *         - 1b : violation
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatProtViolF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_PVIOL_MASK) >> FTFC_FSTAT_PVIOL_SHIFT);
}

/*! \brief Sets the flash protection violation error flag
 *
 * This function sets the flash protection violation error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash protection violation error flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatProtViolF(FtfcRegType *obj, uint8_t value)
{
    /* Clear the affected bit-field and write '0' to the w1c bits to avoid
     * side-effects */
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_PVIOL_SHIFT)) & FTFC_FSTAT_PVIOL_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the flash ecc sec error flag
 *
 * This function gets the current flash ecc sec error flag.
 * presents whether flash happens ecc sec error
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash ecc sec error flag
 *         - 0b : not ecc sec error
 *         - 1b : ecc sec error
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatSecF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_SECF_MASK) >> FTFC_FSTAT_SECF_SHIFT);
}

/*! \brief Sets the flash ecc sec error flag
 *
 * This function sets the flash ecc sec error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash ecc sec error flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatSecF(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_SECF_SHIFT)) & FTFC_FSTAT_SECF_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the ftfc ecc ded error flag
 *
 * This function gets the current ftfc ecc ded error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return ftfc ecc ded error flag
 *         - 0b : not ecc ded error
 *         - 1b : ecc ded error
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatDedF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_DEDF_MASK) >> FTFC_FSTAT_DEDF_SHIFT);
}

/*! \brief Sets the flash ecc ded error flag
 *
 * This function sets the flash ecc ded error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash ecc ded error flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatDedF(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_DEDF_SHIFT)) & FTFC_FSTAT_DEDF_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the flash ahb bus response error flag
 *
 * This function gets the current flash ahb bus response error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash ahb bus response error flag
 *         - 0b : no response error
 *         - 1b : response error occurred
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatRspErrF(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_RSPERR_MASK) >> FTFC_FSTAT_RSPERR_SHIFT);
}

/*! \brief Sets the flash ahb bus response error flag
 *
 * This function sets the current flash ahb bus response error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash ecc sec error flag
 *                    - 0b : no effect
 *                    - 1b : clear the flag
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFstatRspErrF(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = 0;
    tmp          = (((uint32_t)(((uint32_t)(value)) << FTFC_FSTAT_RSPERR_SHIFT)) & FTFC_FSTAT_RSPERR_MASK);
    obj->FSTAT   = tmp;
}

/*! \brief Gets the flash command run error flag
 *
 * This function gets the current flash command run error flag.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash command run error flag
 *         - 0b : no run error
 *         - 1b : run error has happened
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFstatMgStat(const FtfcRegType *obj)
{
    return ((obj->FSTAT & FTFC_FSTAT_MGSTAT0_MASK) >> FTFC_FSTAT_MGSTAT0_SHIFT);
}

/*! \brief Gets the flash ahb bus read access time
 *
 * This function gets the current flash ahb bus read access time.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return the flash ahb bus read access time(T presents one cycle of ahb bus clock, requires "n*T >= 20.83ns" )
 *         - 0h : 1T
 *         - 1h : 2T
 *         - 2h : 3T
 *         - 3h : 4T
 *         - 4h : 5T
 *         - 5h : 6T
 *         - 6h : 7T
 *         - 7h : 8T
 *         - 8h : 9T
 *         - 9h : 10T
 *         - Ah : 11T
 *         - Bh : 12T
 *         - Ch : 13T
 *         - Dh : 14T
 *         - Eh : 15T
 *         - Fh : 16T
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFcnfgBusReadTm(const FtfcRegType *obj)
{
    return ((obj->FCNFG & FTFC_FCNFG_BUSRD_T_MASK) >> FTFC_FCNFG_BUSRD_T_SHIFT);
}

/*! \brief Sets the flash ahb bus read access time
 *
 * This function gets the current flash ahb bus read access time.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash ahb bus read access time
 *  (T presents one cycle of ahb bus clock, requires "n*T >= 20.83ns" )
 *         - 0h : 1T
 *         - 1h : 2T
 *         - 2h : 3T
 *         - 3h : 4T
 *         - 4h : 5T
 *         - 5h : 6T
 *         - 6h : 7T
 *         - 7h : 8T
 *         - 8h : 9T
 *         - 9h : 10T
 *         - Ah : 11T
 *         - Bh : 12T
 *         - Ch : 13T
 *         - Dh : 14T
 *         - Eh : 15T
 *         - Fh : 16T
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFcnfgBusReadTm(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = obj->FCNFG;

    tmp &= ~FTFC_FCNFG_BUSRD_T_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_FCNFG_BUSRD_T_SHIFT)) & FTFC_FCNFG_BUSRD_T_MASK);
    obj->FCNFG = tmp;
}

/*! \brief Gets the erase sector suspend
 *
 * This function gets the current erase sector suspend.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return erase sector suspend
 *         - 0b : not suspend
 *         - 1b : suspend
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFcnfgErsSus(const FtfcRegType *obj)
{
    return ((obj->FCNFG & FTFC_FCNFG_ERS_SUS_MASK) >> FTFC_FCNFG_ERS_SUS_SHIFT);
}

/*! \brief Sets the erase sector suspend
 *
 * This function sets the erase sector suspend.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of erase sector suspend
 *                    - 0b : not suspend
 *                    - 1b : suspend
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFcnfgErsSus(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = obj->FCNFG;

    tmp &= ~FTFC_FCNFG_ERS_SUS_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_FCNFG_ERS_SUS_SHIFT)) & FTFC_FCNFG_ERS_SUS_MASK);
    obj->FCNFG = tmp;
}

/*! \brief Gets the bus error response enable flag
 *
 * This function gets the current bus error response enable flag
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return bus error response enable
 *         - 0b : disable 
 *         - 1b : enable 
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFcnfgRspErrBE(const FtfcRegType *obj)
{
    return ((obj->FCNFG & FTFC_FCNFG_RSP_ERR_BE_MASK) >> FTFC_FCNFG_RSP_ERR_BE_SHIFT);
}

/*! \brief Sets the bus error response 
 *
 * This function sets the bus error response.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of bus error response 
 *                    - 0b : disable
 *                    - 1b : enable
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFcnfgRspErrBE(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = obj->FCNFG;

    tmp &= ~FTFC_FCNFG_RSP_ERR_BE_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_FCNFG_RSP_ERR_BE_SHIFT)) & FTFC_FCNFG_RSP_ERR_BE_MASK);
    obj->FCNFG = tmp;
}

/*! \brief Gets the bus error response interrupt enable
 *
 * This function gets the current bus error response interrupt enable.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return bus error response interrupt enable
 *         - 0b : disable interupt
 *         - 1b : enable interrupt
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFcnfgRspErrIE(const FtfcRegType *obj)
{
    return ((obj->FCNFG & FTFC_FCNFG_RSP_ERR_IE_MASK) >> FTFC_FCNFG_RSP_ERR_IE_SHIFT);
}

/*! \brief Sets the bus error response interrupt enable
 *
 * This function sets the bus error response interrupt enable.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of bus error response interrupt enable
 *                    - 0b : disable interupt
 *                    - 1b : enable interrupt
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFcnfgRspErrIE(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = obj->FCNFG;

    tmp &= ~FTFC_FCNFG_RSP_ERR_IE_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_FCNFG_RSP_ERR_IE_SHIFT)) & FTFC_FCNFG_RSP_ERR_IE_MASK);
    obj->FCNFG = tmp;
}

/*! \brief Gets the flash command complete interrupt enable
 *
 * This function gets the current flash command complete interrupt enable.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash command complete interrupt enable
 *         - 0b : disable interupt
 *         - 1b : enable interrupt
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFcnfgCcifIE(const FtfcRegType *obj)
{
    return ((obj->FCNFG & FTFC_FCNFG_CCIF_IE_MASK) >> FTFC_FCNFG_CCIF_IE_SHIFT);
}

/*! \brief Sets the flash command complete interrupt enable
 *
 * This function sets the flash command complete interrupt enable.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash command complete interrupt enable
 *                    - 0b : disable interupt
 *                    - 1b : enable interrupt
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFcnfgCcifIE(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = obj->FCNFG;

    tmp &= ~FTFC_FCNFG_CCIF_IE_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_FCNFG_CCIF_IE_SHIFT)) & FTFC_FCNFG_CCIF_IE_MASK);
    obj->FCNFG = tmp;
}

/*! \brief Gets the flash read collide interrupt enable
 *
 * This function gets the current flash read collide interrupt enable.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return flash read collide interrupt enable
 *         - 0b : disable interupt
 *         - 1b : enable interrupt
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFcnfgRdColIE(const FtfcRegType *obj)
{
    return ((obj->FCNFG & FTFC_FCNFG_RDCOL_IE_MASK) >> FTFC_FCNFG_RDCOL_IE_SHIFT);
}

/*! \brief Sets the flash read collide interrupt enable
 *
 * This function sets the flash read collide interrupt enable.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of flash read collide interrupt enable
 *                    - 0b : disable interupt
 *                    - 1b : enable interrupt
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFcnfgRdColIE(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = obj->FCNFG;

    tmp &= ~FTFC_FCNFG_RDCOL_IE_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_FCNFG_RDCOL_IE_SHIFT)) & FTFC_FCNFG_RDCOL_IE_MASK);
    obj->FCNFG = tmp;
}

/*! \brief Gets the verify backdoor key enable
 *
 * This function gets the current verify backdoor key enable.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return verify backdoor key enable
 *         - 00b : disable
 *         - 01b : disable
 *         - 10b : enable
 *         - 11b : disable
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFsecKeyEn(const FtfcRegType *obj)
{
    return ((obj->FSEC & FTFC_FSEC_KEYEN_MASK) >> FTFC_FSEC_KEYEN_SHIFT);
}

/*! \brief Gets the mass erase enable
 *
 * This function gets the current mass erase enable.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return mass erase enable
 *         - 00b : enable
 *         - 01b : enable
 *         - 10b : disable
 *         - 11b : enable
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFsecMeen(const FtfcRegType *obj)
{
    return ((obj->FSEC & FTFC_FSEC_MEEN_MASK) >> FTFC_FSEC_MEEN_SHIFT);
}

/*! \brief Gets the secure setting
 *
 * This function gets the current secure setting.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return secure setting
 *         - 0b : unsecure
 *         - 1b : secure
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFsecSecure(const FtfcRegType *obj)
{
    return ((obj->FSEC & FTFC_FSEC_SECURE_MASK) >> FTFC_FSEC_SECURE_SHIFT);
}

/*! \brief Gets the pflash protection setting
 *
 * This function gets the current pflash protection setting.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return pflash protection setting
 *         - 0b : unprotect
 *         - 1b : protect
 */
__attribute__((always_inline)) static inline uint32_t FtfcReg_GetPfProtecion(const FtfcRegType *obj)
{
    return ((obj->PFPROT & FTFC_PFPROT_PFPROT_MASK) >> FTFC_PFPROT_PFPROT_SHIFT);
}

/*! \brief Sets the pflash protection setting
 *
 * This function sets the pflash protection setting.
 * pflash protection bits can only change from 0(unprotection) to 1(protection)
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of pflash protection setting
 *                    - 0b : unprotect
 *                    - 1b : protect
 */
__attribute__((always_inline)) static inline void FtfcReg_SetPfProtecion(FtfcRegType *obj,
                                                                         uint32_t     value)
{
    uint32_t tmp = obj->PFPROT;

    tmp &= ~FTFC_PFPROT_PFPROT_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_PFPROT_PFPROT_SHIFT)) & FTFC_PFPROT_PFPROT_MASK);
    obj->PFPROT = tmp;
}

/*! \brief Gets the dflash protection setting
 *
 * This function gets the current dflash protection setting.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return dflash protection setting
 *         - 0b : unprotect
 *         - 1b : protect
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetDfProtecion(const FtfcRegType *obj)
{
    return ((obj->DFPROT & FTFC_DFPROT_DFPROT_MASK) >> FTFC_DFPROT_DFPROT_SHIFT);
}

/*! \brief Sets the dflash protection setting
 *
 * This function sets the dflash protection setting.
 * dflash protection bits can only change from 0 to 1, unprotection to
 * protection;
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of dflash protection setting
 *                    - 0b : unprotect
 *                    - 1b : protect
 */
__attribute__((always_inline)) static inline void FtfcReg_SetDfProtection(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = obj->DFPROT;

    tmp &= ~FTFC_DFPROT_DFPROT_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_DFPROT_DFPROT_SHIFT)) & FTFC_DFPROT_DFPROT_MASK);
    obj->DFPROT = tmp;
}

/*! \brief Gets the eee_ram protection setting
 *
 * This function gets the current eee_ram protection setting.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \return eee_ram protection setting
 *         - 0b : unprotect
 *         - 1b : protect
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetEfProtecion(const FtfcRegType *obj)
{
    return ((obj->EFPROT & FTFC_EFPROT_EFPROT_MASK) >> FTFC_EFPROT_EFPROT_SHIFT);
}

/*! \brief Sets the eee_ram protection setting
 *
 * This function sets the eee_ram protection setting.
 * eee_ram protection bits can only change from 0 to 1, unprotection to
 * protection;
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] value : the value of eee_ram protection setting
 *                    - 0b : unprotect
 *                    - 1b : protect
 */
__attribute__((always_inline)) static inline void FtfcReg_SetEfProtection(FtfcRegType *obj, uint8_t value)
{
    uint32_t tmp = obj->EFPROT;

    tmp &= ~FTFC_EFPROT_EFPROT_MASK;
    tmp |= (((uint32_t)(((uint32_t)(value)) << FTFC_EFPROT_EFPROT_SHIFT)) & FTFC_EFPROT_EFPROT_MASK);
    obj->EFPROT = tmp;
}

/*! \brief Gets the flash common command object
 *
 * This function gets the current flash common command object.
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] index : the index of command object
 *                    - 0 : FCCOB0
 *                    - 1 : FCCOB1
 *                    - 2 : FCCOB2
 *                    - 3 : FCCOB3
 *                    - 4 : FCCOB4
 *                    - 5 : FCCOB5
 *                    - 6 : FCCOB6
 *                    - 7 : FCCOB7
 *                    - 8 : FCCOB8
 *                    - 9 : FCCOB9
 *                    - 10 : FCCOBa
 *                    - 11 : FCCOBb
 *                    - 12 : FCCOBc
 *                    - 13 : FCCOBd
 *                    - 14 : FCCOBe
 *                    - 15 : FCCOBf
 * \return flash common command object
 */
__attribute__((always_inline)) static inline uint8_t FtfcReg_GetFccob(const FtfcRegType *obj, uint8_t index)
{
    uint8_t retval = 0;

    retval = obj->FCCOB[index];

    return retval;
}

/*! \brief Sets the flash common command object
 *
 * This function sets the flash common command object.
 * when CCIF=0, can not modify this register;
 *
 * \param[in] obj : pointer to FTFC register instance
 * \param[in] index : the index of command object
 *                    - 0 : FCCOB0
 *                    - 1 : FCCOB1
 *                    - 2 : FCCOB2
 *                    - 3 : FCCOB3
 *                    - 4 : FCCOB4
 *                    - 5 : FCCOB5
 *                    - 6 : FCCOB6
 *                    - 7 : FCCOB7
 *                    - 8 : FCCOB8
 *                    - 9 : FCCOB9
 *                    - 10 : FCCOBa
 *                    - 11 : FCCOBb
 *                    - 12 : FCCOBc
 *                    - 13 : FCCOBd
 *                    - 14 : FCCOBe
 *                    - 15 : FCCOBf
 * \param[in] value : the value of flash common command object
 */
__attribute__((always_inline)) static inline void FtfcReg_SetFccob(FtfcRegType *obj, uint8_t index, uint8_t value)
{
    uint32_t tmp  = 0;
    uint32_t mask = 0xff;
    tmp           = obj->FCCOB[index];
    tmp &= ~mask;
    tmp |= ((uint8_t)(value)&mask);
    obj->FCCOB[index] = tmp;
}

#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /* _FTFC_REG_H_ */
