/*******************************************************************************
*
* (c) Copyright 2016-2017 Xilinx, Inc. All rights reserved.
*
* This file contains confidential and proprietary information of Xilinx, Inc.
* and is protected under U.S. and international copyright and other
* intellectual property laws.
*
* DISCLAIMER
* This disclaimer is not a license and does not grant any rights to the
* materials distributed herewith. Except as otherwise provided in a valid
* license issued to you by Xilinx, and to the maximum extent permitted by
* applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
* FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
* IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
* MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
* and (2) Xilinx shall not be liable (whether in contract or tort, including
* negligence, or under any other theory of liability) for any loss or damage
* of any kind or nature related to, arising under or in connection with these
* materials, including for any direct, or any indirect, special, incidental,
* or consequential loss or damage (including loss of data, profits, goodwill,
* or any type of loss or damage suffered as a result of any action brought by
* a third party) even if such damage or loss was reasonably foreseeable or
* Xilinx had been advised of the possibility of the same.
*
* CRITICAL APPLICATIONS
* Xilinx products are not designed or intended to be fail-safe, or for use in
* any application requiring fail-safe performance, such as life-support or
* safety devices or systems, Class III medical devices, nuclear facilities,
* or any other applications that could lead to death, personal injury, or 
* severe property or environmental damage (individually and collectively, 
* "Critical Applications"). Customer assumes the sole risk and liability of any
* use of Xilinx products in Critical Applications, subject only to applicable 
* laws and regulations governing limitations on product liability.
* THE MATERIALS ARE NOT WARRANTED FOR USE IN APPLICATIONS RELATED TO DEPLOYMENT 
* OF AIRBAGS OR FOR USE IN APPLICATIONS THAT AFFECT CONTROL OF A VEHICLE 
* ("SAFETY APPLICATION") UNLESS THERE IS A SAFETY CONCEPT OR REDUNDANCY FEATURE 
* (CONSISTENT WITH THE ISO-26262 AUTOMOTIVE SAFETY STANDARD OR APPLICABLE 
* UPDATED STANDARD) ("SAFETY DESIGN").  LICENSEE SHALL, PRIOR TO USING OR 
* DISTRIBUTING ANY SYSTEMS THAT INCORPORATE THE MATERIALS, THOROUGHLY TEST THE
* SAME FOR SAFETY PURPOSES.  USE OF THE MATERIALS IN A SAFETY APPLICATION 
* WITHOUT A SAFETY DESIGN IS FULLY AT THE RISK OF CUSTOMER, SUBJECT ONLY TO 
* APPLICABLE LAWS AND REGULATIONS GOVERNING LIMITATIONS ON PRODUCT LIABILITY.
*
* THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
* AT ALL TIMES.
*
*******************************************************************************/
/******************************************************************************/
/**
*
* file: Fls.c
*
* This file contains functionality of FLS driver
*
* <pre>
*
* 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:4342)-1 An expression of essentially unsigned           **
**                 type (unsigned long) is being cast to                      **
**                 enum type  MemIf_StatusType                                **
** Rule          : MISRA-C:2004 Rule 11.3  MISRA C:2012 Rule-11.4, Rule-11.6; **
**                 REFERENCE - ISO-6.3.4 Semantics                            **
** Justification : Type Casting is done to MemIf_StatusType for Return Value, **
**                 As the return value is always a Enum Value.                **
** Verification  : However, part of the code is verified manually and it is   **
**                 not having any impact.                                     **
** Reference     : Look for START Msg (5:4342)-1 and                          **
**                 END Msg (5:4342)-1 tags in the code.                       **
**                                                                            **
*******************************************************************************/
/*******************************************************************************
**                      MISRA C Rule Violations                               **
********************************************************************************
** 2. MISRA C RULE VIOLATION:                                                 **
** Message       : (7:0310)-2 Casting to different object pointer type.       **
** Rule          : MISRA C:2012 Rule-11.3; REFERENCE - ISO:C90-6.3.4          **
**                 Cast Operators - Semantics                                 **
** Justification : Typecasting is done to FLS_CfgType from Fls_MemConfigType  **
**                 to access correct elements However,part of the code is     **
**                 verified manually and it is not having any impact.         **
** Verification  : Part of the code is verified manually and it is working    **
**                 fine                                                       **
**                 not having any impact.                                     **
** Reference     : Look for START Msg (7:0310)-2 and                          **
**                 END Msg (7:0310)-2 tags in the code.                       **
**                                                                            **
*******************************************************************************/

