AUTOSAR_SWS_OCUDriver

AUTOSAR_SWS_OCUDriver

简介和功能概述


本规范规定了 AUTOSAR 基础软件模块 OCU 驱动程序的功能、API 和配置。

每个 OCU 软件通道都链接到属于微控制器的硬件 OCU 外设。输出引脚可以选择性地连接到此通道。

驱动程序提供初始化和控制微控制器内部 OCU 功能(输出比较单元)的功能。OCU 驱动程序允许在计数器的值与定义的阈值匹配时自动进行比较和采取行动。OCU 驱动程序提供以下服务和配置参数:
  • 启动和停止比较过程
  • 设置比较阈值
  • 启用和禁用通知机制
  • 获取计数器值
  • 改变输出引脚状态
  • 如果可用,则触发一些硬件资源(ADCDMA
通道计数器的一个滴答的时长取决于通道特定设置(OCU 驱动程序的一部分)以及系统时钟和 MCU 模块控制的时钟树的设置。滴答的时长不受此规范的限制。

一些微控制器有专用的 OCU 硬件单元,而是有一个通用定时器模块,可以配置为提供 OCU 功能和其他定时器功能。此规范假设硬件架构。相反,它定义了参数和 API,以便它们可以在任何合适的硬件架构上实现。下图显示了 OCU 通道的典型表示。

输出”是比较匹配时实际执行的操作。


首字母缩略词和缩写


以下词汇表包含与 OCU 驱动程序模块相关的首字母缩略词和缩写,这些缩略词和缩写未包含在 [1,AUTOSAR 词汇表中] 中。

具有局部范围的首字母缩略词和缩写出现在以下词汇表中。具有全局范围的首字母缩略词和缩写包含在 AUTOSAR 词汇表中。



约束和假设


时钟

驱动程序不支持时钟的动态变化。

由于系统时钟完全由 MCU 模块管理,因此系统时钟设置中的任何动态变化都会影响此模块。

该模块不在睡眠模式下运行。

资源

资源分配完全由 SWHW 完成,以避免共享资源问题。

例如:使用 API Ocu_SetPinState。不能调用此 API 来更改处于 RUNNING 状态的通道的引脚状态,否则硬件在比较匹配时自动设置的状态与 API 设置的状态之间可能会发生冲突。

计数和比较

我们的假设是操作该驱动程序的硬件具有以下计数器抽象模型(位计数器的示例)。


  • 最小值为 0
  • 最大值为 255
当计数器超过最大值时,将重新加载 0。这意味着它有 256 个计数步骤。

由于计数的量化,将计数器的内容与阈值进行比较时可能出现两种同的情况。比较可以在进入退出一个计数器状态时发生,如下图所示


该驱动程序的预期行为是在进入阈值所代表的状态时进行比较。

对其他模块的依赖


DET 模块

如果为 OCU 驱动程序启用了开发错误检测,则每当此模块遇到开发错误时,驱动程序就会向默认错误跟踪器 (DET) 发出错误

DEM 模块

OCU 驱动程序应向诊断事件管理器 (DEM) 报告生产错误。

MCU 驱动程序 模块

微控制器单元驱动程序 (MCU 驱动程序) 主要负责初始化和控制芯片内部时钟源和时钟预分频器。OCU 依赖于系统时钟。因此,系统时钟的变化(例如 PLL 开启 PLL 关闭)也会影响 OCU 硬件的时钟设置。

MCU 驱动程序将设置全局预分频器和 OCU 时钟。OCU 驱动程序不会在其初始化函数中设置配置全局时钟、全局预分频器和 PLL 的寄存器。这必须由 MCU 模块完成。OCU 驱动程序仅配置本地(OCU 外设特定)资源。

文档 AUTOSAR_TPS_ECUConfiguration [3] 包含章节“4.8 时钟树配置”,其中详细介绍了向外设提供参考时钟信号的机制。

Port 模块

OCU 用作输出的端口引脚的配置由 Port 驱动程序完成。因此,在使用 OCU 功能之前必须初始化 Port 驱动程序。

文件结构

[SWS_Ocu_00001]

[SRS_BSW_00419]
[SRS_BSW_00346]
[SRS_BSW_00314]
  • 本规范中不完全定义代码文件结构。此处应指出,代码文件结构应包括以下文件:
    • Ocu_Lcfg.c - 用于链接时的可配置参数
    • Ocu_PBcfg.c - 用于构建后的可配置参数
  • 这些文件应包含所有链接时和构建后的可配置参数。

[SWS_Ocu_00006]

[ ]
  • Ocu.c 应包含 Ocu.hDet.h

需求追踪

下表引用了 <CITATIONS_OF_CONTRIBUTED_DOCUMENTS> 中指定的要求,并链接到这些要求的实现情况。

请注意,如果特定要求的“满足”列为空,则表示本文档满足该要求。


功能规格


一般行为

OCU 通道由两个主要元素组成:自由运行计数器和比较阈值。这两个元素共同作用以生成用户所需的操作。自由运行计数器可以由硬件软件提供,而阈值是用户设置的值。每次计数器增加一个单位时,都会将阈值计数器的当前内容进行比较。


每次计数器增加一个单位时,驱动程序都会比较两个值。如果相等,可以执行种不同类型的操作:
  • 通过通知功能向上层上报信息。
  • 作用于已配置的输出引脚

OCU 驱动程序提供以下服务来管理通道
  • 开始一个通道
  • 停止一个通道
  • 设置比较阈值
  • 启用禁用通道的通知功能
  • 获取计数器
  • 改变输出引脚状态

输出比较通道的状态和状态转换如下图所示。


OCU 通道具有简单的状态图,状态如上所示。驱动程序的所有通道都使用 API Ocu_Init() 一次性初始化。没有 API 可以单独初始化每个通道

根据硬件架构,与 OCU 通道绑定的硬件可能由 OCU 单元或微控制器中的任何其他计时器模块管理。

版本检查


背景与理由

应避免集成兼容的文件。最低限度的实现是检查.c 文件内的头文件的版本(.c 和 .h 文件的版本号必须相同)。

[SWS_Ocu_00012]

[SRS_BSW_00004]
  • OCU 驱动程序应执行模块间检查,以避免集成兼容的文件。应通过预处理指令检查导入的包含文件。
  • 需要验证以下版本号:
    • <MODULENAME>_AR_RELEASE_MAJOR_VERSION
    • <MODULENAME>_AR_RELEASE_MINOR_VERSION
  • 其中 <MODULENAME> 是其他(外部)模块的模块短名称,这些模块提供 OCU 驱动程序包含的头文件。如果值与预期值相同,则应报告错误

时间单位滴答


背景与理由

要从寄存器值中获取时间,必须知道振荡器频率、预分频器和整个系统时钟的一些其他设置。由于这些设置是在 MCU 和/或其他模块中进行的,因此无法计算此类时间。

因此,时间和刻度之间的转换应属于上层的一部分。

需求

[SWS_Ocu_00013]

[SRS_BSW_00343]
  • OCU 驱动程序的 API 服务中使用的所有时间单位都应为单位滴答。

错误分类


[SWS_Ocu_00016]

[SRS_BSW_00337]
[SRS_BSW_00323]
[SRS_BSW_00327]
[SRS_BSW_00331]
[SRS_BSW_00385]
[SRS_BSW_00386]
  • OCU 驱动程序应能够根据其构建版本(开发/生产模式)检测以下错误

开发错误

[SWS_Ocu_00015]

[SRS_BSW_00337]
  • 开发错误值的类型为 uint8

[SWS_Ocu_91001]

[ ]

[SWS_Ocu_00017]

[SRS_BSW_00337]
[SRS_BSW_00339]
[SRS_BSW_00385]
[SRS_BSW_00386]
  • 由于特定实现和/或特定硬件属性而检测到的额外错误应添加到 OCU 设备特定实现规范中。分类和枚举应与上面列出的错误兼容。

运行时错误

[SWS_Ocu_91002]

[ ]

错误检测


[SWS_Ocu_00018]

[SRS_BSW_00369]
[SRS_BSW_00386)]
  • 开发错误检测可在预编译时配置(开启/关闭)。开关 OcuDevErrorDetectApi 应激活或停用所有开发错误检测。

