/******************************************************************************/
/**
 *
 * file: Fls_Private.c
 *
 * Description: This file contains Internal functions implementation of
 * Fls Component.
 *
 *
 *
 * MODIFICATION HISTORY:
 * Ver     Who   Date    Changes
 * -----  ---- -------- --------------------------------------------------------
 * 1.0.0  KPIT 01/12/17 First release.
 * 1.0.1  KPIT 01/16/17 As per CR 10 banner is updated.
 * 1.0.2  KPIT 04/11/17 As per CR11 and CR19
                       Parallel mode is supported.
                       Generic Implementation is Adapted for All Supported Flash
                       Devices.
                       Write Enable Command issued before Entering-4-ByteAdd
                       Mode.
                       Compiler abstraction added for asm and volatile.
 * 1.0.3 KPIT 11/11/19  The FLS driver does not support writing less than a configurable
 *                      page size and does not guarantee that a write transfer does not
 *                      exceed a physical page
 *                      Fls_MainFunction function will be executed even if Fls module is not initialized.
 *                      FLS Supports Macronix flash as well.
 *                      Version for external modules checks are removed.
 * </pre>
 *
 *******************************************************************************/

/*******************************************************************************
 **                      MISRA C Rule Violations                               **
 ********************************************************************************
 ** 1. MISRA C RULE VIOLATION:                                                 **
 ** Message       : (5:0306)-1 Cast between a pointer to object and            **
 **                 an integral type.                                          **
 ** Rule          : MISRA-C:2004 Rule 11.3  MISRA C:2012 Rule-11.4, Rule-11.6; **
 **                 REFERENCE - ISO-6.3.4 Semantics                            **
 ** Justification : Typecasting is done as per the register size, to access    **
 **                 hardware registers.                                        **
 ** Verification  : However, part of the code is verified manually and it is   **
 **                 not having any impact.                                     **
 ** Reference     : Look for START Msg (5:0306)-1 and                          **
 **                 END Msg (5:0306)-1 tags in the code.                       **
 **                                                                            **
 *******************************************************************************/

/*******************************************************************************
 **                      MISRA C Rule Violations                               **
 ********************************************************************************
 ** 2. MISRA C RULE VIOLATION:                                                 **
 ** Message       : Msg(4:3453) A function could probably be used instead of   **
 **                 Function like macro.                                       **
 ** Rule          : MISRA C:2012 Dir-4.9                                       **
 ** Justification : For Fast access  function macro is used instead of         **
 **                 function for faster access which will reduce execution time**
 ** Verification  : However, part of the code is verified manually and it is   **
 **                 not having any impact.                                     **
 ** Reference     : Look for START Msg (4:3453)-1 and                          **
 **                 END Msg (4:3453)-1 tags in the code.                       **
 **                                                                            **
 *******************************************************************************/

#ifdef __cplusplus
extern "C"{
#endif
/*******************************************************************************
 **                      INCLUDE FILES                                         **
 *******************************************************************************/

#include <string.h>

#include "Stubs.h"

#include "Fls_Private.h"
#include "Fls_Spi.h"


#if (FLS_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif                            /* FLS_DEV_ERROR_DETECT == STD_ON */
//#include "SchM_Fls.h"
/*******************************************************************************
 **                      LOCAL CONSTANTS and MACROS                            **
 *******************************************************************************/

#define FLS_VENDOR_ID_PRIVATE_C   39u
#define FLS_MODULE_ID_PRIVATE_C   92u

#define FLS_AR_RELEASE_MAJOR_VERSION_PRIVATE_C     4u
#define FLS_AR_RELEASE_MINOR_VERSION_PRIVATE_C     2u
#define FLS_AR_RELEASE_REVISION_VERSION_PRIVATE_C  2u

#define FLS_SW_MAJOR_VERSION_PRIVATE_C     1u
#define FLS_SW_MINOR_VERSION_PRIVATE_C     0u
#define FLS_SW_PATCH_VERSION_PRIVATE_C     3u

/*
 * Common flash commands followed by many flash manufacturer.
 * NOTE: Apart for these commands, there are extended commands
 * which differs among manufacturers.
 */
#define FLS_CMD_READ              (0x03)  /**< Read */
#define FLS_CMD_4BYTE_FAST_READ   (0x0C)  /**< Fast read */
#define FLS_CMD_FAST_READ         (0x0B)  /**< Fast read */
#define FLS_CMD_RDID              (0x9F)  /**< Read ID */
#define FLS_CMD_WREN              (0x06)  /**< Write enable */
#define FLS_CMD_WRDI              (0x04)  /**< Write disable */
#define FLS_CMD_RDSR              (0x05)  /**< Read status */
#define FLS_CMD_RCFR              (0x35)  /**< Read configuration */
#define FLS_CMD_WRSR              (0x01)  /**< Write status */
#define FLS_CMD_PP                (0x02)  /**< Page program */
#define FLS_CMD_4BYTE_PP          (0x12)  /**< Page program for 4-BYTE */
#define FLS_CMD_SSE               (0x20)  /**< Sub-sector erase */
#define FLS_CMD_SE                (0xD8)  /**< Sector erase */
#define FLS_CMD_4BYTE_SE          (0xD8)  /**< Sector erase */
#define FLS_CMD_BE                (0xC7)  /**< Bulk erase */
#define FLS_CMD_RES               (0xAB)  /**< Read electronic signature */
#define FLS_CMD_DOFR              (0x3B)  /**< Dual output fast read */
#define FLS_CMD_4BYTE_DOFR        (0x3C)  /**< Dual output fast read 4-BYTE */
#define FLS_CMD_DIOFR             (0xBB)  /**< Dual input/ouput fast read */
#define FLS_CMD_QOFR              (0x6B)  /**< Quad output fast read */
#define FLS_CMD_4BYTE_QOFR        (0x6C)  /**< Quad output fast read */
#define FLS_CMD_QIOFR             (0xEB)  /**< Quad input/output fast read*/
#define FLS_CMD_RFSR              (0x70)  /**< Read flag status */

/* Flash status register bit fields */
#define FLS_STATUS_WIP_MASK       (0x1U)   /**< WIP Bit mask */
#define FLS_STATUS_WEL_MASK       (0x02)   /**< WEL Bit mask */
#define FLS_STATUS_FLAG_MASK      (0x80)   /**< WIP Bit mask */
#define FLS_DUMMY_CLOCKS_CYCL       1U  /* Number of dummy bytes for fast,and dual  reads - Corresponds to 8 clocks cycles */
#define FLS_DUMMY_CLOCKS_CYCL_10   10U  /* Number of dummy bytes for fast,
                                          and quad*/
VAR(FLS_LenType, AUTOMATIC) Fls_Len;
VAR(uint8, FLS_VAR_CLEARED) Fls_ApiStatus = FALSE;
/*******************************************************************************
 **                      LOCAL STRUCTURES, ENUMS, TYPEDEFS                     **
 *******************************************************************************/
/**
 * Flash memory operation type
 */
typedef uint32 Fls_OpsType;
/** Sub-operation state none */
#define FLS_OPS_NONE              (0x0UL)   /**< No operation */
#define FLS_OPS_INIT              (0x1UL)   /**< Init operation */
#define FLS_OPS_DEINIT            (0x3UL)   /**< DeInit operation */
#define FLS_OPS_ERASE             (0x4UL)   /**< Erase operation */
#define FLS_OPS_WRITE             (0x5UL)   /**< Write operation */
#define FLS_OPS_READ              (0x6UL)   /**< Read operation */
#define FLS_OPS_CANCEL            (0x7UL)   /**< Cancel operation */
#define FLS_OPS_COMPARE           (0x8UL)   /**< Compare operation */
#define FLS_OPS_BLANK_CHECK       (0x9UL)   /**< Blank check operation */
#define FLS_OPS_GET_STATUS        (0xAUL)  /**< Get status operation */
#define FLS_OPS_GET_JOB_RESULT    (0xBUL)  /**< Get ops result operation */
#define FLS_OPS_SET_MODE          (0xCUL)  /**< Set mode operation */

/**
 * Flash memory operation state type
 */
typedef uint32 Fls_OpsStateType;
/** Erase operation state config lane - write enable */
#define FLS_OPS_ERASE_STATE_CFGLANES_WE     (0x26UL)
/** Erase operation state config lane - write status */
#define FLS_OPS_ERASE_STATE_CFGLANES_WS     (0x27UL)
/** Erase operation state write enable */
#define FLS_OPS_ERASE_STATE_WE              (0x28UL)
/** Erase operation state sector erase */
#define FLS_OPS_ERASE_STATE_SE              (0x29UL)
/** Erase operation state done */
#define FLS_OPS_ERASE_STATE_DONE            (0x2AUL)
/** Erase operation state error */
#define FLS_OPS_ERASE_STATE_ERROR           (0x2BUL)
/** Erase operation state exit.*/
#define FLS_OPS_ERASE_STATE_EXIT            (0x2CUL)


/** Write operation state read enable */
#define FLS_OPS_WRITE_STATE_CMD_RD          (0x30UL)
/** Write operation state dummy cycle enable */
#define FLS_OPS_WRITE_STATE_DUMMY_CYC       (0x31UL)
/** Write operation state read Data */
#define FLS_OPS_WRITE_STATE_RD              (0x32UL)
/** Write operation state read Data compare */
#define FLS_OPS_WRITE_STATE_CMP             (0x33UL)
/** Write operation state write enable */
#define FLS_OPS_WRITE_STATE_WE              (0x34UL)
/** Write operation state write data */     
#define FLS_OPS_WRITE_STATE_WR              (0x35UL)
/** Write operation state done */           
#define FLS_OPS_WRITE_STATE_DONE            (0x36UL)
/** Write operation state error */          
#define FLS_OPS_WRITE_STATE_ERROR           (0x37UL)
/** Write operation state error */          
#define FLS_OPS_WRITE_STATE_EXIT            (0x38UL)

/** Read operation state config lane - write enable */
#define FLS_OPS_READ_STATE_CFGLANES_WE      (0x3CUL)
/** Read operation state config lane - write status */
#define FLS_OPS_READ_STATE_CFGLANES_WS      (0x3DUL)
/** Read operation state read */            
#define FLS_OPS_READ_STATE_READ             (0x3EUL)
/** Read operation state read */            
#define FLS_OPS_READ_STATE_READ_REMAIN      (0x3FUL)
/** Read operation state done */            
#define FLS_OPS_READ_STATE_DONE             (0x40UL)
/** Read operation state error */           
#define FLS_OPS_READ_STATE_ERROR            (0x41UL)
/** Read operation state exit */            
#define FLS_OPS_READ_STATE_EXIT             (0x42UL)


/** Compare operation state config lane - write enable */
#define FLS_OPS_COMPARE_STATE_CFGLANES_WE   (0x4EUL)
/** Compare operation state config lane - write status */
#define FLS_OPS_COMPARE_STATE_CFGLANES_WS   (0x4FUL)
/** Compare operation state read */         
#define FLS_OPS_COMPARE_STATE_RD            (0x50UL)
/** Compare operation state compare */      
#define FLS_OPS_COMPARE_STATE_CMP           (0x51UL)
/** Compare operation state done */         
#define FLS_OPS_COMPARE_STATE_DONE          (0x52UL)
/** Compare operation state error */        
#define FLS_OPS_COMPARE_STATE_ERROR         (0x53UL)
/** Compare operation state exit */         
#define FLS_OPS_COMPARE_STATE_EXIT          (0x54UL)


/** Blank check operation state config lane - write enable */
#define FLS_OPS_BLANKCHK_STATE_CFGLANES_WE  (0x58UL)
/** Blank check operation state config lane - write status */
#define FLS_OPS_BLANKCHK_STATE_CFGLANES_WS  (0x59UL)
/** Blank check operation state read */     
#define FLS_OPS_BLANKCHK_STATE_RD           (0x5AUL)
/** Blank check operation state compare */  
#define FLS_OPS_BLANKCHK_STATE_CMP          (0x5BUL)
/** Blank check operation state done */     
#define FLS_OPS_BLANKCHK_STATE_DONE         (0x5CUL)
/** Blank check operation state error */    
#define FLS_OPS_BLANKCHK_STATE_ERROR        (0x5DUL)
/** Blank check operation state exit */     
#define FLS_OPS_BLANKCHK_STATE_EXIT         (0x5EUL)

/**
 * Fls sub-operation state type
 */
typedef uint32 Fls_SubOpsStateType;
/** Sub-operation state Write enable */
#define FLS_SUBOPS_STATE_WE       (0x0UL)
/** Sub-operation state sector erase */
#define FLS_SUBOPS_STATE_SE       (0x1UL)
/** Sub-operation state read status */
#define FLS_SUBOPS_STATE_RS       (0x2UL)
/** Sub-operation state verify WEL bit in read status */
#define FLS_SUBOPS_STATE_VER_WEL  (0x3UL)
/** Sub-operation state verify WIP bit read status */
#define FLS_SUBOPS_STATE_VER_WIP  (0x4UL)
/** Sub-operation state page program */
#define FLS_SUBOPS_STATE_PP       (0x5UL)
/** Sub-operation state write data */
#define FLS_SUBOPS_STATE_WR       (0x6UL)
/** Sub-operation state write status */
#define FLS_SUBOPS_STATE_WS       (0x7UL)

/**
 * Flash memory error flag type
 */
typedef uint32 Fls_ErrFlagType;

/**
 * Flash memory operation indication flag type
 */
typedef uint32 Fls_IndFlagType;
#define FLS_INDFLAG_NO_IND        (0x0UL) /**< Flag for no indication */
#define FLS_INDFLAG_DONE_IND      (0x1UL) /**< Flag for done indication */
#define FLS_INDFLAG_ERR_IND       (0x2UL) /**< Flag for error indication */

/* Helper macros */
/* START Msg (4:3453)-1 */
#define FLS_ADDRESS32_24(addr)          (((addr) >> 24UL) & 0xFFUL)
/* END Msg (4:3453)-1 */

/* START Msg (4:3453)-1 */
#define FLS_ADDRESS23_16(addr)          (((addr) >> 16UL) & 0xFFUL)
/* END Msg (4:3453)-1 */

/* START Msg (4:3453)-1 */
#define FLS_ADDRESS15_8(addr)           (((addr) >>  8UL) & 0xFFUL)
/* END Msg (4:3453)-1 */

/* START Msg (4:3453)-1 */
#define FLS_ADDRESS7_0(addr)            ((addr) & 0xFFUL)
/* END Msg (4:3453)-1 */

#define FLS_DUMMY_DATA                  (0x0)

/* Flash status register length. Most of the flashes have only 2bytes
   status register. But kept 4byte for future extensions */
#define FLS_STATUS_REG_LEN              (0x4UL)

/* Read status loop count */
#define FLS_READ_STATUS_LOOP_COUNT      (0xAUL)

/* Flash sector list size */
#define FLS_FLASHABLE_SECTOR_LIST_SZ    (0x40UL) /*Flash sector list size */

/**
 * FLASH operation info structure
 */
typedef struct {
    FLS_AddrType      ulOpsAddr;       /**< Flash address */
    /**< Write data buffer pointer */
    P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pOpsTxData;
    /**< Read data buffer pointer */
    P2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) pOpsRxData;
    FLS_LenType       ulOpsLen;        /**< Length */
    FLS_AddrType      ulTmpAddr;       /**< Intermediate flash address */
    /**< Intermediate Tx buffer pointer */
    P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pTmpTxData;
    /**< Intermediate Rx buffer pointer */
    P2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) pTmpRxData;
    FLS_LenType       ulTmpLen;        /**< Intermediate length */
    FLS_LenType       ulTmpLenRem;     /**< Intermediate length remaining */
    FLS_LenType       ulTmpRxLen;      /**< Intermediate Read length */
    FLS_LenType       ulTmpTxLen;      /**< Intermediate Transmit length */
    FLS_LenType       ulPrevRxLen;     /**< Previous read length */
    FLS_LenType       ulPrevTxLen;     /**< Previous transmit length */
    uint32            ulReadStatusCnt; /**< Read status loop count */
    Fls_IndFlagType   ulIndFlag;      /**< Flag to identify indication type */
} FLS_OpsInfoType;
/**
 * FLASH read-write device structure
 */
