/**********************************************************************************************************************
 *  COPYRIGHT
 *  -------------------------------------------------------------------------------------------------------------------
 *  \verbatim
 *                 TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
 *
 *                 Property of Texas Instruments, Unauthorized reproduction and/or distribution
 *                 is strictly prohibited.  This product  is  protected  under  copyright  law
 *                 and  trade  secret law as an  unpublished work.
 *                 (C) Copyright Texas Instruments - 2014.  All rights reserved.
 *
 *  \endverbatim
 *  -------------------------------------------------------------------------------------------------------------------
 *  FILE DESCRIPTION
 *  -------------------------------------------------------------------------------------------------------------------
 *         File:  fee.h
 *      Project:  Tms570_FEEDriver
 *       Module:  FEE Driver
 *    Generator:  None
 *
 *  Description:  This file implements the FEE Api.
 *---------------------------------------------------------------------------------------------------------------------
 * Author:  Vishwanath Reddy
 *---------------------------------------------------------------------------------------------------------------------
 * Revision History
 *---------------------------------------------------------------------------------------------------------------------
 * Version        Date         Author               Change ID        Description
 *---------------------------------------------------------------------------------------------------------------------
 * 02.21.00       30Sept2014   Vishwanath reddy     SDOCM00113128    Initial Version
 * 02.21.01       30June2016   Vishwanath Reddy     SDOCM00122388    Update patch version FEE_SW_PATCH_VERSION.
 * 02.21.02       04Augu2016   Vishwanath Reddy     SDOCM00122571    Update patch version FEE_SW_PATCH_VERSION.
 * 02.21.03       23Augu2016   Vishwanath Reddy     SDOCM00122617    Update patch version FEE_SW_PATCH_VERSION. 
 *                                                                   Fee_JobEndNotification and 
 *                                                                   Fee_JobErrorNotification API's added as required 
 *                                                                   by Autosar spec.
 * 05.30.00       15Mar2017    Sudhakar Singh       SDOCM00122834    Version supports TMS570LSxx Family of Devices.
 *********************************************************************************************************************/


#ifndef FEE_H
#define FEE_H

/**********************************************************************************************************************
 * INCLUDES
 *********************************************************************************************************************/
#include "Std_Types.h"
#include "ti_fee.h"
#include "Fee_Cfg.h"


/**********************************************************************************************************************
 * Fee Published Information
 *********************************************************************************************************************/
#define FEE_VENDOR_ID          ((uint16)44U)
#define FEE_MODULE_ID          ((uint16)21U)
#define FEE_INSTANCE_ID        ((uint8) 0x00U)

#define FEE_AR_MAJOR_VERSION    (4U)
#define FEE_AR_MINOR_VERSION    (0U)
#define FEE_AR_PATCH_VERSION    (3U)
#define FEE_SW_MAJOR_VERSION               (5U)
#define FEE_SW_MINOR_VERSION               (30U)
#define FEE_SW_PATCH_VERSION               (0U)
#define FEE_VENDOR_API_INFIX


/**********************************************************************************************************************
 *  GLOBAL CONSTANT MACROS
 *********************************************************************************************************************/
#define FEE_VIRTUAL_SECTOR_VERSION  1U

/* SourceId : FEE_SourceId_014 */
/* DesignId : FEE4x_DesignId_001 */
/* Requirements : AR_FEE_SR16, AR_FEE_SR17 */
/* DET error defines */
#ifndef FEE_E_UNINIT
#define FEE_E_UNINIT			((uint8)0x01U)
#endif

#ifndef FEE_E_INVALID_BLOCK_NO
#define FEE_E_INVALID_BLOCK_NO	((uint8)0x02U)
#endif

#ifndef FEE_E_INVALID_BLOCK_OFS
#define FEE_E_INVALID_BLOCK_OFS	((uint8)0x03U)
#endif

#ifndef FEE_E_INVALID_DATA_PTR
#define	FEE_E_INVALID_DATA_PTR	((uint8)0x04U)
#endif

#ifndef FEE_E_INVALID_BLOCK_LEN
#define FEE_E_INVALID_BLOCK_LEN	((uint8)0x05U)
#endif

#ifndef FEE_E_BUSY
#define	FEE_E_BUSY				((uint8)0x06U)
#endif

#ifndef FEE_E_BUSY_INTERNAL
#define	FEE_E_BUSY_INTERNAL		((uint8)0x07U)
#endif

#ifndef FEE_E_INVALID_CANCEL
#define	FEE_E_INVALID_CANCEL	((uint8)0x08U)
#endif

