1.前言:autosar通信系列介绍
这个系列是全新的系列,整个系列会通过实际操作,调试实际的代码,以can为例,完整的解析autosar的从底层mcal 到com等上层模块的通信链路层。重点讲述数据的流向,以及各个模块的作用,配置方法。
通过这个系列,将会以代码的视角,了解如ipdu lpdu sdu hoh hth hrh mb等autosar抽象概念的实际实现及其数据结构,以及在真实的autosar 架构软件中,can canif pdur com cantp 等模块中数据的传输,配置参数,函数的调用等各个方面。让我们在使用autosar配置通信的同时,不被其架空,不当只会配置的工具人。
系列将会从mcal自底向上,一步步分析各个模块,搞清楚整个通信的发送机制,和通信的接收机制。
2.can_write函数介绍,以及hoh抽象的实施 messgebuffer介绍
整个的can发送,实际上是由can模块里面的can_write实现的。我们先以s32k14x mcal代码为实例,介绍can_write函数的发送机制,以对l_pdu hoh hth message buffer这些抽象建立起基本的概念。
ecu执行完必要的初始化函数和设置controller模式后,我们就可以调用can_write函数来发送报文了。
can_write函数的传入参数有两个:
hth:hardware transmit handle 硬件传输句柄。这个的详细讲解在后面。pduinfo(此即lpdu data link layer protocol)结构体成员如下:
id:can报文id
swpduhandle:lpdu 句柄,此句柄在canif层定义。每个句柄表示的是1个lpdu.用来在发送的最后时刻触发pdu的tx_confirmation.
length:lpdu数据长度,即报文的长度。
sdu:lpdu的数据指针。实例:can_write函数介绍,以及hoh抽象的实施 messgebuffer介绍
我们以一个简单的例子说明:
如下是代码:
如下是报文:
这个例子介绍了autosar发送报文的最底层接口的使用方法,可以先建立一个直观的印象。
can_write的第一个参数hth是autosar标准里面的一个概念,接下来的内容的讲解目的是为了透彻的理解hth。
autosar从mcal开始 就对can进行抽象了,抽象出hoh hardware object handle 硬件处理对象,hoh以发送和接收的不同,分为了hth,hrh,这俩可以统称为hoh。
hoh对象包括很多属性,如
can implementation type(full/basic)
can id message type(standard/mixed/extend)
can controller reference (使用哪个can controler)
number of hw objects used to implement one hoh
等等属性。
当我们用其中的一个hoh作为对象来发送报文时,这个报文的发送属性会继承这个hoh对象的所有属性。
举例说明:
eb(s32k148)中配置了如下几个hoh:
这里的配置实际会影响的是can_pbcfg中的messgebuffer的配置结构体,messgebuffer结构体数组是hoh的具体实施,它的含义下文详细描述。can object id即为hoh的id。
在can_write例子中我们传入hth的是4,即利用hoh_3_ecutestnode_cancluster这个hoh作为对象,进行发送。
深入can_write中,调用的是can_flexcan_write的这个函数:
他会先搜索messge buffer配置结构体中u32hwobjid为hth,即为4的这个配置。
messge buffer的配置结构体的部分成员:
static const(can_mbconfigobjecttype, can_const) messagebufferconfigs0_pb[can_maxmbcount_pb] ={ /* hoh_0_ecutestnode_cancluster message buffer of can controller id = 0u*/ { (can_hwhandletype)0x0u, /* uidmaskindex */ (uint8)0u, /* controllerid - based on the order from cancontroller list */ (canidtype)can_standard, /* id type: extended, standard, mixed */ (can_objtype)can_receive, /* receive/transmit mb configuration */ (can_idtype)0x0u, /* messageid */ (uint8)0x0u, /* local priority bits used for arbitration */ (can_hwhandletype)0x0u, /* hardware object id */ #if (can_fd_mode_enable == std_on) (uint8)0u, #endif /* read/write period reference used when polling mode is selected for the controller */ (uint8)0u, /* hoh configured for interrupt mode, reference not used */ (uint16)0x0080u, /* address of message buffer */ (uint8)8u, /* payload lenth of message buffer */ (uint8)0u /* the index of mb in message buffer memory */ #if (can_trigger_transmit_en == std_on) /* the parameter is used to detect the mb which run with trigger transmit feature */ ,(boolean)false #endif }, /* hoh_3_udstx_node message buffer of can controller id = 0u*/ { (can_hwhandletype)can_maxmaskcount, /* uidmaskindex */ (uint8)0u, /* controllerid - based on the order from cancontroller list */ (canidtype)can_standard, /* id type: extended, standard, mixed */ (can_objtype)can_transmit, /* receive/transmit mb configuration */ (can_idtype)0x7eau, /* messageid */ (uint8)0x0u, /* local priority bits used for arbitration */ (can_hwhandletype)0x1u, /* hardware object id */ #if (can_fd_mode_enable == std_on) (uint8)0u, #endif /* read/write period reference used when polling mode is selected for the controller */ (uint8)0u, /* hoh configured for interrupt mode, reference not used */ (uint16)0x0180u, /* address of message buffer */ (uint8)8u, /* payload lenth of message buffer */ (uint8)16u /* the index of mb in message buffer memory */ #if (can_trigger_transmit_en == std_on) /* the parameter is used to detect the mb which run with trigger transmit feature */ ,(uint8)false #endif }, /* hoh_3_nmtx_node message buffer of can controller id = 0u*/ { (can_hwhandletype)can_maxmaskcount, /* uidmaskindex */ (uint8)0u, /* controllerid - based on the order from cancontroller list */ (canidtype)can_standard, /* id type: extended, standard, mixed */ (can_objtype)can_transmit, /* receive/transmit mb configuration */ (can_idtype)0x424u, /* messageid */ (uint8)0x0u, /* local priority bits used for arbitration */ (can_hwhandletype)0x2u, /* hardware object id */ #if (can_fd_mode_enable == std_on) (uint8)0u, #endif /* read/write period reference used when polling mode is selected for the controller */ (uint8)0u, /* hoh configured for interrupt mode, reference not used */ (uint16)0x0190u, /* address of message buffer */ (uint8)8u, /* payload lenth of message buffer */ (uint8)17u /* the index of mb in message buffer memory */ #if (can_trigger_transmit_en == std_on) /* the parameter is used to detect the mb which run with trigger transmit feature */ ,(uint8)false #endif }, /* hoh_3_xcptx_node message buffer of can controller id = 0u*/ { (can_hwhandletype)can_maxmaskcount, /* uidmaskindex */ (uint8)0u, /* controllerid - based on the order from cancontroller list */ (canidtype)can_standard, /* id type: extended, standard, mixed */ (can_objtype)can_transmit, /* receive/transmit mb configuration */ (can_idtype)0x667u, /* messageid */ (uint8)0x0u, /* local priority bits used for arbitration */ (can_hwhandletype)0x3u, /* hardware object id */ #if (can_fd_mode_enable == std_on) (uint8)0u, #endif /* read/write period reference used when polling mode is selected for the controller */ (uint8)0u, /* hoh configured for interrupt mode, reference not used */ (uint16)0x01a0u, /* address of message buffer */ (uint8)8u, /* payload lenth of message buffer */ (uint8)18u /* the index of mb in message buffer memory */ #if (can_trigger_transmit_en == std_on) /* the parameter is used to detect the mb which run with trigger transmit feature */ ,(uint8)false #endif }, /* hoh_3_ecutestnode_cancluster message buffer of can controller id = 0u*/ { (can_hwhandletype)can_maxmaskcount, /* uidmaskindex */ (uint8)0u, /* controllerid - based on the order from cancontroller list */ (canidtype)can_standard, /* id type: extended, standard, mixed */ (can_objtype)can_transmit, /* receive/transmit mb configuration */ (can_idtype)0x110u, /* messageid */ (uint8)0x0u, /* local priority bits used for arbitration */ (can_hwhandletype)0x4u, /* hardware object id */ #if (can_fd_mode_enable == std_on) (uint8)0u, #endif /* read/write period reference used when polling mode is selected for the controller */ (uint8)0u, /* hoh configured for interrupt mode, reference not used */ (uint16)0x01b0u, /* address of message buffer */ (uint8)8u, /* payload lenth of message buffer */ (uint8)19u /* the index of mb in message buffer memory */ #if (can_trigger_transmit_en == std_on) /* the parameter is used to detect the mb which run with trigger transmit feature */ ,(uint8)false #endif }, /* hoh_3_ecutestnode_cancluster message buffer of can controller id = 0u*/ { (can_hwhandletype)can_maxmaskcount, /* uidmaskindex */ (uint8)0u, /* controllerid - based on the order from cancontroller list */ (canidtype)can_standard, /* id type: extended, standard, mixed */ (can_objtype)can_transmit, /* receive/transmit mb configuration */ (can_idtype)0x110u, /* messageid */ (uint8)0x0u, /* local priority bits used for arbitration */ (can_hwhandletype)0x4u, /* hardware object id */ #if (can_fd_mode_enable == std_on) (uint8)0u, #endif /* read/write period reference used when polling mode is selected for the controller */ (uint8)0u, /* hoh configured for interrupt mode, reference not used */ (uint16)0x01c0u, /* address of message buffer */ (uint8)8u, /* payload lenth of message buffer */ (uint8)20u /* the index of mb in message buffer memory */ #if (can_trigger_transmit_en == std_on) /* the parameter is used to detect the mb which run with trigger transmit feature */ ,(uint8)false #endif },........所以上文函数搜索到的第一个结构体成员一定是第一个hardware object id为4的这个mb 结构体:
/* hoh_3_ecutestnode_cancluster message buffer of can controller id = 0u*/ { (can_hwhandletype)can_maxmaskcount, /* uidmaskindex */ (uint8)0u, /* controllerid - based on the order from cancontroller list */ (canidtype)can_standard, /* id type: extended, standard, mixed */ (can_objtype)can_transmit, /* receive/transmit mb configuration */ (can_idtype)0x110u, /* messageid */ (uint8)0x0u, /* local priority bits used for arbitration */ (can_hwhandletype)0x4u, /* hardware object id */ #if (can_fd_mode_enable == std_on) (uint8)0u, #endif /* read/write period reference used when polling mode is selected for the controller */ (uint8)0u, /* hoh configured for interrupt mode, reference not used */ (uint16)0x01b0u, /* address of message buffer */ (uint8)8u, /* payload lenth of message buffer */ (uint8)19u /* the index of mb in message buffer memory */ #if (can_trigger_transmit_en == std_on) /* the parameter is used to detect the mb which run with trigger transmit feature */ ,(uint8)false #endif },以这个成员的配置去改变对应的寄存器,从而让发送的报文继承这里面的属性。
我们现在需要搞明白的就剩这个messgebuffer配置结构体。
结构体里面的属性的含义,这些看eb的can模块的配置手册可以搞明白,我想介绍的是messgebuffer这个机制。这是s32k flex can的机制
这是 flex can的报文缓冲。报文缓冲有很多,配置好相关寄存器,最后将报文数据写入报文缓冲,可完成发送。
我们注意到messagebufferconfigs0_pb中的每个结构体成员都有表示address of message buffer的属性和表示the index of mb in message buffer memory的属性。这属性各个成员全不同并且是序号,地址按顺序递增的现象。所以这些结构体成员就是一个一个不同的messagebuffer。再注意到之前提到的can_write中传入的hth即是这里的hardware object id。最后两个结构体,你发现他们虽然message buffer的地址不同,但是共用一个hth号4.实际上完整的messagebuffer的定义,有十个结构体成员都是共用4号hth.
这是由eb配置项number of hw objects used to implement one hoh配为10决定的。这里 hw objects即不同的messagebuffer。但是他们关联了同个hth。换言之1个hth中可以包括多个messagebuffer。即hth是比messagebuffer是更高层的抽象,例子中向can_write传入这个id为4的hth,可以有10个messagebuffer供选择写入数据,一个messgebuffer被占了我再找下个messagebuffer。这样的配置作用就是使用这个hth,可以在极短时间同时支持最多10个报文的发送。
以上例子can_write函数的底层实现的逻辑简化说明如下:
1.轮询messge buffer配置结构体中u32hwobjid为hth是4的mb结构体成员。
2找到第一个hth为4的messagebuffer。传入lpdu数据,尝试更新messagebuffer发送,再判断是否是can_busy状态。假如是,找下一个hth为4的mb继续尝试发送,直到成功发送出去一次,返回can_ok。
这期的介绍就到这里,本期我们可以搞清楚什么是lpdu,什么是hoh和hth。从hoh的实际实施可以看出,所谓的autosar抽象,即将某个对象的所有配置,用结构体数组打包在一起,然后给他们编号。这个编号和各个对象的配置一一对应。后面需要使用这个对象的时候即使用编号去索引对应的结构体数组即可。这个思路会贯穿整个的autosar实现。
圆柱电池46XX产品提升户外储能安全性能
MaximD类功率放大器,MAX98355与MAX98356优势性能介绍
比特币价格出现波动的原因是什么
如何利用5G技术解决移动端云游戏的两大痛点?
手机屏幕的任何地方都能进行身份识别?韩国创出新型透明柔性指纹传感器
CAN发送的底层逻辑:CANwrite函数机制介绍
携住科技与华为达成合作,推出“携住数智酒店”服务卡片
电子封装陶瓷基板
晶圆代工产能供不应求在2021上半年难以解决
富士康iPhone 5产量已达每天15万部
高效可靠的驱动电源温控解决方案:TB02温度开关
GDPR对企业的影响分析
2019年科技新趋势:生物识别技术将进入大规模应用阶段
通过Vivado HLS 为软件编写加速器实例分析
2023年5月新能源市场:增速复苏 插电混动走强
5G网络切片的优势和技术挑战
连接器周报:排名第一巨头,如何连接未来?
2011年的三星Galaxy S2为何能够适配Android 11系统?
2021年星链首发成功,SpaceX发射卫星总数已超1000颗
OCTEON III处理器能有低功耗、高吞吐量的处理能力离不开64位MIPS架构