typedef struct {
    FLS_StatusType            ulStatus;     /**< Current controller status */
    Fls_OpsType               ulCurrOps;    /**< Operation being processed */
    /** Current state for current operation */
    Fls_OpsStateType          ulCurrOpsState;
    /** Current state for current sub-operation */
    Fls_SubOpsStateType       ulSubOpsState;
    /** Pointer to config for runtime usage */
    FLS_CfgType               config;
    FLS_OpsResultType         ulOpsRes;    /**< Result of last ops processed */
    FLS_OpsInfoType           opsInfo;    /**< Operation information */
    Fls_ErrFlagType           ulErrFlag;    /**< Error flag */
    /** Xfer transmit buffer */
    uint8                     ucXferTxBuf[MSPI_FIFO_LEN];
    /** Xfer receive buffer */
    uint8                     ucXferRxBuf[MSPI_FIFO_LEN];
    /** Flag to indicate flash read lane configuration done */
    uint32                    ulIsLaneCfgDone;
} FLS_RWDevType;
/**
 * FLASH IO structure
 */
typedef struct flashIO {
    uint32                retVal;     /**< Return value */
    FLS_HwIDType          hwID;       /**< Controller ID */
    FLS_AddrType          addr;       /**< Flash address */
    /**< Write data buffer pointer */
    P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) txBuf;
    /**< Read data buffer pointer */
    P2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) rxBuf;
    FLS_LenType           len;        /**< Length */
    /**< Flash configuration */
    P2CONST(FLS_CfgType, AUTOMATIC, FLS_APPL_DATA) config;
    uint32                isErr;      /**< Error flag */
} FlashIO;
/*******************************************************************************
 **                      LOCAL VARIABLES                                       **
 *******************************************************************************/

VAR(uint8, AUTOMATIC) __attribute__((aligned(4))) Fls_TempBuffer[MSPI_FIFO_LEN];

#define FLS_START_SEC_VAR_FAST_CLEARED_ASIL_C_UNSPECIFIED
#include "Fls_MemMap.h"
static VAR(FLS_RWDevType, FLS_VAR_FAST_CLEARED) FLS_RWDev =
         {
           FLS_STATUS_UNINIT,
           FLS_OPS_NONE,
           FLS_OPS_RESULT_OK,

          };
#define FLS_STOP_SEC_VAR_FAST_CLEARED_ASIL_C_UNSPECIFIED
#include "Fls_MemMap.h"

#define FLS_START_SEC_VAR_FAST_CLEARED_ASIL_C_UNSPECIFIED
#include "Fls_MemMap.h"

static VAR(FLS_FlsableSecType, FLS_VAR_FAST_CLEARED) FLS_FlsableSecList[FLS_FLASHABLE_SECTOR_LIST_SZ];

#define FLS_STOP_SEC_VAR_FAST_CLEARED_ASIL_C_UNSPECIFIED
#include "Fls_MemMap.h"

/*******************************************************************************
 **                      VERSION CHECK                                         **
 *******************************************************************************/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if (FLS_DEV_ERROR_DETECT == STD_ON)
//    #if ((FLS_AR_RELEASE_MAJOR_VERSION != DET_AR_RELEASE_MAJOR_VERSION) || \
//         (FLS_AR_RELEASE_MINOR_VERSION != DET_AR_RELEASE_MINOR_VERSION))
//        #error "Autosar version numbers of Fls.h and Det.h are different."
//    #endif
#endif
#endif

#if ((FLS_SW_MAJOR_VERSION_PRIVATE_C != FLS_SW_MAJOR_VERSION_PRIVATE_H) || \
        (FLS_SW_MINOR_VERSION_PRIVATE_C != FLS_SW_MINOR_VERSION_PRIVATE_H) || \
        (FLS_SW_PATCH_VERSION_PRIVATE_C != FLS_SW_PATCH_VERSION_PRIVATE_H))
#error "The SW version number of Fls_Private.c and Fls_Private.h are different."
#endif

#if ((FLS_SW_MAJOR_VERSION_PRIVATE_C != FLS_SW_MAJOR_VERSION) || \
        (FLS_SW_MINOR_VERSION_PRIVATE_C != FLS_SW_MINOR_VERSION) || \
        (FLS_SW_PATCH_VERSION_PRIVATE_C != FLS_SW_PATCH_VERSION))
#error "The SW version number of Fls_Private.c and Fls.h are different."
#endif

#if ((FLS_SW_MAJOR_VERSION_PRIVATE_C != FLS_SW_MAJOR_VERSION_QSPI_H) || \
        (FLS_SW_MINOR_VERSION_PRIVATE_C != FLS_SW_MINOR_VERSION_QSPI_H) || \
        (FLS_SW_PATCH_VERSION_PRIVATE_C != FLS_SW_PATCH_VERSION_QSPI_H))
#error "The SW version number of Fls_Private.c and Fls_Qspi.h are different."
#endif
/*******************************************************************************
 **                      FUNCTION DEFINITIONS                                  **
 *******************************************************************************/

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
static FUNC(uint32, FLS_CODE_FAST) Fls_OpsBlankCheck(VAR(FLS_AddrType, AUTOMATIC) ulAddr, VAR(FLS_LenType, AUTOMATIC) ulLen);
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
static FUNC(uint32, FLS_CODE_FAST) Fls_OpsCompare(VAR(FLS_AddrType, AUTOMATIC) ulAddr, CONSTP2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pBuf, VAR(FLS_LenType, AUTOMATIC) ulLen);
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

static FUNC(void, FLS_CODE_FAST) Fls_OpsDoneInd (void);

#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

static FUNC(uint32, FLS_CODE_FAST) Fls_CalculateWriteLength(void);

#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_CmdWriteEnable                                     **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To send write enable command by QSPI                   **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_CmdWriteEnable(void)
{

    FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_WREN;

    return Fls_SPI_SendCmdFlsDevice(&(FLS_RWDev.ucXferTxBuf[0]), 1);

    //return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), NULL_PTR, 1UL, QSPI_XFER_STOP, TRUE);

}      
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_CmdReadStatus                                      **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : RetVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To get read status of operation                        **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_CmdReadStatus(void)
{
    FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_RDSR;
    FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_DUMMY_DATA;

    return Fls_SPI_ReadFlsDeviceReg(&(FLS_RWDev.ucXferTxBuf[0]), &(FLS_RWDev.ucXferRxBuf[0]), 2UL);

    //return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), &(FLS_RWDev.ucXferRxBuf[0]), 1UL, QSPI_XFER_STOP, TRUE);
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_CmdReadFlagStatus                                  **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : RetVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To get operation flag status                           **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_CmdReadFlagStatus(void)
{
    FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_RFSR;
    FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_DUMMY_DATA;

    return Fls_SPI_ReadFlsDeviceReg(&(FLS_RWDev.ucXferTxBuf[0]), &(FLS_RWDev.ucXferRxBuf[0]), 2UL);

    //return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), &(FLS_RWDev.ucXferRxBuf[0]), 2UL, QSPI_XFER_STOP, TRUE);
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_CmdPageProg                                        **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : RetVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To send page program command                           **
 *******************************************************************************/
//static FUNC(uint32, FLS_CODE_FAST) Fls_CmdPageProg(void)
//{
//    VAR(uint32, AUTOMATIC) ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;
//
//#if (FLS_4BYTE_ADDRESS_MODE == STD_ON)
//    FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_PP;
//    FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS32_24(ulAddr);
//    FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS23_16(ulAddr);
//    FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS15_8(ulAddr);
//    FLS_RWDev.ucXferTxBuf[4] = (uint8)FLS_ADDRESS7_0(ulAddr);
//    return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), NULL_PTR, 5UL, QSPI_XFER_CONTINUE, TRUE);
//
//#else
//    FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_PP;
//    FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS23_16(ulAddr);
//    FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS15_8(ulAddr);
//    FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS7_0(ulAddr);
//    return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), NULL_PTR, 4UL, QSPI_XFER_CONTINUE, TRUE);
//#endif
//}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : FLS_CmdWriteData                                       **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : RetVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To write command data                                  **
 *******************************************************************************/
//static FUNC(uint32, FLS_CODE_FAST) Fls_CmdWriteData(void)
//{
//    P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pTxData;
//    VAR(uint32, AUTOMATIC) ulLen = Fls_CalculateWriteLength();
//
//    pTxData = FLS_RWDev.opsInfo.pTmpTxData;
//    return Fls_QSPI_Xfer(pTxData, NULL_PTR, ulLen, QSPI_XFER_STOP, FALSE);
//}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_CmdSectorErase                                     **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : RetVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To send sector erase command                           **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_CmdSectorErase(void)
{
    VAR(uint32, AUTOMATIC) ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;

#if (FLS_4BYTE_ADDRESS_MODE == STD_ON)
    FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_SE;
    FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS32_24(ulAddr);
    FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS23_16(ulAddr);
    FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS15_8(ulAddr);
    FLS_RWDev.ucXferTxBuf[4] = (uint8)FLS_ADDRESS7_0(ulAddr);
    //return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), NULL_PTR, 5UL, QSPI_XFER_STOP, TRUE);
    //return FLS_SPI_ProcessWriteCmd(&(FLS_RWDev.ucXferTxBuf[0]), NULL_PTR, 5UL);
    return Fls_SPI_SendCmdFlsDevice(&(FLS_RWDev.ucXferTxBuf[0]), 5UL);

#else
    FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_SE;
    FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS23_16(ulAddr);
    FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS15_8(ulAddr);
    FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS7_0(ulAddr);
    return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), NULL_PTR, 4UL, QSPI_XFER_STOP, TRUE);
#endif

        }
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_SubOpsWriteEnable                                  **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : pIsSubStateEnd, pIsTrigAgain                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : This service handle sub-operation of flash             **
 **                     write operation.                                       **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_SubOpsWriteEnable(CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsSubStateEnd, CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain)
{
    VAR(uint32, AUTOMATIC) retVal;

    *pIsSubStateEnd = FALSE;
    *pIsTrigAgain = FALSE;

    switch(FLS_RWDev.ulSubOpsState)
    {

    case FLS_SUBOPS_STATE_WE: /* case 0: */
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
        FLS_RWDev.opsInfo.ulReadStatusCnt = 0UL;
        retVal = Fls_CmdWriteEnable();
        *pIsTrigAgain = TRUE;
        break;

    case FLS_SUBOPS_STATE_RS: /* case 1: */
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_VER_WEL;
        retVal = Fls_CmdReadStatus();
        *pIsTrigAgain = TRUE;
        break;

    case FLS_SUBOPS_STATE_VER_WEL: /* case 2: */
        if (FLS_READ_STATUS_LOOP_COUNT > FLS_RWDev.opsInfo.ulReadStatusCnt)
        {
            if(((FLS_RWDev.ucXferRxBuf[0]) & ((uint8)FLS_STATUS_WEL_MASK)) != ((uint8)FLS_STATUS_WEL_MASK))
            {
                /* Write enable failure & trigger sub state machine again */
                FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
                (FLS_RWDev.opsInfo.ulReadStatusCnt)++;
                *pIsTrigAgain = TRUE;
            }
            else
            {
                /* Write enable success */
                *pIsSubStateEnd = TRUE;
                FLS_RWDev.opsInfo.ulReadStatusCnt = 0UL;
            }
            retVal = ERR_OK;
        }
        else
        {
            *pIsTrigAgain = FALSE;
            *pIsSubStateEnd = TRUE;
            retVal = ERR_TIME_OUT;
        }
        break;
    default:
        /* Shall never reach here */
        retVal = ERR_INVAL_STATE;
        break;
    }
    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00218, SWS_Fls_00327, SWS_Fls_00328           **
 **                      SWS_Fls_00329, SWS_Fls_00330, SWS_Fls_00220,          **
 **                      SWS_Fls_00221, SWS_Fls_00020, SWS_Fls_00021,          **
 **                      SWS_Fls_00065, SWS_Fls_00023, SWS_Fls_00145,          **
 **                                                                            **
 ** Syntax            : Fls_SubOpsSectorErase                                  **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : pIsSubStateEnd, pIsTrigAgain                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       :  To handle sector erase operation                      **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_SubOpsSectorErase(CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsSubStateEnd, CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain)
{
    VAR(uint32, AUTOMATIC) retVal;

    *pIsSubStateEnd = FALSE;
    *pIsTrigAgain = FALSE;

    switch(FLS_RWDev.ulSubOpsState)
    {
    case FLS_SUBOPS_STATE_SE:
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
        retVal = Fls_CmdSectorErase();
        break;

    case FLS_SUBOPS_STATE_RS:
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_VER_WIP;
        if(Fls_MemConfig.flsID == MICRON_FLASH)
        {
            retVal = Fls_CmdReadFlagStatus();
        }
        else
        {
            retVal = Fls_CmdReadStatus();
        }
        break;

    case FLS_SUBOPS_STATE_VER_WIP:
        if(Fls_MemConfig.flsID == MICRON_FLASH)
        {
            if (((FLS_RWDev.ucXferRxBuf[0]) & ((uint8)FLS_STATUS_FLAG_MASK)) == ((uint8)FLS_ZERO))
            {
                /* Command in progress and trigger sub state again */
                FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
                *pIsTrigAgain = TRUE;
            }
            else
            {
                /* Command complete */
                *pIsSubStateEnd = TRUE;
            }
        }
        else
        {
            if (((FLS_RWDev.ucXferRxBuf[0]) & ((uint8)FLS_STATUS_WIP_MASK)) != ((uint8)FLS_ZERO))
            {
                /* Command in progress and trigger sub state again */
                FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
                *pIsTrigAgain = TRUE;
            }
            else
            {
                /* Command complete */
                *pIsSubStateEnd = TRUE;
            }
        }
        retVal = ERR_OK;
        break;
    default:
        /* Shall never reach here */
        retVal = ERR_INVAL_STATE;
        break;
    }

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"


#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

/*******************************************************************************
 ** Traceability       : SWS_Fls_00251, SWS_Fls_00223, SWS_Fls_00332,          **
 **                      SWS_Fls_00334, SWS_Fls_00225, SWS_Fls_00001,          **
 **                      SWS_Fls_00333, SWS_Fls_00226, SWS_Fls_00167,          **
 **                                                                            **
 ** Syntax            : Fls_SubOpsWrite                                        **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        :  NA                                                    **
 **                                                                            **
 ** Sync/Async        :  NA                                                    **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : pIsSubStateEnd, pIsTrigAgain                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : Sub-operation of write operation                       **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_SubOpsWrite( CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsSubStateEnd,
                                                    CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulAddr;
    VAR(uint32, AUTOMATIC) ulLen = 0;

    *pIsTrigAgain = FALSE;
    *pIsSubStateEnd = FALSE;

    switch(FLS_RWDev.ulSubOpsState)
    {
    case FLS_SUBOPS_STATE_PP:
        //FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WR;
        //retVal = Fls_CmdPageProg();
        ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_PP;
        FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS32_24(ulAddr);
        FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS23_16(ulAddr);
        FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS15_8(ulAddr);
        FLS_RWDev.ucXferTxBuf[4] = (uint8)FLS_ADDRESS7_0(ulAddr);

        ulLen = Fls_CalculateWriteLength();
        retVal = FLS_SPI_ProcessWriteCmd(FLS_RWDev.ucXferTxBuf, FLS_RWDev.opsInfo.pTmpTxData, ulLen);
        *pIsTrigAgain =TRUE;
        break;

//    case FLS_SUBOPS_STATE_WR:
//        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
//        retVal = Fls_CmdWriteData();
//        break;

    case FLS_SUBOPS_STATE_RS:
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_VER_WIP;
        if(Fls_MemConfig.flsID == MICRON_FLASH)
        {
            retVal = Fls_CmdReadFlagStatus();
        }
        else
        {
            retVal = Fls_CmdReadStatus();
        }
        *pIsTrigAgain =TRUE;
        break;

    case FLS_SUBOPS_STATE_VER_WIP:
        if(Fls_MemConfig.flsID == MICRON_FLASH)
        {
            if (((FLS_RWDev.ucXferRxBuf[0]) & ((uint8)FLS_STATUS_FLAG_MASK)) == ((uint8)FLS_ZERO))
            {
                /* Command in progress and trigger sub state again */
                FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
                *pIsTrigAgain = TRUE;
            }
            else
            {
                /* Command complete */
                *pIsSubStateEnd = TRUE;
            }
        }
        else
        {
            if (((FLS_RWDev.ucXferRxBuf[0]) & ((uint8)FLS_STATUS_WIP_MASK)) != ((uint8)FLS_ZERO))
            {
                /* Command in progress and trigger sub state again */
                FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_RS;
                *pIsTrigAgain = TRUE;
            }
            else
            {
                /* Command complete */
                *pIsSubStateEnd = TRUE;
            }
        }

        retVal = ERR_OK;
        break;

    default:
        /* Shall never reach here */
        retVal = ERR_INVAL_STATE;
        break;
    }

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