[SWS_Ocu_00019]

[SRS_BSW_00386]
[SRS_BSW_00369]
[SRS_BSW_00339]
  • 如果开关 OcuDevErrorDetectApi 开启,则开启 API 参数检查。检测到的错误的详细描述可以在错误分类章节和 API 规范章节中找到。

[SWS_Ocu_00020]

[SRS_BSW_00339]
  • 生产错误检测无法被关闭。

错误通知


[SWS_Ocu_00021]

[SRS_BSW_00339]
  • 如果设置了预处理器开关 OcuDevErrorDetectApi,则应使用默认错误跟踪器 (DET) 的服务 Det_ReportError 报告检测到的开发错误

调试支持


[SWS_Ocu_00023]

[ ]
  • 每个应由 AUTOSAR 调试访问的变量应定义为全局变量。

[SWS_Ocu_00024]

[ ]
  • 所有需要调试的变量的类型定义都应可以通过头文件 Ocu.h 访问。

[SWS_Ocu_00025]

[ ]
  • 头文件中变量的声明应当能够通过C语言的“sizeof”计算出变量的大小。

[SWS_Ocu_00026]

[ ]
  • 可用于调试的变量应在相应的 OCU 驱动程序描述中描述。

API 规范


导入的类型

本章列出了以下文件中包含的所有类型。

