1.前言:AUTOSAR通信系列介紹
這個系列是全新的系列,整個系列會通過實際操作,調(diào)試實際的代碼,以CAN為例,完整的解析AUTOSAR的從底層MCAL 到COM等上層模塊的通信鏈路層。重點講述數(shù)據(jù)的流向,以及各個模塊的作用,配置方法。
通過這個系列,將會以代碼的視角,了解如IPDU LPDU SDU HOH HTH HRH MB等AUTOSAR抽象概念的實際實現(xiàn)及其數(shù)據(jù)結(jié)構(gòu),以及在真實的AUTOSAR 架構(gòu)軟件中,CAN CANIF PDUR COM CANTP 等模塊中數(shù)據(jù)的傳輸,配置參數(shù),函數(shù)的調(diào)用等各個方面。讓我們在使用AUTOSAR配置通信的同時,不被其架空,不當(dāng)只會配置的工具人。
系列將會從MCAL自底向上,一步步分析各個模塊,搞清楚整個通信的發(fā)送機(jī)制,和通信的接收機(jī)制。
2.Can_write函數(shù)介紹,以及HOH抽象的實施 MessgeBuffer介紹
整個的CAN發(fā)送,實際上是由Can模塊里面的Can_write實現(xiàn)的。我們先以S32K14x MCAL代碼為實例,介紹Can_write函數(shù)的發(fā)送機(jī)制,以對L_PDU HOH HTH Message Buffer這些抽象建立起基本的概念。
ECU執(zhí)行完必要的初始化函數(shù)和設(shè)置controller模式后,我們就可以調(diào)用Can_Write函數(shù)來發(fā)送報文了。
Can_Write函數(shù)的傳入?yún)?shù)有兩個:
- hth:hardware transmit handle 硬件傳輸句柄。這個的詳細(xì)講解在后面。
- PduInfo(此即LPDU Data link Layer protocol)結(jié)構(gòu)體成員如下:
id:CAN報文ID
swPduHandle:LPDU 句柄,此句柄在Canif層定義。每個句柄表示的是1個LPDU.用來在發(fā)送的最后時刻觸發(fā)PDU的tx_confirmation.
length:LPDU數(shù)據(jù)長度,即報文的長度。
sdu:LPDU的數(shù)據(jù)指針。
實例:Can_write函數(shù)介紹,以及HOH抽象的實施 MessgeBuffer介紹
我們以一個簡單的例子說明:
如下是代碼:
如下是報文:
這個例子介紹了AUTOSAR發(fā)送報文的最底層接口的使用方法,可以先建立一個直觀的印象。
can_write的第一個參數(shù)hth是AUTOSAR標(biāo)準(zhǔn)里面的一個概念,接下來的內(nèi)容的講解目的是為了透徹的理解hth。
AUTOSAR從MCAL開始 就對CAN進(jìn)行抽象了,抽象出HOH Hardware object handle 硬件處理對象,HOH以發(fā)送和接收的不同,分為了HTH,HRH,這倆可以統(tǒng)稱為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
等等屬性。
當(dāng)我們用其中的一個HOH作為對象來發(fā)送報文時,這個報文的發(fā)送屬性會繼承這個HOH對象的所有屬性。
舉例說明:
EB(S32K148)中配置了如下幾個HOH:
這里的配置實際會影響的是Can_PBcfg中的MessgeBuffer的配置結(jié)構(gòu)體,MessgeBuffer結(jié)構(gòu)體數(shù)組是HOH的具體實施,它的含義下文詳細(xì)描述。Can Object ID即為HOH的ID。
在Can_write例子中我們傳入HTH的是4,即利用HOH_3_EcuTestNode_CanCluster這個HOH作為對象,進(jìn)行發(fā)送。
深入Can_write中,調(diào)用的是Can_FlexCan_Write的這個函數(shù):
他會先搜索Messge Buffer配置結(jié)構(gòu)體中u32HWObjID為hth,即為4的這個配置。
Messge Buffer的配置結(jié)構(gòu)體的部分成員:
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
},........
所以上文函數(shù)搜索到的第一個結(jié)構(gòu)體成員一定是第一個Hardware Object ID為4的這個MB 結(jié)構(gòu)體:
/* 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
},
以這個成員的配置去改變對應(yīng)的寄存器,從而讓發(fā)送的報文繼承這里面的屬性。
我們現(xiàn)在需要搞明白的就剩這個MessgeBuffer配置結(jié)構(gòu)體。
結(jié)構(gòu)體里面的屬性的含義,這些看EB的CAN模塊的配置手冊可以搞明白,我想介紹的是MessgeBuffer這個機(jī)制。這是S32K Flex CAN的機(jī)制
這是 Flex CAN的報文緩沖。報文緩沖有很多,配置好相關(guān)寄存器,最后將報文數(shù)據(jù)寫入報文緩沖,可完成發(fā)送。
我們注意到MessageBufferConfigs0_PB中的每個結(jié)構(gòu)體成員都有表示Address of Message Buffer的屬性和表示The index of MB in message buffer memory的屬性。這屬性各個成員全不同并且是序號,地址按順序遞增的現(xiàn)象。所以這些結(jié)構(gòu)體成員就是一個一個不同的Messagebuffer。再注意到之前提到的Can_Write中傳入的Hth即是這里的Hardware Object ID。最后兩個結(jié)構(gòu)體,你發(fā)現(xiàn)他們雖然Message Buffer的地址不同,但是共用一個Hth號4.實際上完整的Messagebuffer的定義,有十個結(jié)構(gòu)體成員都是共用4號Hth.
這是由EB配置項Number of Hw objects used to implement one HOH配為10決定的。這里 Hw objects即不同的MessageBuffer。但是他們關(guān)聯(lián)了同個Hth。換言之1個Hth中可以包括多個MessageBuffer。即HTH是比MessageBuffer是更高層的抽象,例子中向Can_Write傳入這個ID為4的hth,可以有10個MessageBuffer供選擇寫入數(shù)據(jù),一個MessgeBuffer被占了我再找下個MessageBuffer。這樣的配置作用就是使用這個HTH,可以在極短時間同時支持最多10個報文的發(fā)送。
以上例子Can_write函數(shù)的底層實現(xiàn)的邏輯簡化說明如下:
1.輪詢Messge Buffer配置結(jié)構(gòu)體中u32HWObjID為hth是4的MB結(jié)構(gòu)體成員。
2找到第一個hth為4的MessageBuffer。傳入LPDU數(shù)據(jù),嘗試更新MessageBuffer發(fā)送,再判斷是否是CAN_BUSY狀態(tài)。假如是,找下一個Hth為4的MB繼續(xù)嘗試發(fā)送,直到成功發(fā)送出去一次,返回CAN_OK。
這期的介紹就到這里,本期我們可以搞清楚什么是LPDU,什么是HOH和HTH。從HOH的實際實施可以看出,所謂的AUTOSAR抽象,即將某個對象的所有配置,用結(jié)構(gòu)體數(shù)組打包在一起,然后給他們編號。這個編號和各個對象的配置一一對應(yīng)。后面需要使用這個對象的時候即使用編號去索引對應(yīng)的結(jié)構(gòu)體數(shù)組即可。這個思路會貫穿整個的AUTOSAR實現(xiàn)。
-
寄存器
+關(guān)注
關(guān)注
31文章
5372瀏覽量
121284 -
CAN通信
+關(guān)注
關(guān)注
5文章
94瀏覽量
17947 -
緩沖器
+關(guān)注
關(guān)注
6文章
1953瀏覽量
45676 -
AUTOSAR
+關(guān)注
關(guān)注
10文章
363瀏覽量
21802 -
PDU
+關(guān)注
關(guān)注
0文章
94瀏覽量
17038
發(fā)布評論請先 登錄
相關(guān)推薦
邏輯函數(shù)與邏輯問題的介紹
ESM6802 Android版支持雙CAN通信
請問CAN接收中斷DSP底層會怎么樣?
EPP邏輯接口WinDriver底層驅(qū)動的可視化
iTOP-iMX6開發(fā)板-Android-can測試?yán)?b class='flag-5'>介紹
在can底層驅(qū)動配置好的前提下,向DSP發(fā)送任何數(shù)據(jù),can就能接收到數(shù)據(jù)嗎
邏輯代數(shù)與邏輯函數(shù)
邏輯函數(shù)與邏輯問題的描述
![<b class='flag-5'>邏輯</b><b class='flag-5'>函數(shù)</b>與<b class='flag-5'>邏輯</b>問題的描述](https://file1.elecfans.com//web2/M00/A4/B5/wKgZomUMNVyAN3xfAAABT7GAGtI797.gif)
CAN為什么會發(fā)送失敗
![<b class='flag-5'>CAN</b>為什么會<b class='flag-5'>發(fā)送</b>失敗](https://file1.elecfans.com//web2/M00/A6/C8/wKgZomUMQGSAS482AAGuk1SPenQ038.jpg)
CAN底層驅(qū)動數(shù)據(jù)的傳輸需要注意什么
![<b class='flag-5'>CAN</b><b class='flag-5'>底層</b>驅(qū)動數(shù)據(jù)的傳輸需要注意什么](https://file.elecfans.com/web2/M00/00/4D/pYYBAGC5zhOAERf4AABF_AQ998g581.png)
評論