/*******************************************************************************
 ** Traceability       : SWS_Fls_00218, SWS_Fls_00327, SWS_Fls_00328           **
 **                      SWS_Fls_00329, SWS_Fls_00330, SWS_Fls_00220,          **
 **                      SWS_Fls_00221, SWS_Fls_00020, SWS_Fls_00021,          **
 **                                                                            **
 ** Syntax            : Fls_EraseStateHandler                                  **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : pIsTrigAgain                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : This service handle sub-operation of flash             **
 **                     erase operation.                                       **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_EraseStateHandler(CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulIsSubStateEnd;
    VAR(uint32, AUTOMATIC) ulIsSubStateTrigAgain;

    Fls_ApiStatus = FALSE;

    *pIsTrigAgain = FALSE;

    if (TRUE == FLS_RWDev.ulErrFlag)
    {
        FLS_RWDev.ulErrFlag = FALSE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_ERASE_STATE_ERROR;
    }

    switch(FLS_RWDev.ulCurrOpsState)
    {
    case FLS_OPS_ERASE_STATE_WE:
        retVal = Fls_SubOpsWriteEnable(&ulIsSubStateEnd, &ulIsSubStateTrigAgain);
        if ((ERR_OK == retVal) && (TRUE == ulIsSubStateEnd))
        {
            FLS_RWDev.ulCurrOpsState = FLS_OPS_ERASE_STATE_SE;
            FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_SE;
            *pIsTrigAgain = TRUE;
        }
        if ((ERR_OK == retVal) && (TRUE == ulIsSubStateTrigAgain))
        {
            *pIsTrigAgain = TRUE;
        }
        break;

    case FLS_OPS_ERASE_STATE_SE:
        retVal = Fls_SubOpsSectorErase(&ulIsSubStateEnd,&ulIsSubStateTrigAgain);
        if ((ERR_OK == retVal) && (TRUE == ulIsSubStateEnd))
        {
            if(FLS_RWDev.config.ucFlsQspiHwConnectionMode == FLS_XQSPI_CONNECTION_MODE_PARALLEL)
            {
                FLS_RWDev.opsInfo.ulTmpAddr += ((FLS_RWDev.config.sectorSize)/FLS_TWO);
            }
            else
            {
                FLS_RWDev.opsInfo.ulTmpAddr += FLS_RWDev.config.sectorSize;
            }

            FLS_RWDev.opsInfo.ulTmpLen -=  FLS_RWDev.config.sectorSize;

            if (0UL == FLS_RWDev.opsInfo.ulTmpLen)
            {
                FLS_RWDev.ulCurrOpsState = FLS_OPS_ERASE_STATE_DONE;
            }
            else
            {
                FLS_RWDev.ulCurrOpsState = FLS_OPS_ERASE_STATE_WE;
                FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WE;
            }
            *pIsTrigAgain = TRUE;
        }

        if ((ERR_OK == retVal) && (TRUE == ulIsSubStateTrigAgain))
        {
            *pIsTrigAgain = TRUE;
        }
        break;

    case FLS_OPS_ERASE_STATE_DONE:
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        /* SWS_Fls_00022: Verification of erase */
        retVal=Fls_OpsBlankCheck( FLS_RWDev.opsInfo.ulOpsAddr, FLS_RWDev.opsInfo.ulOpsLen);
        /* retVal = ERR_OK;*/
#else
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_ERASE_STATE_EXIT;
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_OK;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_DONE_IND;
        retVal = ERR_OK;
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
        break;

    case FLS_OPS_ERASE_STATE_ERROR:
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_FAIL;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_ERASE_STATE_EXIT;
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_ERR_IND;
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        /* SWS_Fls_00315, SWS_Fls_00104 */
        (void) Det_ReportRuntimeError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_ERASE_SID, FLS_E_ERASE_FAILED);
#endif
        retVal = ERR_OK;
        break;

    default:
        /* Wrong current operation state */
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_ERASE_SID, FLS_E_INVALID_OPERATION);
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

        retVal = ERR_INVAL_STATE;
        break;
    };

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability      : SWS_FLS_00236                                          **
 **                                                                            **
 ** Syntax            : Fls_CmdRead                                            **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To send read command on QSPI bus                       **
 *******************************************************************************/
//static FUNC(uint32, FLS_CODE_FAST) Fls_CmdRead(void)
//{
//    VAR(uint32, AUTOMATIC) ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;
//
//#if (FLS_4BYTE_ADDRESS_MODE == STD_ON)
//    if(FLS_RWDev.config.readLane == FLS_READ_LANE_SINGLE)
//    {
//        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_FAST_READ;
//    }
//    else if(FLS_RWDev.config.readLane == FLS_READ_LANE_DUAL)
//    {
//        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_DOFR;
//    }
//    else if(FLS_RWDev.config.readLane == FLS_READ_LANE_QUAD)
//    {
//        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_QOFR;
//    }
//    else
//    {
//        /*Do nothing*/
//    }
//
//    FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS32_24(ulAddr);
//    FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS23_16(ulAddr);
//    FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS15_8(ulAddr);
//    FLS_RWDev.ucXferTxBuf[4] = (uint8)FLS_ADDRESS7_0(ulAddr);
//
//    return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), NULL_PTR, 5UL, QSPI_XFER_CONTINUE, TRUE);
//#else
//    if(FLS_RWDev.config.readLane == FLS_READ_LANE_SINGLE)
//    {
//        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_FAST_READ;
//    }
//    else if(FLS_RWDev.config.readLane == FLS_READ_LANE_DUAL)
//    {
//        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_DOFR;
//    }
//    else if(FLS_RWDev.config.readLane == FLS_READ_LANE_QUAD)
//    {
//        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_QOFR;
//    }
//    else
//    {
//        /*Do nothing*/
//    }
//
//    FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS23_16(ulAddr);
//    FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS15_8(ulAddr);
//    FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS7_0(ulAddr);
//
//    return Fls_QSPI_Xfer(&(FLS_RWDev.ucXferTxBuf[0]), NULL_PTR, 4UL, QSPI_XFER_CONTINUE, TRUE);
//
//#endif
//
//}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_CmdSendDummyCycles                                 **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To send dummy cycles on QSPI bus                       **
 *******************************************************************************/
//static FUNC(uint32, FLS_CODE_FAST) Fls_CmdSendDummyCycles(void)
//{
//    VAR(uint32, AUTOMATIC) retVal;
//    VAR(uint32, AUTOMATIC) dummyCycles;
//
//    if(FLS_RWDev.config.readLane == FLS_READ_LANE_QUAD)
//    {
//        retVal = Fls_QSPI_Xfer( NULL_PTR, NULL_PTR, FLS_DUMMY_CLOCKS_CYCL_10, QSPI_XFER_CONTINUE, TRUE);
//    }
//    else
//    {
//
//        dummyCycles = FLS_DUMMY_CLOCKS_CYCL;
//        retVal = Fls_QSPI_Xfer( NULL_PTR, NULL_PTR, dummyCycles, QSPI_XFER_CONTINUE, TRUE);
//    }
//    return retVal;
//}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            :  Fls_WriteStateHandlerThread_1                         **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        :  NA                                                    **
 **                                                                            **
 ** Sync/Async        :  NA                                                    **
 **                                                                            **
 ** Reentrancy        :  None                                                  **
 **                                                                            **
 ** Parameters (in)   :  pIsTrigAgain,pcWriteCmpChkErrFlag                     **
 **                                                                            **
 ** Parameters (out)  :  None                                                  **
 **                                                                            **
 ** Return value      :  uint32                                                **
 **                                                                            **
 ** Description       : Sub Function of Fls_WriteStateHandler                  **
 **                     to reduce Code Complexity.                             **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_WriteStateHandlerThread_1(
        CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain,
        CONSTP2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) pcWriteCmpChkErrFlag)
{

    VAR(uint32, AUTOMATIC) retVal=ERR_OK;
    VAR(uint32, AUTOMATIC) ulLen = 0UL;
    VAR(uint32, AUTOMATIC) ulAddr;

    switch(FLS_RWDev.ulCurrOpsState)
    {
#if (FLS_DEV_ERROR_DETECT == STD_ON)
    case FLS_OPS_WRITE_STATE_CMD_RD:
        //retVal = Fls_CmdRead();
        ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;
        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_FAST_READ;
        FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS32_24(ulAddr);
        FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS23_16(ulAddr);
        FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS15_8(ulAddr);
        FLS_RWDev.ucXferTxBuf[4] = (uint8)FLS_ADDRESS7_0(ulAddr);
        retVal = ERR_OK;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_RD;
        //FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_DUMMY_CYC;
        //*pIsTrigAgain = TRUE;
        *pcWriteCmpChkErrFlag = (uint8) FLS_ZERO;
        //break; No break to save time

//    case FLS_OPS_WRITE_STATE_DUMMY_CYC:
//        *pIsTrigAgain = TRUE;
//        FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_RD;
//        FLS_RWDev.ulIsLaneCfgDone = TRUE;
//        retVal = Fls_CmdSendDummyCycles();
//        break;

    case FLS_OPS_WRITE_STATE_RD:
        if (0UL < FLS_RWDev.opsInfo.ulTmpLen)
        {
            ulLen = FLS_RWDev.opsInfo.ulTmpLen;
            if (MSPI_FIFO_LEN < ulLen)
            {
                ulLen = MSPI_FIFO_LEN;
            }
        }
        FLS_RWDev.opsInfo.ulTmpLen -= ulLen;
        FLS_RWDev.opsInfo.ulPrevRxLen = ulLen;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_CMP;
        retVal = FLS_SPI_ProcessFastReadCmd((uint8 *)FLS_RWDev.ucXferTxBuf, (uint8 *)FLS_RWDev.ucXferRxBuf, ulLen);
        //*pIsTrigAgain = TRUE;
        //retVal = Fls_QSPI_Read(FLS_RWDev.opsInfo.ulTmpAddr, FLS_RWDev.ucXferRxBuf, ulLen);
        //break; No break to save time

    case FLS_OPS_WRITE_STATE_CMP:
        if(Fls_DMA_IsBusy() != TRUE)
        {
            (void) memset(FLS_RWDev.ucXferTxBuf, 0xFF, (uint32)MSPI_FIFO_LEN);
            retVal = (uint32) (memcmp(FLS_RWDev.ucXferRxBuf, FLS_RWDev.ucXferTxBuf, (uint32)FLS_RWDev.opsInfo.ulPrevRxLen));

            if(FLS_RWDev.config.ucFlsQspiHwConnectionMode == FLS_XQSPI_CONNECTION_MODE_PARALLEL)
            {
                FLS_RWDev.opsInfo.ulTmpAddr +=  ((FLS_RWDev.opsInfo.ulPrevRxLen)/FLS_TWO);
            }
            else
            {
                FLS_RWDev.opsInfo.ulTmpAddr += FLS_RWDev.opsInfo.ulPrevRxLen;
            }

            if (retVal == FLS_ZERO)
            {
                if (0UL < FLS_RWDev.opsInfo.ulTmpLen)
                {
                    FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_CMD_RD;
                }
                else
                {
                    FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_WE;
                    FLS_RWDev.opsInfo.ulTmpLen = FLS_RWDev.opsInfo.ulOpsLen;
                    FLS_RWDev.opsInfo.ulTmpAddr = FLS_RWDev.opsInfo.ulOpsAddr;
                }
            }
            else
            {
                FLS_RWDev.ulErrFlag = TRUE;
                FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_ERROR;
                *pcWriteCmpChkErrFlag = (uint8) FLS_ONE;
                /* SWS_Fls_00055 */
                (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_MAINFUNCTION_SID, FLS_E_VERIFY_ERASE_FAILED);
            }
            retVal = ERR_OK;
            *pIsTrigAgain = TRUE;
        }
        break;
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
    default:break;
    }
    return retVal;
}

