DEENESPTFRRUARHIKOZHNL

CAN Driver (Can)

ModulCan (CAN Driver)
BSW-Modul-ID80
Standard-Header#include "Can.h"
SWS-SpezifikationAUTOSAR_SWS_CANDriver.pdf
ClusterCAN

模块指南人工智能生成

控制 CAN 控制器硬件,并在 CAN Interface 之间转发发送、接收和状态切换。
AI 生成 未审核 模型: claude-opus-5-5 · 推理强度: high · 温度: 不可控 · 提示词: b6833c934a77 来源 未决问题(2)
因果锚点:R20-11 自 R20-11 起有效 为此规范版本重新合成。
译自德文指南AI 生成gemini-3.8-flash-low · 2026-10-13 · 德文原文

控制 CAN 控制器硬件,并在 CAN Interface 之间转发发送、接收和状态切换。

CAN 驱动程序控制硬件单元的 CAN 控制器,并且是 CAN Interface 下方的硬件层。它通过回调向 CAN Interface 报告接收、发送确认、Bus-off 和模式切换 [SWS_Can_00234]。在 Can_Init 之后,所有控制器均处于 STOPPED。每个控制器均使用 Can_SetControllerMode 单独且异步启动;成功与否随后才会报告 [SWS_Can_00230]。通过硬件发送句柄使用 Can_Write 进行发送。如果没有可用的发送对象,驱动程序将返回 CAN_BUSY,并且 CanIf 会对请求进行缓冲。

CAN 驱动程序封装了对硬件单元 CAN 控制器的所有访问。它专门为 CAN Interface 提供服务,并通过固定的 CanIf 回调报告接收、发送确认、Bus-off 和模式切换 [SWS_Can_00234]。ECU State Manager 使用 Can_Init 和硬件特定的 Can_ConfigType 对其进行初始化 [SWS_Can_00223]。随后驱动程序处于 CAN_READY,所有控制器处于 STOPPED SWS CANDriver 第29页。

kontext EcuM EcuM Can Can (CAN-Treiber) EcuM->Can Can_Init / Can_DeInit SchM BSW Scheduler SchM->Can Can_MainFunction_* CanSM CanSM CanIf CanIf CanSM->CanIf 模式请求 CanIf->CanSM 模式与 Bus-off 报告 CanIf->Can Can_Write, Can_SetControllerMode, Can_CheckWakeup, Abfragen Can->EcuM EcuM_CheckWakeup, EcuM_SetWakeupEvent Can->CanIf CanIf_RxIndication, CanIf_TxConfirmation, CanIf_ControllerBusOff, CanIf_ControllerModeIndication HW CAN-Controller (Hardware) Can->HW Registerzugriff Det Det Can->Det Det_ReportError / Det_ReportRuntimeError Os Os Can->Os GetCounterValue HW->Can Interrupts / Statusflags

上下文图:Can 嵌入在 EcuM、BSW 调度器、CanIf、DET、Os 和控制器硬件之间。来源:[SWS_Can_00234]、SWS CANDriver 第78页

每个控制器依次经历状态 UNINIT、STOPPED、STARTED 和 SLEEP [SWS_Can_91013]。它使用 Can_SetControllerMode 单独且异步启动:E_OK 仅表示“已接受” [SWS_Can_00230]。驱动程序稍后通过 CanIf_ControllerModeIndication 报告达到的状态 SWS CANDriver 第33页。Bus-off 会在没有硬件恢复的情况下将控制器带入 STOPPED;总线唤醒会将其从 SLEEP 带入 STOPPED SWS CANDriver 第35页。

controllerzustand reset Power-on-Reset UNINIT CAN_CS_UNINIT reset->UNINIT STOPPED CAN_CS_STOPPED UNINIT->STOPPED Can_Init STOPPED->UNINIT Can_DeInit STOPPED->STOPPED Can_SetBaudrate STARTED CAN_CS_STARTED STOPPED->STARTED Can_SetControllerMode(CAN_CS_STARTED) SLEEP CAN_CS_SLEEP STOPPED->SLEEP Can_SetControllerMode(CAN_CS_SLEEP) STARTED->STOPPED Can_SetControllerMode(CAN_CS_STOPPED) 或 Bus-off(硬件) SLEEP->UNINIT Can_DeInit SLEEP->STOPPED Can_SetControllerMode(CAN_CS_STOPPED) 或来自总线的唤醒 SLEEP->SLEEP Can_SetBaudrate

状态图:控制器通过软件调用以及 Bus-off 和唤醒事件进行转换。来源:[SWS_Can_91010]、SWS CANDriver 第38页

使用 Can_Write(Hth, PduInfo) 发送。Can_IdType 的最高两位用于区分 CAN 2.0 与 CAN FD,以及标准 ID 与扩展 ID [SWS_Can_00233] [SWS_Can_00416]。如果没有可用的发送对象,驱动程序将返回 CAN_BUSY,并且 CanIf 会对请求进行缓冲 [SWS_Can_00039] SWS CANDriver 第47页。事件通过中断或轮询检测。针对轮询,提供了周期性主函数 SWS CANDriver 第41页:

  • Write 和 Read:发送确认与接收
  • BusOff 和 Wakeup:Bus-off 和唤醒事件
  • Mode:模式转换

主函数定义在 [SWS_Can_00225] 至 [SWS_Can_00228] 以及 [SWS_Can_00368] 中。

发生错误时,驱动程序会向 DET 报告开发错误(如 CAN_E_UNINIT 或 CAN_E_TRANSITION)[SWS_Can_91019]。带有返回值的函数随后会返回 E_NOT_OK SWS CANDriver 第48页。Bus-off 恢复由 CanSM 通过 CanIf 接管。据推测,重新启动应再次通过 Can_SetControllerMode(CAN_CS_STARTED) 执行 SWS CANInterface 第138页。错误状态和错误计数器可供查询;但计数器值不被视为可靠的总线状态 [SWS_Can_91004] [SWS_Can_00516]。 问题 (未决)

角色:位于 CanIf 与 CAN 控制器之间的底层驱动程序

CAN 驱动程序封装了对硬件单元(Hardware-Unit)的 CAN 硬件的所有访问。控制器的状态更改仅通过 Can_Init、Can_SetBaudrate 和 Can_SetControllerMode 进行。在此过程中,驱动程序本身并不存储状态转换 SWS CANDriver 第30页。它向上对接的伙伴是 CAN 接口(CAN Interface)。驱动程序调用的所有回调均在 CanIf 中实现且不可配置:CanIf_RxIndication、CanIf_TxConfirmation、CanIf_ControllerBusOff 和 CanIf_ControllerModeIndication。此外,它还需要 Det_ReportRuntimeError 以及 Os 服务 GetCounterValue [SWS_Can_00234] SWS CANDriver 第73页。导入的类型除其他外来自 ComStack_Types、EcuM 和 Os [SWS_Can_00222]。

ECU State Manager 通过 Can_Init 初始化驱动程序。根据实现说明,它在运行时最多调用该函数一次 [SWS_Can_00223] SWS CANDriver 第29页。BSW Scheduler 直接调用周期性主函数。它们既没有参数也没有返回值,且不可重入;执行顺序未作规定 SWS CANDriver 第78页。驱动程序向下不提供回调。外部 CAN 控制器只能通过 SPI 等同步 MCAL API 进行访问 SWS CANDriver 第76页。