[SWS_Ocu_00027]

[ ]

类型定义

Ocu_ChannelType

[SWS_Ocu_00028]

[ ]

Ocu_ValueType

[SWS_Ocu_00029]

[SRS_SPAL_12063]

Ocu_PinStateType

[SWS_Ocu_00031]

[ ]

Ocu_PinActionType

[SWS_Ocu_00032]

[ ]

Ocu_ConfigType

[SWS_Ocu_00033]

[SRS_Ocu_00002]
[SRS_SPAL_12263]
[SRS_BSW_00405]
[SRS_BSW_00438]

Ocu_ReturnType

[SWS_Ocu_00138]

[ ]

函数定义


Ocu_Init

[SWS_Ocu_00035]

[ ]

[SWS_Ocu_00036] 

[SRS_BSW_00344]
[SRS_BSW_00404]
[SRS_BSW_00101]
[SRS_SPAL_12057]
  • 函数 Ocu_Init 将根据 ConfigPtr 引用的配置集初始化微控制器的所有内部变量和使用的 OCU 结构。

注意:所有通道均由 API Ocu_Init 一次性初始化。没有 API 可以单独初始化每个通道。

[SWS_Ocu_00010] 

[SRS_SPAL_12125]
  • 如果 OCU 单元的自由运行计数器可由另一个计时器模块使用,则 OCU 驱动程序启动停止自由运行计数器

[SWS_Ocu_00011] 

[SRS_SPAL_12125]
  • API Ocu_Init 将启动所有自由运行的计数器,这些计数器仅由该驱动程序使用。

[SWS_Ocu_00037] 

[SRS_SPAL_12057]
[SRS_SPAL_12125]
  • 函数 Ocu_Init 只会初始化已配置的资源,而不会触碰配置文件中未配置的资源。

有关控制器寄存器初始化的以下规则应适用于此驱动程序实现:

[SWS_Ocu_00038]

[SRS_SPAL_12461]
  • 如果硬件只允许寄存器(仅专用于 OCU 资源的寄存器)被使用次,那么 OCU 驱动程序负责初始化该寄存器。

[ ]

[SRS_SPAL_12461]
  • 注 1:如果寄存器可以影响多个硬件模块,并且它不是 I/O 寄存器,则它应由 MCU 驱动程序初始化。

[ ]

[SRS_SPAL_12461]
  • 注2:复位后需要直接初始化的一次性可写寄存器应由启动代码初始化。

[ ]

[SRS_SPAL_12461]
  • 注3:所有其他寄存器均须由启动代码初始化。

[ ]

[SRS_SPAL_12461]
  • 注4:如果一个寄存器可以影响多个硬件模块,并且它是一个 I/寄存器,它应该由 Port 驱动程序初始化。

[SWS_Ocu_00039]

[SRS_SPAL_12057]
  • 函数 Ocu_Init 将停止所有通道

[SWS_Ocu_00040]

[SRS_SPAL_12057]
  • 函数 Ocu_Init 将禁用所有通知

原因是这些通知的用户可能还没有准备好。他们可以调用 Ocu_EnableNotification() 来开始获取通知

[SWS_Ocu_00043]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测,并且在 OCU 驱动程序和硬件已经初始化时调用函数 Ocu_Init,则函数 Ocu_Init 将引发开发错误 OCU_E_ALREADY_INITIALIZED 并返回而不采取任何操作。

[SWS_Ocu_00044]

[ ]
  • 在通过执行函数 Ocu_Init 重新初始化 OCU 驱动程序之前,需要执行函数 Ocu_DeInit 进行取消初始化。

Ocu_DeInit

[SWS_Ocu_00045]

[SRS_Ocu_00005]

[SWS_Ocu_00046]

[SRS_BSW_00336]
[SRS_SPAL_12163]
  • Ocu_DeInit 函数将取消之前在 OCU 变量和寄存器上由 Ocu_Init 完成的初始化,使其处于与上电复位状态相当的状态。可写入的寄存器值除外。

注意:硬件设计的责任是确保状态不会导致 C 程序中定义的活动。

[SWS_Ocu_00047]

[SRS_SPAL_12163]
  • 函数 Ocu_DeInit 将禁用所有已被使用的中断通知

[SWS_Ocu_00048]

[ ]
  • Ocu_DeInit 函数仅影响由静态配置分配的外围设备和/或上次调用 Ocu_Init() 传递的运行时配置集。

[SWS_Ocu_00136]

[SRS_SPAL_12125]
  • API Ocu_DeInit 将停止所有自由运行的计数器,这些计数器仅由该驱动程序使用。