/* These are the service IDs of the functions in the ASR SWS specification */
#define FEE_SID_INIT					((uint8)0x00U)
#define FEE_SID_SETMODE					((uint8)0x01U)
#define FEE_SID_READ					((uint8)0x02U)
#define FEE_SID_WRITE					((uint8)0x03U)
#define FEE_SID_CANCEL					((uint8)0x04U)
#define FEE_SID_GETSTATUS				((uint8)0x05U)
#define FEE_SID_GETJOBRESULT			((uint8)0x06U)
#define FEE_SID_INVALIDATEBLOCK			((uint8)0x07U)
#define FEE_SID_GETVERSIONINFO			((uint8)0x08U)
#define FEE_SID_ERASEIMMEDIATEBLOCK		((uint8)0x09U)
#define FEE_SID_JOBENDNOTIFICATION		((uint8)0x10U)
#define FEE_SID_JOBERRORNOTIFICATION	((uint8)0x11U)
#define FEE_SID_MAINFUNCTION			((uint8)0x12U)

/**********************************************************************************************************************
 *  TypeDefs
 *********************************************************************************************************************/
 
typedef void Fee_CallbackType(void);

/* Structure used to contain General device options */
typedef struct
{
   boolean FeeDevErrorDetect;                        /* Indicates if Development Error Detection is enabled */
                                                     /* Default: STD_OFF */
   uint32  FeeIndex;                                 /* Instance ID of this module. Should always be 0 */
                                                     /* Fixed Value: 0 */
   Fee_CallbackType * FeeNvmJobEndNotification;       /* Mapping to upper level job end notification */
                                                     /* Default: generic Nvm definition */
   Fee_CallbackType * FeeNvmJobErrorNotification;     /* Mapping to upper level job error notification */
                                                     /* Default: generic Nvm definition */
   boolean FeePollingMode;                           /* Indicates if polling mode is enabled */
                                                     /* Default: STD_OFF */
   boolean FeeVersionInfoApi;                        /* Indicates if the user can use the function Fee_GetVersionInfo() */
                                                     /* Default: STD_OFF */   
   uint16  FeeVirtualPageSize;                       /* Defines the virtual page size.  Our implementation is currently a static 8 byte Page Size */
                                                     /* Fixed value: 8 */      
} Fee_GeneralConfigType;

/* Structure used to contain Published Information */
typedef struct
{
   uint8   FeeBlockOverhead;                         /* Block overhead in bytes */
                                                     /* Calc: (Chunks==True?16:0) + 8 */
   float32   FeeMaximumBlockingTime;                 /* Maximum Blocking Time in uS */
                                                     /* Calc: Device max write time + 50us */
                                                     /* Default: 600us */
                                                     /* Min: 50us; Max: 2ms */
   uint8   FeePageOverhead;                          /* Page overhead in bytes - for our methods, there is none */
                                                     /* Fixed Value: 0 */
   uint8   FeeVirtualSectorOverhead;                 /* Virtual Sector overhead in bytes */
                                                     /* Fixed Value: 16 */
} Fee_PublishedInformationType;


/**********************************************************************************************************************
 * EXTERN Declarations
 *********************************************************************************************************************/
/*  Fee Global Variables */
extern const Fee_PublishedInformationType Fee_PublishedInformation;

/**********************************************************************************************************************
 *  GLOBAL FUNCTION PROTOTYPES
 *********************************************************************************************************************/
extern void Fee_Cancel(void);
extern Std_ReturnType Fee_EraseImmediateBlock(uint16 BlockNumber);
extern MemIf_JobResultType Fee_GetJobResult(void);
extern MemIf_StatusType Fee_GetStatus(void);
#if (FEE_VERSION_INFO_API == STD_ON)
extern void Fee_GetVersionInfo(Std_VersionInfoType* VersionInfoPtr);
#endif
extern void Fee_Init(void);
extern Std_ReturnType Fee_InvalidateBlock(uint16 BlockNumber);
extern Std_ReturnType Fee_Read(uint16 BlockNumber,
                               uint16 BlockOffset,
                               uint8* DataBufferPtr,
                               uint16 Length);
extern void Fee_SetMode(MemIf_ModeType Mode);
extern Std_ReturnType Fee_Write(uint16 BlockNumber,
                                uint8* DataBufferPtr);

/*  BSW Functions */
extern void Fee_MainFunction(void);
extern void Fee_JobEndNotification(void);
extern void Fee_JobErrorNotification(void);

#endif /* FEE_H */
/**********************************************************************************************************************
 *  END OF FILE: fee.h
 *********************************************************************************************************************/