kontext EcuM EcuM Can Can (CAN-Treiber) EcuM->Can Can_Init / Can_DeInit SchM BSW Scheduler SchM->Can Can_MainFunction_* CanSM CanSM CanIf CanIf CanSM->CanIf 模式请求 CanIf->CanSM 模式与 Bus-off 报告 CanIf->Can Can_Write, Can_SetControllerMode, Can_CheckWakeup, Abfragen Can->EcuM EcuM_CheckWakeup, EcuM_SetWakeupEvent Can->CanIf CanIf_RxIndication, CanIf_TxConfirmation, CanIf_ControllerBusOff, CanIf_ControllerModeIndication HW CAN-Controller (Hardware) Can->HW Registerzugriff Det Det Can->Det Det_ReportError / Det_ReportRuntimeError Os Os Can->Os GetCounterValue HW->Can Interrupts / Statusflags

上下文图:Can 由 EcuM 初始化,由 BSW Scheduler 周期性调用,并由 CanIf 使用。它向 CanIf、EcuM 和 DET 报告,并使用 Os 处理超时。来源:[SWS_Can_00234]、SWS CANDriver 第45页、SWS CANDriver 第78页

从上电到 STARTED:驱动程序与控制器状态

驱动程序作为一个整体仅具有 CAN_UNINIT 和 CAN_READY 状态。复位后它处于 CAN_UNINIT。Can_Init 根据配置初始化所有控制器,随后切换到 CAN_READY。Can_DeInit 在去初始化控制器之前将模块状态设置为 CAN_UNINIT [SWS_Can_00223] [SWS_Can_91002] SWS CANDriver 第29页。

与之分开,每个控制器具有来自 Can_ControllerStateType 的四种状态:CAN_CS_UNINIT、CAN_CS_STOPPED、CAN_CS_STARTED 和 CAN_CS_SLEEP [SWS_Can_91013]。

  • 在 STOPPED 状态下,控制器已初始化,但不参与总线通信,既不发送错误帧(Error Frames)也不发送确认(Acknowledges)。
  • STARTED 为正常运行状态。
  • SLEEP 仅在具备睡眠模式的硬件上与 STOPPED 有所区别 SWS CANDriver 第31页。

Can_Init 将所有控制器置于 STOPPED SWS CANDriver 第32页。Can_DeInit 将它们从 STOPPED 或 SLEEP 引导至 UNINIT [SWS_Can_91010] SWS CANDriver 第38页。从 STARTED 没有直接转入 UNINIT 的路径 SWS CANDriver 第38页。

controllerzustand reset Power-on-Reset UNINIT CAN_CS_UNINIT reset->UNINIT STOPPED CAN_CS_STOPPED UNINIT->STOPPED Can_Init STOPPED->UNINIT Can_DeInit STOPPED->STOPPED Can_SetBaudrate STARTED CAN_CS_STARTED STOPPED->STARTED Can_SetControllerMode(CAN_CS_STARTED) SLEEP CAN_CS_SLEEP STOPPED->SLEEP Can_SetControllerMode(CAN_CS_SLEEP) STARTED->STOPPED Can_SetControllerMode(CAN_CS_STOPPED) 或 Bus-off(硬件) SLEEP->UNINIT Can_DeInit SLEEP->STOPPED Can_SetControllerMode(CAN_CS_STOPPED) 或来自总线的唤醒 SLEEP->SLEEP Can_SetBaudrate

状态图:CAN 控制器的生命周期。软件与总线事件触发转换;唯有 Can_DeInit 能从 STOPPED 或 SLEEP 转回 UNINIT。来源:[SWS_Can_91013]、[SWS_Can_91010]、SWS CANDriver 第38页、SWS CANDriver 第34页、SWS CANDriver 第35页

每个控制器通过 Can_SetControllerMode(CAN_CS_STARTED) 单独启动 SWS CANDriver 第29页。该服务为异步工作:E_OK 仅表示请求已被接受 [SWS_Can_00230]。每次转换至 STARTED 时,控制器都会被重新初始化,并采用 Can_Init 或 Can_SetBaudrate 最近使用的配置 SWS CANDriver 第59页。硬件可能会延迟应用此切换。因此,驱动程序仅在事后通过 CanIf_ControllerModeIndication 报告所达到的状态;是否达到目标状态由上一层监控 SWS CANDriver 第33页。轮询模式转换由 Can_MainFunction_Mode 识别 [SWS_Can_00368]。Can_GetControllerMode 同步查询当前模式 [SWS_Can_91014]。

CAN 控制器的初始化与启动EcuMCanIf-Nutzer (z. B. CanSM)CanIfCanBSW SchedulerCAN-ControllerUse Case: InitialisierungCan_Init(Config)配置所有控制器Controller: CAN_CS_STOPPEDModul: CAN_READYUse Case: Controller einzeln startenCanIf_SetControllerMode(STARTED)Can_SetControllerMode(Controller, CAN_CS_STARTED)Neuinitialisierung,Start anfordernE_OK (Anforderung angenommen)E_OKloop直至转换生效Can_MainFunction_Mode()Statusflag lesenCanIf_ControllerModeIndication(ControllerId, CAN_CS_STARTED)<User_ControllerModeIndication>

时序图:通过 EcuM 进行初始化以及控制器的异步启动。成功通知仅在 Can_MainFunction_Mode 中轮询之后发出。来源:[SWS_Can_00230]、[SWS_Can_00368]、SWS CANInterface 第156页、SWS CANDriver 第29页

通过硬件发送句柄进行发送

CanIf 使用 Can_Write(Hth, PduInfo) 传递发送请求。Hth 指定了硬件发送对象,并由此指定了控制器,因为 HTH 编号在硬件单元内是唯一的 [SWS_Can_00233]。Can_HwHandleType 默认包含 0..0x0FF,当硬件对象超过 255 个时,包含最高至 0xFFFF 的扩展范围 [SWS_Can_00429]。Can_PduType 捆绑了字段 swPduHandle、length、id 和 sdu [SWS_Can_00415]。

在 Can_IdType 中,两个最高有效位对帧类型进行编码 [SWS_Can_00416]:

  • 00:带标准 ID 的 CAN
  • 01:带标准 ID 的 CAN FD
  • 10:带扩展 ID 的 CAN
  • 11:带扩展 ID 的 CAN FD

只要控制器的 FD 波特率配置处于激活状态,就可以在帧级别混合使用 CAN 2.0 帧和 CAN FD 帧 SWS CANDriver 第49页 SWS CANInterface 第71页。

Can_Write 必须是线程安全的,因为 CanIf_Transmit 是可重入的。当没有空闲发送对象或抢占式调用无法以可重入方式执行时,驱动程序返回 CAN_BUSY [SWS_Can_00039] SWS CANDriver 第47页。CanIf 随后缓冲该请求。一旦有对象空闲,CanIf 会按优先级顺序重新调用 Can_Write SWS CANInterface 第48页。驱动程序将 swPduHandle 保留至对应的 CanIf_TxConfirmation 为止 SWS CANDriver 第35页。为了防止优先级反转,可以静态配置多路复用发送(Multiplexed Transmission);此时多个硬件对象构成一个 HTH SWS CANDriver 第40页。

带确认的 L-PDU 发送CanIfCanCAN-ControllerBSW SchedulerCan_Write(Hth, PduInfo)altHardware-Sendeobjekt freiswPduHandle je HTH merkenL-PDU ins Hardwareobjekt,触发发送E_OK无可用对象或不可重入执行CAN_BUSY在 CanIfTxBuffer 中缓冲 L-PDU报文已发送并获得总线确认altInterrupt-BetriebTX-InterruptPolling-BetriebCan_MainFunction_Write()检查待处理的确认CanIf_TxConfirmation(swPduHandle)opt该 HTH 的已缓冲 L-PDUCan_Write(Hth, 最高优先级 L-PDU)