注意:为了防止在初始化期间出现定义的行为,用户必须在调用 API Ocu_DeInit 之前停止所有正在运行的通道(通过调用函数 Ocu_StopChannel)。因此有以下要求。

[SWS_Ocu_00137]

[ ]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果在调用函数 Ocu_DeInit 时通道仍处于运行状态,则该函数将引发开发错误OCU_E_PARAM_INVALID_STATE”并返回而不采取任何操作。

[SWS_Ocu_00049]

[SRS_BSW_00171]
  • 函数 Ocu_DeInit 应在编译前通过配置参数 OcuDeInitApi {OCU_DE_INIT_API} 配置为/

[SWS_Ocu_00050]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果驱动程序初始化,则函数 Ocu_DeInit 将引发错误 OCU_E_UNINIT

Ocu_StartChannel

[SWS_Ocu_00051]

[SRS_Ocu_00008]

[SWS_Ocu_00052]

[SRS_Ocu_00008]
  • 函数 Ocu_StartChannel 将通过允许所有比较匹配的已配置操作的执行来启动 OCU 通道

[SWS_Ocu_00053]

[ ]
  • 如果为不同的通道调用函数 Ocu_StartChannel,则该函数必须是重入的。

[SWS_Ocu_00054]

[ ]
  • 如果函数 Ocu_StartChannel 已成功执行,则所选通道的状态应设置为“RUNNING”。

[SWS_Ocu_00055]

[SRS_BSW_00406]
[SRS_SPAL_12448]
  • 如果在处于“RUNNING”状态的通道上调用函数 Ocu_StartChannel,则该函数将引发错误 OCU_E_BUSY 并返回而不执行任何操作。

[SWS_Ocu_00056]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果参数 ChannelNumber 无效(不在配置指定的范围内),函数 Ocu_StartChannel 将引发错误 OCU_E_PARAM_INVALID_CHANNEL 并返回而不采取任何操作。

[SWS_Ocu_00057]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果驱动程序未初始化,则函数 Ocu_StartChannel 将引发错误 OCU_E_UNINIT 并返回而不采取任何操作。

Ocu_StopChannel

[SWS_Ocu_00058]

[SRS_Ocu_00008]

[SWS_Ocu_00059]

[SRS_Ocu_00008]
  • 函数 Ocu_StopChannel 将通过停止通道的比较匹配的已配置操作来停止 OCU 通道

[SWS_Ocu_00060]

[ ]
  • 函数 Ocu_StopChannel 不会停止与通道相关的自由运行计数器

注意:这是因为自由运行的计数器可以与OCU 通道相关联。因此,停止该计数器将损害其他通道的运行。

[SWS_Ocu_00061]

[ ]
  • 如果为同的通道调用函数 Ocu_StopChannel,则该函数必须是可重入的。

[SWS_Ocu_00062]

[ ]
  • 如果函数 Ocu_StopChannel 成功执行,则选定通道的状态应设置为“STOPPED”。

[SWS_Ocu_00063]

[ ]
  • 如果在处于“STOPPED”状态的通道上调用函数 Ocu_StopChannel,则该函数将执行任何操作(改变通道状态),并且会引发开发错误

[SWS_Ocu_00064]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果参数 ChannelNumber 无效(在配置指定的范围内),函数 Ocu_StopChannel 将引发错误 OCU_E_PARAM_INVALID_CHANNEL 并返回而采取任何操作。

[SWS_Ocu_00065]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果驱动程序初始化,则函数 Ocu_StopChannel 将引发错误 OCU_E_UNINIT 并返回而采取任何操作。

Ocu_SetPinState

[SWS_Ocu_00066]

[SRS_Ocu_00011]

[SWS_Ocu_00067]

[SRS_Ocu_00011]
  • 函数 Ocu_SetPinState 将把与通道关联的引脚设置为“PinState”指示的电平。

[SWS_Ocu_00068]

[ ]
  • 如果为同的通道调用函数 Ocu_SetPinState,则该函数必须是重入的。

[SWS_Ocu_00069]

[ ]
  • 仅当通道不处于 RUNNING 状态时,才应使用函数 Ocu_SetPinState

注意:先前的要求还意味着可以通过此 API 改变已停止的通道的状态。

[SWS_Ocu_00070]

[SRS_BSW_00171]
  • 函数 Ocu_SetPinState 应在编译前通过配置参数配置开/关:OcuSetPinStateApi {OCU_SET_PIN_STATE_API}。

[SWS_Ocu_00071]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果参数 ChannelNumber 无效(不在配置指定的范围内),函数 Ocu_SetPinState 将引发错误 OCU_E_PARAM_INVALID_CHANNEL 并返回而采取任何操作。

