【Memory协议栈】Memory Abstraction Interface模块介绍

目录

前言

正文

1.功能简介

2.关键概念

3.关键类型定义

3.1 MemIf_StatusType

3.2 MemIf_JobResultType

3.3 MemIf_ModeType

4.关键API定义

4.1 MemIf_SetMode

4.2 MemIf_Read

4.3 MemIf_Write

4.4 MemIf_Cancel

4.5 MemIf_GetStatus

4.6 MemIf_GetJobResult

4.7 MemIf_InvalidateBlock

4.8 MemIf_EraseImmediateBlock

4.9 MemIf_EraseImmediateBlock

5.依赖的接口

6.小结


前言

存储协议栈负责ECU中非易失性数据的存储管理。存储协议栈的分享包括NVM、MemI、Ea、Fea、Eep、Fls模块的详细介绍及代码分析,具体的项目实战请关注本号的后续文章,本篇为Memory Abstraction Interface(MemIf)模块详细介绍篇。

正文

1.功能简介

MemIf模提供统一的接口让NVRAM管理器访问几个内存抽象模块(FEE或EA模块)。

内存抽象接口(MemIf)应从底层FEE或EA模块的数量中抽象,并在统一的线性地址空间上提供虚拟分割。

2.关键概念

Fast Mode: 例如,在启动/关闭期间,底层驱动程序可以被切换到快速模式,以便在这些阶段允许快速读/写。

Slow Mode: 在正常操作期间,底层驱动程序可以以慢速模式使用,以减少在底层设备/通信媒体的运行时或阻塞时间方面的资源使用。

注意:Fast Mode和Slow Mode可能取决于驱动程序的实现和底层设备的功能。也可能取决于NVRAM Manage的配置,因此也取决于特定项目的需求。

3.关键类型定义

3.1 MemIf_StatusType

图片

MemIf_StatusType类型标示底层抽象模块和设备驱动器的当前状表态。

3.2 MemIf_JobResultType

图片

图片

MemIf_JobResultType表示上一个作业的结果。

3.3 MemIf_ModeType

图片

MemIf_ModeType表示底层抽象模块和设备驱动程序的操作模式。

4.关键API定义

MemIf模块没有自己内部的功能逻辑,所有的API接口都会直接映射到对应的底层抽象模块(Ea, FEE)的API。

如果只配置了一个内存抽象模块,则内存抽象接口应实现为一组宏,将内存抽象接口API映射到相应的内存抽象模块的API。

参数设备索引应用于选择内存抽象模块(以及内存设备)。如果只配置了一个内存抽象模块,则应忽略参数设备索引。

例如

#define MemIf_Write(DeviceIndex, BlockNumber, DataPtr) \Fee_Write(BlockNumber, DataPtr)

如果配置了多个内存抽象模块,则内存抽象接口应使用有效的机制将API调用映射到适当的内存抽象模块。

注意:一种解决方案是使用指向函数的指针表,其中参数开发索引被用作数组索引。​​​​​​​

typedef struct{  uint8 DeviceIndex;  Std_ReturnType  (WriteFctPtr)(uint16 BlockNumber, uint8* DataBufferPtr);}MemIf_Write;
MemIf_Write MemIf_WriteFctPtr[] ={  {0, Fee_Write},  {1, Ea_Write},}

Example:​​​​​​​

#define MemIf_Write(DeviceIndex, BlockNumber, DataPtr) \MemIf_WriteFctPtr[DeviceIndex](BlockNumber,DataPtr)

如果配置了多个内存抽象模块,并且为该模块启用了开发错误检测,则内存抽象接口API的功能应检查参数设备指数是否为现有设备或模块服务中的广播标识符。

内存抽象接口API的功能应向默认错误参数跟踪器(DET)报告检测到的错误,错误代码为MEMIF_E_PARAM_DEVICE,不得执行被调用的服务。