#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            :  Fls_WriteStateHandlerThread_2                         **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        :  NA                                                    **
 **                                                                            **
 ** Sync/Async        :  NA                                                    **
 **                                                                            **
 ** Reentrancy        :  None                                                  **
 **                                                                            **
 ** Parameters (in)   :  pIsTrigAgain,pcWriteCmpChkErrFlag                     **
 **                                                                            **
 ** Parameters (out)  :  None                                                  **
 **                                                                            **
 ** Return value      :  uint32                                                **
 **                                                                            **
 ** Description       : Sub Function of Fls_WriteStateHandler                  **
 **                     to reduce Code Complexity.                             **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_WriteStateHandlerThread_2(
        CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain,
        P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pcWriteCmpChkErrFlag)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulIsSubStateEnd;
    VAR(uint32, AUTOMATIC) ulIsSubStateTrigAgain;
    VAR(uint32, AUTOMATIC) ulLen;

    switch(FLS_RWDev.ulCurrOpsState)
    {
    case FLS_OPS_WRITE_STATE_WE:
        retVal = Fls_SubOpsWriteEnable(&ulIsSubStateEnd,&ulIsSubStateTrigAgain);
        if ((ERR_OK == retVal) && (TRUE == ulIsSubStateEnd))
        {
            FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_WR;
            FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_PP;
            *pIsTrigAgain = TRUE;
        }

        if ((ERR_OK == retVal) && (TRUE == ulIsSubStateTrigAgain))
        {
            *pIsTrigAgain = TRUE;
        }
        break;

    case FLS_OPS_WRITE_STATE_WR:
        retVal = Fls_SubOpsWrite(&ulIsSubStateEnd, &ulIsSubStateTrigAgain);
        if ((ERR_OK == retVal) && (TRUE == ulIsSubStateEnd))
        {
            if(FLS_RWDev.config.ucFlsQspiHwConnectionMode == FLS_XQSPI_CONNECTION_MODE_PARALLEL)
            {
                FLS_RWDev.opsInfo.ulTmpLen -=  (FLS_RWDev.config.pageSize);
                FLS_RWDev.opsInfo.ulTmpAddr += (FLS_RWDev.config.pageSize/FLS_TWO);
                FLS_RWDev.opsInfo.pTmpTxData = &(FLS_RWDev.opsInfo.pTmpTxData[(FLS_RWDev.config.pageSize)]);
            }
            else
            {
                ulLen = Fls_CalculateWriteLength();
                FLS_RWDev.opsInfo.ulTmpLen -= ulLen;
                FLS_RWDev.opsInfo.ulTmpAddr += ulLen;
                FLS_RWDev.opsInfo.pTmpTxData = &(FLS_RWDev.opsInfo.pTmpTxData[ulLen]);
            }
            if (0UL == FLS_RWDev.opsInfo.ulTmpLen)
            {
                FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_DONE;
            }
            else
            {
                FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_WE;
                FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WE;
            }
            *pIsTrigAgain = TRUE;
        }
        if ((ERR_OK == retVal) && (TRUE == ulIsSubStateTrigAgain))
        {
            *pIsTrigAgain = TRUE;
        }
        break;

    case FLS_OPS_WRITE_STATE_DONE:
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        /* SWS_Fls_00056: Verification of write */
        retVal=Fls_OpsCompare(FLS_RWDev.opsInfo.ulOpsAddr, FLS_RWDev.opsInfo.pOpsTxData, FLS_RWDev.opsInfo.ulOpsLen);

#else
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_EXIT;
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_OK;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_DONE_IND;
        retVal = ERR_OK;
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
        break;

    case FLS_OPS_WRITE_STATE_ERROR:
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_FAIL;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_EXIT;
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_ERR_IND;
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        /* SWS_Fls_00316, SWS_Fls_00105 */
        if(*pcWriteCmpChkErrFlag != FLS_ONE)
        {
            (void) Det_ReportRuntimeError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_WRITE_SID, FLS_E_WRITE_FAILED);
        }
        else
        {
            /*Do nothing*/
        }
#endif
        retVal = ERR_OK;
        break;
    default:break;

    }
    return retVal;
}

#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"



#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00251, SWS_Fls_00223, SWS_Fls_00332,          **
 **                      SWS_Fls_00334, SWS_Fls_00225, SWS_Fls_00001,          **
 **                      SWS_Fls_00333, SWS_Fls_00226, SWS_Fls_00167,          **
 **                      SWS_Fls_00209, SWS_Fls_00026,                         **
 **                                                                            **
 ** Syntax            : Fls_WriteStateHandler                                  **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : pIsTrigAgain                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : This service handle Write operation state handler      **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_WriteStateHandler(CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain)
{
    VAR(uint32, AUTOMATIC) retVal;
    static VAR(uint8, AUTOMATIC) ucWriteCmpChkErrFlag = (uint8) FLS_ZERO;

    *pIsTrigAgain = FALSE;
    Fls_ApiStatus = FALSE;

    if (TRUE == FLS_RWDev.ulErrFlag)
    {
        FLS_RWDev.ulErrFlag = FALSE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_ERROR;
    }
    if((FLS_RWDev.ulCurrOpsState>=(uint32)(0x30)) && (FLS_RWDev.ulCurrOpsState<=(uint32)(0x33)))
    {
        retVal=Fls_WriteStateHandlerThread_1(pIsTrigAgain,&ucWriteCmpChkErrFlag);
    }
    else if((FLS_RWDev.ulCurrOpsState>=(uint32)(0x34)) && (FLS_RWDev.ulCurrOpsState<=(uint32)(0x38)))
    {
        retVal=Fls_WriteStateHandlerThread_2(pIsTrigAgain,&ucWriteCmpChkErrFlag);
    }
    else
    {
        /* Wrong current operation state */
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_WRITE_SID, FLS_E_INVALID_OPERATION);
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

        retVal = ERR_INVAL_STATE;
    }



    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"



#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

/*******************************************************************************
 ** Traceability.      : SWS_Fls_00256, SWS_Fls_00236, SWS_Fls_00337           **
 **                      SWS_Fls_00338, SWS_Fls_00339, SWS_Fls_00340,          **
 **                      SWS_Fls_00238, SWS_Fls_00239,                         **
 **                                                                            **
 ** Syntax            : Fls_ReadStateHandler                                   **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Re-entrant                                          **
 **                                                                            **
 ** Parameters (in)   : pIsTrigAgain                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To handle read operation states                        **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_ReadStateHandler( CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulLen = 0UL;
    static VAR(uint32, AUTOMATIC) ulLenRemain = 0UL;
    VAR(uint32, AUTOMATIC) ulRemaindertoRead = 0;
    VAR(uint32, AUTOMATIC) ulAddr;

    *pIsTrigAgain = FALSE;
    Fls_ApiStatus = FALSE;
    /*take buffer to copy data first here and after that to Ram
	for Alignment issue */

    if (TRUE == FLS_RWDev.ulErrFlag)
    {
        FLS_RWDev.ulErrFlag = FALSE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_ERROR;
    }

    switch(FLS_RWDev.ulCurrOpsState)
    {
    case FLS_OPS_READ_STATE_CFGLANES_WE:
        //FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_CFGLANES_WS;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_READ;
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WS;
        *pIsTrigAgain = TRUE;
        ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;
        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_FAST_READ;
        FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS32_24(ulAddr);
        FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS23_16(ulAddr);
        FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS15_8(ulAddr);
        FLS_RWDev.ucXferTxBuf[4] = (uint8)FLS_ADDRESS7_0(ulAddr);
//        retVal = ERR_OK;
//        //retVal = Fls_CmdRead();
//        break; No break to save time

//    case FLS_OPS_READ_STATE_CFGLANES_WS:
//        *pIsTrigAgain = TRUE;
//        FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_READ;
//        FLS_RWDev.ulIsLaneCfgDone = TRUE;
//        retVal = Fls_CmdSendDummyCycles();
//        break;

    case FLS_OPS_READ_STATE_READ:
        if(Fls_DMA_IsBusy() != TRUE)
        {
            if (0UL < FLS_RWDev.opsInfo.ulTmpLen)
            {
                ulLen = FLS_RWDev.opsInfo.ulTmpLen;
                if (MSPI_FIFO_LEN < ulLen)
                {
                    ulLen = MSPI_FIFO_LEN;
                }
            }
            if (MSPI_FIFO_LEN > ulLen)
            {
                /* check if lenght is divisible with 4.
    	  			if not add required number of bytes */
                ulRemaindertoRead = FLS_RWDev.opsInfo.ulTmpLen % (uint32)FLS_FOUR;
                if (ulRemaindertoRead != 0)
                {
                    ulRemaindertoRead = 4 - ulRemaindertoRead;
                }
            }
            FLS_RWDev.opsInfo.ulTmpLen -= ulLen;
            FLS_RWDev.opsInfo.ulPrevRxLen = ulLen;
            FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_READ_REMAIN;
            /*Copy Data from Flash to temporary buffer and after that to Ram buffer */
            //retVal = Fls_QSPI_Read(FLS_RWDev.opsInfo.ulTmpAddr,  &Fls_TempBuffer, ulLen + ulRemaindertoRead);
            retVal = FLS_SPI_ProcessFastReadCmd((uint8 *)FLS_RWDev.ucXferTxBuf, (uint8 *)Fls_TempBuffer, ulLen + ulRemaindertoRead);
            *pIsTrigAgain = TRUE;

        }
        else
        {
            retVal = ERR_OK;
            *pIsTrigAgain = TRUE;
        }

        break;

    case FLS_OPS_READ_STATE_READ_REMAIN:
        if(Fls_DMA_IsBusy() != TRUE)
        {
            /* Moved memcpy after DMA transfer is not busy. */
            (void)memcpy(FLS_RWDev.opsInfo.pOpsRxData, &Fls_TempBuffer, FLS_RWDev.opsInfo.ulPrevRxLen);
            if(FLS_RWDev.config.ucFlsQspiHwConnectionMode == FLS_XQSPI_CONNECTION_MODE_PARALLEL)
            {
                FLS_RWDev.opsInfo.ulTmpAddr += ((FLS_RWDev.opsInfo.ulPrevRxLen)/FLS_TWO);
            }
            else
            {
                FLS_RWDev.opsInfo.ulTmpAddr += FLS_RWDev.opsInfo.ulPrevRxLen;
            }

            FLS_RWDev.opsInfo.pOpsRxData = &(FLS_RWDev.opsInfo.pOpsRxData[FLS_RWDev.opsInfo.ulPrevRxLen]);
            if (FLS_RWDev.opsInfo.ulTmpLen != 0UL)
            {
                ulLenRemain +=  FLS_RWDev.opsInfo.ulPrevRxLen;
                FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_CFGLANES_WE;
            }
            else
            {
                FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_DONE;
                ulLenRemain = 0;
            }

            retVal = ERR_OK;
            *pIsTrigAgain = TRUE;
        }
        else
        {
            retVal = ERR_OK;
            *pIsTrigAgain = TRUE;
        }
        break;

    case FLS_OPS_READ_STATE_DONE:
        if(Fls_DMA_IsBusy() != TRUE)
        {
            FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_OK;
            FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
            FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_EXIT;
            FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
            FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_DONE_IND;
            retVal = ERR_OK;
            *pIsTrigAgain = FALSE;
        }
        else
        {
            retVal = ERR_OK;
            *pIsTrigAgain = FALSE;
        }
        break;

    case FLS_OPS_READ_STATE_ERROR:
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_FAIL;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_EXIT;
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_ERR_IND;
        ulLenRemain = 0;/* Initialize Number of remaining bytes to be read*/
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        /* SWS_Fls_00317, SWS_Fls_00106 */
        (void) Det_ReportRuntimeError(FLS_MODULE_ID, FLS_INSTANCE_ID,  FLS_READ_SID, FLS_E_READ_FAILED);
#endif
        retVal = ERR_OK;
        break;
    default:
        /* Wrong current operation state */
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_READ_SID, FLS_E_INVALID_OPERATION);
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
        retVal = ERR_INVAL_STATE;
        break;
    };
    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