#ifdef __cplusplus
extern "C"{
#endif
/*******************************************************************************
**                      INCLUDE FILES                                         **
*******************************************************************************/
#include <include/Fls.h>
#include <include/Fls_Private.h>

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


/*******************************************************************************
**                      GLOBAL VARIABLES                                      **
*******************************************************************************/
#define FLS_START_SEC_VAR_FAST_CLEARED_ASIL_C_UNSPECIFIED

#include "Fls_MemMap.h"

P2CONST(Fls_ConfigType, FLS_VAR_CLEARED, FLS_APPL_DATA) Fls_ConfigPtr;

#define FLS_STOP_SEC_VAR_FAST_CLEARED_ASIL_C_UNSPECIFIED
#include "Fls_MemMap.h"

#define FLS_START_SEC_VAR_FAST_CLEARED_ASIL_C_8
#include "Fls_MemMap.h"

#if (FLS_DEV_ERROR_DETECT == STD_ON)
/* Variable to store the ApiID to report Det error */
VAR(uint8, FLS_VAR_CLEARED) Fls_ApiId = FALSE;
#endif /* FLS_DEV_ERROR_DETECT == STD_ON */


#define FLS_STOP_SEC_VAR_FAST_CLEARED_ASIL_C_8
#include "Fls_MemMap.h"

/*******************************************************************************
**                      LOCAL STRUCTURES, ENUMS, TYPEDEFS                     **
*******************************************************************************/

/*******************************************************************************
**                      LOCAL CONSTANTS and MACROS                            **
*******************************************************************************/
#define FLS_VENDOR_ID_C   39u
#define FLS_MODULE_ID_C   92u

#define FLS_AR_RELEASE_MAJOR_VERSION_C     4u
#define FLS_AR_RELEASE_MINOR_VERSION_C     2u
#define FLS_AR_RELEASE_REVISION_VERSION_C  2u

#define FLS_SW_MAJOR_VERSION_C     1u
#define FLS_SW_MINOR_VERSION_C     0u
#define FLS_SW_PATCH_VERSION_C     3u

#define ERR_OK              (0UL)   /*< No error */
/*******************************************************************************
**                      LOCAL FUNCTION PROTOTYPES                             **
*******************************************************************************/

/*******************************************************************************
**                      LOCAL VARIABLES                                       **
*******************************************************************************/

/*******************************************************************************
**                      VERSION CHECK                                         **
*******************************************************************************/
/* [SWS_BSW_00036] Inter module 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

/* SW version check of *.h/c of the own module */
#if ((FLS_SW_MAJOR_VERSION_C != FLS_SW_MAJOR_VERSION) || \
     (FLS_SW_MINOR_VERSION_C != FLS_SW_MINOR_VERSION) || \
     (FLS_SW_PATCH_VERSION_C != FLS_SW_PATCH_VERSION))
    #error "The SW version number of Fls.c and Fls.h are different."
#endif