[SWS_Ocu_00072]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果引脚通道没有关联(在通道配置中定义),则函数 Ocu_SetPinState 将引发错误 OCU_E_PARAM_NO_PIN 并返回而采取任何操作。

[SWS_Ocu_00073]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果参数 PinState 无效(在配置指定的范围内),函数 Ocu_SetPinState 将引发错误 OCU_E_PARAM_INVALID_STATE 并返回而不采取任何措施。

[SWS_Ocu_00074]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果驱动程序初始化,则函数 Ocu_SetPinState 将引发错误 OCU_E_UNINIT 并返回而不采取任何操作。

[SWS_Ocu_00075]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果通道处于 RUNNING 状态,则函数 Ocu_SetPinState 将引发错误 OCU_E_PARAM_INVALID_STATE 并返回而不采取任何操作。

Ocu_SetPinAction

[SWS_Ocu_00076]

[SRS_Ocu_00012]

[SWS_Ocu_00077]

[SRS_Ocu_00012]
  • Ocu_SetPinAction 函数应设置在下一次比较匹配时相应 OCU 通道中硬件需要自动执行的操作。

[SWS_Ocu_00078]

[ ]
  • 如果为不同的通道调用函数 Ocu_SetPinAction,则该函数必须是可重入的。

[SWS_Ocu_00079]

[SRS_BSW_00171]
  • 函数 Ocu_SetPinAction 应在编译前通过配置参数进行配置:OcuSetPinActionApi {OCU_SET_PIN_ACTION_API}。

[SWS_Ocu_00080]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果参数 ChannelNumber 无效(不在配置指定的范围内),函数 Ocu_SetPinAction 将引发错误 OCU_E_PARAM_INVALID_CHANNEL 并返回而不采取任何操作。

[SWS_Ocu_00081]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果引脚通道没有关联(未在通道配置中定义),则函数 Ocu_SetPinAction 将引发错误 OCU_E_PARAM_NO_PIN 并返回而不采取任何操作。

[SWS_Ocu_00082]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果参数 PinAction 无效(不在类型指定的范围内),函数 Ocu_SetPinAction 将引发错误 OCU_E_PARAM_INVALID_ACTION 并返回而不采取任何操作。

[SWS_Ocu_00083]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果驱动程序初始化,则函数 Ocu_SetPinAction 将引发错误 OCU_E_UNINIT 并返回而不采取任何操作。

[SWS_Ocu_00084]

[ ]
  • 如果某个引脚与某个通道关联,则比较匹配时应执行与该引脚相关的操作。

Ocu_GetCounter

[SWS_Ocu_00085]

[SRS_Ocu_00009]

[SWS_Ocu_00086]

[SRS_Ocu_00009]
  • 函数 Ocu_GetCounter 应读取并返回 ChannelNumber 指示的通道计数器的值。

[SWS_Ocu_00087]

[ ]
  • 函数 Ocu_GetCounter 应为可重入的。

[SWS_Ocu_00088]

[SRS_BSW_00171]
  • Ocu_GetCounter 函数应在编译前通过配置参数进行配置:OcuGetCounterApi {OCU_GET_COUNTER_API}。

[SWS_Ocu_00089]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果参数 ChannelNumber 无效(不在配置指定的范围内),则函数 Ocu_GetCounter 将引发错误 OCU_E_PARAM_INVALID_CHANNEL 并返回值“0”。

[SWS_Ocu_00090]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果驱动程序未初始化,则函数 Ocu_GetCounter 将引发错误 OCU_E_UNINIT 并返回值“0”。

Ocu_SetAbsoluteThreshold

[SWS_Ocu_00091]

[SRS_Ocu_00010]

[SWS_Ocu_00092]

[SRS_Ocu_00010]
  • 函数 Ocu_SetAbsoluteThreshold通道阈值(比较值)设置为 AbsoluteValue 给出的值。

[SWS_Ocu_00093]

[ ]
  • 如果为不同通道调用函数 Ocu_SetAbsoluteThreshold,则该函数必须是可重入的。

[SWS_Ocu_00094]

[SRS_BSW_00171]
  • 函数 Ocu_SetAbsoluteThreshold 应在编译前通过配置参数配置/OcuSetAbsoluteThresholdApi {OCU_SET_ABSOLUTE_THRESHOLD_API}。

[SWS_Ocu_00095]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果驱动程序初始化,则函数 Ocu_SetAbsoluteThreshold 将引发错误 OCU_E_UNINIT 并返回而采取任何操作。

[SWS_Ocu_00096]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • 如果为 OCU 驱动程序启用了开发错误检测:如果参数 ChannelNumber 无效(不在配置指定的范围内),函数 Ocu_SetAbsoluteThreshold 将引发错误 OCU_E_PARAM_INVALID_CHANNEL 并返回而采取任何操作。