时序图:包含路径 E_OK 和 CAN_BUSY 的发送请求,随后是通过中断或轮询的确认。之后 CanIf 可以跟进发送已缓冲的 L-PDU。来源:[SWS_Can_00233]、[SWS_Can_00039]、SWS CANInterface 第142页、SWS CANInterface 第48页

接收与周期性主函数

接收时,驱动程序调用 CanIf_RxIndication。它传递 ID、硬件对象和抽象的 CanIf-ControllerId 以及 L-SDU 的长度和指针。对于扩展帧,它设置 ID 的 MSB,以便 CanIf 识别帧类型 SWS CANDriver 第43页。此前可选择性接入一个可配置的 L-PDU 标注(Callout)<LPDU_CalloutName> [SWS_Can_00443]。如果它返回 false,根据文档出处(R25-11),该 L-PDU 将不再进一步处理 SWS CANDriver 第77页。

事件通过中断或通过轮询状态标志来识别。完全不使用中断的纯轮询运行模式必须是可配置的。在轮询时,主函数调用相同的回调,只是处于任务上下文而非 ISR 上下文中 SWS CANDriver 第41页。每个主函数轮询一种事件类型:

Read 和 Write 的 R20-11 说明仅提到了 POLLING 的情况 [SWS_Can_00225] [SWS_Can_00226]。后续版本的文档出处补充了 MIXED;此时仅轮询带有 CanHardwareObjectUsesPolling = TRUE 的对象 SWS CANDriver 第81页 SWS CANDriver 第79页。R20-11 需求未证实这一扩展。如果通过 CanMainFunctionRWPeriods 配置了多个周期,则函数名称带有后缀 _<ShortName> [SWS_Can_00441] SWS CANDriver 第122页。在没有任何轮询的情况下,主函数可以实现为空 define SWS CANDriver 第81页。

轮询模式下接收 L-PDUBSW SchedulerCanCAN-ControllerL-PDU-CalloutCanIfCanIf-NutzerloopzyklischCan_MainFunction_Read()检查是否有新的 L-PDUaltneue L-PDU vorhandenID normieren (Extended: MSB = 1),Daten ggf. in angepassten PufferoptL-PDU-Callout konfiguriert<LPDU_CalloutName>(Hrh, CanId, CanDataLegth, CanSduPtr)true / false若为 false:丢弃 L-PDUCanIf_RxIndication(Mailbox, PduInfoPtr)向用户发送 Rx 指示无新 L-PDU

时序图:轮询运行模式下的接收,包含 ID 规范化、可选的 L-PDU 标注以及向 CanIf 的传递。来源:[SWS_Can_00226]、[SWS_Can_00443]、SWS CANInterface 第153页、SWS CANDriver 第43页

睡眠、唤醒与中断控制

驱动程序仅处理控制器自身识别出的唤醒,不处理通过收发器识别出的唤醒 SWS CANDriver 第45页。发生硬件唤醒时,控制器从 SLEEP 转入 STOPPED。触发唤醒的 L-PDU 不会被进一步处理。EcuM_CheckWakeup 在中断或 Can_MainFunction_Wakeup 中被调用,使用通过 CanWakeupSourceRef 配置的源 SWS CANDriver 第35页。随后 EcuM 通过 CanIf 调用 Can_CheckWakeup。该函数通过 EcuM_SetWakeupEvent 报告识别到的唤醒 [SWS_Can_00360] SWS CANDriver 第63页。针对虚假唤醒,EcuM 和 CanIf 在没有驱动程序参与的情况下进行验证 SWS CANDriver 第45页。

Can_DisableControllerInterrupts 和 Can_EnableControllerInterrupts 是可重入的且具有嵌套效果。在 n 次 Disable 调用后,需要 n 次 Enable 调用。在没有事先 Disable 的情况下进行 Enable 不会产生任何效果 [SWS_Can_00231] [SWS_Can_00232] SWS CANDriver 第61页 SWS CANDriver 第62页。

来自 CAN 总线的唤醒CAN-ControllerCanEcuMCanIfUse Case: Controller in CAN_CS_SLEEP来自总线的唤醒事件altInterrupt-BetriebWakeup-ISRPolling-BetriebCan_MainFunction_Wakeup()Controller SLEEP -> STOPPED,不处理触发唤醒的 L-PDUEcuM_CheckWakeup(来自 CanWakeupSourceRef 的源)通过 CanIf 检查唤醒源Can_CheckWakeup(Controller)optWakeup erkanntEcuM_SetWakeupEventE_OKValidierung gegen Fehlwakeups由 EcuM 和 CanIf 执行,无需 Can

时序图:从 SLEEP 发生的总线唤醒、向 EcuM 的报告以及通过 CanIf 使用 Can_CheckWakeup 进行的回查。来源:[SWS_Can_00360]、[SWS_Can_00228]、SWS CANDriver 第45页、SWS CANDriver 第35页

配置集、分区与实例关联

Can_Init 接收指向 Can_ConfigType 的指针。该硬件特定结构包含适用于所有控制器的设置以及对单个控制器配置的引用 [SWS_Can_00223] [SWS_Can_00413]。该模块支持 VARIANT-PRE-COMPILE 和 VARIANT-POST-BUILD SWS CANDriver 第96页。在 Post-build 示例中,调用 Can_Init 时会选择多个配置集之一 EXP LayeredSoftwareArchitecture 第120页。针对每个控制器,CanController 确定了包括 CanRxProcessing、CanTxProcessing、CanBusoffProcessing、CanWakeupProcessing 以及至少一个 CanControllerBaudrateConfig 在内的内容 SWS CANDriver 第101页。

在多分区系统中,该模块在每个分区中作为一个独立的实例工作。API 调用仅在其自身的分区内生效 [SWS_Can_CONSTR_00508]。分区分配遵循三条规则:

一个 ECU 中的多个 Can 模块通过更改函数前缀来区分 SWS CANDriver 第51页。

发生错误时的行为

当开发错误检测(Development Error Detection)激活时,驱动程序向 DET 报告开发错误。错误代码范围从 CAN_E_PARAM_POINTER(0x01)、CAN_E_UNINIT(0x05)和 CAN_E_TRANSITION(0x06)直至 CAN_E_INIT_FAILED(0x09)[SWS_Can_91019]。从 DET 返回后,函数立即返回;带有返回值的函数随后返回 E_NOT_OK SWS CANDriver 第48页。一些示例:

作为运行时错误,针对丢失的接收消息定义了 CAN_E_DATALOST [SWS_Can_91020]。它大概会通过所要求的 Det_ReportRuntimeError 进行报告 [SWS_Can_00234]。 问题 Q-50225b25430c9660 (未决)

当控制器进入 Bus-off 时,它从 STARTED 切换到 STOPPED。驱动程序不执行硬件恢复。它通过中断或在 Can_MainFunction_BusOff 中通过 CanIf_ControllerBusOff 报告该事件 [SWS_Can_00227] SWS CANDriver 第35页。恢复由 CanSM 接管,CanIf 通过 CanSM_ControllerBusOff 通知 CanSM SWS CANInterface 第138页。解释:重启大概率会再次通过 Can_SetControllerMode(CAN_CS_STARTED) 进行,并在该过程中重新加载配置 SWS CANDriver 第59页。 问题 Q-83e484ab9f8b1aac (未决)