/*******************************************************************************
**                      FUNCTION DEFINITIONS                                 **
*******************************************************************************/
#define FLS_START_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"
/*******************************************************************************
** Traceability       : SWS_Fls_00323, SWS_Fls_00324, SWS_Fls_00249,          **
**                      SWS_Fls_00015, SWS_Fls_00310, SWS_Fls_00268,          **
**                      SWS_Fls_00191, SWS_Fls_00014,SWS_Fls_00086,           **
**                                                                            **
**                                                                            **
** Syntax             : Fls_Init                                              **
** [/cover]                                                                   **
**                                                                            **
** Service ID         : 0x00                                                  **
**                                                                            **
** Sync/Async         : Synchronous                                           **
**                                                                            **
** Reentrancy         : Non Reentrant                                         ** 
**                                                                            **
** Parameters (in)    : ConfigPtr                                             **
**                                                                            **
** Parameters (out)   : None                                                  **
**                                                                            **
** Return Value       : None                                                  **
**                                                                            **
** Description        : Service for Fls initialization.                       **
*******************************************************************************/
FUNC(void, FLS_CODE_SLOW) Fls_Init(
                   P2CONST(Fls_ConfigType, AUTOMATIC, FLS_APPL_DATA) ConfigPtr)
{
#ifdef FLS_VARIANT_POST_BUILD
  #if (FLS_DEV_ERROR_DETECT == STD_ON)
  if (NULL_PTR == ConfigPtr)
  {
   (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID,
                                      FLS_INIT_SID, FLS_E_PARAM_CONFIG);
  }
  else
  #endif /* FLS_DEV_ERROR_DETECT == STD_ON */
  {
    Fls_ConfigPtr = ConfigPtr;
    /* START Msg (7:0310)-2 */
    Fls_InterfaceInit((const FLS_CfgType * const)&(Fls_MemConfig));
    /* START Msg (7:0310)-2 */
  }

#endif

#ifdef FLS_VARIANT_PRE_COMPILE
  Fls_ConfigPtr = &Fls_Config;
  Fls_InterfaceInit((const FLS_CfgType * const)&(Fls_MemConfig));
#endif


} /* End of Fls_Init */
#define FLS_STOP_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"


#define FLS_START_SEC_CODE_SLOW_ASIL_C
#include "Fls_MemMap.h"
#if (FLS_VERSION_INFO_API == STD_ON)
/*******************************************************************************
** Traceability       : SWS_Fls_00363, SWS_Fls_00259                          ** 
**                                                                            **
** Syntax             : Fls_GetVersionInfo                                    **
** [/cover]                                                                   **
**                                                                            **
** Service ID         : 0x10                                                  **
**                                                                            **
** Sync/Async         : Synchronous                                           **
**                                                                            **
** Reentrancy         : Re-entrant                                            **
**                                                                            **
** Parameters (in)    : versioninfo                                           **
**                                                                            **
** Parameters (out)   : void                                                  **
**                                                                            **
** Return Value       : None                                                  **
**                                                                            **   
** Description        : To return the version information of this module.     **
**                                                                            **
*******************************************************************************/
FUNC(void, FLS_CODE_SLOW) Fls_GetVersionInfo(
          CONSTP2VAR(Std_VersionInfoType, AUTOMATIC, Fls_APPL_DATA) versioninfo)
{
  VAR(Std_ReturnType, AUTOMATIC) RetValue = E_OK;
   
  #if (FLS_DEV_ERROR_DETECT == STD_ON)
  if(versioninfo == NULL_PTR) {
    (void) Det_ReportError(FLS_MODULE_ID, FLS_INSTANCE_ID,
                             FLS_GET_VERSION_INFO_SID, FLS_E_PARAM_POINTER);
    RetValue = E_NOT_OK;
  }
  else {
    RetValue = E_OK;
  }
  #endif /* FLS_DEV_ERROR_DETECT == STD_ON */

  if(RetValue == E_OK) {
     versioninfo->vendorID = FLS_VENDOR_ID_C;
     versioninfo->moduleID = FLS_MODULE_ID_C;
     versioninfo->sw_major_version = FLS_SW_MAJOR_VERSION_C;
     versioninfo->sw_minor_version = FLS_SW_MINOR_VERSION_C;
     versioninfo->sw_patch_version = FLS_SW_PATCH_VERSION_C;      
  }
  else {
     /* Do nothing */
  }
}
#endif /* #if (FLS_VERSION_INFO_API == STD_ON)*/

