CAN模块是用来配置CAN Driver的,里面有CanConfigSet是用来配置驱动内容的,CanGeneral配置参数。涉及四个文件Can_Lcfg.c/Can_Lcfg.h/Can_Cfg.c/Can_Cfg.h
CanConfigSet
CanControllers
CAN控制器,我们这里的CAN控制器只有一个,名字是默认的。
里面能够选择的就是用哪个CAN控制器,选完之后下面的基地址会改变,这个控制器是指我们MCU里面的CAN外设。
CAN控制器对应的内容是DemoFbl\Appl\GenData\Can_Lcfg.c里面,主要改变的就是基地址。
CONST(Can_ControllerConfigType, CAN_CONST) Can_ControllerConfig[1] = { /* PRQA S 1514, 1533 */ /* MD_CSL_ObjectOnlyAccessedOnce */
/* Index BaseAddress CanControllerDefaultBaudrate TxPollingMask1 CanControllerDefaultBaudrateIdx InterruptMask1 MailboxRxBasicEndIdx MailboxRxBasicLength MailboxRxBasicStartIdx MailboxTxBasicEndIdx MailboxTxBasicLength MailboxTxBasicStartIdx MailboxUnusedEndIdx MailboxUnusedLength MailboxUnusedStartIdx NumberOfFilters NumberOfFullConfigurableFilters NumberOfMaxMailboxes RFFN RxBasicHwStart RxBasicHwStop RxFullHwStart RxFullHwStop TxBasicHwStart TxBasicHwStop TxFullHwStart TxFullHwStop UnusedHwStart UnusedHwStop Comment Referable Keys */
{ /* 0 */ 0x40024000u, 500u, 0x0100u, 0u, 0x00u, 2u /* RX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 1u /* RX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 1u /* RX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 1u /* TX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 1u /* TX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 0u /* TX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 4u /* UNUSED_CAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 2u /* UNUSED_CAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 2u /* UNUSED_CAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 0x08u, 0x08u, 0x20u, 0x00u, 0u, 1u, 8u, 8u, 8u, 9u, 9u, 9u, 1u, 32u } /* [CT_HSCAN_bce71fc0] */ /* [/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0] */
};
发送和接收处理可以选择为轮询或者中断
/* Interrupt / Polling */
#define CAN_TX_PROCESSING CAN_POLLING /* CAN318_Conf */
#define CAN_RX_PROCESSING CAN_POLLING /* CAN317_Conf */
#define CAN_BUSOFF_PROCESSING CAN_POLLING /* CAN314_Conf */
#define CAN_WAKEUP_PROCESSING CAN_POLLING /* CAN319_Conf */
CanControllerBaudrateConfigs
里面只有一个CanControllerBaudrateConfig,包含CAN控制器的位时序相关配置参数,这些参数熟悉CAN通讯的基本一眼就能看出来,就是个波特率时钟、波特率分频、波特率和采样点、采样模式。TASD Value是发送仲裁延迟。
对应的内容是DemoFbl\Appl\GenData\Can_Lcfg.c里面的,这里的值就是上面配置的数值,能够一一对应的,查一下芯片规格书就行,这里就不再赘述了。
定义基地址、波特率、
#define CAN_START_SEC_CONST_UNSPECIFIED
/*lint -save -esym(961, 19.1) */
#include "MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */
/*lint -restore */
CONST(Can_ControllerConfigType, CAN_CONST) Can_ControllerConfig[1] = { /* PRQA S 1514, 1533 */ /* MD_CSL_ObjectOnlyAccessedOnce */
/* Index BaseAddress CanControllerDefaultBaudrate TxPollingMask1 CanControllerDefaultBaudrateIdx InterruptMask1 MailboxRxBasicEndIdx MailboxRxBasicLength MailboxRxBasicStartIdx MailboxTxBasicEndIdx MailboxTxBasicLength MailboxTxBasicStartIdx MailboxUnusedEndIdx MailboxUnusedLength MailboxUnusedStartIdx NumberOfFilters NumberOfFullConfigurableFilters NumberOfMaxMailboxes RFFN RxBasicHwStart RxBasicHwStop RxFullHwStart RxFullHwStop TxBasicHwStart TxBasicHwStop TxFullHwStart TxFullHwStop UnusedHwStart UnusedHwStop Comment Referable Keys */
{ /* 0 */ 0x40025000u, 500u, 0x0100u, 0u, 0x00u, 2u /* RX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 1u /* RX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 1u /* RX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 1u /* TX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 1u /* TX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 0u /* TX_BASICCAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 4u /* UNUSED_CAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 2u /* UNUSED_CAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 2u /* UNUSED_CAN_TYPE/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0 (DefRef: /MICROSAR/Can_ImxFlexcan3/Can/CanConfigSet/CanController) */, 0x08u, 0x08u, 0x10u, 0x00u, 0u, 1u, 8u, 8u, 8u, 9u, 9u, 9u, 1u, 16u } /* [CT_HSCAN_bce71fc0] */ /* [/ActiveEcuC/Can/CanConfigSet/CT_HSCAN_bce71fc0] */
};
#define CAN_STOP_SEC_CONST_UNSPECIFIED
/*lint -save -esym(961, 19.1) */
#include "MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */
/*lint -restore */
定义采样点
/**********************************************************************************************************************
Can_InitObject
**********************************************************************************************************************/
/**
\var Can_InitObject
\brief This table contains information about the init object: e.g. bustiming register contents.
\details
Element Description
CBT
Control1
*/
#define CAN_START_SEC_CONST_UNSPECIFIED
/*lint -save -esym(961, 19.1) */
#include "MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */
/*lint -restore */
CONST(Can_InitObjectType, CAN_CONST) Can_InitObject[1] = { /* PRQA S 1514, 1533 */ /* MD_CSL_ObjectOnlyAccessedOnce */
/* Index CBT Control1 Comment */
{ /* 0 */ 0x812010C2u, 0x09322004u } /* ["CT_HSCAN_bce71fc0 - CanControllerBaudrateConfig", init object index: 0] */
};
#define CAN_STOP_SEC_CONST_UNSPECIFIED
/*lint -save -esym(961, 19.1) */
#include "MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */
/*lint -restore */
CanFilterMask
是描述CAN标识符基于硬件过滤的掩码,receiveID & Mask == Code & Mask时过滤,一般不会过滤,都是0。
如果你使用了,就会体现在DemoFbl\Appl\GenData\Can_Lcfg.c的Can_InitBasicCan里面。
CanHardwareObjects
这里面没什么好配置的,就是默认一个发送对象和一个接收对象。
拿发送对象举个例子,CanFdPaddingValue是填充数据,CanHandleType可以选择基础CAN还是full CAN。CanIdType选择CAN ID是标准、扩展还是混合的,由于我们这里是乘用车,就只需要基础的。CanIdValue也就是CAN掩码。CanObjectType只是方向是发送还是接收。
CanGeneral
CAN硬件参数配置,处理Can_MainFunction_Busoff(处理总线关闭)、Can_MainFunction_Mode(状态迁移)、Can_MainFunction_Wakeup(总线唤醒)函数的调用周期。