注意:参考值是来自上层的信息。参考值绝对值的结合提供了一个区间(定义为“参考区间”,下图中的绿色区域),提供该区间的原因主要是考虑到计数器连续运行的事实,并且调用者更新比较阈值的请求与实际修改该阈值之间可能存在延迟

为了简化此处的描述,我们假设由于内部 MCU 和外围设备的时序,对硬件比较寄存器的写入操作始终完成:
  • 在进行实际比较之前,这甚至可能在同个时钟周期内(情况 1)
  • 实际比较完成后,这甚至可能在同个时钟周期内(情况 2)

如下图示例 Ocu_SetAbsoluteThreshold( 1, 30, 35);  所示。
  • 情况 1 在目标比较匹配发生写入阈值

图 8.1:在目标比较匹配发生之写入阈值

  • 情况 2 在目标比较匹配发生写入阈值

图 8.2:在目标比较匹配写入阈值

参考区间考虑了计数器可能的翻转,如下图所示。

Ocu_SetAbsoluteThreshold( 1, 70, 20);

计数器范围从 0255

图 8.3:参考区间的定义

根据上述情况解释的结果,驱动程序的预期行为如下。
  • 仅在比较匹配(硬件)时才向上层发出通知:因此,对于每个参考区间,应存在一个唯一通知(请参阅下文有关如何管理写入的阈值)与被写入的阈值对应
  • API Ocu_SetAbsoluteThreshold 应返回一个状态通知调用者是否:
    • 写入是在当前参考区间内被完成的(在实际比较匹配之,甚至有可能在 API 返回之前已经发生了比较匹配)(情况 1)
    • 写入是在当前参考区间之外被进行的。(情况 2)

状态将帮助调用者(应用程序)决定如何继续。

[SWS_Ocu_00098]

[ ]
  • 设置新的阈值后,API Ocu_SetAbsoluteThreshold 应返回一个状态,以通知调用者在当前参考区间期间是否会发生(或已经发生)比较匹配,作为设置新阈值的结果。

对于上次调用 API Ocu_SetAbsoluteThreshold 时写入的阈值,驱动程序的预期行为如下:

先前写入的阈值已被当前调用删除

注意:

由于实时行为,在调用 API 后,先前写入的阈值可能仍会产生比较匹配,在该比较匹配中写入的阈值实际上尚未生效。

[SWS_Ocu_00097]

[ ]
  • 在实际设置阈值时,先前的阈值(在最后一次调用此 API 时写入)将不再产生比较匹配。

Ocu_SetRelativeThreshold

[SWS_Ocu_00100]

[SRS_Ocu_00010]

The behaviour of this API is as follows.  
  • On entry, the API reads the counter value (ReadValue). Then the new threshold value is computed and written according to the following formula: 

NewThresholdValue = ReadValue + RelativeValue. 

The rest of the behaviour is then the same as for the API Ocu_SetAbsoluteThreshold where the reference value is now ReadValue, and the Reference Interval is between Readvalue and the new programmed threshold (NewThresholdValue) as shown in the picture below. 

Example with Ocu_SetRelativeThreshold(1,5);


Note: 

As for the API Ocu_SetAbsoluteThreshold, the possible rollover of the counter is also included in the Reference Interval as shown in the figure below. Example with Ocu_SetRelativeThreshold(1,20), with ReadValue equals to 253. As a result, this API behaves like Ocu_SetAbsoluteThreshold, hence the requirements below.


[SWS_Ocu_00101]

[ ]
  • The function Ocu_SetRelativeThreshold shall add RelativeValue to the value of the counter on entering the function to compute the new threshold relative to the counter.

[SWS_Ocu_00106]

[ ]
  • After setting a new threshold value, the API Ocu_SetRelative Threshold shall return a status to inform the caller whether the compare match will occur (or has already occured) during the current Reference Interval, as a result of setting the new threshold value.

[SWS_Ocu_00107]

[ ]
  • Upon actual setting of a new threshold value (absolute or relative), the previous threshold value shall no longer produce a compare match.

[SWS_Ocu_00102]

[ ]
  • The fuction OCU Ocu_SetAbsoluteThreshold shall be reentrant if it is called for different channels.

[SWS_Ocu_00103]

[SRS_BSW_00171]
  • The function Ocu_SetRelativeThreshold shall be pre compile time configurable On/Off by the configuration parameter: OcuSetRelativeThresholdApi {OCU_SET_RELATIVE_THRESHOLD_API}.

[SWS_Ocu_00104]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver: If the driver is not initialized, the function Ocu_SetRelativeThreshold shall raise the error OCU_E_UNINIT and return without any action.

[SWS_Ocu_00105]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver: if the parameter ChannelNumber is invalid (not within the range specified by the configuration), the function Ocu_SetRelativeThreshold shall raise the error OCU_E_PARAM_INVALID_CHANNEL and return without any action.