Bus-off 检测与报告CAN-ControllerCanBSW SchedulerCanIfCanSMController erreicht Bus-offaltInterrupt-BetriebBus-off-InterruptPolling-BetriebCan_MainFunction_BusOff()Statusbit lesenSTARTED -> STOPPED,无硬件恢复CanIf_ControllerBusOff(ControllerId)CanSM_ControllerBusOffBus-off 恢复由 CanSM 负责Use Case: Neustart (Interpretation)Neustart anfordern (Interpretation)Can_SetControllerMode(Controller, CAN_CS_STARTED)使用以下内容重新初始化zuletzt verwendeter Konfiguration

时序图:直至 CanSM 的 Bus-off 识别与报告。标记为解释的重启未得到显式证实。来源:[SWS_Can_00227]、[SWS_Can_00234]、SWS CANDriver 第35页、SWS CANInterface 第138页

对于诊断,Can_GetControllerErrorState 提供错误状态:ACTIVE、PASSIVE 或 BUSOFF [SWS_Can_91004] [SWS_Can_91003]。Rx 和 Tx 错误计数器同样可被查询。如果控制器不提供这些计数器,函数返回 E_NOT_OK。由于硬件以异步方式维护计数器,因此这些值不适合用于推测总线状态 [SWS_Can_00511] [SWS_Can_00516] SWS CANDriver 第67页。Can_ErrorType 描述了典型硬件错误类型的超集,从位错误到总线锁定 [SWS_Can_91021]。

针对无响应的硬件,驱动程序使用 OsCounter 处理超时 SWS CANDriver 第23页。如果在 CanTimeoutDuration 内模式切换未生效,Can_SetControllerMode 将退出函数,而不是持续阻塞 SWS CANDriver 第33页。如果在转入睡眠模式的过程中发生总线唤醒,Can_SetControllerMode(CAN_CS_STOPPED) 将返回 E_NOT_OK SWS CANDriver 第35页。

进一步详细证据

许多文档出处来自 R23-11 至 R25-11。对于 R20-11 具有规范效力的是所引用的需求。状态图表 SWS CANDriver 第38页 直接出自 R20-11。

基于负载中为 R20-11 提供的需求和文档出处由 AI 生成的指南。推测已标记为解释;最终仍以规范为准。

CAN Driver (Can)

The CAN driver provides hardware-dependent access to the internal and external CAN controllers (CAN 2.0B, CAN FD, CAN XL).

Funktionen — Übersicht

Typen — Übersicht

Funktionen & Typen — Detailansicht

函数 Can_Init [SWS_Can_00223] 📄 PDF

void Can_Init (const Can_ConfigType* Config);

This function initializes the module.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 8afbe47dbadd 来源
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

同步且不可重入的函数 Can_Init 根据传入的配置初始化整个 CAN 驱动程序模块以及关联的硬件单元 [SWS_Can_00223]。

用法与调用上下文

在 ECU 的启动阶段中,Can_Init 的调用由 ECU State Manager 强制执行,且必须在允许调用 CAN 驱动程序的任何其他函数之前进行 [SWS_Can_91012]。作为参数,该函数通过 Config 接收指向驱动程序配置(const Can_ConfigType*)的指针,且不返回任何返回值 [SWS_Can_00223]。

初始化范围与状态转换

在初始化过程中,该函数设置所有必需的硬件寄存器并初始化所有 CAN 控制器 AUTOSAR_SWS_CANDriver 第33页:

通过该函数调用触发 CAN 硬件的状态转换 AUTOSAR_SWS_CANDriver 第10页,其中 Can_Init 执行寄存器配置,以将控制器转换至预期的基本状态 [SWS_Can_91010] AUTOSAR_SWS_CANDriver 第36页。

并发性与限制

由于 Can_Init 被指定为不可重入,因此在正在运行的初始化期间不得发生并行或重复调用 [SWS_Can_00223]。此外,硬件单元的某些全局设置只能在 Can_Init 内设置 AUTOSAR_SWS_CANDriver 第33页。

本使用说明根据 AUTOSAR Classic R20-11 的规范数据自动生成。

实现者指南即将推出(复杂度 I1)

函数 Can_DeInit [SWS_Can_91002] 📄 PDF

void Can_DeInit (void);

This function de - initializes the module.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 982976925c7a 来源 未决问题(2)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

函数 Can_DeInit 用于 CAN 驱动程序模块的去初始化 ([SWS_Can_91002])。它具有签名 void Can_DeInit(void),不接收任何参数,不返回任何返回值,并以同步且不可重入的方式执行 ([SWS_Can_91002])。该接口可通过头文件 Can.h 获取 ([SWS_Can_91002])。

该调用触发一个软件控制的状态转换 (AUTOSAR_SWS_CANDriver 第10页;AUTOSAR_SWS_CANDriver 第41页)。在此过程中,Can_DeInit 切换模块状态 (AUTOSAR_SWS_CANDriver 第33页) 并重置所有 CAN 控制器 (AUTOSAR_SWS_CANDriver 第41页)。

并发性与限制

对于执行,在硬件和模块状态方面存在严格的前提条件和顺序要求:

相互作用

错误与转换行为反映了经清理的驱动程序流程,根据该流程,无效的状态转换将被统一步骤捕获 ([SWS_Can_00441])。

本段文本由 AI 基于 AUTOSAR CP R20-11 规范生成。

函数 Can_SetBaudrate [SWS_CAN_00491] 📄 PDF

Std_ReturnType Can_SetBaudrate (uint8 Controller, uint16 BaudRateConfig ID); ⚠️

This service shall set the baud rate configuration of the CAN controller. Depending on necessary baud rate modifications the controller might have to reset.

函数 Can_SetControllerMode [SWS_Can_00230] 📄 PDF

Std_ReturnType Can_SetControllerMode (uint8 Controller, Can_ControllerStateType Transition);

This function performs software triggered state transitions of the CAN controller State machine.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: a4b356b48b8a 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

函数 Can_SetControllerMode(通过 Can.h 提供,服务 ID 为 0x03)执行 CAN 控制器状态机的软件触发状态转换([SWS_Can_00230], AUTOSAR_SWS_CANDriver 第35页)。它执行与硬件相关的寄存器设置,以实现基本控制器状态 UNINIT、STOPPED、STARTED 和 SLEEP 之间的转换([SWS_Can_91010], AUTOSAR_SWS_CANDriver §7.3 “CAN Controller State Machine”)。

用法与语义

调用时使用参数 Controller 来标识 CAN 控制器,并使用类型为 Can_ControllerStateType 的 Transition 来指定所需的状态转换([SWS_Can_00230])。该服务被定义为异步且不可重入(Non Reentrant)([SWS_Can_00230])。返回值 E_OK 确认请求已被接受;E_NOT_OK 指示请求被拒绝且存在开发错误([SWS_Can_00230], [SWS_Can_00441])。

流程与交互

在设置寄存器配置后,将退出 Can_SetControllerMode(AUTOSAR_SWS_CANDriver 第38页)。由于 Can 模块本身不存储硬件的状态切换([SWS_Can_91010]),周期性函数 Can_Mainfunction_Mode 可能承担由 Can_SetControllerMode 发起的状态转换的异步完成或检查(AUTOSAR_SWS_CANDriver 第38页)。 问题 Q-03edb1b665a1624b (未决)

此文本由 AI 基于 AUTOSAR R20-11 的规范数据生成。

实现者指南即将推出(复杂度 I1)

函数 Can_DisableControllerInterrupts [SWS_Can_00231] 📄 PDF

void Can_DisableControllerInterrupts (uint8 Controller);

This function disables all interrupts for this CAN controller.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 9d72b1d46d5d 来源 未决问题(2)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

同步且可重入的函数 Can_DisableControllerInterrupts 为指定的 CAN 控制器禁用所有中断([SWS_Can_00231])。通过参数 Controller 传入,无返回值([SWS_Can_00231])。

