>>返回AUTOSAR系列文章目录<<
Fee模块全称Flash EEPROM Emulation Module,属于ECU抽象层
Fee模块本身是脱离硬件的,但是Fee模块可能会引用的Fls模块定制API,所以只能算半抽象
本文中,由于Fls模块提供的API都是Fls_17_Dmu
打头的非标准API,所以Fee模块也必须使用英飞凌的定制版本
Fee模块最精简任务包括:
在【AUTOSAR-Fls模块】2.1 Flash Emulation EEPROM已经介绍在Fls模块层面上的Flash Emulation EEPROM原理
在Fee模块层面上,首先将所管辖的Flash分为分区(Partition),每个Fls模块的FlsSector为一个Partition(通常只有1个)
每个Partition分为2个逻辑扇区(FeeLogicalSector),也称为Virtual Sector,等价于Fls模块的FlsPhysicalSector
Fee模块以FeeLogicalSector为单位进行Erase操作
双扇区算法换扇区过程在英飞凌中称为GC(Garbage Collection)
GC过程:
Actived
,FeeLogicalSector1状态为Not Actived
Actived
Not Actived
Actived
Not Actived
Fee模块向上层提供32位虚拟地址空间(Virtual Linear Address Space),其中
Fee模块地址最小单位为Virtual Page,当前AUTOSAR下Virtual Page必须为8 byte
每个Logical Block首地址必须与一个VirtualPage首地址对齐,Logical Block尾地址如果不与一个Virtual Page对齐,则自动添加unused地址,对齐到最近的VirtualPage尾地址
Logical Block的Block Number是由NvM模块决定的,唯一但不连续
包含即时数据(Immediate Data)的块必须即时写入,不允许出现Immediate Data写到一半,突然发现FeeLogicalSector0写不下,要等待换扇区的情况
为了避免这一情况,在FeeLogicalSector上设定阈值空间(Threshold Value),当FeeLogicalSector上剩余空间小于Threshold Value时,自动触发换扇区操作
显然Threshold Value必须大于所有包含Immediate Data的Logical Block的和
Immediate Write是最高优先级操作,NvM模块会取消正在进行的低优先级Read/Erase/Write或Compare作业
Fee模块作为ECU抽象层的模块,需要在Fls模块后初始化
Fee模块需要一个用const修饰的静态外部变量Fee_Config
存放模块初始化时所需的配置参数,Fee_Config
保存在数据段(.data)
Fee模块需要一个静态外部变量FeeStateVar
存放模块状态参数,FeeStateVar
保存在未初始化段(.bss)。Fee模块每一个操作中都需要读取或修改FeeStateVar
>>返回AUTOSAR系列文章目录<<
静态文件 | 描述 |
---|---|
Fee.h | 包含API所需的状态枚举常量、类定义、状态指针FeeStateVar 声明 |
Fee.c | API代码 |
Fee_Cbk.h | Callback Function声明 |
动态文件 | 描述 |
---|---|
StartApplication_Fee_ecuc.arxml | Configurator生成的本地配置文件 |
Fee_Bswmd.arxml | |
Fee_Cfg.h | 包含项目所需的常量宏定义、开关宏定义 |
Fee_PBcfg.h | 包含配制指针Fee_Config 声明 |
Fee_PBcfg.c | 包含配制指针Fee_Config 赋值 |
MemIf定义的类 | 描述 | 定义来源 |
---|---|---|
MemIf_StatusType | 描述Fls模块的Module Status: 1. MEMIF_UNINIT 模块未初始化 2. MEMIF_IDLE 没有需要处理的job 3. MEMIF_BUSY 模块正在处理job,不接受新job |
MemIf_Types.h |
MemIf_JobResultType | 描述Fls模块的Job Result 1. MEMIF_JOB_OK job处理成功 2. MEMIF_JOB_FAILED job处理以error结束 3. MEMIF_JOB_PENDING job正在处理 4. MEMIF_JOB_CANCELLED job已经取消 |
MemIf_Types.h |
MemIf_ModeType | 描述Fls模块的Processing Mode: 1. MEMIF_MODE_SLOW Slow模式 2. MEMIF_MODE_FAST Fast模式 |
MemIf_Types.h |
Std定义的类 | 描述 | 定义来源 |
---|---|---|
Std_ReturnType | 描述Job Request结果 1. E_OK 对同步指令,表示指令执行成功 对异步指令,表示指令被队列接受 2. E_NOT_OK 对同步指令,表示指令执行失败 对异步指令,表示指令被队列拒绝 |
Std_Type.h |
Fee_Config
在Fee_PBcfg.c中赋值,示例如下:const Fee_ConfigType Fee_Config =
{
/* State结构体指针,未赋值 */
.FeeStatePtr = &(Fee_StateDataType)FeeStateVar,
/* Pointer to Logical Block configuration */
.FeeBlockConfigPtr = &(Fee_BlockType)Fee_BlockConfig[0],
/* Fee Job End Notification Api */
.FeeNvMJobEndNotificationPtr = &(Fee_NotificationPtrType)NvM_JobEndNotification,
/* Fee Job Error Notification Api */
.FeeNvMJobErrorNotificationPtr = &(Fee_NotificationPtrType)NvM_JobErrorNotification,
/* Fee threshold value */
.FeeThresholdLimit = (uint32)1024U,
/* Number of block configurated */
.FeeBlkCnt = (uint16)81U,
/* Fee settings for unconfigured blocks and GC restart */
.FeeGCConfigSetting =
{
/* Treatment to unconfigured blocks */
.FeeUnconfigBlock = FEE_UNCONFIG_BLOCK_IGNORE,
/* when Garbage Collection restart */
.FeeGcResertPoint = FEE_GC_RESTART_INIT,
/* Enable or disable Erase Suspend feature */
.FeeUseEraseSuspend = FEE_ERASE_SUSPEND_DISABLE,
/* Reserved */
.unused = 0U,
}, // Fee_GCConfigType
/* Fee Illegal State Notification */
.FeeNvMIllegalStateNotification = (Fee_NotificationPtrType)NULL_PTR,
/* Fee QS Illegal State Notification */
.FeeQsIllegalStateNotification = (Fee_NotificationPtrType)NULL_PTR,
/* Fee Hardening Error Notification */
.FeeQsHardenErrorNotification = (Fee_NotificationPtrType)NULL_PTR,
/* Enable or disable Erase All feature */
.FeeEraseAllEnable = (boolean)True
}
FeeStateVar
在Fee.h中定义类型,在Fee_PBcfg.c中声明typedef struct
{
/* Fee Sector Info */
Fee_SectorInfoType FeeSectorInfo[FEE_SECTORS];
/* Fee Cache Info */
Fee_CacheType FeeBlockInfo[FEE_TOTAL_BLOCK_COUNT];
/* Last Written Block Info */
Fee_LastWrittenBlkInfoType FeeLastWrittenBlkInfo;
/* Current Block Being Written during GC */
Fee_GcBlkInfoType FeeGcCurrBlkInfo;
//以下省略
}Fee_StateDataType;
Fee_StateDataType FeeStateVar;
void Fee_Init (Fee_ConfigType* Fee_Config ) |
---|
Fee_Init
完成对Fee模块的初始化Fee_Init
需要排在Fls_17_Dmu_Init
的后面Fee_Config
中,初始化包括对DMU寄存器的初始化和对状态指针FeeStateVar
的初始化MEMIF_IDLE
,Job Result=MEMIF_JOB_OK
void Fee_Mainfunction (void) |
---|
Fee_MainFunction
在Default_BSW_Async_Task_Core0
中以10ms周期被调用,负责执行异步jobFee_MainFunction
根据FeeStateVar->FeeMainJob
确定当前任务,FeeStateVar->FeeMainJob
有以下状态:FEE_MAIN_UNINIT
FEE_MAIN_INITGC
FEE_MAIN_CACHEUPDATE
FEE_MAIN_READ
FEE_MAIN_WRITE
FEE_MAIN_GC
Fee_MainFunction
在一次周期中处理的数据量取决于配置的Processing Mode = Fast Mode / Slow ModeFee_MainFunction
在处理完一个job后,将调用Job End Notification,或者如果发生错误,将执行Job Error NotificationStd_ReturnType Fee_Read ( uint16 BlockNumber ,uint16 BlockOffset ,uint8* DataBufferPtr ,uint16 Length ) |
---|
Fee_Read
设置状态FeeMainJob=FEE_MAIN_READ
Fee_MainFunction
执行后检测到FEE_MAIN_READ
,开始处理BlockNumber
转为BlockId
,通过BlockOffset
、Length
获取数据的虚拟地址Fls_17_Dmu_Read
,将实际地址上的数据存入DataBufferPtr
指向的RAM区域Fee_MainFunction
中执行MEMIF_IDLE
才能请求Std_ReturnType Fee_Write ( uint16 BlockNumber ,uint8* DataBufferPtr ) |
---|
Fee_Write
设置状态FeeMainJob=FEE_MAIN_WRITE
Fee_MainFunction
执行后检测到FEE_MAIN_WRITE
,开始处理BlockNumber
转为BlockId
,转换为Block Instance在Flash中的实际地址Fls_17_Dmu_Write
Fls_17_Dmu_MainFunction
中执行MEMIF_IDLE
才能请求void Fee_Cancel (void) |
---|
MemIf_StatusType Fee_GetStatus (void) |
---|
MemIf_StatusType Fee_GetJobResult (void) |
---|
void Fee_SetMode (MemIf_ModeType Mode ) |
---|
Fls_SetMode
MEMIF_IDLE
才能请求void Fee_JobEndNotification (void) |
---|
Fee_JobEndNotification
会调用Fls_17_Dmu_GetNotifCaller
,获取状态&FlsStateVar->NotifCaller
,从而知道哪个Job返回此Callback Functionvoid Fee_JobErrorNotification (void) |
---|
Fee_JobErrorNotification
会调用Fls_17_Dmu_GetNotifCaller
,获取状态&FlsStateVar->NotifCaller
,从而知道哪个Job返回此Callback FunctionStd_ReturnType Det_ReportError ( uint16 ModuleId ,uint8 InstanceId ,uint8 ApiId ,uint8 ErrorId ) |
---|
来自Det模块的API,检测并报告开发错误,由Dev Error Detect启用
ModuleId
==FEE_MODULE_ID
或21
InstanceId
=0
ErrorId
有7个,示例如下
FEE_E_UNINIT
FEE_E_INVALID_BLOCK_NO
Std_ReturnType Mcal_ReportSafetyError ( uint16 ModuleId ,uint8 InstanceId ,uint8 ApiId ,uint8 ErrorId ) |
---|
ModuleId
,InstanceId
,ApiId
同 Det_ReportError
ErrorId
有8个,示例如下FEE_SE_UNINIT
FEE_SE_INVALID_BLOCK_NO
void NvM_JobEndNotification (void) |
---|
Fee_JobEndNotification
后,向NvM模块返回此回调函数NvM_JobEndNotification
会在当前NVRAM块信息中写入NVM_REQ_OK
void NvM_JobErrorNotification (void) |
---|
Fee_JobErrorNotification
后,向NvM模块返回此回调函数NvM_JobErrorNotification
会在当前NVRAM块信息中写入NVM_REQ_NOT_OK
、NVM_REQ_NV_INVALIDATE
或NVM_REQ_INTEGRITY_FAILED
>>返回AUTOSAR系列文章目录<<
每个Logical Block都有一个FeeBlockConfiguration页面,配制Logical Block的基本属性
配制 | Configurator选项 | Device Index -> referrence |
---|
配制 | Configurator选项 | Blcok Number -> [1, 65535] |
---|---|---|
影响 | Fee_PBcfg.c | static const Fee_BlockType Fee_BlockConfig []{ .BlockNumber= } |
配制 | Configurator选项 | Blcok Size -> [1, 65535] |
---|---|---|
影响 | Fee_PBcfg.c | static const Fee_BlockType Fee_BlockConfig []{ .Size= } |
配制 | Configurator选项 | Immediate Data -> True/False |
---|---|---|
影响 | Fee_PBcfg.c | static const Fee_BlockType Fee_BlockConfig []{ .FeeImmdiateData= } |
配制 | Configurator选项 | Number Of Write Cycles -> [1, :] |
---|---|---|
影响 | Fee_PBcfg.c | static const Fee_BlockType Fee_BlockConfig []{ .CycleCountLimit= } |
1200000
配制 | Configurator选项 | Quasi Static Manager -> True/False |
---|
FEE_SECTOR_AND_QUASI_STATIC_DATA
或者FEE_QUASI_STATIC_DATA_ONLY
才有意义配制 | Configurator选项 | Qs Block Address -> [0, :] |
---|
FEE_SECTOR_AND_QUASI_STATIC_DATA
或者FEE_QUASI_STATIC_DATA_ONLY
才有意义配制 | Configurator选项 | Qs Block Instances -> [0, 128] |
---|
FEE_SECTOR_AND_QUASI_STATIC_DATA
或者FEE_QUASI_STATIC_DATA_ONLY
才有意义FeeGeneral部分主要对应Fee_Cfg.h文件中的常量宏定义和开关宏定义
配制 | Configurator选项 | Main Function Period [s] -> [0.001, 1] |
---|
Fee_MainFunction
调用周期,要和NvM_MainFunction
一致,通常为0.01
配制 | Configurator选项 | Virtual Page Size -> [8] |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_VIRTUAL_PAGE_SIZE |
8
配制 | Configurator选项 | Polling Mode -> True/False |
---|
False
配制 | Configurator选项 | Block Type Configured -> enum:FEE_DOUBLE_SECTOR_DATA_ONLY FEE_DOUBLE_SECTOR_AND_QUASI_STATIC_DATA FEE_QUASI_STATIC_DATA_ONLY |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_DATA_BLOCK_SUPPORTED |
FEE_DOUBLE_SECTOR_DATA_ONLY
配制 | Configurator选项 | Nvm Job End Notification -> NvM_JobEndNotification 或 不填 |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { .FeeNvMJobEndNotificationPtr = } |
NvM_JobEndNotification
回调函数Fee_Config.FeeNvMJobEndNotification
赋值NULL_PTR
配制 | Configurator选项 | Nvm Job Error Notification -> NvM_JobErrorNotification 或 不填 |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { .FeeNvMJobErrorNotificationPtr = } |
NvM_JobErrorNotification
回调函数Fee_Config.FeeNvMJobErrorNotification
赋值NULL_PTR
配制 | Configurator选项 | Qs Job End Notification -> Qs_JobEndNotification 或 不填 |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { .FeeQsJobEndNotificationPtr = } |
FEE_SECTOR_AND_QUASI_STATIC_DATA
或者FEE_QUASI_STATIC_DATA_ONLY
才有意义配制 | Configurator选项 | Qs Job Error Notification -> Qs_JobErrorNotification 或 不填 |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { .FeeQaJobErrorNotificationPtr = } |
FEE_SECTOR_AND_QUASI_STATIC_DATA
或者FEE_QUASI_STATIC_DATA_ONLY
才有意义配制 | Configurator选项 | Dev Error Detect -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_DEV_ERROR_DETECT |
#include Det.h
并启用APIDet_ReportError
False
配制 | Configurator选项 | Safety Enable -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_SAFETY_ENABLE |
#include Mcal_SafetyError.h
,启用APIMcal_ReportSafetyError
False
配制 | Configurator选项 | Init Check Api -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_INITCHECK_API |
Fee_InitCheck
,返回Fee模块是否完成初始化False
配制 | Configurator选项 | Set Mode supported -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_SET_MODE_SUPPORTED |
Fee_SetMode
False
配制 | Configurator选项 | Version Info Api -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_VERSION_INFO_API |
Fee_GetVersionInfo
False
此页操作英飞凌特有的配制信息
配制 | Configurator选项 | Cancel All Api -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_CANCEL_ALL_API |
Fee_17_CancelAll
FEE_SECTOR_AND_QUASI_STATIC_DATA
才有意义False
配制 | Configurator选项 | Erase All Enable -> True/False |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { .FeeEraseAllEnable= } |
Fee_Config->FeeEraseAllEnable
赋值True
:当Sector处于illegal state时,将DF0_EEPROM格式化然后恢复之前的数据False
:当Sector处于illegal state时无法恢复,陷入死循环True
配制 | Configurator选项 | Gc Restart -> enum:FEE_GC_RESTART_INIT FEE_GC_RESTART_WRITE |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { .FeeGCConfigSetting { .FeeGcResertPoint= } } |
Fee_Config->FeeGCConfigSetting->FeeGcResertPoint
赋值FEE_GC_RESTART_INIT
:当Fee模块初始化后,restart GCFEE_GC_RESTART_WRITE
:当Fee模块初始化且第一个Read/Write/Invalidate请求后,restart GCFEE_GC_RESTART_INIT
配制 | Configurator选项 | Get Cycle Count Api -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_GET_CYCLE_COUNT_API |
Fee_17_GetCycleCount
获取block cycle和erase cycleTrue
配制 | Configurator选项 | Get Cycle Count Api -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_GET_PREV_DATA_API |
Fee_17_GetPrevData
获取上一个Block Instance数据False
配制 | Configurator选项 | Max Block Count -> [1, :] |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_MAX_BLOCK_COUNT |
配制 | Configurator选项 | Max Bytes Per Cycle -> enum:FEE_MAX_BYTES_64 FEE_MAX_BYTES_128 FEE_MAX_BYTES_256 FEE_MAX_BYTES_512 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_MAX_BYTES_PER_CYCLE |
Fee_MainFunction
周期内最大数据处理量FEE_MAX_BYTES_512
配制 | Configurator选项 | Nvm Illegal State Notification -> NvM_IllegalStateNotification 或 不填 |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { … } |
Fee_NvMIllegalStateNotification
回调函数Fee_Config.NvMIllegalStateNotification
赋值NULL_PTR
配制 | Configurator选项 | Qs Harden Error Notification -> 不填 |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { … } |
FEE_SECTOR_AND_QUASI_STATIC_DATA
或者FEE_QUASI_STATIC_DATA_ONLY
才有意义配制 | Configurator选项 | Qs Illegal State Notification -> 不填 |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { … } |
FEE_SECTOR_AND_QUASI_STATIC_DATA
或者FEE_QUASI_STATIC_DATA_ONLY
才有意义配制 | Configurator选项 | State Var Struct -> FeeStateVar |
---|---|---|
影响 | Fee_PBcfg.c | static Fee_StateDataType FeeStateVar |
配制 | Configurator选项 | Threshold Value -> [0, :] |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { … } |
配制 | Configurator选项 | Um Config Blk Overflow Handler -> enum:FEE_CONTINUE FEE_STOP_AT_GC |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { … } |
FEE_CONTINUE
: GC时遇到unconfigurated block直接跳过FEE_STOP_AT_GC
: GC时遇到unconfigurated block短暂进入只读状态FEE_CONTINUE
配制 | Configurator选项 | Um Config Blk Overflow Handler -> enum:FEE_UNCONFIG_BLOCK_IGNORE FEE_UNCONFIG_BLOCK_KEEP |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { … } |
FEE_UNCONFIG_BLOCK_IGNORE
: GC时不复制unconfigurated blockFEE_UNCONFIG_BLOCK_KEEP
: GC时赋值unconfigurated blockFEE_UNCONFIG_BLOCK_IGNORE
配制 | Configurator选项 | Use Erase Suspend -> True/False |
---|---|---|
影响 | Fee_PBcfg.c | const Fee_ConfigType Fee_Config { … } |
False
配制 | Configurator选项 | Virgin Flash Illegal State -> True/False |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_VIRGIN_FLASH_ILLEGAL_STATE |
False
本页是Error后Dem模块对应的Action,不填代表FEE_DISABLE_DEM_REPORT
配制 | Configurator选项 | E GC ERASE -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_GC_ERASE_DEM_REPORT |
配制 | Configurator选项 | E GC INIT -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_GC_INIT_DEM_REPORT |
配制 | Configurator选项 | E GC READ -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_GC_READ_DEM_REPORT |
配制 | Configurator选项 | E GC TRIG -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_GC_TRIG_DEM_REPORT |
配制 | Configurator选项 | E GC WRITE -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_GC_WRITE_DEM_REPORT |
配制 | Configurator选项 | E INVALIDATE -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_INVALIDATE_DEM_REPORT |
配制 | Configurator选项 | E READ -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_READ_DEM_REPORT |
配制 | Configurator选项 | E UNCONFIG BLK EXCEEDED -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_UNCFG_BLK_DEM_REPORT |
配制 | Configurator选项 | E WRITE -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_WRITE_DEM_REPORT |
配制 | Configurator选项 | E WRITE CUCLES EXHAUSTED -> 不填 |
---|---|---|
影响 | Fee_Cfg.h | #define FEE_WRITE_CYCLES_DEM_REPORT |
>>返回AUTOSAR系列文章目录<<