/*******************************************************************************
 ** Traceability.      : SWS_Fls_00257, SWS_Fls_00241, SWS_Fls_00342,          **
 **                      SWS_Fls_00343, SWS_Fls_00244, SWS_Fls_00344,          **
 **                      SWS_FLS_00243,                                        **
 **                                                                            **
 ** Syntax            : Fls_CompareStateHandler                                **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : pIsTrigAgain                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To start compare operation                             **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_CompareStateHandler( CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulLen = 0UL;
    VAR(uint32, AUTOMATIC) ulAddr;

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    static VAR(uint8, AUTOMATIC) ucDataIntegErrOccur = 0;
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

    Fls_ApiStatus = FALSE;

    *pIsTrigAgain = FALSE;
    retVal = ERR_INVAL_STATE;
    if (TRUE == FLS_RWDev.ulErrFlag)
    {
        FLS_RWDev.ulErrFlag = FALSE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_ERROR;
    }

    switch(FLS_RWDev.ulCurrOpsState)
    {
    case FLS_OPS_COMPARE_STATE_CFGLANES_WE:
        //FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_CFGLANES_WS;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_RD;
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WS;
        ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;
        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_FAST_READ;
        FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS32_24(ulAddr);
        FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS23_16(ulAddr);
        FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS15_8(ulAddr);
        FLS_RWDev.ucXferTxBuf[4] = (uint8)FLS_ADDRESS7_0(ulAddr);
//        retVal = ERR_OK;
//        *pIsTrigAgain = TRUE;
//        //retVal = Fls_CmdRead();
//        break; No break to save time

//    case FLS_OPS_COMPARE_STATE_CFGLANES_WS:
//        *pIsTrigAgain = TRUE;
//        FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_RD;
//        FLS_RWDev.ulIsLaneCfgDone = TRUE;
//        retVal = Fls_CmdSendDummyCycles();
//        break;

    case FLS_OPS_COMPARE_STATE_RD:
        if (0UL < FLS_RWDev.opsInfo.ulTmpLen)
        {
            ulLen = FLS_RWDev.opsInfo.ulTmpLen;
            if (MSPI_FIFO_LEN < ulLen)
            {
                ulLen = MSPI_FIFO_LEN;
            }
        }
        FLS_RWDev.opsInfo.ulTmpLen -= ulLen;
        FLS_RWDev.opsInfo.ulPrevRxLen = ulLen;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_CMP;
        retVal = FLS_SPI_ProcessFastReadCmd((uint8 *)FLS_RWDev.ucXferTxBuf, (uint8 *)FLS_RWDev.ucXferRxBuf, ulLen);
//        *pIsTrigAgain = TRUE;
//        //retVal = Fls_QSPI_Read(FLS_RWDev.opsInfo.ulTmpAddr, FLS_RWDev.ucXferRxBuf, ulLen);
//        break; No break to save time

    case FLS_OPS_COMPARE_STATE_CMP:
        if(Fls_DMA_IsBusy() != TRUE)
        {
            ulLen =  FLS_RWDev.opsInfo.ulOpsLen - (FLS_RWDev.opsInfo.ulTmpLen + FLS_RWDev.opsInfo.ulPrevRxLen);
            retVal = (uint32) (memcmp(FLS_RWDev.ucXferRxBuf,  &(FLS_RWDev.opsInfo.pOpsTxData[ulLen]), (uint32)FLS_RWDev.opsInfo.ulPrevRxLen));
            if(FLS_RWDev.config.ucFlsQspiHwConnectionMode == FLS_XQSPI_CONNECTION_MODE_PARALLEL)
            {
                FLS_RWDev.opsInfo.ulTmpAddr +=((FLS_RWDev.opsInfo.ulPrevRxLen)/FLS_TWO);
            }
            else
            {
                FLS_RWDev.opsInfo.ulTmpAddr += FLS_RWDev.opsInfo.ulPrevRxLen;
            }
            if (retVal == FLS_ZERO)
            {
                if (0UL < FLS_RWDev.opsInfo.ulTmpLen)
                {
                    FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_CFGLANES_WE;
                }
                else
                {
                    FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_DONE;
                }
            }
            else
            {
                FLS_RWDev.ulErrFlag = TRUE;
#if (FLS_DEV_ERROR_DETECT == STD_ON)
                ucDataIntegErrOccur = 1;
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
            }
            retVal = ERR_OK;
            *pIsTrigAgain = TRUE;
        }
        break;

    case FLS_OPS_COMPARE_STATE_DONE:
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_OK;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_EXIT;
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_DONE_IND;
        retVal = ERR_OK;
        break;

    case FLS_OPS_COMPARE_STATE_ERROR:
        /* Ref: SWS_Fls_00200, FLS_OPS_RESULT_FAIL; */
        FLS_RWDev.ulOpsRes = FLS_OPS_RSLT_BLK_INCONSISTENT;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_EXIT;
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_ERR_IND;
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        if((ucDataIntegErrOccur) == ((uint8) FLS_ZERO))
        {
            /* SWS_Fls_00318, SWS_Fls_00154 */
            (void) Det_ReportRuntimeError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_COMPARE_SID, FLS_E_COMPARE_FAILED);
        }
        else
        {
            /* SWS_Fls_00056 */
            (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_MAINFUNCTION_SID, FLS_E_VERIFY_WRITE_FAILED);
            ucDataIntegErrOccur = 0;
        }
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
        retVal = ERR_OK;
        break;
    default:
        /* Wrong current operation state */
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_COMPARE_SID, FLS_E_INVALID_OPERATION);
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

        retVal = ERR_INVAL_STATE;
        break;
    };

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

/*******************************************************************************
 ** Traceability       : SWS_Fls_00371, SWS_Fls_00375, SWS_Fls_00376,          **
 **                      SWS_Fls_00377, SWS_Fls_00378,                         **
 **                                                                            **
 ** Syntax            : Fls_BlankCheckStateHandler                             **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : pIsTrigAgain                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : Blank check state handler                              **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_BlankCheckStateHandler( CONSTP2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pIsTrigAgain)
        {
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulLen = 0UL;
    VAR(uint32, AUTOMATIC) ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;

    Fls_ApiStatus = FALSE;

    *pIsTrigAgain = FALSE;
    retVal = ERR_INVAL_STATE;
    if (TRUE == FLS_RWDev.ulErrFlag)
    {
        FLS_RWDev.ulErrFlag = FALSE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_ERROR;
    }

    switch(FLS_RWDev.ulCurrOpsState)
    {
    case FLS_OPS_BLANKCHK_STATE_CFGLANES_WE:
        FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_RD;
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WS;
        ulAddr = FLS_RWDev.opsInfo.ulTmpAddr;
        FLS_RWDev.ucXferTxBuf[0] = (uint8)FLS_CMD_4BYTE_FAST_READ;
        FLS_RWDev.ucXferTxBuf[1] = (uint8)FLS_ADDRESS32_24(ulAddr);
        FLS_RWDev.ucXferTxBuf[2] = (uint8)FLS_ADDRESS23_16(ulAddr);
        FLS_RWDev.ucXferTxBuf[3] = (uint8)FLS_ADDRESS15_8(ulAddr);
        FLS_RWDev.ucXferTxBuf[4] = (uint8)FLS_ADDRESS7_0(ulAddr);
//        retVal = ERR_OK;
//        *pIsTrigAgain = TRUE;
        //retVal = Fls_CmdRead();
        //break; No break to save time

//    case FLS_OPS_BLANKCHK_STATE_CFGLANES_WS:
//        *pIsTrigAgain = TRUE;
//        FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_RD;
//        FLS_RWDev.ulIsLaneCfgDone = TRUE;
//        retVal = Fls_CmdSendDummyCycles();
//        break;

    case FLS_OPS_BLANKCHK_STATE_RD:
        if (0UL < FLS_RWDev.opsInfo.ulTmpLen)
        {
            ulLen = FLS_RWDev.opsInfo.ulTmpLen;
            if (MSPI_FIFO_LEN < ulLen)
            {
                ulLen = MSPI_FIFO_LEN;
            }
        }
        FLS_RWDev.opsInfo.ulTmpLen -= ulLen;
        FLS_RWDev.opsInfo.ulPrevRxLen = ulLen;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_CMP;

        retVal = FLS_SPI_ProcessFastReadCmd((uint8 *)FLS_RWDev.ucXferTxBuf, (uint8 *)FLS_RWDev.ucXferRxBuf, ulLen);
        //*pIsTrigAgain = TRUE;
        //retVal = Fls_QSPI_Read(FLS_RWDev.opsInfo.ulTmpAddr, FLS_RWDev.ucXferRxBuf, ulLen);

        //break; No break to save time

    case FLS_OPS_BLANKCHK_STATE_CMP:
        if(Fls_DMA_IsBusy() != TRUE)
        {
            (void) memset(FLS_RWDev.ucXferTxBuf, 0xFF, (uint32)MSPI_FIFO_LEN);

            retVal = (uint32) memcmp(FLS_RWDev.ucXferRxBuf, FLS_RWDev.ucXferTxBuf, (uint32)FLS_RWDev.opsInfo.ulPrevRxLen);
            if(FLS_RWDev.config.ucFlsQspiHwConnectionMode == FLS_XQSPI_CONNECTION_MODE_PARALLEL)
            {
                FLS_RWDev.opsInfo.ulTmpAddr += ((FLS_RWDev.opsInfo.ulPrevRxLen)/FLS_TWO);
            }
            else
            {
                FLS_RWDev.opsInfo.ulTmpAddr += FLS_RWDev.opsInfo.ulPrevRxLen;
            }

            if (retVal == FLS_ZERO)
            {
                if (0UL < FLS_RWDev.opsInfo.ulTmpLen)
                {
                    FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_CFGLANES_WE;
                }
                else
                {
                    FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_DONE;
                }
            }
            else
            {
                FLS_RWDev.ulErrFlag = TRUE;
#if (FLS_DEV_ERROR_DETECT == STD_ON)
                /* SWS_Fls_00022 */
                (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_MAINFUNCTION_SID, FLS_E_VERIFY_ERASE_FAILED);
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
            }
            retVal = ERR_OK;
            *pIsTrigAgain = TRUE;
        }
        break;

    case FLS_OPS_BLANKCHK_STATE_DONE:
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_OK;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_EXIT;
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_DONE_IND;
        retVal = ERR_OK;
        break;

    case FLS_OPS_BLANKCHK_STATE_ERROR:
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_FAIL;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_EXIT;
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
        FLS_RWDev.opsInfo.ulIndFlag = FLS_INDFLAG_ERR_IND;
        retVal = ERR_OK;
        break;

    default:
        /* Wrong current operation state */