关于调用上下文和并发性,该函数设计为可重入并支持多次调用(AUTOSAR_SWS_CANDriver §8.3 “Can_DisableControllerInterrupts”)。Interpretation:多次调用可能会增加一个内部嵌套计数器,从而使中断仅在相应次数的使能调用之后才重新激活(AUTOSAR_SWS_CANDriver §8.3 “Can_DisableControllerInterrupts”, AUTOSAR_SWS_CANDriver §8.3 “Can_DisableControllerInterrupts”)。 问题 Q-61be56207aa92ee0 (未决)

在错误处理方面,若驱动程序模块在调用时尚未初始化,规范要求触发错误 CAN_E_UNINIT(AUTOSAR_SWS_CANDriver §8.3 “Can_DisableControllerInterrupts”)。此外,规范要求触发另一个错误(AUTOSAR_SWS_CANDriver §8.3 “Can_DisableControllerInterrupts”);这可能用于检查是否存在无效的控制器标识。 问题 (未决)

在 CAN 驱动程序内部的交互中,该调用用于在控制器保持活动状态的同时保护与控制器相关的临界区(AUTOSAR_SWS_CANDriver §7.5 “Interrupt handling”)。驱动程序的形式清理和历史接口变更记录在发行说明中([SWS_Can_00441])。

此文本由 AI 生成,用作规范的补充使用说明。

函数 Can_EnableControllerInterrupts [SWS_Can_00232] 📄 PDF

void Can_EnableControllerInterrupts (uint8 Controller);

This function enables all allowed interrupts.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 374e141963cb 来源 未决问题(2)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

同步且可重入的函数 Can_EnableControllerInterrupts 为通过参数 Controller 指定的 CAN 控制器重新激活所有允许的中断([SWS_Can_00232])。它没有返回值,并通过头文件 Can.h 提供([SWS_Can_00232])。

关于执行流程,该函数读取软件端控制标志(AUTOSAR_SWS_CANDriver 第65页)。如果先前已多次禁用该控制器的中断,则在实际使能之前必须同样多次调用 Can_EnableControllerInterrupts(AUTOSAR_SWS_CANDriver 第65页)。Interpretation:驱动程序可能通过内部计数器或标志来管理嵌套的锁定段,使得硬件中断仅在完全抵消所有禁用调用之后才被重新激活。 问题 Q-6781f0fc9ad7d221 (未决)

如果在 CAN 驱动程序正确初始化之前调用该函数,它将报告错误 CAN_E_UNINIT(AUTOSAR_SWS_CANDriver 第66页)。在驱动程序上下文中,这可能被作为开发错误来处理([SWS_Can_00441])。 问题 Q-efbbcf03a2589e4e (未决)在未初始化状态下,该函数不对控制器执行任何进一步的操作(AUTOSAR_SWS_CANDriver 第66页)。

本使用说明基于规范自动生成。

函数 Can_CheckWakeup [SWS_Can_00360] 📄 PDF

Std_ReturnType Can_CheckWakeup (uint8 Controller);

This function checks if a wakeup has occurred for the given controller.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 720a4fc64f2a 来源
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

使用与行为

同步函数 Can_CheckWakeup 针对特定 CAN 控制器检查是否检测到唤醒事件([SWS_Can_00360], AUTOSAR_SWS_CANDriver 第48页, AUTOSAR_SWS_CANDriver 第67页)。它可通过头文件 Can.h 使用,并具有服务 ID 0x0b([SWS_Can_00360])。

  • 参数:Controller(in)表示要检查其状态是否存在唤醒的 CAN 控制器的标识符([SWS_Can_00360])。
  • 返回值:返回 Std_ReturnType。返回值 E_OK 指示 API 调用已被接受,而 E_NOT_OK 则指示拒绝([SWS_Can_00360])。
  • 并发性:该函数被定义为不可重入(Non Reentrant)([SWS_Can_00360])。

配置与错误处理

该函数的可用性可在预编译时配置;服务 Can_CheckWakeup 可据此包含在代码中或从中移除 (AUTOSAR_SWS_CANDriver 第67页, AUTOSAR_SWS_CANDriver 第97页)。如果在 CAN 驱动程序初始化之前调用该函数,它将报告错误 CAN_E_UNINIT (AUTOSAR_SWS_CANDriver 第67页)。

相互作用

对 Can_CheckWakeup 的调用通常由 CAN 接口触发 (AUTOSAR_SWS_CANDriver 第48页)。在总线发生唤醒事件的情况下,CanIf_CheckWakeup 可以在执行 EcuM_CheckWakeup 期间被调用 (AUTOSAR_SWS_CANInterface §7.18.4.1 “Wake-up detection”)。根据 [SWS_CANIF_00395],CanIf 在此通过 Can_CheckWakeup() 或 CanTrcv_CheckWakeup() 查询具体是哪个硬件设备触发了总线唤醒 (AUTOSAR_SWS_CANInterface 第55页)。

本使用说明由自动系统生成,且完全基于 AUTOSAR 规范版本 R20-11。

函数 Can_GetControllerRxErrorCounter [SWS_Can_00511] 📄 PDF

Std_ReturnType Can_GetControllerRxErrorCounter (uint8 ControllerId, uint8* RxErrorCounterPtr);

Returns the Rx error counter for a CAN controller. This value might not be available for all CAN controllers, in which cas e E_ NOT_ OK would be returned. Please note that the value of the counter might not be correct at the moment the API returns it, because the Rx counter is handled asynchronously in hardware. Applications should not trust this value for any assumption about the current bus state.

函数 Can_GetControllerTxErrorCounter [SWS_Can_00516] 📄 PDF

Std_ReturnType Can_GetControllerTxErrorCounter (uint8 ControllerId, uint8* TxErrorCounterPtr);

Returns the Tx error counter for a CAN controller. This value might not be available for all CAN controllers, in which case E_ NOT_ OK would be returned. Please note that the value of the counter might not be correct at the moment the API returns it, because the Tx counter is handled asynchronously in hardware. Applications should not trust this value for any assumption about the current bus state.

函数 Can_Write [SWS_Can_00233] 📄 PDF

Std_ReturnType Can_Write (Can_HwHandleType Hth, const Can_PduType* PduInfo);

This function is called by Can If to pass a CAN message to Can Drv for transmission.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: f2d4ad3f2f32 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

用法与语义

模块 CanIf 同步调用函数 Can_Write,以将待传输的 CAN 消息传递给 CAN 驱动程序(CanDrv)([SWS_Can_00233])。调用方在此传递两个参数:

  • Hth:硬件发送句柄,用于指定要使用的发送对象并隐式确定控制器,因为句柄编号在硬件单元内是唯一的([SWS_Can_00233])。
  • PduInfo:指向包含 SDU 有效载荷数据、数据长度和 CAN 标识符的结构的指针([SWS_Can_00233])。

在发送之前,该函数检查被寻址的硬件发送对象(SWS_CANDriver 第73页)并保存传入的 swPduHandle(SWS_CANDriver 第43页)。通过类型为 Std_ReturnType(SRS_BSWGeneral §5.2.3.6 “Types and keywords”)的返回值,E_OK 指示接受请求,而 CAN_BUSY 则指示没有可用的硬件发送缓冲区([SWS_Can_00233], SWS_CANDriver 第51页)。

错误处理

如果在执行期间发生开发错误,该函数将返回 E_NOT_OK([SWS_Can_00233], [SWS_Can_00441])。Interpretation:在可用摘录中未明确提及具体 DET 错误代码;然而,错误的句柄或无效指针可能会导致返回 E_NOT_OK。 问题 Q-ca947a7e0e4fd7d6 (未决)