#define FLS_STOP_SEC_CODE_SLOW_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,          **
**                      SWS_Fls_00001, SWS_Fls_00209, SWS_Fls_00220,          **
**                      SWS_Fls_00037, SWS_Fls_00065, SWS_Fls_00311,          **
**                      SWS_Fls_00023, SWS_Fls_00312, SWS_Fls_00039,          **
**                      SWS_Fls_00346, SWS_Fls_00196                          **
**                                                                            **
** Syntax              : Fls_Erase                                            **
** [/cover]                                                                   **
**                                                                            **
** Service ID          : 0x01                                                 **
**                                                                            **   
** Sync/Async          : Asynchronous                                         **
**                                                                            **
** Reentrancy          : Non Reentrant                                        **
**                                                                            **
** Parameters (in)     : Target Address, Length                               **
**                                                                            **
** Parameters (out)    : None                                                 **
**                                                                            **
** Return Value        : Std_ReturnType                                       ** 
**                                                                            **
** Description         : Service for Erases flash sector.                     **
**                                                                            **
*******************************************************************************/

FUNC(Std_ReturnType, FLS_CODE_FAST) Fls_Erase( 
                                 VAR(Fls_AddressType, AUTOMATIC) TargetAddress,
                                 VAR(Fls_LengthType, AUTOMATIC) Length)
{
  /* Local variable to hold the return value of the function */
  VAR(Std_ReturnType, AUTOMATIC) LddReturnValue;
  VAR(uint32, AUTOMATIC) retVal;

  //dwdReset();
  retVal = Fls_InterfaceErase(TargetAddress, Length);
  if(retVal != ERR_OK)
  {
    LddReturnValue = E_NOT_OK;
  }
  else
  {
    /* Command accepted - Return E_OK */
    LddReturnValue = E_OK;
    #if (FLS_DEV_ERROR_DETECT == STD_ON)
    Fls_ApiId = FLS_ERASE_SID;
    #endif /* FLS_DEV_ERROR_DETECT == STD_ON */
  }
  return(LddReturnValue);
} /* End of FLS_Erase */

#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                          **
**                                                                            **
** Service Name       : Fls_Write                                             **
**                                                                            **
** Service ID (hex)   : 0x02                                                  **
**                                                                            **
** Sync/Async         : Asynchronous                                          ** 
**                                                                            **
** Reentrancy         : Non Re-entrant                                        **
**                                                                            **
** Parameters (IN)    : TargetAddress, Source Address Ptr & Length            **
**                                                                            **
** Parameters (INOUT) : None                                                  **
**                                                                            **
** Parameters (OUT)   : None                                                  **
**                                                                            **
** Return Value       : Std_ReturnType                                        **
**                                                                            **
** Description        : Writes one or more complete flash pages.              **
**                                                                            **
*******************************************************************************/
FUNC(Std_ReturnType, FLS_CODE_FAST) Fls_Write(
                    VAR(Fls_AddressType, AUTOMATIC) TargetAddress,
                    P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) SourceAddressPtr,
                    VAR(Fls_LengthType, AUTOMATIC) Length)
{
  /* Local variable to hold the return value of the function */
  VAR(Std_ReturnType, AUTOMATIC) LddReturnValue;
  VAR(uint32, AUTOMATIC) retVal;

  //dwdReset();
  retVal = Fls_InterfaceWrite(TargetAddress, SourceAddressPtr, Length);
  if(retVal != ERR_OK)
  {
    LddReturnValue = E_NOT_OK;
  }
  else
  {
    /* Command accepted - Return E_OK */
    LddReturnValue = E_OK;
    #if (FLS_DEV_ERROR_DETECT == STD_ON)
    Fls_ApiId = FLS_WRITE_SID;
    #endif /* FLS_DEV_ERROR_DETECT == STD_ON */
  }
  return(LddReturnValue);
  
} /* End of Fls_Write */
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_ASIL_C
#include "Fls_MemMap.h"
#if (FLS_CANCEL_API == STD_ON)