如果内存抽象接口API的调用函数检测到属于非法参数设备索引的错误并具有返回值,则应设置如下:

MemIf_GetStatus: MEMIF_UNINIT

MemIf_GetJobResult: MEMIF_JOB_FAILED

All other functions: E_NOT_OK

4.1 MemIf_SetMode

图片

MemIf_SetMode调用所有底层内存抽象模块的“SetMode”功能。

注意:上述功能中故意遗漏了设备索引,即内存接口应将所有底层模块切换到请求的模式。在这种情况下,不需要一个额外的“广播”参数,因为设备不能单独切换到不同的模式。

4.2 MemIf_Read

图片

图片

MemIf_Read调用由参数DeviceIndex所选择的底层内存抽象模块的“读取”功能。

4.3 MemIf_Write

图片

MemIf_Write调用由参数设备索引所选择的底层内存抽象模块的“写入”功能。

4.4 MemIf_Cancel

图片

图片

MemIf_Cancel调用由参数设备索引所选择的底层内存抽象模块的“取消”功能。

4.5 MemIf_GetStatus

图片

MemIf_GetStatus调用由参数开发索引所选择的底层内存抽象模块的“GetStatus”功能。

4.6 MemIf_GetJobResult

图片

MemIf_GetJobResult调用由参数DeviceIndex所选择的底层内存抽象模块的“GetJobResult”功能。

4.7 MemIf_InvalidateBlock

图片

MemIf_InvalidateBlock调用由参数设备索引选择的底层内存抽象模块的“无效验证块”功能。

4.8 MemIf_EraseImmediateBlock

图片

4.9 MemIf_EraseImmediateBlock

图片

MemIf_EraseImmediateBlock调用由参数设备索引选择的底层内存抽象模块的“立即删除块”功能。

5.依赖的接口

图片

6.小结

如果不同时使用Fee和Ea,则MemIf模块的功能非常简单,就是一个底层Ea或者Fee的宏封装层。

图片

  • 27
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
The STM32 is a family of microcontrollers developed by STMicroelectronics. The AT24C256 is an EEPROM memory IC manufactured by Atmel. The HAL (Hardware Abstraction Layer) is a software library provided by STMicroelectronics for the STM32 microcontroller family. It provides an easy-to-use API for accessing the various peripherals and features of the microcontroller. To use the AT24C256 with an STM32 microcontroller, you would typically use the I2C interface to communicate with the memory IC. The HAL provides functions for setting up and configuring the I2C interface, as well as for reading and writing data to the memory IC. Here is an example of how to use the HAL to read data from the AT24C256: 1. Initialize the I2C interface using the HAL_I2C_Init() function. 2. Send a start condition using the HAL_I2C_Master_Transmit() function. 3. Send the device address (0xA0 for write, 0xA1 for read) using the HAL_I2C_Master_Transmit() function. 4. Send the memory address to read from using the HAL_I2C_Master_Transmit() function. 5. Send another start condition using the HAL_I2C_Master_Receive() function. 6. Receive the data from the memory IC using the HAL_I2C_Master_Receive() function. 7. Send a stop condition using the HAL_I2C_Master_Transmit() function. Here is some sample code: ```c // Initialize I2C interface HAL_I2C_Init(&hi2c1); // Read data from AT24C256 uint8_t data[2]; uint16_t mem_address = 0x1234; // Send start condition HAL_I2C_Master_Transmit(&hi2c1, 0xA0, &mem_address, 2, 100); // Send memory address to read from HAL_I2C_Master_Transmit(&hi2c1, 0xA0, &mem_address, 2, 100); // Send start condition again HAL_I2C_Master_Receive(&hi2c1, 0xA1, data, 2, 100); // Receive data from memory IC HAL_I2C_Master_Receive(&hi2c1, 0xA1, data, 2, 100); // Send stop condition HAL_I2C_Master_Transmit(&hi2c1, 0xA0, 0, 0, 100); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汽车电子嵌入式

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值