并发性与限制

Can_Write 被指定为可重入或线程安全([SWS_Can_00233], SWS_CANDriver 第49页)。如果驱动程序端无法以可重入方式执行抢占式调用,这也将通过返回值 CAN_BUSY 报告给 CanIf([SWS_Can_00233])。调用方必须确保 PDU 内存直到函数调用返回为止保持不变且有效(SWS_CANDriver 第45页)。

相互作用

在调用时通过 [SWS_Can_00416] 传递所涉及的 PDU 类型(SWS_CANDriver 第51页),其中驱动程序支持直至最大 PDU 长度的传输(SWS_CANDriver 第52页)。

本使用说明基于 AUTOSAR R20-11 的规范文档自动生成。

函数 <LPDU_CalloutName> [SWS_Can_00443] 📄 PDF

boolean <LPDU_CalloutName> (uint8 Hrh, Can_IdType CanId, uint8 CanDataLegth, const uint8* CanSduPtr);

-

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 3538baa0cf7b 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

用法与调用上下文

可配置的标注(Call-out)接口 <LPDU_CalloutName> 在每次接收到 L-PDU 时由 AUTOSAR CAN 模块可选调用(SWS_CANDriver §8.4.1 “Call-out function”)。该函数的声明通过头文件 Can_Externals.h 提供([SWS_Can_00443])。函数的实际名称根据项目具体进行配置([SWS_Can_00443])。

作为输入参数传递硬件接收句柄 Hrh、标识符 CanId、数据长度 CanDataLegth 以及指向有效载荷数据的指针 CanSduPtr([SWS_Can_00443])。

过滤与返回值

该函数返回一个 boolean 值。如果标注返回 false,则不得对接收到的 L-PDU 进行进一步处理([SWS_Can_00444])。解释:如果调用返回 true,则应将 L-PDU 正常转发至上层。 问题 Q-e96e75e93881c3af (未决)

并发性与限制

该函数带有服务 ID 0x20,并被指定为异步(Asynchronous)且不可重入(Non Reentrant)([SWS_Can_00443])。由于其不可重入,因此不得在同一上下文中发生并行调用。

本段文本由 AI 生成,旨在提供指导参考。具有约束力的是 AUTOSAR 规范中的要求。

函数 Can_MainFunction_Write [SWS_Can_00225] 📄 PDF

void Can_MainFunction_Write (void);

This function performs the polling of TX confirmation when CAN_ TX_ PROCESSING is set to POLLING.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: a6cd22a9e2b1 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

只要参数 CAN_TX_PROCESSING 配置为 POLLING,函数 Can_MainFunction_Write 就会执行发送确认(TX-Confirmation)的周期性轮询 [SWS_Can_00225], AUTOSAR SWS CAN Driver §7 “Scheduled functions”。它无参数(void Can_MainFunction_Write(void)),具有服务 ID 0x01,并通过头文件 SchM_Can.h 提供给调度程序 [SWS_Can_00225]。通过配置开关可以启用或禁用该函数以进行 PDU 传输的处理 AUTOSAR SWS CAN Driver §10 “CanMainFunctionWrite”。

如果系统中完全不使用针对发送过程的轮询,根据规范应将 Can_MainFunction_Write 实现为空 define AUTOSAR SWS CAN Driver §7 “Scheduled functions”。在纯中断驱动的系统中,这可能有助于避免不必要的调度程序开销。 问题 Q-2152a35397130945 (未决)

在与 Can_MainFunction_Read 和 Can_MainFunction_BusOff 的交互中,该例程构成了驱动程序到 SchM 的周期性接口 AUTOSAR SWS CAN Driver §7 “Scheduled functions”。确认处理取决于模式,直接在硬件资源上或在 Can_MainFunction_Write 的上下文中进行 AUTOSAR SWS CAN Driver §7 “Hardware Resources”。具体调用和分配取决于分别引用的元素 AUTOSAR SWS CAN Driver §10 “CanMainFunctionWrite”、AUTOSAR SWS CAN Driver §10 “Call Context”,并由基于控制器的 Tx 处理提供支持 [SWS_Can_00441]。

本使用说明是基于规范 AUTOSAR R20-11 自动生成的。

函数 Can_MainFunction_Read [SWS_Can_00226] 📄 PDF

void Can_MainFunction_Read (void);

This function performs the polling of RX indications when CAN_ RX_ PROCESSING is set to POLLING.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 2c7a6a6247b4 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

函数 Can_MainFunction_Read 用于 CAN 接收消息([SWS_Can_00226])的周期性查询(轮询)。它具有签名 void Can_MainFunction_Read (void) 及服务 ID 0x08,并通过头文件 SchM_Can.h 提供给流程控制([SWS_Can_00226])。

使用与配置

当配置参数 CAN_RX_PROCESSING 设置为 POLLING 时,该函数执行 RX 指示的轮询([SWS_Can_00226])。在系统中,可以按控制器对该处理进行配置([SWS_Can_00441])。如果 CAN 驱动程序中完全不使用轮询,则可将 Can_MainFunction_Read 定义为空宏(AUTOSAR_SWS_CANDriver 第77页)。

并发性与限制

根据参数化的触发周期(AUTOSAR_SWS_CANDriver 第22页),在调度程序上下文中周期性进行调用。执行时适用严格的条件:

Interpretation:由于不可重入(AUTOSAR_SWS_CANDriver 第47页),任务的已配置调用间隔可能必须设定为使得一个处理阶段始终在下一个周期开始之前结束。 问题 Q-1f2fa9db14970b12 (未决)

本段文本由人工智能基于 AUTOSAR 规范 R20-11 生成。

函数 Can_MainFunction_BusOff [SWS_Can_00227] 📄 PDF

void Can_MainFunction_BusOff (void);

This function performs the polling of bus - off events that are configured statically as 'to be polled'.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: d6a62aee0c17 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

计划的主函数 Can_MainFunction_BusOff 用于周期性轮询 CAN 控制器的 Bus-Off 事件,前提是这些控制器被静态配置为待轮询 [SWS_Can_00227], [SWS_Can_00109]。它具有签名 void Can_MainFunction_BusOff(void),不接收参数,不返回值,并通过头文件 SchM_Can.h 提供给流程控制 [SWS_Can_00227]。

使用与交互

在 CAN 驱动程序中,硬件事件可以通过中断或通过轮询相应状态标志来捕获,其中查询的配置取决于硬件 [SWS_Can_00099]。驱动程序也可以配置为完全不使用中断 [SWS_Can_00007]。如果全系统根本不采用轮询,Can 模块可以将该函数实现为空宏 [SWS_Can_00183]。

如果在 Can_MainFunction_BusOff 中通过状态位检测到 Bus-Off 事件,该模块将进行必要的寄存器设置——例如用于避免硬件自动恢复 SWS_CANDriver §7.3 “CAN Controller State Machine”, [SWS_Can_91010]。随后,该模块通过相应的回调通知上层 CanIf,控制器的软件状态更改在该回调中发生 SWS_CANDriver §7.3 “CAN Controller State Machine”。

调用上下文与限制

在轮询模式下,回调通知的调用上下文不是 ISR,而是 Can_MainFunction_BusOff 的执行任务;尽管如此,所有回调函数都必须以如同从 ISR 上下文调用的方式实现 SWS_CANDriver §7.9 “Notification concept”。关于可重入性,有效载荷未包含明确说明;该函数可能是不可重入的,因为它访问全局控制器寄存器和状态。 问题 Q-38fcd72c40ce3e66 (未决)

