(73条消息) AUTOSAR-Fee模块_一ye残雪的博客-CSDN博客_fee 配置
0 前言
Fee模块全称Flash EEPROM Emulation Module,属于ECU抽象层
Fee模块本身是脱离硬件的,但是Fee模块可能会引用的Fls模块定制API,所以只能算半抽象
本文中,由于Fls模块提供的API都是Fls_17_Dmu打头的非标准API,所以Fee模块也必须使用英飞凌的定制版本
Fee模块最精简任务包括:
1 Fee模块的设计原理
1.1 逻辑扇区和双扇区算法
在【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)
过程:
1.2 逻辑块和地址空间
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模块决定的,唯一但不连续
1.3 立即数据和阈值空间
包含即时数据(Immediate Data)的块必须即时写入,不允许出现Immediate Data写到一半,突然发现FeeLogicalSector0写不下,要等待换扇区的情况
为了避免这一情况,在FeeLogicalSector上设定阈值空间(Threshold Value),当FeeLogicalSector上剩余空间小于Threshold Value时,自动触发换扇区操作
显然Threshold Value必须大于所有包含Immediate Data的Logical Block的和
Immediate Write是最高优先级操作,NvM模块会取消正在进行的低优先级Read/Erase/Write或Compare作业
1.4 配置指针和状态指针
Fee模块作为ECU抽象层的模块,需要在Fls模块后初始化
Fee模块需要一个用const修饰的静态外部变量Fee_Config存放模块初始化时所需的配置参数,Fee_Config保存在数据段(.data)
Fee模块需要一个静态外部变量FeeStateVar存放模块状态参数,FeeStateVar保存在未初始化段(.bss)。Fee模块每一个操作中都需要读取或修改FeeStateVar
2 Fee模块的C语言实现
2.1 C文件架构
2.2 使用到的类定义和状态枚举
2.3 配置指针和状态指针
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
}
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;
2.4 Fee模块提供的API
Fee_Init
void Fee_Init(Fee_ConfigType* Fee_Config)
由EcuM模块调用Fee_Init完成对Fee模块的初始化
Fee_Init需要排在Fls_17_Dmu_Init的后面
初始化所需参数在配置指针Fee_Config中,初始化包括对DMU寄存器的初始化和对状态指针FeeStateVar的初始化
初始化后,Fee模块的Module Status==MEMIF_IDLE,Job Result=MEMIF_JOB_OK
Fee_MainFunction
void Fee_Mainfunction (void)
Fee_MainFunction在Default_BSW_Async_Task_Core0中以10ms周期被调用,负责执行异步job
Fee_MainFunction根据FeeStateVar->FeeMainJob确定当前任务,FeeStateVar->FeeMainJob有以下状态:
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 Mode
Fee_MainFunction在处理完一个job后,将调用Job End Notification,或者如果发生错误,将执行Job Error Notification
Fee_Read
Std_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获取数据的虚拟地址
虚拟地址转换为Block Instance在Flash中的实际地址
调用Fls_17_Dmu_Read,将实际地址上的数据存入DataBufferPtr指向的RAM区域
异步Job,在Fee_MainFunction中执行
此Job只有在Module Status==MEMIF_IDLE才能请求
Fee_Write
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
异步Job,在Fls_17_Dmu_MainFunction中执行
此Job只有在Module Status==MEMIF_IDLE才能请求
Fee_Cancel
void Fee_Cancel (void) |
Fee_GetStatus
MemIf_StatusType Fee_GetStatus (void)
返回Fee模块的Module Status
同步job,立即执行
Fee_GetJobResult
MemIf_StatusType Fee_GetJobResult (void)
返回最近或当前处理的Job Result
同步job,立即执行
Fee_SetMode
void Fee_SetMode (MemIf_ModeType Mode)
调用Fls_SetMode
同步job,立即执行
此job只有在Module Status==MEMIF_IDLE才能请求
Set Mode supported决定是否启用API
2.5 Fee模块提供的Callback
Fee_JobEndNotification
void Fee_JobEndNotification (void)
当Fls模块成功处理一个Job时,向Fee模块返回此回调函数
Fee_JobEndNotification会调用Fls_17_Dmu_GetNotifCaller,获取状态&FlsStateVar->NotifCaller,从而知道哪个Job返回此Callback Function
Fee_JobErrorNotification
void Fee_JobErrorNotification (void)
当Fls模块处理一个Job失败时,向Fee模块返回此回调函数
Fee_JobErrorNotification会调用Fls_17_Dmu_GetNotifCaller,获取状态&FlsStateVar->NotifCaller,从而知道哪个Job返回此Callback Function
2.6 Fee模块使用的外部API
Det_ReportError
Std_ReturnType Det_ReportError
(
uint16 ModuleId,
uint8 InstanceId,
uint8 ApiId,
uint8 ErrorId
)
来自Det模块的API,检测并报告开发错误,由Dev Error Detect启用
ModuleId==FEE_MODULE_ID或21
InstanceId=0
ApiId如下
ErrorId有7个,示例如下
FEE_E_UNINIT
FEE_E_INVALID_BLOCK_NO
Mcal_ReportSafetyError
Std_ReturnType Mcal_ReportSafetyError
(
uint16 ModuleId,
uint8 InstanceId,
uint8 ApiId,
uint8 ErrorId
)
来自MCAL的API,检测并报告安全错误,由Safety Enable启用
安全错误是指DMU寄存器中记录的错误,由内联函数读取,其中部分错误和开发错误相同
ModuleId,InstanceId,ApiId同 Det_ReportError
ErrorId有8个,示例如下
FEE_SE_UNINIT
FEE_SE_INVALID_BLOCK_NO
2.7 Fee模块使用的外部Callback
NvM_JobEndNotification
void NvM_JobEndNotification (void)
Fee模块接收到Fls模块发送的Fee_JobEndNotification后,向NvM模块返回此回调函数
NvM_JobEndNotification会在当前NVRAM块信息中写入NVM_REQ_OK
NvM_JobErrorNotification
void NvM_JobErrorNotification (void)
Fee模块接收到Fls模块发送的Fee_JobErrorNotification后,向NvM模块返回此回调函数
NvM_JobErrorNotification会在当前NVRAM块信息中写入NVM_REQ_NOT_OK、NVM_REQ_NV_INVALIDATE或NVM_REQ_INTEGRITY_FAILED
3 Fee模块的DaVinci Configurator配制
3.1 Fee\FeeBlockConfigurations
每个Logical Block都有一个FeeBlockConfiguration页面,配制Logical Block的基本属性
属性 | 说明 |
Device Index | 将当前Block关联到Fls\FlsGeneral |
Blcok Number | 根据NvM模块配制自动生成,无法修改 |
Blcok Size | • 自动生成,系统在NvM模块定义的Block Length基础上加CRC长度(32位CRC则加4byte) • CRC长度取决于NvM模块的Crc Type |
Immediate Data | • Immediate Data开启表明Block包含Immediate Data 依据NvM模块自动生成 |
Number Of Write Cycles | • Block的最大Write寿命 • 选择1200000 |
Quasi Static Manager | Block Type Configured选择FEE_SECTOR_AND_QUASI_STATIC_DATA或者FEE_QUASI_STATIC_DATA_ONLY才有意义 |
Qs Block Address | Block Type Configured选择FEE_SECTOR_AND_QUASI_STATIC_DATA或者FEE_QUASI_STATIC_DATA_ONLY才有意义 |
Qs Block Instances | Block Type Configured选择FEE_SECTOR_AND_QUASI_STATIC_DATA或者FEE_QUASI_STATIC_DATA_ONLY才有意义 |
4.2 Fee\FeeGeneral
FeeGeneral部分主要对应Fee_Cfg.h文件中的常量宏定义和开关宏定义
属性 | 说明 |
Main Function Period [s] | Fee_MainFunction调用周期,要和NvM_MainFunction一致,通常为0.01 |
Virtual Page Size | Virtual Page Size必须是Flash Page的整数倍 在AUTOSAR中已经被限制只能填8 |
Polling Mode | 开启则选择Polling Mode,关闭则选择Callback Mode 选择False |
Block Type Configured | 使用NvM模块则必须选择FEE_DOUBLE_SECTOR_DATA_ONLY |
Nvm Job End Notification | NvM模块提供NvM_JobEndNotification回调函数 不填则给Fee_Config.FeeNvMJobEndNotification 赋值NULL_PTR |
Nvm Job Error Notification | NvM模块提供NvM_JobErrorNotification回调函数 不填则给Fee_Config.FeeNvMJobErrorNotification 赋值NULL_PTR |
Qs Job End Notificatio | Block Type Configured选择FEE_SECTOR_AND_QUASI_STATIC_DATA或者FEE_QUASI_STATIC_DATA_ONLY才有意义 |
Qs Job Error Notification | Block Type Configured选择FEE_SECTOR_AND_QUASI_STATIC_DATA或者FEE_QUASI_STATIC_DATA_ONLY才有意义 |
Dev Error Detect | 宏定义开关,是否启用Det模块检测开发错误 如果启用Dev Error Detect,则添加#include Det.h并启用APIDet_ReportError 选择False |
Safety Enable | 宏定义开关,是否启用MCAL层检测安全错误 如果使用Safety Enable,则模块添加#include Mcal_SafetyError.h,启用APIMcal_ReportSafetyError 选择False |
Init Check Api | 宏定义开关,是否启用API Fee_InitCheck,返回Fee模块是否完成初始化 选择False |
Set Mode supported | 宏定义开关,是否启用API Fee_SetMode 选择False |
Version Info Api | 宏定义开关,是否启用APIFee_GetVersionInfo 选择False |
3.3 Fee\FeeIfxSpecificConfig
此页操作英飞凌特有的配制信息
属性 | 说明 |
Cancel All Api | 宏定义开关,是否启用API Fee_17_CancelAll 开启则允许取消所有当前任务,优先Write high priority quasi static data Block Type Configured选择FEE_SECTOR_AND_QUASI_STATIC_DATA才有意义 选择False |
Erase All Enable | 给Fee_Config->FeeEraseAllEnable赋值 True:当Sector处于illegal state时,将DF0_EEPROM格式化然后恢复之前的数据 False:当Sector处于illegal state时无法恢复,陷入死循环 选择True |
Gc Restart | 给Fee_Config->FeeGCConfigSetting->FeeGcResertPoint赋值 FEE_GC_RESTART_INIT:当Fee模块初始化后,restart GC FEE_GC_RESTART_WRITE:当Fee模块初始化且第一个Read/Write/Invalidate请求后,restart GC 选择FEE_GC_RESTART_INIT |
Get Cycle Count Api | 宏定义开关,是否启用API Fee_17_GetCycleCount获取block cycle和erase cycle 选择True |
Get Prev Data Api | 宏定义开关,是否启用API Fee_17_GetPrevData获取上一个Block Instance数据 选择Fals |
Max Block Count | 配制的Block数量 |
Max Bytes Per Cycle | 一个Fee_MainFunction周期内最大数据处理量 选择FEE_MAX_BYTES_512 |
Nvm Illegal State Notification | Fee模块提供Fee_NvMIllegalStateNotification回调函数 不填则给Fee_Config.NvMIllegalStateNotification 赋值NULL_PTR 一般不填 |
Qs Harden Error Notification | Block Type Configured选择FEE_SECTOR_AND_QUASI_STATIC_DATA或者FEE_QUASI_STATIC_DATA_ONLY才有意义 |
Qs Illegal State Notification | Block Type Configured选择FEE_SECTOR_AND_QUASI_STATIC_DATA或者FEE_QUASI_STATIC_DATA_ONLY才有意义 |
State Var Struct | 定义Fee模块状态指针名称,默认的就够用了 |
Threshold Value | Sector中剩余内存小于Threshold Value时触发garbage collect和sector change |
Um Config Blk Overflow Handler | FEE_CONTINUE: GC时遇到unconfigurated block直接跳过 FEE_STOP_AT_GC: GC时遇到unconfigurated block短暂进入只读状态 选FEE_CONTINUE |
Um Config Block | FEE_UNCONFIG_BLOCK_IGNORE: GC时不复制unconfigurated block FEE_UNCONFIG_BLOCK_KEEP: GC时赋值unconfigurated block 选FEE_UNCONFIG_BLOCK_IGNORE |
Use Erase Suspend | 启用时,Fee模块可以中断GC操作,优先进行Read/Write请求 这是TC389的硬件功能 选择False |
Virgin Flash Illegal State | 选择False |
3.4 Fee\FeeDemEventParamterRefs
本页是Error后Dem模块对应的Action,不填代表FEE_DISABLE_DEM_REPORT
E GC ERASE
E GC INIT
E GC READ
E GC TRIG
E GC WRITE
E INVALIDATE
E READ
E UNCONFIG BLK EXCEEDED
E WRITE
E WRITE CYCLES EXHAUSTED