Ocu_DisableNotification 

[SWS_Ocu_00108]

[SRS_Ocu_00007]

[SWS_Ocu_00109]

[SRS_Ocu_00007]
  • The function Ocu_DisableNotification shall disable the OCU compare match notification.

[SWS_Ocu_00110]

[ ]
  • The fuction OCU Ocu_DisableNotification shall be reentrant if it is called for different channels.

[SWS_Ocu_00111]

[SRS_BSW_00171]
  • The function Ocu_DisableNotification shall be pre compile time configurable On/Off by the configuration parameter: OcuNotificationSupported {OCU_ NOTIFICATION_SUPPORTED}.

[SWS_Ocu_00112]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver: If the driver is not initialized, the function Ocu_DisableNotification shall raise the error OCU_E_UNINIT and return without any action.

[SWS_Ocu_00113]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver: If the parameter Channel is invalid (not within the range specified by configuration), the function Ocu_DisableNotification shall raise the error OCU_E_PARAM_INVALID_ CHANNEL and return without any action.

[SWS_Ocu_00114]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver: If the notification function is the NULL pointer, the function Ocu_DisableNotification shall raise the error OCU_E_NO_VALID_NOTIF and return without any action.

Ocu_EnableNotification 

[SWS_Ocu_00115]

[SRS_Ocu_00007]

[SWS_Ocu_00116]

[SRS_Ocu_00007]
  • The function Ocu_EnableNotification shall enable the OCU compare match notification of the indexed channel.

[SWS_Ocu_00117]

[ ]
  • The function Ocu_EnableNotification shall be reentrant if it is called for different channels.

[SWS_Ocu_00118]

[SRS_BSW_00171]
  • The function Ocu_EnableNotification shall be pre compile time configurable On/Off by the configuration parameter: OcuNotificationSupported {OCU_ NOTIFICATION_SUPPORTED}.

[SWS_Ocu_00119]

[SRS_BSW_00406]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver: If the driver is not initialized, the function Ocu_EnableNotification shall raise the error OCU_E_UNINIT and return without any action.

[SWS_Ocu_00120]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver: If the parameter Channel is invalid (not within the range specified by configuration), then the function Ocu_EnableNotification shall raise the error OCU_E_PARAM_INVALID_CHANNEL and return without any action.

[SWS_Ocu_00121]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver: If the notification function is the NULL pointer, the function Ocu_EnableNotification shall raise the error OCU_E_NO_VALID_NOTIF and return without any action.

Ocu_GetVersionInfo 

[SWS_Ocu_00122]

[ ]

[SWS_Ocu_00123]

[SRS_BSW_00407]
  • The function Ocu_GetVersionInfo shall return the version information of this module. The version information includes:  
    • Module Id  
    • Vendor Id  
    • Vendor specific version numbers.

[SWS_Ocu_00124]

[SRS_BSW_00407]
[SRS_BSW_00411]
  • The function Ocu_GetVersionInfo shall be pre compile time configurable On/Off by the configuration parameter: OcuVersionInfoApi {OCU_VERSION_ INFO_API}.

[SWS_Ocu_00125]

[ ]
  • If source code for caller and callee of Ocu_GetVersionInfo is available; the OCU driver should realize Ocu_GetVersionInfo as a macro, defined in the module's header file.

[SWS_Ocu_00126]

[SRS_BSW_00323]
[SRS_BSW_00386]
[SRS_SPAL_12448]
  • If development error detection is enabled for the OCU driver, the function Ocu_GetVersionInfo shall raise development error OCU_E_PARAM_ POINTER if parameter versioninfo is a null pointer, and return without any action.

Expected interfaces

Optional interfaces 

This section defines all interfaces, which are required to fulfill an optional functionality of the module.

[SWS_Ocu_00127]

[ ]

Configurable interfaces 

In this section, all interfaces are listed where the target function could be configured. The target function is usually a callback function. The names of this kind of interfaces are not fixed because they are configurable. 

[SWS_Ocu_00128]

[SRS_BSW_00359]
[SRS_BSW_00360]
[SRS_SPAL_00157]

The notification prototype Ocu_Notification_<channel#> is for the notification callback function provided by the upper layer and shall be implemented by the user.

[SWS_Ocu_00129]

[SRS_SPAL_00157]
  • The OCU driver shall call the function Ocu_Notification_<Channel#> according to the last call of Ocu_EnableNotification/Ocu_DisableNotification for channel <Channel#>, if there's a compare match on that channel.

[SWS_Ocu_00130]

[SRS_SPAL_12129]
  • The OCU driver shall reset the interrupt flag (if needed by hardware) associated with the notification Ocu_Notification_<Channel#>.