/*******************************************************************************
** Traceability.      : SWS_Fls_00252, SWS_Fls_00229, SWS_Fls_00230,          **
**                      SWS_Fls_00336, SWS_Fls_00033, SWS_Fls_00183,          **
**                      SWS_Fls_00147, SWS_Fls_00348, SWS_Fls_00356           **
**                                                                            **
** Service Name       :Fls_Cancel                                             **
**                                                                            **
** Service ID (hex)   :0x03                                                   **
**                                                                            **
** Sync/Async         :Synchronous                                            **
**                                                                            **
** Reentrancy         :Non Re-entrant                                         ** 
**                                                                            **
** Parameters (IN)    :None                                                   **
**                                                                            **
** Parameters (INOUT) :None                                                   **
**                                                                            **
** Parameters (OUT)   :None                                                   **
**                                                                            **
** Return Value       :None                                                   **
**                                                                            **
** Description        :Cancels an ongoing job.                                **   
**                                                                            **
*******************************************************************************/

FUNC(void, FLS_CODE) Fls_Cancel(void) 
{
  /*Hardware does not support this functionality */

}/* End of Function Fls_Cancel */

#endif /* #if (FLS_CANCEL_API == STD_ON) */
#define FLS_STOP_SEC_CODE_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
#if (FLS_GET_STATUS_API == STD_ON)
/*******************************************************************************
** Traceability.      :SWS_Fls_00034, SWS_Fls_00253                           **
**                                                                            **
** Service Name       :Fls_GetStatus                                          **
**                                                                            **
** Service ID (hex)   :0x04                                                   **
**                                                                            **
** Sync/Async         :Synchronous                                            **
**                                                                            **
** Reentrancy         :Re-entrant                                             ** 
**                                                                            **
** Parameters (IN)    :None                                                   **
**                                                                            **
** Parameters (INOUT) :None                                                   **
**                                                                            **
** Parameters (OUT)   :None                                                   **
**                                                                            **
** Return Value       :MemIf_StatusType                                       **
**                                                                            **
** Description        :Returns the driver state..                             **
**                                                                            **
*******************************************************************************/

FUNC(MemIf_StatusType, FLS_CODE_FAST) Fls_GetStatus(void) 
{
  /* Local variable to store the driver status */
  uint32 LenStatus;

  LenStatus =(uint32) MEMIF_UNINIT;

  (void)Fls_InterfaceGetStatus(&LenStatus);
  
  /*START Msg (5:4342)-1*/
  return((MemIf_StatusType)LenStatus);
  /*END Msg (5:4342)-1*/ 

} /* End of Fls_GetStatus */

#endif /* #if (FLS_GET_STATUS_API == STD_ON) */

#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
#if (FLS_GET_JOB_RESULT_API == STD_ON)
/*******************************************************************************
** Traceability.      : SWS_Fls_00254, SWS_Fls_00036, SWS_Fls_00035,          **
**                      SWS_Fls_00358,                                        **
**                                                                            **
** Service Name       :Fls_GetJobResult                                       **
**                                                                            **
** Service ID (hex)   :0x05                                                   **
**                                                                            **
** Sync/Async         :Synchronous                                            ** 
**                                                                            **
** Reentrancy         :Re-entrant                                             **
**                                                                            **
** Parameters (IN)    :None                                                   **
**                                                                            **
** Parameters (INOUT) :None                                                   **
**                                                                            **
** Parameters (OUT)   :None                                                   ** 
**                                                                            **
** Return Value       :MemIf_JobResultType                                    **
**                                                                            **
** Description        :Returns the result of the last job.                    **
**                                                                            **
*******************************************************************************/
FUNC(MemIf_JobResultType, FLS_CODE_FAST) Fls_GetJobResult(void)
{
  /* Local variable to store the job result */
  uint32 LenJobResult;

  /* Set the default values */
  LenJobResult = (uint32) MEMIF_JOB_FAILED;

  (void)Fls_GetOpsResult(&LenJobResult);

  /*START Msg (5:4342)-1*/
  return (MemIf_JobResultType)LenJobResult;
  /*END Msg (5:4342)-1*/
   
} /* End of Fls_GetJobResult */
#endif /* #if (FLS_GET_JOB_RESULT_API == STD_ON)*/