#if (FLS_DEV_ERROR_DETECT == STD_ON)
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_BLANK_CHECK_SID, FLS_E_INVALID_OPERATION);
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

        retVal = ERR_INVAL_STATE;
        break;
    };

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 **                                                                            **
 ** Syntax            : Fls_ConvVirtualAddrToPhyAddr                           **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : ulAddr                                                 **
 **                                                                            **
 ** Parameters (out)  : phAddr                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To                                                     **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_ConvVirtualAddrToPhyAddr(VAR(FLS_AddrType, AUTOMATIC) ulAddr)
{
    P2VAR(FLS_FlsableSecType, AUTOMATIC, FLS_APPL_DATA) addrList;
    VAR(uint32, AUTOMATIC) addrListSize;
    VAR(uint32, AUTOMATIC) ulIndex;
    VAR(FLS_AddrType, AUTOMATIC) phAddr;
    FLS_LenType  sectorSizeOffset;
    FLS_LenType  currSectorListSize;
    FLS_AddrType sectorSize = FLS_RWDev.config.sectorSize;

    addrList = &(FLS_FlsableSecList[0UL]);
    addrListSize = FLS_RWDev.config.flsableSecListSize;
    sectorSizeOffset = 0;
    phAddr = 0;

    for (ulIndex = 0UL; ulIndex < addrListSize; ulIndex++)
    {
        currSectorListSize = (addrList[ulIndex].numSectors * sectorSize);
        if (ulAddr < (sectorSizeOffset + currSectorListSize))
        {
            phAddr = addrList[ulIndex].startAddr + (ulAddr - sectorSizeOffset);
            ulIndex = addrListSize;
            break;
        }
        else
        {
            sectorSizeOffset = sectorSizeOffset + currSectorListSize;
        }
    }

    if(FLS_RWDev.config.ucFlsQspiHwConnectionMode == FLS_XQSPI_CONNECTION_MODE_PARALLEL)
    {
        phAddr = phAddr/FLS_TWO;
    }
    else if(FLS_RWDev.config.ucFlsQspiHwConnectionMode == FLS_XQSPI_CONNECTION_MODE_STACKED)
    {
        // Not supported

//        if(phAddr >= FLS_TOTAL_SIZE)
//        {
//            phAddr = phAddr - FLS_TOTAL_SIZE;
//            /*Select Upper CS*/
//            (void)Fls_QSPI_SelectGenFifoChipSelect(FLS_XQSPI_GENFIFO_CS_UPPER);
//        }
//        else
//        {
//            /*Select Lower CS*/
//            //phAddr = phAddr;
//            (void)Fls_QSPI_SelectGenFifoChipSelect(FLS_XQSPI_GENFIFO_CS_LOWER);
//        }

    }
    else
    {
        /* Do Nothing */
    }
    return phAddr;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00323, SWS_Fls_00324, SWS_Fls_00249,          **
 **                      SWS_Fls_00310, SWS_Fls_00191, SWS_Fls_00014           **
 **                      SWS_Fls_00086,                                        **
 **                                                                            **
 **                                                                            **
 ** Syntax            : Fls_OpsInit                                            **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : pConfig                                                **
 **                                                                            **
 ** Parameters (out)  : None                                                   **
 **                                                                            **
 ** Return value      : None                                                   **
 **                                                                            **
 ** Description       : To initialise operation states                         **
 *******************************************************************************/
static FUNC(void, FLS_CODE_SLOW) Fls_OpsInit(CONSTP2CONST(FLS_CfgType, AUTOMATIC, FLS_APPL_DATA) pConfig)
{
    VAR(Std_ReturnType, AUTOMATIC) ReturnValue = E_OK;
    VAR(QSPI_ConfigType, AUTOMATIC) QSPI_Config;

    FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
    FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_PENDING;
    FLS_RWDev.ulCurrOps = FLS_OPS_INIT;

    (void)memset(&(FLS_RWDev.opsInfo), 0x0, (uint32)sizeof(FLS_OpsInfoType));

    (void)memset(&(FLS_FlsableSecList[0UL]), 0x0, ((uint32) ((FLS_FLASHABLE_SECTOR_LIST_SZ) * (sizeof(FLS_FlsableSecType)))));

    /* Keep config for runtime usage */
    (void)memcpy(&(FLS_RWDev.config), pConfig, (uint32)sizeof(FLS_CfgType));

    /* Copy the flash able sector list */
    if ((pConfig->flsableSecListSize > 0UL) && (NULL_PTR != pConfig->flsableSecList))
    {
        (void )memcpy(&(FLS_FlsableSecList[0UL]), pConfig->flsableSecList, (uint32) (pConfig->flsableSecListSize * sizeof(FLS_FlsableSecType)));
    }
    else
    {
        FLS_RWDev.config.flsableSecListSize = 0UL;
    }

    /* Set QSPI configurations */

    QSPI_Config.ulFlsQspiHwMode = pConfig->SPIMode;
    QSPI_Config.ulFlsQspiBaudRateDiv = pConfig->ucFlsQspiHwBaudRateDiv;
    QSPI_Config.ulFlsQspiBusWidth = pConfig->readLane;
    QSPI_Config.ucFlsQspiConnectionMode = pConfig->ucFlsQspiHwConnectionMode;

    /* Initialise QSPI */
    ReturnValue = Fls_QSPI_Init(&QSPI_Config);

    if(ReturnValue == E_OK)
    {
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_OK;
        FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
        FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
    }
    else
    {
        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_FAIL;
        FLS_RWDev.ulCurrOps = FLS_OPS_DEINIT;
        FLS_RWDev.ulStatus = FLS_STATUS_UNINIT;
    }
}
#define FLS_STOP_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_OpsDeInit                                          **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : None                                                   **
 **                                                                            **
 ** Parameters (out)  : None                                                   **
 **                                                                            **
 ** Return value      : None                                                   **
 **                                                                            **
 ** Description       : To De-initialise operation states                      **
 *******************************************************************************/
static FUNC(void, FLS_CODE_SLOW) Fls_OpsDeInit(void)
{
    /* Set current operation to none */
    FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
    FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_OK;

    /* Set driver state to unitialised */
    FLS_RWDev.ulStatus = FLS_STATUS_UNINIT;

#if (FLS_USE_INTERRUPTS == STD_ON)
    Fls_QspiDeInit();
#endif /* #if (FLS_USE_INTERRUPTS == STD_ON) */
}

#define FLS_STOP_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 **                                                                            **
 ** Syntax            : Fls_OpsCancel                                          **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : ERR_OK                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To cancel the current FLS operation                    **
 *******************************************************************************/
//static FUNC(uint32, FLS_CODE) Fls_OpsCancel(void)
//{
//    /* Set current operation to none */
//    FLS_RWDev.ulCurrOps = FLS_OPS_NONE;
//
//    if (FLS_OPS_RESULT_PENDING == FLS_RWDev.ulOpsRes)
//    {
//        FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_CANCELLED;
//    }
//
//    /* Set driver state to IDLE */
//    FLS_RWDev.ulStatus = FLS_STATUS_IDLE;
//
//    return ERR_OK;
//}
#define FLS_STOP_SEC_CODE_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00218, SWS_Fls_00327, SWS_Fls_00328           **
 **                      SWS_Fls_00329, SWS_Fls_00330, SWS_Fls_00220,          **
 **                      SWS_Fls_00221, SWS_Fls_00020, SWS_Fls_00021,          **
 **                      SWS_Fls_00065, SWS_Fls_00023, SWS_Fls_00145,          **
 **                                                                            **
 ** Syntax            : Fls_OpsErase                                           **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,ulLen                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To set operation states for erase operation            **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_OpsErase(VAR(FLS_AddrType, AUTOMATIC) ulAddr, VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulIsTrigAgain;

    FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
    FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_PENDING;
    FLS_RWDev.ulCurrOps = FLS_OPS_ERASE;
    FLS_RWDev.ulCurrOpsState = FLS_OPS_ERASE_STATE_WE;
    FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WE;

    /* Set Operation Info */
    /*START Msg (5:0306)-1*/
    (void)memset(&(FLS_RWDev.opsInfo), 0x0, (uint32)sizeof(FLS_OpsInfoType));
    /*END Msg (5:0306)-1*/
    FLS_RWDev.opsInfo.ulOpsAddr = ulAddr;
    FLS_RWDev.opsInfo.ulOpsLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpAddr = ulAddr;

    /* Set ulErrFlag to FALSE */
    FLS_RWDev.ulErrFlag = FALSE;

    /* Call FLASH_Erase State Machine */
    do {
        retVal = Fls_EraseStateHandler(&ulIsTrigAgain);
    } while((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00251, SWS_Fls_00223, SWS_Fls_00332,          **
 **                      SWS_Fls_00334, SWS_Fls_00225, SWS_Fls_00226,          **
 **                      SWS_Fls_00333,                                        **
 **                                                                            **
 ** Syntax            : Fls_OpsWrite                                           **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,pBuf,ulLen                                      **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : TO set operation states for write operation.           **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_OpsWrite(
        VAR(FLS_AddrType, AUTOMATIC) ulAddr,
        CONSTP2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pBuf,
        VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulIsTrigAgain;

    FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
    FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_PENDING;
    FLS_RWDev.ulCurrOps = FLS_OPS_WRITE;
    FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_WE;
    FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WE;

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    FLS_RWDev.ulCurrOpsState = FLS_OPS_WRITE_STATE_CMD_RD;
    FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WE;
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

    /* Set Operation Info */
    /*START Msg (5:0306)-1*/
    (void)memset(&(FLS_RWDev.opsInfo), 0x0,(uint32) sizeof(FLS_OpsInfoType));
    /*END Msg (5:0306)-1*/
    FLS_RWDev.opsInfo.ulOpsAddr = ulAddr;
    FLS_RWDev.opsInfo.pOpsTxData = pBuf;
    FLS_RWDev.opsInfo.ulOpsLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpAddr = ulAddr;
    FLS_RWDev.opsInfo.pTmpTxData = pBuf;

    /* Set ulErrFlag to FALSE */
    FLS_RWDev.ulErrFlag = FALSE;

    /* Call FLASH_Write State Machine handler */
    do {
        retVal = Fls_WriteStateHandler(&ulIsTrigAgain);
    } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability.      : SWS_Fls_00223, SWS_Fls_00236, SWS_Fls_00337           **
 **                      SWS_Fls_00338, SWS_Fls_00339, SWS_Fls_00340,          **
 **                      SWS_Fls_00239,                                        **
 **                                                                            **
 ** Syntax            : Fls_OpsRead                                            **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,pBuf,ulLen                                      **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : TO set operation states for read operation             **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_OpsRead(
        VAR(FLS_AddrType, AUTOMATIC) ulAddr,
        P2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) pBuf,
        VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulIsTrigAgain;

    FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
    FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_PENDING;
    FLS_RWDev.ulCurrOps = FLS_OPS_READ;
    if (TRUE == FLS_RWDev.ulIsLaneCfgDone)
    {
        FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_READ;
    }
    else
    {
        FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_CFGLANES_WE;
        FLS_RWDev.ulSubOpsState = FLS_SUBOPS_STATE_WE;
    }
    FLS_RWDev.ulCurrOpsState = FLS_OPS_READ_STATE_CFGLANES_WE;
    /* Set Operation Info */
    /*START Msg (5:0306)-1*/
    (void)memset(&(FLS_RWDev.opsInfo), 0x0, (uint32)sizeof(FLS_OpsInfoType));
    /*END Msg (5:0306)-1*/
    FLS_RWDev.opsInfo.ulOpsAddr = ulAddr;
    FLS_RWDev.opsInfo.pOpsRxData = pBuf;
    FLS_RWDev.opsInfo.ulOpsLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpAddr = ulAddr;

    /* Set ulErrFlag to FALSE */
    FLS_RWDev.ulErrFlag = FALSE;

    /* Call FLASH_Read State Machine handler */
    do {
        retVal = Fls_ReadStateHandler(&ulIsTrigAgain);
    } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability.      : SWS_Fls_00257, SWS_Fls_00241, SWS_Fls_00342,          **
 **                      SWS_Fls_00343, SWS_Fls_00243, SWS_Fls_00244,          **
 **                                                                            **
 ** Syntax            : Fls_OpsCompare                                         **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,pBuf,ulLen                                      **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To set operation states for Flash compare operation    **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_OpsCompare(
        VAR(FLS_AddrType, AUTOMATIC) ulAddr,
        CONSTP2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pBuf,
        VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulIsTrigAgain;

    FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
    FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_PENDING;
    FLS_RWDev.ulCurrOps = FLS_OPS_COMPARE;
    FLS_RWDev.ulCurrOpsState = FLS_OPS_COMPARE_STATE_CFGLANES_WE;

    /* Set Operation Info */
    /*START Msg (5:0306)-1*/
    (void)memset(&(FLS_RWDev.opsInfo), 0x0, (uint32)sizeof(FLS_OpsInfoType));
    /*END Msg (5:0306)-1*/
    FLS_RWDev.opsInfo.ulOpsAddr = ulAddr;
    FLS_RWDev.opsInfo.pOpsTxData = pBuf;
    FLS_RWDev.opsInfo.ulOpsLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpLenRem = ulLen;
    FLS_RWDev.opsInfo.ulTmpAddr = ulAddr;
    FLS_RWDev.opsInfo.pTmpTxData = pBuf;

    /* Set ulErrFlag to FALSE */
    FLS_RWDev.ulErrFlag = FALSE;

    /* Call FLASH_Compare State Machine handler */
    do {
        retVal = Fls_CompareStateHandler(&ulIsTrigAgain);
    } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00375, SWS_Fls_00376, SWS_Fls_00377,          **
 **                      SWS_Fls_00378, SWS_Fls_00379,                         **
 **                                                                            **
 ** Syntax            : Fls_OpsBlankCheck                                      **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,ulLen                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To set operation states for blank check operation      **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_OpsBlankCheck(
        VAR(FLS_AddrType, AUTOMATIC) ulAddr,
        VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulIsTrigAgain;

    FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
    FLS_RWDev.ulOpsRes = FLS_OPS_RESULT_PENDING;
    FLS_RWDev.ulCurrOps = FLS_OPS_BLANK_CHECK;
    FLS_RWDev.ulCurrOpsState = FLS_OPS_BLANKCHK_STATE_CFGLANES_WE;

    /* Set Operation Info */
    /*START Msg (5:0306)-1*/
    (void) memset(&(FLS_RWDev.opsInfo), 0x0, (uint32)sizeof(FLS_OpsInfoType));
    /*END Msg (5:0306)-1*/
    FLS_RWDev.opsInfo.ulOpsAddr = ulAddr;
    FLS_RWDev.opsInfo.ulOpsLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpLen = ulLen;
    FLS_RWDev.opsInfo.ulTmpLenRem = ulLen;
    FLS_RWDev.opsInfo.ulTmpAddr = ulAddr;

    /* Set ulErrFlag to FALSE */
    FLS_RWDev.ulErrFlag = FALSE;

    /* Call FLASH_BlankCheck State Machine handler */
    do {
        retVal = Fls_BlankCheckStateHandler(&ulIsTrigAgain);
    } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

/*******************************************************************************
 ** Traceability      : SWS_Fls_00256, SWS_Fls_00251, SWS_Fls_00257,           **
 **                     SWS_Fls_00250, SWS_Fls_00371, SWS_Fls_00001,           **
 **                                                                            **
 ** Syntax            : Fls_IntOpsHandler                                      **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        :  NA                                                    **
 **                                                                            **
 ** Sync/Async        :  NA                                                    **
 **                                                                            **
 ** Reentrancy        :  Reentrant                                             **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To handle the interrupts for FLS operations            **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_IntOpsHandler(void)
{
    VAR(uint32, AUTOMATIC) retVal = ERR_UNKNOWN;
    VAR(uint32, AUTOMATIC) ulIsTrigAgain;

    /* Based on operation call corresponding state handlers */
    switch(FLS_RWDev.ulCurrOps)
    {
    case FLS_OPS_NONE:
        /*Reach here in case, flash operation is cancelled after
        checking for ulCurrOps in this handler */
        break;
    case FLS_OPS_ERASE:
        do {
            retVal = Fls_EraseStateHandler(&ulIsTrigAgain);
        } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));
        break;

    case FLS_OPS_WRITE:
        do {
            retVal = Fls_WriteStateHandler(&ulIsTrigAgain);
        } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));
        break;

    case FLS_OPS_READ:
        do {
            retVal = Fls_ReadStateHandler(&ulIsTrigAgain);
        } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));
        break;

    case FLS_OPS_COMPARE:
        do {
            retVal = Fls_CompareStateHandler(&ulIsTrigAgain);
        } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));
        break;

    case FLS_OPS_BLANK_CHECK:
        do {
            retVal = Fls_BlankCheckStateHandler(&ulIsTrigAgain);
        } while ((TRUE == ulIsTrigAgain) && (ERR_OK == retVal));
        break;

    default:
        /* Shall never reach here */
        break;
    }

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

/*******************************************************************************
 **                                                                            **
 ** Syntax            : Fls_OpsHandler                                         **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To handle the interrupt operations                     **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_OpsHandler(void)
{
    VAR(uint32, AUTOMATIC) retVal;

    retVal = Fls_IntOpsHandler();

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability      : <list the requirements that are covered under this Api>**
 **                                                                            **
 ** Syntax            : Fls_IRQHandler                                         **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : Interrupt handler                                      **
 *******************************************************************************/