本使用说明由 AI 生成,并仅基于 AUTOSAR 版本 R20-11 的规范摘录。

函数 Can_MainFunction_Wakeup [SWS_Can_00228] 📄 PDF

void Can_MainFunction_Wakeup (void);

This function performs the polling of wake - up events that are configured statically as 'to be polled'.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: ce643213c50c 来源
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

主函数 Can_MainFunction_Wakeup 对静态配置为待轮询的唤醒事件执行周期性轮询([SWS_Can_00228])。该函数具有签名 void Can_MainFunction_Wakeup(void),不接收参数,不返回返回值,并通过头文件 SchM_Can.h 提供给调度管理器(AUTOSAR_SWS_CANDriver 第79页)。该函数的执行周期以秒为单位进行配置(AUTOSAR_SWS_CANDriver 第92页)。

在 CAN 控制器的状态机(SWS_CANDriver §7.3 “CAN Controller State Machine”)框架内,外部硬件唤醒事件可以通过在 Can_MainFunction_Wakeup 中查询的状态位来指示,而不是通过中断([SWS_Can_91010])。此外,在状态转换时,该函数轮询 CAN 状态寄存器的相应标志,直到其指示更改生效([SWS_Can_00370])。状态成功切换后,CAN 驱动程序使用回调函数 CanIf_ControllerModeIndication 向 CAN 接口报告新状态,涉及抽象的 CanIf ControllerId([SWS_Can_00370])。

关于配置和资源利用,可以启用或禁用用于处理唤醒事件的 API Can_MainFunction_Wakeup()(AUTOSAR_SWS_CANDriver 第97页)。如果在 ECU 中完全不使用针对唤醒事件的轮询,则可将 Can_MainFunction_Wakeup 定义为空宏(AUTOSAR_SWS_CANDriver 第79页)。

此使用说明基于 AUTOSAR CP R20-11 规范自动生成。

函数 Can_MainFunction_Mode [SWS_Can_00368] 📄 PDF

void Can_MainFunction_Mode (void);

This function performs the polling of CAN controller mode transitions.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: feee99301166 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

使用与工作原理

计划的主函数 Can_MainFunction_Mode ([SWS_Can_00368]) 执行 CAN 控制器状态转换的轮询。它既没有传入参数,也没有返回值 (void Can_MainFunction_Mode(void),服务 ID 0x0c),并通过头文件 SchM_Can.h 声明 SWS_CANDriver §8.5.1.5 “Can_MainFunction_Mode”。

该函数会被持续周期性调用 (AUTOSAR_SWS_CANInterface 第143页)。它检查硬件以确认 CAN 控制器的模式是否已发生改变。在检测到更改时,将通过调用 CanIf_ControllerModeIndication(Controller, ControllerMode) 通知 CAN 接口。

异步模式监控

如果此前通过 Can_SetControllerMode() 请求了模式更改,并且该调用成功返回至 CanIf,则 Can_MainFunction_Mode 会识别控制器硬件已完成的状态转换。随后它通过 CanIf_ControllerModeIndication 将新状态(例如 CAN_CS_STARTED)异步通知给 CanIf AUTOSAR_SWS_CANInterface 第144页。

调用上下文与约束条件

由于通过 SchM_Can.h 提供并被定义为计划函数(Scheduled Function),周期性调用应由 BSW 调度程序执行。 问题 Q-42edbc2aa591e8d7 (未决)在载荷中并未为该函数定义具体的错误代码或开发步骤。

本文由 AI 基于 AUTOSAR 规范生成。

实现者指南即将推出(复杂度 I1)

类型 Can_ConfigType [SWS_Can_00413] 📄 PDF

This is the type of the external data structure containing the overall initialization data for the CAN driver and SFR settings affecting all controllers. Furthermore it contains pointers to controller configuration structures. The contents of the initializ ation data structure are CAN hardware specific.

类型 Can_PduType [SWS_Can_00415] 📄 PDF

This type unites Pdu Id (sw Pdu Handle), Sdu Length (length), Sdu Data (sdu), and Can Id (id) for any CAN L - SDU.

类型 Can_IdType [SWS_Can_00416] 📄 PDF

Represents the Identifier of an L - PDU. The two most significant bits specify the frame type: 00 CAN message with Standard CAN ID 01 CAN FD frame with Standard CAN ID 10 CAN message with Extended CAN ID 11 CAN FD frame with Extended CAN ID

类型 Can_HwHandleType [SWS_Can_00429] 📄 PDF

Represents the hardware object handles of a CAN hardware unit. For CAN hardware units with more than 255 HW objects use extended range.

类型 Can_HwType [SWS_CAN_00496] 📄 PDF

This type defines a data structure which clearly provides an Hardware Object Handle including its corresponding CAN Controller and therefore Can Drv as well as the specific Can Id.

类型 Can_ErrorStateType [SWS_Can_91003] 📄 PDF

Error states of a CAN controller.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 0cb922d28e06 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

来自 Can_GeneralTypes.h 的枚举类型 Can_ErrorStateType 描述了 CAN 控制器的错误和运行状态 [SWS_Can_91003]。它通过三种状态映射控制器在 CAN 总线上的行为 SWS_CANDriver §8.2.7 “Can_ErrorStateType”:

  • CAN_ERRORSTATE_ACTIVE:CAN 控制器完全参与总线通信 [SWS_Can_91003]。
  • CAN_ERRORSTATE_PASSIVE:CAN 控制器参与通信,但不再发送主动错误帧(Error Frames)[SWS_Can_91003]。
  • CAN_ERRORSTATE_BUSOFF:CAN 控制器因严重传输错误而与总线隔离,不再参与通信 [SWS_Can_91003]。

在运行时,通过同步驱动程序服务 Can_GetControllerErrorState 查询该状态 [SWS_Can_91004]。其输出参数 ErrorStatePtr 接收所确定的值。CAN 接口中的上层函数 CanIf_GetControllerErrorState 也使用相同的签名 AUTOSAR_SWS_CANInterface 第78页 “CanIf_GetControllerErrorState”。关于并发性,针对同一 ControllerId,Can_GetControllerErrorState 被指定为不可重入 [SWS_Can_91004]。

在出错时 Can_GetControllerErrorState 返回返回值 E_NOT_OK,成功查询时返回 E_OK [SWS_Can_91004]。在启用开发错误检测(DET)的情况下,在驱动程序初始化之前调用会导致错误 CAN_E_UNINIT [SWS_Can_91005]。无效的 ControllerId 会触发开发错误 CAN_E_PARAM_CONTROLLER [SWS_Can_91006],并且为 ErrorStatePtr 传入空指针会被开发错误拒绝 [SWS_Can_91007]。

解释:调用者可能必须自行负责为 ErrorStatePtr 分配内存区域,因为该接口将指针视为纯输出参数,并通过开发错误排除空指针。 问题 Q-5c907c21bcb50893 (未决)

本段文本由人工智能基于 AUTOSAR 规范 R20-11 生成。

实现者指南即将推出(复杂度 I1)

类型 Can_ControllerStateType [SWS_Can_91013] 📄 PDF

States that are used by the several Controller Mode functions.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: 5eb69ce0444e 来源
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

枚举类型 Can_ControllerStateType 定义了 CAN 控制器的基本运行状态:CAN_CS_UNINIT、CAN_CS_STARTED、CAN_CS_STOPPED 和 CAN_CS_SLEEP [SWS_Can_91013]。该类型跨模块用于 CAN 控制器状态机的软件控制状态管理 [SWS_Can_00017]。

这些值在以下上下文中使用:

关于并发性和错误处理:驱动程序函数 Can_SetControllerMode 和 Can_GetControllerMode 不可重入 [SWS_Can_00230], [SWS_Can_91014]。若在驱动程序初始化之前调用 Can_GetControllerMode,则会报告开发错误 CAN_E_UNINIT 并返回 E_NOT_OK [SWS_Can_91016]。回调函数 CanSM_ControllerModeIndication 针对不同的控制器是可重入的,并向 DET 报告未配置的控制器 ID 为 CANSM_E_PARAM_CONTROLLER [SWS_CanSM_00396], [SWS_CanSM_00397]。

本使用说明基于 AUTOSAR Classic R20-11 中 CAN 驱动程序、CAN 接口和 CAN 状态管理器的规范规定。

实现者指南即将推出(复杂度 I1)

类型 Can_ErrorType [SWS_Can_91021] 📄 PDF

The enumeration represents a superset of CAN Error Types which typical CAN HW is able to report. That means not all CAN HW will be able to support the complete set.

AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: e538be0a65be 来源 未决问题(1)
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

枚举类型 Can_ErrorType 定义了典型 CAN 硬件能够采集并报告给上层的 CAN 错误原因的标准超集 [SWS_Can_91021]。它通过头文件 Can_GeneralTypes.h 提供 SWS_CANDriver §8.2.9 “Can_ErrorType”。

由于该枚举被设计为超集,因此并非每个 CAN 控制器都必然支持所有指定的值 [SWS_Can_91021]。已定义的错误状态包括:

  • 总线监控时的位错误(CAN_ERROR_BIT_MONITORING1、CAN_ERROR_BIT_MONITORING0 或统称为 CAN_ERROR_BIT),
  • 应答错误(CAN_ERROR_CHECK_ACK_FAILED、CAN_ERROR_ACK_DELIMITER),
  • 发送器仲裁丢失(CAN_ERROR_ARBITRATION_LOST),
  • 由于接收缓冲区满导致的过载状态(CAN_ERROR_OVERLOAD),
  • 格式违规和位填充违规(CAN_ERROR_CHECK_FORM_FAILED、CAN_ERROR_CHECK_STUFFING_FAILED),
  • CRC 错误(CAN_ERROR_CHECK_CRC_FAILED)以及
  • 总线在显性电平上的持续阻塞(CAN_ERROR_BUS_LOCK)SWS_CANDriver §8.2.9 “Can_ErrorType”。

在 BSW 模块的协作中,该类型用作回调函数 CanIf_ErrorNotification 的参数,用于将控制器错误转发到 CAN 接口 AUTOSAR_SWS_CANInterface §8.x “CanIf_ErrorNotification”。传入的值应与底层硬件所确定的错误状态相对应 AUTOSAR_SWS_CANDriver §7.x “Error Notification”。 问题 Q-d23c45dd3b23ec71 (未决)

本文由 AI 生成,用于技术指导。

Request a governed re-review of this record. The record is not changed immediately.

Record
AUTOSAR/AP/record/CP_MOD_Can
Status
unspecified
Version
AUTOSAR/AP/record/CP_MOD_Can@rel:R20-11#017fb731
Content hash
017fb731
Source
https://www.autosar.org/fileadmin/standards/R20-11/CP/AUTOSAR_SWS_CANDriver.pdf#nameddest=SWS_Can_00223

初始化与状态

Can_DeInit 函数

This function de - initializes the module.

void Can_DeInit (void);

This function returns the version information of this module.

void Can_GetVersionInfo (Std_VersionInfoType* versioninfo);
Can_Init 函数

This function initializes the module.

void Can_Init (const Can_ConfigType* Config);

服务

This function checks if a wakeup has occurred for the given controller.

Std_ReturnType Can_CheckWakeup (uint8 Controller);

This function disables all interrupts for this CAN controller.

void Can_DisableControllerInterrupts (uint8 Controller);

This function enables all allowed interrupts.

void Can_EnableControllerInterrupts (uint8 Controller);

This service obtains the error state of the CAN controller.

Std_ReturnType Can_GetControllerErrorState (uint8 ControllerId, Can_ErrorStateType* ErrorStatePtr);

This service reports about the current status of the requested CAN controller.

Std_ReturnType Can_GetControllerMode (uint8 Controller, Can_ControllerStateType* ControllerModePtr);

Returns the Rx error counter for a CAN controller. This value might not be available for all CAN controllers, in which cas e E_ NOT_ OK would be returned. Please note that the value of the counter might not be correct at the moment the API returns it, because the Rx counter is handled asynchronously in hardware. Applications should not trust this value for any assumption about the current bus state.

Std_ReturnType Can_GetControllerRxErrorCounter (uint8 ControllerId, uint8* RxErrorCounterPtr);

Returns the Tx error counter for a CAN controller. This value might not be available for all CAN controllers, in which case E_ NOT_ OK would be returned. Please note that the value of the counter might not be correct at the moment the API returns it, because the Tx counter is handled asynchronously in hardware. Applications should not trust this value for any assumption about the current bus state.

Std_ReturnType Can_GetControllerTxErrorCounter (uint8 ControllerId, uint8* TxErrorCounterPtr);

This service shall set the baud rate configuration of the CAN controller. Depending on necessary baud rate modifications the controller might have to reset.

Std_ReturnType Can_SetBaudrate (uint8 Controller, uint16 BaudRateConfig ID); ⚠️

This function performs software triggered state transitions of the CAN controller State machine.

Std_ReturnType Can_SetControllerMode (uint8 Controller, Can_ControllerStateType Transition);
Can_Write 函数

This function is called by Can If to pass a CAN message to Can Drv for transmission.

Std_ReturnType Can_Write (Can_HwHandleType Hth, const Can_PduType* PduInfo);

Callout 与预期接口

-

boolean <LPDU_CalloutName> (uint8 Hrh, Can_IdType CanId, uint8 CanDataLegth, const uint8* CanSduPtr);

周期性

This function performs the polling of bus - off events that are configured statically as 'to be polled'.

void Can_MainFunction_BusOff (void);

This function performs the polling of CAN controller mode transitions.

void Can_MainFunction_Mode (void);

This function performs the polling of RX indications when CAN_ RX_ PROCESSING is set to POLLING.

void Can_MainFunction_Read (void);

This function performs the polling of wake - up events that are configured statically as 'to be polled'.

void Can_MainFunction_Wakeup (void);

This function performs the polling of TX confirmation when CAN_ TX_ PROCESSING is set to POLLING.

void Can_MainFunction_Write (void);

类型

This is the type of the external data structure containing the overall initialization data for the CAN driver and SFR settings affecting all controllers. Furthermore it contains pointers to controller configuration structures. The contents of the initializ ation data structure are CAN hardware specific.

States that are used by the several Controller Mode functions.

Error states of a CAN controller.

The enumeration represents a superset of CAN Error Types which typical CAN HW is able to report. That means not all CAN HW will be able to support the complete set.

Represents the hardware object handles of a CAN hardware unit. For CAN hardware units with more than 255 HW objects use extended range.

Can_HwType 类型

This type defines a data structure which clearly provides an Hardware Object Handle including its corresponding CAN Controller and therefore Can Drv as well as the specific Can Id.

Can_IdType 类型

Represents the Identifier of an L - PDU. The two most significant bits specify the frame type: 00 CAN message with Standard CAN ID 01 CAN FD frame with Standard CAN ID 10 CAN message with Extended CAN ID 11 CAN FD frame with Extended CAN ID

This type unites Pdu Id (sw Pdu Handle), Sdu Length (length), Sdu Data (sdu), and Can Id (id) for any CAN L - SDU.