#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,                         **
**                                                                            **
**                                                                            **
** Service Name       :Fls_Read                                               **
**                                                                            **
** Service ID (hex)   :0x07                                                   **
**                                                                            **
** Sync/Async         :Asynchronous                                           ** 
**                                                                            **
** Reentrancy         :Non Re-entrant                                         ** 
**                                                                            **
** Parameters (IN)    :Source Address, Length                                 **
**                                                                            **
** Parameters (INOUT) :TargetAddressPtr                                       **
**                                                                            **
** Parameters (OUT)   :None                                                   **   
**                                                                            **
** Return Value       :Std_ReturnType                                         **
**                                                                            **
** Description.       :Reads from flash memory.                               **
**                                                                            **
*******************************************************************************/
FUNC(Std_ReturnType, FLS_CODE_FAST) Fls_Read(
                     VAR(Fls_AddressType, AUTOMATIC) SourceAddress,
                     P2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) TargetAddressPtr,
                     VAR(Fls_LengthType, AUTOMATIC) Length) 
{
  /* Local variable to hold the return value of the function */
  VAR(Std_ReturnType, AUTOMATIC) LddReturnValue;
  VAR(uint32, AUTOMATIC) retVal;

  //dwdReset();
  retVal = Fls_InterfaceRead(SourceAddress, TargetAddressPtr, Length);
  
  if(retVal != ERR_OK)
  {
    LddReturnValue = E_NOT_OK;
  }
  else
  {
    /* Command accepted - Return E_OK */
    LddReturnValue = E_OK;
    #if (FLS_DEV_ERROR_DETECT == STD_ON)
    Fls_ApiId = FLS_READ_SID;
    #endif /* FLS_DEV_ERROR_DETECT == STD_ON */
  }   

  return(LddReturnValue);
} /* End of Fls_Read */
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#if (FLS_COMPARE_API == STD_ON)
/*******************************************************************************
** 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           **
**                                                                            **
** Service Name       :Fls_Compare                                            **
**                                                                            **
** Service ID (hex)   :0x08                                                   **
**                                                                            **
** Sync/Async         :Asynchronous                                           **
**                                                                            **
** Reentrancy         :Non Re-entrant                                         ** 
**                                                                            **
** Parameters (IN)    :Source Address, Target address Ptr, Length             **
**                                                                            **
** Parameters (INOUT) :None                                                   **
**                                                                            **
** Parameters (OUT)   :None                                                   **
**                                                                            **
** Return Value       :Std_ReturnType                                         **
**                                                                            **
** Description        :This API performs the comparing of an area of flash    **
**                     memory with that of an application data buffer.        **
**                     The API will copy the given parameters to module       **
**                     internal variables,initiate a compare job,set the      **
**                     job result to MEMIF_JOB_PENDING and return with E_OK.  **
**                     Request is handled by the job processing function.     **
**                                                                            **                    
*******************************************************************************/
FUNC(Std_ReturnType, FLS_CODE_FAST) Fls_Compare(
                     VAR(Fls_AddressType, AUTOMATIC) SourceAddress,
                     P2CONST(uint8, AUTOMATIC, FLS_APPL_DATA) TargetAddressPtr,
                     VAR(Fls_LengthType, AUTOMATIC) Length)
{
  /* Local variable to hold the return value of the function */
  VAR(Std_ReturnType, AUTOMATIC) LddReturnValue;
  VAR(uint32, AUTOMATIC) retVal;

  //dwdReset();
  retVal = Fls_InterfaceCompare( SourceAddress,TargetAddressPtr,Length);
  if(retVal != ERR_OK)
  {
    LddReturnValue = E_NOT_OK;
  }
  else
  {
    /* Command accepted - Return E_OK */
    LddReturnValue = E_OK;
    #if (FLS_DEV_ERROR_DETECT == STD_ON)
    Fls_ApiId = FLS_COMPARE_SID;
    #endif /* FLS_DEV_ERROR_DETECT == STD_ON */
  }

  return(LddReturnValue);
  
} /* End of Fls_Compare */