//#if (FLS_USE_INTERRUPTS == STD_OFF)
//static FUNC(uint32, FLS_CODE_FAST) Fls_IRQHandler(void)
//        {
//    VAR(uint32, AUTOMATIC) retVal;
//
//    retVal = Fls_QSPI_IRQHandler();
//
//    return retVal;
//        }
//#endif
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 **                                                                            **
 ** Syntax            : Fls_QSPICmdProcess                                     **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : ulIsErr                                                **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To process QSPI command                                **
 *******************************************************************************/
//static FUNC(uint32, FLS_CODE_FAST) Fls_QSPICmdProcess(VAR(uint32, AUTOMATIC) ulIsErr)
//{
//    VAR(FlashIO, AUTOMATIC) flashIO;
//    VAR(uint32, AUTOMATIC) retVal;
//
//    flashIO.retVal = ERR_UNKNOWN;
//    flashIO.isErr = ulIsErr;
//
//    retVal = Fls_QSPI_CmdHandler(flashIO.isErr);
//
//    return retVal;
//}

#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00323, SWS_Fls_00324, SWS_Fls_00042,          **
 **                      SWS_Fls_00015, SWS_Fls_00310, SWS_Fls_00268,          **
 **                      SWS_Fls_00191, SWS_Fls_00014, SWS_Fls_00086,          **
 **                                                                            **
 ** Syntax            : Fls_InterfaceInit                                      **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : pConfig                                                **
 **                                                                            **
 ** Parameters (out)  : none                                                   **
 **                                                                            **
 ** Return value      : void                                                   **
 **                                                                            **
 ** Description       : To Fls initialization.                                 **
 *******************************************************************************/
FUNC(void, FLS_CODE_SLOW) Fls_InterfaceInit(CONSTP2CONST(FLS_CfgType, AUTOMATIC, FLS_APPL_DATA) aConfig)
{
    VAR(FlashIO, AUTOMATIC) flashIO;
    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;

#if (FLS_DEV_ERROR_DETECT == STD_ON)

    if (NULL_PTR == aConfig)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_INIT_SID, FLS_E_PARAM_CONFIG);
        DetResultValue = E_NOT_OK;
    }
    /* Check the controller status */
    else if (FLS_STATUS_BUSY == FLS_RWDev.ulStatus)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_INIT_SID, FLS_E_BUSY);
        DetResultValue = E_NOT_OK;
    }
    else
    {
        /*Do nothing*/
    }
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

    if(DetResultValue != E_NOT_OK)
    {
        flashIO.retVal = ERR_UNKNOWN;
        flashIO.config = aConfig;
        Fls_OpsInit(flashIO.config);
    }
    else
    {
        /*Do nothing*/
    }
}
#define FLS_STOP_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Syntax            : Fls_DeInit                                             **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : none                                                   **
 **                                                                            **
 ** Return value      : void                                                   **
 **                                                                            **
 ** Description       : To de-initialise fls module                            **
 *******************************************************************************/
FUNC(void, FLS_CODE_SLOW) Fls_DeInit(void)
{
    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    /* Check the controller status */
    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_INIT_SID, FLS_E_UNINIT);
        DetResultValue = E_NOT_OK;
    }
    else
    {
        /*Do nothing*/
    }
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

    if(DetResultValue != E_NOT_OK)
    {
        Fls_OpsDeInit();
    }
    else {
        /*Do nothing*/
    }
}
#define FLS_STOP_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 **                                                                            **
 ** Syntax            : Fls_InterfaceCancel                                    **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To Cancels an ongoing job.                             **
 *******************************************************************************/
FUNC(uint32, FLS_CODE_FAST) Fls_InterfaceCancel(void)
        {
    VAR(uint32, AUTOMATIC) retVal = E_OK;
//    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;
//#if (FLS_DEV_ERROR_DETECT == STD_ON)
//
//    /* Check the controller status */
//    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
//    {
//        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_CANCEL_SID, FLS_E_UNINIT);
//        retVal = ERR_INVAL_STATE;
//        DetResultValue = E_NOT_OK;
//    }
//#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
//
//    if(DetResultValue != E_NOT_OK)
//    {
//        if (TRUE == Fls_QSPI_IsBusy())
//        {
//            retVal = Fls_QSPICmdProcess((uint32) TRUE);
//        }
//        else
//        {
//            /*Do nothing*/
//        }
//    }
//    else
//    {
//        /*Do nothing*/
//    }
//    retVal = Fls_OpsCancel();
//
//    if (ERR_OK == retVal)
//    {
//        /* Raise error indication callback */
//        Fls_OpsErrInd();
//    }
//    else {
//        /*Do nothing*/
//    }

    return retVal;
}

#define FLS_STOP_SEC_CODE_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability.     : SWS_Fls_00034, SWS_Fls_00253                           **
 **                                                                            **
 ** Syntax            : Fls_InterfaceGetStatus                                 **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : ulStatus                                               **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To get operation states                                **
 *******************************************************************************/
FUNC(uint32, FLS_CODE_FAST) Fls_InterfaceGetStatus(CONSTP2VAR(FLS_StatusType, AUTOMATIC, FLS_APPL_DATA) ulStatus)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    if (NULL_PTR == ulStatus)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_GET_STATUS_SID, FLS_E_PARAM_HWID);
        retVal = ERR_INVAL_PARAMS;
        *ulStatus = FLS_STATUS_UNINIT;
        DetResultValue = E_NOT_OK;
    }
    else
    {
        /*Do nothing*/
    }
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

    if(DetResultValue != E_NOT_OK)
    {
        *ulStatus = FLS_RWDev.ulStatus;
        retVal = ERR_OK;
    }
    else {
        /*Do nothing*/
    }

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability.      : SWS_Fls_00358, SWS_Fls_00036, SWS_Fls_00035,          **
 **                                                                            **
 ** Syntax            : Fls_GetOpsResult                                       **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : ulOpsRes                                               **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : To get result of the last job                          **
 *******************************************************************************/
FUNC(uint32, FLS_CODE_FAST) Fls_GetOpsResult(CONSTP2VAR(FLS_OpsResultType, AUTOMATIC, FLS_APPL_DATA) ulOpsRes)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    /* Check the controller status */
    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID,FLS_GET_JOB_RESULT_SID, FLS_E_UNINIT);
        retVal = ERR_INVAL_STATE;
        *ulOpsRes = FLS_OPS_RESULT_FAIL;
        DetResultValue = E_NOT_OK;
    }
    else if (NULL_PTR == ulOpsRes)
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID,FLS_GET_JOB_RESULT_SID, FLS_E_PARAM_HWID);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    else
    {
        /*Do nothing*/
    }
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
    if(DetResultValue != E_NOT_OK)
    {
        *ulOpsRes = FLS_RWDev.ulOpsRes;
        retVal = ERR_OK;
    }
    else
    {
        /*Do nothing*/
    }

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00223, SWS_Fls_00332, SWS_Fls_00331,          **
 **                      SWS_Fls_00334, SWS_Fls_00225, SWS_Fls_00001,          **
 **                      SWS_Fls_00333, SWS_Fls_00226, SWS_Fls_00167,          **
 **                      SWS_Fls_00209, SWS_Fls_00026, SWS_Fls_00347,          **
 **                      SWS_Fls_00027, SWS_Fls_00066, SWS_Fls_00311,          **
 **                      SWS_Fls_00030, SWS_Fls_00157, SWS_Fls_00003,          **
 **                      SWS_Fls_00004, SWS_Fls_00038, SWS_Fls_00335,          **
 **                      SWS_Fls_00346,                                        **
 **                                                                            **
 ** Syntax            : Fls_InterfaceErase                                     **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,ulLen                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : Service to Erase flash sector.                         **
 *******************************************************************************/