[SWS_Ocu_00132]

[SRS_SPAL_12056]
  • If the NULL pointer is configured for a notification call-back, then no call-back shall be executed.

[SWS_Ocu_00133]

[ ]
  • When the notification mechanism is disabled, the OCU driver shall send no notification.

Sequence diagrams


Initialization


De-initialization


Using the Ocu Notifications


Ocu_SetPinState


Ocu_SetPinAction


Setting a new compare threshold 

Refer to the chapters 8.3.8 (Ocu_SetAbsoliteThreshold) and 8.3.9 (Ocu_SetRelativeThreshold).

Configuration specification 


In general, this chapter defines configuration parameters and their clustering into containers. In order to support the specification Chapter 10.1 describes fundamentals. It also specifies a template (table) you shall use for the parameter specification. We intend to leave Chapter 10.1 in the specification to guarantee comprehension. 

Chapter 10.2 specifies the structure (containers) and the parameters of the module OCU. 

Chapter 10.3 specifies published information of the module OCU. 

How to read this chapter 

For details refer to the chapter 10.1 "Introduction to configuration specification" in SWS_BSWGeneral. 

In addition to this section, it is highly recommended to read the documents:  
  • AUTOSAR Layered Software Architecture [4]  
  • AUTOSAR ECU Configuration Specification[3] 
this document describes the AUTOSAR configuration methodology and the AUTOSAR configuration metamodel in detail. 

The following is only a short survey of the topic and it will not replace the ECU Configuration Specification document.

Configuration and configuration parameters 

Configuration parameters define the variability of the generic part(s) of an implementation of a module. This means that only generic or configurable module implementation can be adapted to the environment (software/hardware) in use during system and/or ECU configuration. 

The configuration of parameters can be achieved at different times during the software process: before compile time, before link time or after build time. In the following, the term "configuration class" (of a parameter) shall be used in order to refer to a specific configuration point in time. 

Containers 

Containers structure the set of configuration parameters. This means:  
  • all configuration parameters are kept in containers.
  • (sub-) containers can reference (sub-) containers. It is possible to assign a multiplicity to these references. The multiplicity then defines the possible number of instances of the contained parameters.

Specification template for configuration parameters 

The following tables consist of three sections:  
  • the general section  
  • the configuration parameter section  
  • the section of included/referenced containers 

Pre-compile time - specifies whether the configuration parameter shall be of configuration class Pre-compile time or not


Link time - specifies whether the configuration parameter shall be of configuration class Link time or not


Post Build - specifies whether the configuration parameter shall be of configuration class Post Build or not


Containers and configuration parameters 

The following chapters summarize all configuration parameters. The detailed meanings of the parameters describe Chapter 7 and Chapter 8.

[SWS_Ocu_00170]

[ ]
  • The OCU module shall reject configurations with partition mappings which are not supported by the implementation.

Ocu




OcuGeneral

[SWS_Ocu_CONSTR_00001]

[ ]
  • The ECUC partitions referenced by OcuKernelEcuc PartitionRef shall be a subset of the ECUC partitions referenced by OcuEcucPartition Ref.





[SWS_Ocu_CONSTR_00004]

[ ]
  • If OcuEcucPartitionRef references one or more ECUC partitions, OcuKernelEcucPartitionRef shall have a multiplicity of one and reference one of these ECUC partitions as well.


OcuConfigurationOfOptionalApis











OcuConfigSet




OcuChannel














[SWS_Ocu_CONSTR_00002]

[ ]
  • The ECUC partitions referenced by OcuChannelEcuc PartitionRef shall be a subset of the ECUC partitions referenced by OcuEcucPartition Ref.

[SWS_Ocu_CONSTR_00005]

[ ]
  • If OcuEcucPartitionRef references one or more ECUC partitions, OcuKernelEcucPartitionRef shall have a multiplicity of one and reference one of these ECUC partitions as well.


OcuHWSpecificSettings





Published Information 

For details refer to the chapter 10.3 "Published Information" in SWS_BSWGeneral.

[SWS_Ocu_00169]

[ ]
  • The standardized common published parameters as required by SRS_BSW_00402 in the General Requirements on Basic Software Modules [5] shall be published within the header file of this module and need to be provided in the BSW Module Description. The according module abbreviation can be found in the List of Basic Software Modules [6].

Additional module-specific published parameters are listed in the appendix Chapter A if applicable.

评论

此博客中的热门博文

AUTOSAR_SWS_CANDriver

Linux Driver Char Device 笔记

AUTOSAR_SWS_PWMDriver

AUTOSAR_SWS_PortDriver

AUTOSAR_SWS_ECUStateManager

EB - MCAL - MCU

AUTOSAR_SWS_ICUDriver

EB - MCAL - PWM