#endif /* #if (FLS_COMPARE_API == STD_ON) */
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
#if (FLS_SET_MODE_API == STD_ON)
/*******************************************************************************
** Service Name.      :Fls_SetMode                                            **
**                                                                            **
** Service ID (hex)   :0x09                                                   **
**                                                                            **
** Sync/Async         :Synchronous                                            **
**                                                                            **
** Reentrancy         :Re-entrant                                             **
**                                                                            **
** Parameters (IN)    :Mode                                                   **
**                                                                            **
** Parameters (INOUT) :None                                                   **
**                                                                            **
** Parameters (OUT)   :None                                                   **
**                                                                            **
** Return Value       :None                                                   **
**                                                                            **
** Description        :Sets the flash drivers operation mode.                 **
**                                                                            ** 
*******************************************************************************/
FUNC(void, FLS_CODE_FAST) Fls_SetMode(VAR(MemIf_ModeType, AUTOMATIC) Mode)  
{
  /* This API is not supported */
}
#endif /* #if (FLS_SET_MODE_API == STD_ON) */
#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

#define FLS_START_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"
#if (FLS_BLANK_CHECK == STD_ON)
/*******************************************************************************
** 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           **
**                                                                            **
** Service Name       :Fls_BlankCheck                                         **
**                                                                            **
** Service ID (hex)   :0x0a                                                   **
**                                                                            **
** Sync/Async         :Asynchronous                                           **
**                                                                            **
** Reentrancy         :Non Re-entrant                                         **
**                                                                            **
** Parameters (IN)    :Target Address ad Length                               **
**                                                                            **
** Parameters (INOUT) :None                                                   **
**                                                                            **
** Parameters (OUT)   :None                                                   **
**                                                                            **
** Return Value       :Std_ReturnType                                         **
**                                                                            **
** Description        :The function Fls_BlankCheck shall verify, whether a    **
**                     given memory area has been erased but not (yet)        **
**                     programmed. The function shall limit the maximum number**  
**                     of checked flash cells per main function cycle to the  **
**                     configured value FlsMaxReadNormalMode or               **
**                     FlsMaxReadFastMode respectively.                       **
**                                                                            **
*******************************************************************************/
FUNC(Std_ReturnType, FLS_CODE_FAST) Fls_BlankCheck( 
                          VAR(Fls_AddressType, AUTOMATIC) TargetAddress,
                          VAR(Fls_LengthType, AUTOMATIC) Length)
{
  /* Local variable to hold the return value of the function */
  VAR(Std_ReturnType, AUTOMATIC) LddReturnValue;
  VAR(uint32, AUTOMATIC) retVal;

  //dwdReset();
  retVal = Fls_InterfaceBlankCheck(TargetAddress, Length);
  if(retVal != ERR_OK)
  {
    LddReturnValue = E_NOT_OK;
  }
  else
  {
    /* Command accepted - Return E_OK */
    LddReturnValue = E_OK;
    #if (FLS_DEV_ERROR_DETECT == STD_ON)
    Fls_ApiId = FLS_BLANK_CHECK_SID;
    #endif /* FLS_DEV_ERROR_DETECT == STD_ON */
  }
  return(LddReturnValue);

} /* End of Fls_BlankCheck */  

#endif /* FLS_BLANK_CHECK == STD_ON */
#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,                                        **
**                                                                            **
** Service Name       :Fls_MainFunction                                       **
**                                                                            **
** Service ID (hex)   :0x06                                                   **
**                                                                            **
** Sync/Async         :Synchronous                                            **
**                                                                            **
** Reentrancy         :Re-entrant                                             **
**                                                                            **
** Parameters (IN)    :None                                                   **
**                                                                            **
** Parameters (INOUT) :None                                                   **
**                                                                            **
** Parameters (OUT)   :None                                                   **
**                                                                            **
** Return Value       :None                                                   **
**                                                                            **
** Description        :This API performs the job processing of erase, write,  **
**                     read and compare jobs. This API is called cyclically   **
**                     until the job is processed completely. This API        **
**                     processes as much data in one call cycle as statically **
**                     configured for the current job type (write, read or    **
**                     compare).                                              **
**                                                                            **
*******************************************************************************/
FUNC(void, FLS_CODE_FAST) Fls_MainFunction(void)
{
  /* Call Process function with current job Hardware ID */
  Fls_MainProcess();
}


#define FLS_STOP_SEC_CODE_FAST_ASIL_C
#include "Fls_MemMap.h"

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