FUNC(uint32, FLS_CODE_FAST) Fls_InterfaceErase(VAR(FLS_AddrType, AUTOMATIC) ulAddr, VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(FLS_AddrType, AUTOMATIC) LulPhyAddr;
    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;
    //SchM_Enter_Fls_Exclusive_Area_02();

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID,FLS_ERASE_SID, FLS_E_UNINIT);
        retVal = ERR_INVAL_STATE;
        DetResultValue = E_NOT_OK;
    }
    else if ((0UL == ulLen) || (FLS_RWDev.config.size < (ulAddr + ulLen)) || ((ulLen % FLS_RWDev.config.sectorSize) != 0UL))
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_ERASE_SID, FLS_E_PARAM_LENGTH);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    /* Check ulAddr and ulLen for flash sector size alignment */
    else if (((ulAddr % FLS_RWDev.config.sectorSize) != 0UL))
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_ERASE_SID, FLS_E_PARAM_ADDRESS);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    /* Check the controller ulStatus */
    else
    {
        if (FLS_STATUS_BUSY == FLS_RWDev.ulStatus)
        {
            (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_ERASE_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;

            DetResultValue = E_NOT_OK;
        }
        /* Check QSPI state */
        else if (TRUE == Fls_QSPI_IsBusy())
        {
            (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_ERASE_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;

            DetResultValue = E_NOT_OK;
        }
        else
        {
            /*Do nothing*/
        }
    }

#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
    if(DetResultValue != E_NOT_OK)
    {
        LulPhyAddr = Fls_ConvVirtualAddrToPhyAddr(ulAddr);
        FLS_RWDev.ulStatus = FLS_STATUS_BUSY;

        retVal = Fls_OpsErase(LulPhyAddr, ulLen);

    }
    else
    {
        /*Do nothing*/
    }
    //SchM_Exit_Fls_Exclusive_Area_02();
    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00251, SWS_Fls_00223, SWS_Fls_00332,          **
 **                      SWS_Fls_00334, SWS_Fls_00225, SWS_Fls_00001,          **
 **                      SWS_Fls_00333, SWS_Fls_00226, SWS_Fls_00167,          **
 **                      SWS_Fls_00209, SWS_Fls_00026, SWS_Fls_00347,          **
 **                      SWS_Fls_00027, SWS_Fls_00066, SWS_Fls_00311,          **
 **                      SWS_Fls_00030, SWS_Fls_00157, SWS_Fls_00003,          **
 **                      SWS_Fls_00004, SWS_Fls_00038, SWS_Fls_00335,          **
 **                      SWS_Fls_00346, SWS_Fls_00331                          **
 **                                                                            **
 ** Syntax            : Fls_InterfaceWrite                                     **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,pBuf,ulLen                                      **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : Writes one or more complete flash pages.               **
 *******************************************************************************/
FUNC(uint32, FLS_CODE_FAST) Fls_InterfaceWrite( VAR(FLS_AddrType, AUTOMATIC) ulAddr, P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pBuf, VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(FLS_AddrType, AUTOMATIC) LulPhyAddr;
    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;


    //SchM_Enter_Fls_Exclusive_Area_01();

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    /* Check the controller status */
    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_WRITE_SID, FLS_E_UNINIT);
        retVal = ERR_INVAL_STATE;
        DetResultValue = E_NOT_OK;
    }
    /* Removed as condition below forces write of 1byte at a time to work as len can take many values
     it is up to the FLS driver to handle the write request does not exceed page size which is 256 bytes */
    else if ((0UL == ulLen) || (FLS_RWDev.config.size < (ulAddr + ulLen)))// || ((ulLen % FLS_RWDev.config.pageSize) != 0UL))
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_WRITE_SID, FLS_E_PARAM_LENGTH);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    /*  Check ulLen for flash page size alignment - Removed as condition below forces write of 1byte at a time to work as len can take many values */
    /* it is up to the FLS driver to handle the write request does not exceed page size which is 256 bytes */
    /*else if (((ulLen % FLS_RWDev.config.pageSize) != 0UL))
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_WRITE_SID, FLS_E_PARAM_ADDRESS);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }*/
    else if (NULL_PTR == pBuf)
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID,  FLS_WRITE_SID, FLS_E_PARAM_DATA);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    else
    {
        if (FLS_STATUS_BUSY == FLS_RWDev.ulStatus)
        {
            (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_WRITE_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;

            DetResultValue = E_NOT_OK;
        }

        /* Check QSPI state */
        else if (TRUE == Fls_QSPI_IsBusy())
        {
            (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_WRITE_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;

            DetResultValue = E_NOT_OK;
        }
        else
        {
            /*Do nothing*/
        }
    }

#endif /* FLS_DEV_ERROR_DETECT == STD_ON */

    if(DetResultValue != E_NOT_OK)
    {
        LulPhyAddr = Fls_ConvVirtualAddrToPhyAddr(ulAddr);

        FLS_RWDev.ulStatus = FLS_STATUS_BUSY;

        retVal = Fls_OpsWrite(LulPhyAddr, pBuf, ulLen);
    }
    else
    {
        /*Do nothing*/
    }
    //SchM_Exit_Fls_Exclusive_Area_01();
    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability.      : SWS_Fls_00256, SWS_Fls_00236, SWS_Fls_00337           **
 **                      SWS_Fls_00338, SWS_Fls_00339, SWS_Fls_00340,          **
 **                      SWS_Fls_00238, SWS_Fls_00239, SWS_Fls_00097,          **
 **                      SWS_Fls_00098, SWS_Fls_00099, SWS_Fls_00100,          **
 **                      SWS_Fls_00158, SWS_Fls_00240, SWS_Fls_00311,          **
 **                      SWS_Fls_00030, SWS_Fls_00157, SWS_Fls_00003,          **
 **                      SWS_Fls_00004, SWS_Fls_00038,                         **
 **                                                                            **
 ** Syntax            : Fls_InterfaceRead                                      **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,pBuf,ulLen                                      **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : Reads from flash memory.                               **
 *******************************************************************************/
FUNC(uint32, FLS_CODE_FAST) Fls_InterfaceRead(VAR(FLS_AddrType, AUTOMATIC) ulAddr, CONSTP2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) pBuf, VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(FLS_AddrType, AUTOMATIC) LulPhyAddr;
    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;

    //SchM_Enter_Fls_Exclusive_Area_00();

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    /* Check the controller status */
    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_READ_SID, FLS_E_UNINIT);
        retVal = ERR_INVAL_STATE;
        DetResultValue = E_NOT_OK;
    }
    else if ((ulAddr >= FLS_RWDev.config.size))
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_READ_SID, FLS_E_PARAM_ADDRESS);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    else if ((0UL == ulLen) || (FLS_RWDev.config.size < (ulAddr + ulLen)))
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_READ_SID, FLS_E_PARAM_LENGTH);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    else if (NULL_PTR == pBuf)
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_READ_SID, FLS_E_PARAM_DATA);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    else
    {
        if (FLS_STATUS_BUSY == FLS_RWDev.ulStatus)
        {
            (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_READ_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;

            DetResultValue = E_NOT_OK;
        }
        /* Check QSPI state */
        else if (TRUE == Fls_QSPI_IsBusy())
        {
            (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_READ_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;

            DetResultValue = E_NOT_OK;
        }
        else
        {
            /*Do nothing*/
        }
    }

#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
    if (DetResultValue != E_NOT_OK)
    {
        LulPhyAddr = Fls_ConvVirtualAddrToPhyAddr(ulAddr);
        FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
        retVal = Fls_OpsRead(LulPhyAddr, pBuf, ulLen);
    }
    else
    {
        /*Do nothing*/
    }
    //SchM_Exit_Fls_Exclusive_Area_00();

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability.      : SWS_Fls_00257, SWS_Fls_00241, SWS_Fls_00342,          **
 **                      SWS_Fls_00343, SWS_Fls_00244, SWS_Fls_00344,          **
 **                      SWS_FLS_00243, SWS_Fls_00167, SWS_Fls_00186,          **
 **                      SWS_Fls_00150, SWS_Fls_00347, SWS_Fls_00151,          **
 **                      SWS_Fls_00152, SWS_Fls_00153, SWS_Fls_00273           **
 **                                                                            **
 ** Syntax            : Fls_InterfaceCompare                                   **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,pBuf,ulLen                                      **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : This API performs the comparing of an area of flash    **
 **                     memory with that of an application data buffer.        **
 *******************************************************************************/
FUNC(uint32, FLS_CODE_FAST) Fls_InterfaceCompare(VAR(FLS_AddrType, AUTOMATIC) ulAddr, CONSTP2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) pBuf, VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(FLS_AddrType, AUTOMATIC) LulPhyAddr;
    VAR(uint32, AUTOMATIC) DetResultValue = E_OK;

    //SchM_Enter_Fls_Exclusive_Area_03();

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    /* Check the controller status */
    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_COMPARE_SID, FLS_E_UNINIT);
        retVal = ERR_INVAL_STATE;
        DetResultValue = E_NOT_OK;
    }
    else if ((ulAddr >= FLS_RWDev.config.size))
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_COMPARE_SID, FLS_E_PARAM_ADDRESS);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    else if ((0UL == ulLen) || (FLS_RWDev.config.size < (ulAddr + ulLen)))
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_COMPARE_SID, FLS_E_PARAM_LENGTH);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    else if (NULL_PTR == pBuf)
    {
        (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_COMPARE_SID, FLS_E_PARAM_DATA);
        retVal = ERR_INVAL_PARAMS;
        DetResultValue = E_NOT_OK;
    }
    else
    {
        if (FLS_STATUS_BUSY == FLS_RWDev.ulStatus)
        {
            (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_COMPARE_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;
            DetResultValue = E_NOT_OK;
        }
        /* Check QSPI state */
        else if (TRUE == Fls_QSPI_IsBusy())
        {
            (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_COMPARE_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;
            DetResultValue = E_NOT_OK;
        }
        else
        {
            /*Do nothing*/
        }
    }


#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
    if(DetResultValue != E_NOT_OK)
    {
        LulPhyAddr = Fls_ConvVirtualAddrToPhyAddr(ulAddr);
        FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
        retVal = Fls_OpsCompare(LulPhyAddr, pBuf, ulLen);
    }
    else
    {
        /*Do nothing*/
    }
    //SchM_Exit_Fls_Exclusive_Area_03();
    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"


#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability       : SWS_Fls_00371, SWS_Fls_00375, SWS_Fls_00376,          **
 **                      SWS_Fls_00377, SWS_Fls_00378, SWS_Fls_00379,          **
 **                      SWS_Fls_00380, SWS_Fls_00310, SWS_Fls_00381,          **
 **                      SWS_Fls_00382, SWS_Fls_00373, SWS_Fls_00383           **
 **                                                                            **
 ** Syntax            : Fls_InterfaceBlankCheck                                **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : ulAddr,ulLen                                           **
 **                                                                            **
 ** Parameters (out)  : retVal                                                 **
 **                                                                            **
 ** Return value      : uint32                                                 **
 **                                                                            **
 ** Description       : The function Fls_BlankCheck shall verify, whether a    **
 **                     given memory area has been erased but not yet.         **
 *******************************************************************************/

FUNC(uint32, FLS_CODE_FAST) Fls_InterfaceBlankCheck(VAR(FLS_AddrType, AUTOMATIC)ulAddr, VAR(FLS_LenType, AUTOMATIC) ulLen)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(FLS_AddrType, AUTOMATIC) LulPhyAddr;
    VAR(uint32, AUTOMATIC) ReturnValue = E_OK;

    //SchM_Enter_Fls_Exclusive_Area_04();

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    /* Check the controller status */
    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_BLANK_CHECK_SID, FLS_E_UNINIT);
        retVal = ERR_INVAL_STATE;
        ReturnValue = E_NOT_OK;
    }
    else if ((ulAddr >= FLS_RWDev.config.size))
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_BLANK_CHECK_SID, FLS_E_PARAM_ADDRESS);
        retVal = ERR_INVAL_PARAMS;
        ReturnValue = E_NOT_OK;
    }
    else if ((0UL == ulLen) || (FLS_RWDev.config.size < (ulAddr + ulLen)))
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_BLANK_CHECK_SID, FLS_E_PARAM_LENGTH);
        retVal = ERR_INVAL_PARAMS;
        ReturnValue = E_NOT_OK;
    }
    else
    {

        if (FLS_STATUS_BUSY == FLS_RWDev.ulStatus) {
            (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_BLANK_CHECK_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;
            ReturnValue = E_NOT_OK;
        }

        /* Check QSPI state */
        else if (TRUE == Fls_QSPI_IsBusy())
        {
            (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_BLANK_CHECK_SID, FLS_E_BUSY);
            retVal = ERR_BUSY;
            ReturnValue = E_NOT_OK;
        }
        else
        {
            /*Do nothing*/
        }
    }


#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
    if(ReturnValue != E_NOT_OK)
    {
        if(ulLen == 65536)
            LulPhyAddr = 1;
        LulPhyAddr = Fls_ConvVirtualAddrToPhyAddr(ulAddr);
        FLS_RWDev.ulStatus = FLS_STATUS_BUSY;
        retVal = Fls_OpsBlankCheck(LulPhyAddr, ulLen);

    }
    else
    {
        /*Do nothing*/
    }

    //SchM_Exit_Fls_Exclusive_Area_04();

    return retVal;
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability      : SWS_Fls_00262                                          **
 **                                                                            **
 ** Syntax            : Fls_OpsDoneInd                                         **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : none                                                   **
 **                                                                            **
 ** Return value      : none                                                   **
 **                                                                            **
 ** Description       : To indicate job done status  to higher layer           **
 *******************************************************************************/
static FUNC(void, FLS_CODE_FAST) Fls_OpsDoneInd (void)
{
    Fls_ApiStatus = TRUE;
    if(Fls_ConfigPtr->pFlsJobEndNotificationPtr != NULL_PTR)
    {
        Fls_ConfigPtr->pFlsJobEndNotificationPtr();
    }
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability      : SWS_Fls_00263                                          **
 **                                                                            **
 ** Syntax            : Fls_OpsErrInd                                          **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : none                                                   **
 **                                                                            **
 ** Return value      : none                                                   **
 **                                                                            **
 ** Description       : To indicate error status of operation to higher layer  **
 *******************************************************************************/
FUNC(void, FLS_CODE_FAST) Fls_OpsErrInd (void)
 {
    if(Fls_ConfigPtr->pFlsJobErrorNotificationPtr != NULL_PTR)
    {
        Fls_ConfigPtr->pFlsJobErrorNotificationPtr();
    }
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability      : <list the requirements that are covered under this Api>**
 **                                                                            **
 ** Syntax            : FLASH_IRQProcess                                       **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : none                                                   **
 **                                                                            **
 ** Return value      : void                                                   **
 **                                                                            **
 ** Description       : To perform interrupt related activities                **
 *******************************************************************************/
FUNC(void, FLS_CODE_FAST) Fls_IRQProcess(void)
{
    VAR(uint32, AUTOMATIC) retVal;

#if (FLS_DEV_ERROR_DETECT == STD_ON)
    /* SWS_Fls_00117: Check the controller status */
    if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
    {
        (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_MAINFUNCTION_SID, FLS_E_UNINIT);
    }
    else
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
    {
        /* Check if there is any flash operation in progress */
        if (FLS_OPS_NONE == FLS_RWDev.ulCurrOps)
        {
            /* Do Nothing */
        }
        else
        {
            /* Call QSPI command handler */
//            if (TRUE == Fls_QSPI_IsBusy())
//            {
//                retVal = Fls_QSPICmdProcess(FLS_RWDev.ulErrFlag);
//                if (ERR_OK != retVal)
//                {
//                    FLS_RWDev.ulErrFlag = TRUE;
//                }
//            }

            /* No command in process in QSPI */
            if (TRUE == Fls_QSPI_IsBusy())
            {
                /* Do Nothing */
            }
            else
            {
                /* Call Flash operation handler */
                retVal = Fls_OpsHandler();
                if (ERR_OK != retVal)
                {
                    FLS_RWDev.ulErrFlag = TRUE;
                }
                else
                {
                    /*Do nothing*/
                }

                switch(FLS_RWDev.opsInfo.ulIndFlag)
                {
                case FLS_INDFLAG_DONE_IND:
                    Fls_OpsDoneInd();
                    break;
                case FLS_INDFLAG_ERR_IND:
                    Fls_OpsErrInd();
                    break;
                default:
                    /* No indication to be raised */
                    break;
                }
            }
        }
    }
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability.      : SWS_Fls_00255, SWS_Fls_00037, SWS_Fls_00038,          **
 **                      SWS_Fls_00039, SWS_Fls_00040, SWS_Fls_00104,          **
 **                      SWS_Fls_00105, SWS_Fls_00106, SWS_Fls_00154,          **
 **                      SWS_Fls_00200, SWS_Fls_00022, SWS_Fls_00055,          **
 **                      SWS_Fls_00056, SWS_Fls_00345, SWS_Fls_00346,          **
 **                      SWS_Fls_00232, SWS_Fls_00233, SWS_Fls_00234,          **
 **                      SWS_Fls_00235, SWS_Fls_00272, SWS_Fls_00359,          **
 **                      SWS_Fls_00360, SWS_Fls_00362, SWS_Fls_00117,          **
 **                      SWS_Fls_00196,                                        **
 **                                                                            **
 ** Syntax            : Fls_MainProcess                                        **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Reentrant                                              **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : none                                                   **
 **                                                                            **
 ** Return value      : void                                                   **
 **                                                                            **
 ** Description       : To process the flash read,write,erase and compare jobs **
 *******************************************************************************/
FUNC(void, FLS_CODE_FAST) Fls_MainProcess(void)
{

//    uint32 retVal;
    /* FLS_MainFunction is called when FLS initialization completes */
    if (FLS_STATUS_UNINIT != FLS_RWDev.ulStatus)
    {

#if (FLS_DEV_ERROR_DETECT == STD_ON)
        /* SWS_Fls_00117: Check the controller status */
        if (FLS_STATUS_UNINIT == FLS_RWDev.ulStatus)
        {
            (void)Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID, FLS_MAINFUNCTION_SID, FLS_E_UNINIT);
        }
        else
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */
        {
#if (FLS_USE_INTERRUPTS == STD_OFF)
            //    retVal = Fls_IRQHandler();
            //
            //    if(retVal != FLS_ZERO)
#endif
            {
                Fls_IRQProcess();
            }
#if (FLS_USE_INTERRUPTS == STD_OFF)
//            else
//            {
//                /*Do nothing*/
//            }
#endif

            //retVal = retVal;

        }
    }
}
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
 ** Traceability.     : NA                                                       **
 **                                                                            **
 ** Syntax            : Fls_CalculateWriteLength                               **         **
 ** [/cover]                                                                   **
 **                                                                            **
 ** Service ID        : NA                                                     **
 **                                                                            **
 ** Sync/Async        : NA                                                     **
 **                                                                            **
 ** Reentrancy        : Non-Reentrant                                          **
 **                                                                            **
 ** Parameters (in)   : none                                                   **
 **                                                                            **
 ** Parameters (out)  : none                                                   **
 **                                                                            **
 ** Return value      : void                                                   **
 **                                                                            **
 ** Description       : To Calculate the FLS Write Length                      **
 *******************************************************************************/
static FUNC(uint32, FLS_CODE_FAST) Fls_CalculateWriteLength(void)
{
    VAR(uint32, AUTOMATIC) retVal;
    VAR(uint32, AUTOMATIC) ulRem = FLS_RWDev.opsInfo.ulTmpAddr % FLS_RWDev.config.pageSize;

    if(ulRem == 0u)
    {
        if(FLS_RWDev.opsInfo.ulTmpLen >= FLS_RWDev.config.pageSize)
        {
            retVal = FLS_RWDev.config.pageSize;
        }
        else
        {
            retVal = FLS_RWDev.opsInfo.ulTmpLen;
        }
    }
    else
    {
        if(FLS_RWDev.opsInfo.ulTmpLen >= FLS_RWDev.config.pageSize - ulRem)
        {
            retVal = FLS_RWDev.config.pageSize - ulRem;
        }
        else
        {
            retVal = FLS_RWDev.opsInfo.ulTmpLen;
        }
    }

    return retVal;
}

#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#ifdef __cplusplus
}
#endif
/*******************************************************************************
 **                               End of File                                  **
 *******************************************************************************/
