时间服务规范(Specification of Time Service)

📄 文档 ID:624 🏷 类型:SWS(软件规范说明) 📅 版本:AUTOSAR CP 4.4.0 📑 页数:51 📌 状态:Final 🔗 原 PDF:AUTOSAR_SWS_TimeService.pdf

目录

1 介绍与功能概述

本规范规定了 AUTOSAR 基本软件模块"时间服务(Time Service)"的功能、API 与配置。

Time Service 模块属于服务层(Services Layer)。该模块提供基于时间的服务功能,主要使用场景包括:

图 1 — 架构总览:Time Service 位于服务层,通过 RTE 与应用层交互,绕过 ECU 抽象层直接访问 GPT 驱动所提供的硬件定时器(架构允许 Time Service 与 GPT 之间旁路一层软件)。

Time Service 模块并不使用 GPT 驱动的全部特性,也不充当"定时器栈(Timer Stack)"的顶端。

若干"time type"——即"时间服务预定义定时器(Time Service Predef Timers)"——在硬件支持且被配置启用时可用。

每个预定义定时器(Predef Timer)拥有预定义的刻度时长(tick duration)(即物理时间单位)与位数(物理范围)。借此,可保证时间相关功能在所有支持所需预定义定时器的平台间的兼容性。

时间服务预定义定时器基于所谓的"GPT 预定义定时器(GPT Predef Timers)",后者是由 GPT 驱动提供的自由运行的硬件定时器。

以下时间服务预定义定时器被定义(见 §7.1.2 表 3):

若用户欲实现基于时间的功能,无需对 Time Service 模块进行任何用户特定的配置。用户可实例化任意数量的定时器(仅受可用内存限制),并可完全独立地使用这些定时器实例,从而复用硬件定时器。

提供以下基于时间的服务("…"表示左侧的扩展,即定时器位宽后缀):

所有服务均以轮询模式(polling mode)由用户调用,不支持通知(notifications)

时间服务可用于:

实现 Time Service 模块不需要任何中断。

1.1 使用场景

1.1.1 时间测量

通过使用 Time Service 模块,可测量代码的执行时间与周期时间,甚至以下对象的运行时间与周期时间:

可生成时间戳(time stamps)。

Time Service 模块的服务可用于测量 CPU 负载与任务负载,因为该服务可在 OS 的 PreTaskHook(及 PostTaskHook)中被调用。

1.1.2 基于时间的状态机

"基于时间的状态机"指:状态转移取决于时间。

使用 Time Service 模块可实现基于时间的状态机,其执行几乎独立于调用任务的周期时间。

用户软件必须保证任务的周期时间相对期望的时序行为足够短(取决于对时间信息的轮询)。

1.1.3 超时监督与忙等待

通过使用 Time Service 模块并采用预定义定时器(Predef Timers)替代"循环(loops)"或"空操作指令(nop instructions)"实现超时监督或忙等待,可防止软件模块中的错误与歧义行为。

使用"循环"或"nop 指令"是糟糕且危险的设计,因为以此方式实现的时间区间依赖于:

2 缩略语、缩写与术语

本章仅列出对理解本文档有帮助的少量缩略语与缩写,更全面信息见 AUTOSAR 官方术语表 [8]。

缩略语 / 缩写描述
nopNo Operation(空操作)

表 1 — 缩略语与缩写

下表所定义的术语在本文档中具有局部作用域

术语描述
GPT Predef Timer(GPT 预定义定时器) GPT Predef Timer 是由 GPT 驱动提供的自由运行向上计数器。其可用性取决于硬件(时钟、硬件定时器、预分频器、定时器寄存器宽度等)和配置。GPT Predef Timer 拥有预定义的物理时间单位与范围。
Time Service Predef Timer(时间服务预定义定时器) Time Service Predef Timer 是具有预定义物理时间单位与范围的自由运行向上计数器。其硬件定时器功能基于相应的 GPT Predef Timer。针对每个预定义定时器,Time Service 模块提供一组 API 服务。用户可实例化任意数量的定时器(仅受可用内存限制),并可完全独立地使用这些实例。
Timer instance(定时器实例) 定时器实例是 API 数据类型 Tm_PredefTimer…bitType 的数据对象,即在用户软件层面对时间服务预定义定时器的实例化。用户可实例化任意数量的定时器(仅受可用内存限制),并可完全独立地使用这些定时器实例,方式为调用作为 API 服务提供的方法。
Reference time(参考时间) 参考时间是每个定时器实例所存储的时间值。它是 API 数据类型 Tm_PredefTimer…bitType 中的实现特定元素。

表 2 — 术语

3 相关文档

3.1 输入文档

3.2 相关标准与规范

3.3 相关规范

AUTOSAR 提供了针对基本软件模块的通用规范 [10](SWS BSW General),该规范同样适用于 Time Service。

因此,SWS BSW General 应被视为 Time Service 的附加且必需的规范。

4 约束与假设

4.1 假设

无假设。

4.2 限制

功能基于可能不可用的硬件定时器

Time Service 模块的功能基于由 GPT 驱动提供的硬件定时器(GPT Predef Timers)。

可启用的 GPT Predef Timer 取决于时钟与可用的硬件定时器(预分频器、定时器寄存器宽度)。建议启用所有 GPT Predef Timer,以确保各平台间基于时间的功能的兼容性。

无标准化的 AUTOSAR 接口

本规范未定义标准化的 AUTOSAR 接口。这意味着 Time Service 模块的服务不能被位于 RTE 之上的 AUTOSAR 软件组件(SW-C)所访问。在未来版本/修订中,可能会将标准化的 AUTOSAR 接口加入本规范。

多分区支持

由于 Time Service 模块使用 GPT 模块获取硬件定时器的当前时间,两个模块应运行在同一 BSW 分区上。若 Time Service 模块被用于分布式 BSW 系统(例如多核系统),建议在每个 BSW 分区中均具备含 Time Service 与 GPT 模块的功能簇,以避免跨分区通信。

采用主/从方式(GPT 与 Time Service 主机在同一 BSW 分区,Time Service 从机在另一分区)因性能原因并不合适。

4.3 在汽车领域的适用性

无限制。

5 与其他模块的依赖

本节描述 Time Service 与其他模块的关系。

Time Service 模块对以下 AUTOSAR 模块存在依赖:

5.1 GPT

Time Service 模块的功能基于所谓的"GPT 预定义定时器(GPT Predef Timers)"。GPT Predef Timer 是由 GPT 驱动提供的自由运行向上计数器,见 [11](SWS GPT Driver)。

6 需求追溯

本章引用 SRS 文档(软件需求规范)所规定、适用于本软件模块的输入需求。

下表列出了 SWS 文档中满足输入需求的具体规范条目引用。仅功能需求被引用。

6.1 SRS_Tm_* 需求追溯

需求 ID描述由以下 SWS 需求满足
SRS_Tm_00001 Time Service 模块应支持不同类型的预定义定时器 SWS_Tm_00032, _00033, _00034, _00035, _00038, _00039, _00040, _00041, _00042, _00043, _00044, _00045, _00046, _00047, _00048, _00049, _00050, _00051, _00052, _00053, _00054, _00055, _00056
SRS_Tm_00002 Time Service 模块的预定义定时器应使用 GPT 预定义定时器作为时基 SWS_Tm_00001, _00002, _00003, _00004, _00005, _00057
SRS_Tm_00003 Time Service 模块应允许配置启用哪些预定义定时器 SWS_Tm_00026, _00027
SRS_Tm_00004 Time Service 模块应提供用于重置定时器实例的同步服务 SWS_Tm_00038, _00043, _00048, _00053
SRS_Tm_00005 Time Service 模块应提供用于获取时间跨度的同步服务 SWS_Tm_00009, _00039, _00044, _00049, _00054
SRS_Tm_00006 Time Service 模块应提供用于平移定时器实例参考时间的同步服务 SWS_Tm_00006, _00013, _00040, _00045, _00050, _00055
SRS_Tm_00007 Time Service 模块应提供用于同步两个定时器实例的同步服务 SWS_Tm_00019, _00041, _00046, _00051, _00056
SRS_Tm_00008 Time Service 模块应提供刻度时长为 1µs、通过轮询执行忙等待的同步服务 SWS_Tm_00022, _00023, _00024, _00042, _00047, _00052

6.2 SRS_BSW_* 通用 BSW 需求追溯(汇总)

以下 SRS_BSW_* 通用 BSW 需求(共 57 条)由 Time Service 模块满足。除下列特殊条目外,SWS_Tm_00059 集中满足:

SRS_BSW_*由以下 SWS_Tm_* 满足
SRS_BSW_00312(共享代码应可重入) SWS_Tm_00007, SWS_Tm_00011, SWS_Tm_00017, SWS_Tm_00020, SWS_Tm_00025
SRS_BSW_00323(所有 BSW 模块应检查传入 API 参数的有效性) SWS_Tm_00008, _00012, _00016, _00018, _00021, _00037
SRS_BSW_00337(开发错误分类) SWS_Tm_00030
SRS_BSW_00348(所有 AUTOSAR 标准类型与常量应放在标准类型头文件中) SWS_Tm_00031
SRS_BSW_00369(所有 AUTOSAR BSW 模块不应通过 API 返回特定的开发错误码) SWS_Tm_00008, _00012, _00038, _00039, _00043, _00044, _00048, _00049, _00053, _00054, _00066
SRS_BSW_00407(每个 BSW 模块应提供用于读取模块实现版本信息的函数) SWS_Tm_00036

其余 SRS_BSW_* 需求:SRS_BSW_00005, _00006, _00007, _00009, _00010, _00159, _00160, _00161, _00162, _00167, _00168, _00170, _00172, _00306, _00307, _00308, _00309, _00321, _00325, _00328, _00330, _00331, _00333, _00334, _00335, _00341, _00342, _00344, _00347, _00353, _00357, _00359, _00360, _00361, _00373, _00377, _00378, _00398, _00413, _00415, _00416, _00417, _00422, _00423, _00424, _00425, _00426, _00427, _00428, _00429, _00432, _00433, _00437, _00439, _00440 均由 SWS_Tm_00059 集中满足。

7 功能规范

7.1 通用行为

7.1.1 GPT 预定义定时器

Time Service 模块的功能基于所谓的"GPT 预定义定时器(GPT Predef Timers)",见 [11](SWS GPT Driver)。

7.1.2 时间服务预定义定时器

Time Service Predef Timer 基于相应的 GPT Predef Timer。

针对每个时间服务预定义定时器定义一种数据类型。

时间服务预定义定时器数据类型名 刻度时长 最大刻度值 位数 最大时间跨度(约值)
Tm_PredefTimer1us16bitType1 µs6553516 bit65 ms
Tm_PredefTimer1us24bitType1677721524 bit16 s
Tm_PredefTimer1us32bitType429496729532 bit71 minutes
Tm_PredefTimer100us32bitType100 µs429496729532 bit4.9 days

表 3 — 时间服务预定义定时器特性

定时器实例可通过定义"时间服务预定义定时器数据类型"的数据对象(RAM 数据)创建,例如:

Tm_PredefTimer1us32bitType Timer1;   /* 定义定时器实例 */

数据类型(以及定时器实例)包含所谓的"参考时间(reference time)"。该参考时间对部分 API 服务是必需的。

数据类型的详细定义不在本规范的范围内,因为其结构元素不应在 Time Service 模块之外被使用。

数据类型 Tm_PredefTimer1us32bitType 示例:

typedef struct
{
  uint32 ui32RefTime;   /* 定时器的参考时间 */
} Tm_PredefTimer1us32bitType;

每个时间服务预定义定时器拥有其专属的一组 API 服务,原因在于性能(特别是 1µs 定时器)。这些服务提供"简单"功能,类似秒表:

每个服务至少有一个参数(如 TimerPtr),即用户软件层面所定义的定时器实例的指针。

服务名由两部分组成:

服务名示例:Tm_ResetTimer1us32bit

[SWS_Tm_00001] ⌈ Time Service 模块应使用 GPT 驱动服务 Gpt_GetPredefTimerValue 获取所需预定义定时器的当前时间值。 ⌋(SRS_Tm_00002)

[SWS_Tm_00002] ⌈ "1us16bit" 函数在需要时基时应使用 GPT_PREDEF_TIMER_1US_16BIT 作为时基。 ⌋(SRS_Tm_00002)
"1us16bit" 函数示例:Tm_ResetTimer1us16bit

[SWS_Tm_00003] ⌈ "1us24bit" 函数在需要时基时应使用 GPT_PREDEF_TIMER_1US_24BIT 作为时基。 ⌋(SRS_Tm_00002)

[SWS_Tm_00004] ⌈ "1us32bit" 函数在需要时基时应使用 GPT_PREDEF_TIMER_1US_32BIT 作为时基。 ⌋(SRS_Tm_00002)

[SWS_Tm_00005] ⌈ "100us32bit" 函数在需要时基时应使用 GPT_PREDEF_TIMER_100US_32BIT 作为时基。 ⌋(SRS_Tm_00002)

7.1.3 最大可测量时间跨度

本章需在用户软件层面加以考虑。

可测量的时间跨度受限于相应 GPT 预定义定时器的最大值。定时器的环绕(wrap-around)由 GetTimeSpan 函数处理,见 SWS_Tm_00010

下图所示的"自由运行向上计数器"展示了 GPT 驱动所提供的自由运行向上计数器的一般行为。服务 Tm_ResetTimer…Tm_GetTimeSpan… 被用于示例测量三段时间跨度。

图 2 — 自由运行向上计数器Tm_ResetTimer… 存储参考时间,Tm_GetTimeSpan… 计算时间差。超过最大时间跨度则无法正确计算("3" 段)。

通过调用 Tm_ResetTimer…,相关 GPT 预定义定时器的当前时间被存储为参考时间。详见 §7.1.6。

通过调用 Tm_GetTimeSpan…,当前时间与参考时间之间的时间差被计算并输出。详见 §7.1.7。

对于:

时间跨度将被正确计算。

对于:

由于超出了最大时间跨度,无法计算正确的时间跨度,亦无法检测到此超出。这并非本规范的缺陷,而是由技术原理导致的逻辑必然结果。另见 §7.1.10.1 "BusyWait 服务的非预期行为"。

为确保在所有可能情形下的正确行为,GetTimeSpan 服务的用户必须检查:

7.1.4 时间量化误差

本章需在用户软件层面加以考虑。

在使用/解释 GetTimeSpan 函数所返回的值时,必须考虑量化误差理论。GetTimeSpan 函数所返回值的精度为 ±1 刻度。

例如:

GetTimeSpan 函数返回值实际最小时间实际最大时间注释
1µs约 0 µs约 2 µs见下方"时间量化示例图"
3400µs约 3399 µs约 3401 µs
56100 µs约 5500 µs约 5700 µs

图 3 — 时间量化示例:两次 Tm_GetTimeSpan1us32bit 调用(¹ 和 ²)均返回值 1,即 1 µs。

依据 Tm_ResetTimer1us32bitTm_GetTimeSpan1us32bit 被调用的时间点,实际时间跨度可在约 0 µs 到约 2 µs 范围内。

若使用 GetTimeSpan 函数检查最小时间(如:超时监督、忙等待),用户软件必须观察 n+1 个刻度,以确保已过去至少 n 个刻度的时间区间。另见 SWS_Tm_00024

对于忙等待,请使用 BusyWait 服务(见 §7.1.10)。

7.1.5 服务执行时间与短时间跨度测量

本章需在用户软件层面加以考虑。

若需要在用户软件层测量短时间跨度,则 Tm 服务及底层 GPT 驱动服务的执行时间必须相对于所测量的时间跨度足够短。

执行时间依赖于:

用户必须检查执行时间是否足以满足其使用场景。

7.1.6 ResetTimer 服务

ResetTimer 服务从用户角度重置一个定时器实例。

ResetTimer 函数示例:Tm_ResetTimer1us32bit

[SWS_Tm_00006] ⌈ ResetTimer 函数应重置由参数 TimerPtr 所传递的定时器实例。这意味着定时器实例的参考时间应被设置为相关 GPT 预定义定时器的当前时间。 ⌋(SRS_Tm_00006)

[SWS_Tm_00007] ⌈ ResetTimer 函数应可重入,前提是并发调用中所使用的定时器实例不同。 ⌋(SRS_BSW_00312)

[SWS_Tm_00008] ⌈ 若 Time Service 模块的开发错误检测已启用:当指针参数为 null 指针时,ResetTimer 函数应报告错误 TM_E_PARAM_POINTER 并返回 E_NOT_OK。 ⌋(SRS_BSW_00369, SRS_BSW_00323)

7.1.7 GetTimeSpan 服务

GetTimeSpan 函数示例:Tm_GetTimeSpan1us32bit

[SWS_Tm_00009] ⌈ GetTimeSpan 函数应计算并返回当前时间与定时器实例参考时间之间的时间差。 ⌋(SRS_Tm_00005)

:最大可测量时间跨度的限制必须在用户软件层加以考虑,见 §7.1.3。

:由于 GetTimeSpan 函数以整数值返回时间差,在使用/解释这些值时必须考虑量化误差理论(见 §7.1.4)。

[SWS_Tm_00010] ⌈ GetTimeSpan 函数在执行减法(当前时间 - 参考时间)时,若当前时间值小于参考时间值,应正确处理环绕(wrap-around)。 ⌋()

提示:可按以下 C 代码实现正确的环绕处理:

/* 16bit 定时器:*/
ui16TimeSpan = (uint16)(ui16CurrentTime
                     - TimerPtr->ui16RefTime);
/* 24bit 定时器:*/
ui32TimeSpan = (uint32)(ui32CurrentTime
                     - TimerPtr->ui32RefTime)
                     & (uint32)0x00FFFFFFu;
/* 32bit 定时器:*/
ui32TimeSpan = (uint32)(ui32CurrentTime
                     - TimerPtr->ui32RefTime);

[SWS_Tm_00011] ⌈ GetTimeSpan 函数应完全可重入,即即便对同一定时器实例也是如此。 ⌋(SRS_BSW_00312)

[SWS_Tm_00012] ⌈ 若 Time Service 模块的开发错误检测已启用:当任一指针参数为 null 指针时,GetTimeSpan 函数应报告错误 TM_E_PARAM_POINTER 并返回 E_NOT_OK。 ⌋(SRS_BSW_00369, SRS_BSW_00323)

[SWS_Tm_00065] ⌈ 当检测到错误且参数 TimeSpanPtr 非 null 指针时,GetTimeSpan 函数应返回时间跨度 "0"。 ⌋()
:这是为了在用户软件层获得明确的(可重复的)行为,即使未使用返回值(E_OK, E_NOT_OK)。

7.1.8 ShiftTimer 服务

ShiftTimer 函数示例:Tm_ShiftTimer1us32bit

[SWS_Tm_00013] ⌈ ShiftTimer 函数应平移定时器实例的参考时间。这意味着 TimeValue 值应被加到定时器实例的参考时间上。 ⌋(SRS_Tm_00006)

[SWS_Tm_00014] ⌈ ShiftTimer 函数在执行加法(参考时间 + TimeValue)时,若总和大于定时器的最大值,应正确处理环绕。 ⌋()

提示:可按以下 C 代码实现正确的环绕处理:

/* 16bit 定时器:*/
TimerPtr->ui16RefTime = (uint16)(TimerPtr->ui16RefTime
                                + TimeValue);
/* 24bit 定时器:*/
TimerPtr->ui32RefTime = (uint32)(TimerPtr->ui32RefTime
                                + TimeValue) & (uint32)0x00FFFFFFu;
/* 32bit 定时器:*/
TimerPtr->ui32RefTime = (uint32)(TimerPtr->ui32RefTime
                                + TimeValue);

[SWS_Tm_00015] ⌈ 范围 24bit 的 ShiftTimer 函数应将参数 TimeValue 的值限制为 0xFFFFFF。 ⌋()

[SWS_Tm_00016] ⌈ 若 Time Service 模块的开发错误检测已启用:当参数 TimeValue 的值大于 0xFFFFFF 时,范围 24bit 的 ShiftTimer 函数应报告错误 TM_E_PARAM_VALUE。 ⌋(SRS_BSW_00323)

[SWS_Tm_00017] ⌈ ShiftTimer 函数应可重入,前提是并发调用中所使用的定时器实例不同。 ⌋(SRS_BSW_00312)

[SWS_Tm_00018] ⌈ 若 Time Service 模块的开发错误检测已启用:当指针参数为 null 指针时,ShiftTimer 函数应报告错误 TM_E_PARAM_POINTER。 ⌋(SRS_BSW_00323)

7.1.9 SyncTimer 服务

"SyncTimer" 函数示例:Tm_SyncTimer1us32bit

[SWS_Tm_00019] ⌈ SyncTimer 函数应同步两个定时器实例。这意味着目标定时器实例的参考时间应被设置为源定时器实例的参考时间。 ⌋(SRS_Tm_00007)

[SWS_Tm_00020] ⌈ SyncTimer 函数应可重入,前提是并发调用中所使用的目标定时器实例不同。 ⌋(SRS_BSW_00312)

[SWS_Tm_00021] ⌈ 若 Time Service 模块的开发错误检测已启用:当任一指针参数为 null 指针时,SyncTimer 函数应报告错误 TM_E_PARAM_POINTER。 ⌋(SRS_BSW_00323)

7.1.10 BusyWait 服务

BusyWait 服务通过轮询执行忙等待(active waiting),并保证最短等待时间。BusyWait 服务应被用以替代用户软件层自行实现的方案,以规避错误实现的风险。

风险可能包括:

:BusyWait 函数的规范考虑到了量化误差理论(见 §7.1.4)。

:由于 BusyWait 服务基于轮询,BusyWait 服务的用户有责任避免非预期行为(见 §7.1.10.1)。

该服务仅对刻度时长为 1µs 的预定义定时器可用。等待时间被限制为 8 位(255 µs),以避免长时间阻塞代码执行。

BusyWait 函数示例:Tm_BusyWait1us32bit

[SWS_Tm_00022] ⌈ BusyWait 函数应按参数 WaitingTimeMin 所传递的最短时间执行忙等待。 ⌋(SRS_Tm_00008)

[SWS_Tm_00023] ⌈ BusyWait 函数不应关闭中断。这意味着实际等待时间可能大于期望等待时间。 ⌋(SRS_Tm_00008)

[SWS_Tm_00024] ⌈ BusyWait 函数应保证最短等待时间。这意味着必须观察 n+1 个刻度,以确保至少 n 个刻度的时间区间已过去。 ⌋(SRS_Tm_00008)

[SWS_Tm_00025] ⌈ BusyWait 函数应可重入。 ⌋(SRS_BSW_00312)

[SWS_Tm_00066] ⌈ 当检测到错误时,BusyWait 函数应返回 E_NOT_OK 并立即中止"等待"。 ⌋(SRS_BSW_00369)

7.1.10.1 BusyWait 服务的非预期行为

本章需在用户软件层面加以考虑。

由于 BusyWait 服务基于轮询,BusyWait 服务的用户有责任避免非预期行为。

非预期行为示例:

已用时间(µs)16 位基准定时器值(µs)动作
00任务处于 Running 状态。调用服务 Tm_BusyWait1us16bit(50); /* 等待 50 µs */
22任务转为 Ready 状态
2105521055任务仍处于 Ready 状态
6553565535任务仍处于 Ready 状态,下一刻定时器值发生环绕
655360任务仍处于 Ready 状态
6555923任务再次转为 Running 状态。
问题:尽管自调用以来已过去 65559 µs(> 50 µs),BusyWait 服务仍未返回。

为确保在所有可能情形下的正确行为,BusyWait 服务的用户必须检查:

使用 Tm_BusyWait1us32bit 服务时,仅当调用 BusyWait 服务的任务被抢占(不再执行,处于 Ready 状态)超过 71 分钟时,才会出现上述问题。

7.1.11 API 服务配置

Time Service 模块允许配置启用哪些预定义定时器,详见第 10 章的配置参数。

配置参数示例:TmEnablePredefTimer1us16bit

[SWS_Tm_00026] ⌈ 对每个通过配置启用的预定义定时器,应提供以下 API 服务集合:ResetTimer, GetTimeSpan, ShiftTimer, SyncTimer。 ⌋(SRS_Tm_00003)

[SWS_Tm_00027] ⌈ 对每个通过配置启用的刻度时长为 1 µs 的预定义定时器,应提供 API 服务 BusyWait。 ⌋(SRS_Tm_00003)

7.2 模块初始化

本模块无 Tm_Init 函数的要求。

Time Service 模块不需要初始化任何变量(如状态)或硬件资源。Time Service 模块所需的所有 GPT 预定义定时器(假定已正确配置)在可能时由 GPT 驱动自动运行。这一点由 GPT 驱动保证,见 §7.1.1。

关于开发错误检测,请参阅 §7.6。

7.3 使用场景示例代码

本章给出 §1.1 描述的使用场景之外的额外示例代码。

7.3.1 时间测量

某些情况下需要测量代码的执行时间。示例代码:

#include "Os.h"
#include "Tm.h"

Tm_PredefTimer1us24bitType TimerIsr1;       /* 定义定时器实例 */
Tm_PredefTimer1us24bitType TimerTask100ms;  /* 定义定时器实例 */
uint32 RunTimeIsr1_us;        /* Isr1 的总运行时间 */
uint32 RunTimeTask100ms_us;   /* Task100ms 的总运行时间 */

ISR(Isr1)
{
  (void)Tm_ResetTimer1us24bit(&TimerIsr1);
  /* Code */
  (void)Tm_GetTimeSpan1us24bit(&TimerIsr1, &RunTimeIsr1_us);
}

TASK(Task100ms)
{
  (void)Tm_ResetTimer1us24bit(&TimerTask100ms);
  /* Code */
  (void)Tm_GetTimeSpan1us24bit(&TimerTask100ms, &RunTimeTask100ms_us);
  (void)TerminateTask();
}

7.3.2 基于时间的状态机

通过实现基于时间的状态机,可以使基于时间的功能几乎独立于调用任务的周期时间。示例代码:

#include "Os.h"
#include "Tm.h"

#define MY_INIT   0
#define MY_WAIT1  1
#define MY_WAIT2  2

uint8_least State = MY_INIT;

TASK(Task5ms)
{
  static Tm_PredefTimer1us24bitType Timer;  /* 定义定时器实例 */
  uint32 WaitingTime1_us = 500000u;          /* 500ms */
  uint32 WaitingTime2_us = 250000u;          /* 250ms */
  switch (State)
  {
    case MY_INIT:
    {
      (void)Tm_ResetTimer1us24bit(&Timer);
      State = MY_WAIT1;
      break;
    }
    case MY_WAIT1:
    {
      uint32 Time_us;
      (void)Tm_GetTimeSpan1us24bit(&Timer, &Time_us);
      if (Time_us >= WaitingTime1_us)
      {
        /* Action ... */
        Tm_ShiftTimer1us24bit(&Timer, WaitingTime1_us);
        State = MY_WAIT2;
      }
      break;
    }
    case MY_WAIT2:
    {
      uint32 Time_us;
      (void)Tm_GetTimeSpan1us24bit(&Timer, &Time_us);
      if (Time_us >= WaitingTime2_us)
      {
        /* Action ... */
        Tm_ShiftTimer1us24bit(&Timer, WaitingTime2_us);
        State = MY_WAIT1;
      }
      break;
    }
  }
  (void)TerminateTask();
}

7.3.3 超时监督

在硬件访问 MCAL 驱动时,有时需要在一定的短时间窗口内预期硬件的响应。示例代码:

#include "Register.h"
#include "Tm.h"

Tm_PredefTimer1us32bitType Timer1;   /* 定义定时器实例 */
uint16 StatusRegisterBit0;
uint32 TimeElapsed_us;

void SampleFunction(void)
{
  (void)Tm_ResetTimer1us32bit(&Timer1);
  do
  {
    StatusRegisterBit0 = HW_STATUS_REG & 0x0001u;
    (void)Tm_GetTimeSpan1us32bit(&Timer1, &TimeElapsed_us);
  } while ( (StatusRegisterBit0 != 0x0001u)   /* 等待 bit 0 被置位 */
         && (TimeElapsed_us <= 40) );         /* 超时 40 µs */
}

7.3.4 忙等待

在硬件访问 MCAL 驱动时,有时需要经历一定的短时间窗口。示例代码片段:

#include "Tm.h"
Std_ReturnType CanTrcv_SetOpMode(uint8 Transceiver,
                                 CanIf_TrcvModeType OpMode)
{
  /* Code */
  switch (OpMode)
  {
    case CANIF_TRCV_MODE_NORMAL:
    {
      /* Code */
      break;
    }
    case CANIF_TRCV_MODE_SLEEP:
    {
      /* Code */
      SetPinEnableHigh();
      /* 忙等待:50 µs(TJA1054:至少 50 µs) */
      (void)Tm_BusyWait1us32bit(50);
      SetPinEnableLow();
      /* Code */
      break;
    }
    case CANIF_TRCV_MODE_STANDBY:
    {
      /* Code */
      break;
    }
  }
  /* Code */
}

7.4 版本检查

请参阅 SWS_BSWGeneral 中"Version Check"章节。

7.5 错误分类

7.5.1 开发错误

[SWS_Tm_00028] ⌈ Time Service 模块应按其构建版本(开发/生产)检测以下错误:

错误类型相关性相关错误码十六进制值
API 参数检查:非法指针开发TM_E_PARAM_POINTER0x01
API 参数检查:非法值开发TM_E_PARAM_VALUE0x02

⌋()

[SWS_Tm_00030] ⌈ 因具体实现而检测到的其他错误应在具体实现规范中补充。其分类与枚举应与所列错误兼容。 ⌋(SRS_BSW_00337)

7.5.2 运行时错误

[SWS_Tm_00067]

错误类型相关性相关错误码十六进制值
访问底层硬件定时器失败运行时TM_E_HARDWARE_TIMER0x03

⌋()

7.5.3 瞬态故障

无瞬态故障。

7.5.4 生产错误

Time Service 模块未定义生产错误。

7.5.5 扩展生产错误

无扩展生产错误。

7.6 错误检测

请参阅 SWS_BSWGeneral 中"Error detection"章节。

[SWS_Tm_00063] ⌈ 当发生错误时,对应的 Time Service 函数应不执行任何操作并直接返回,除非该函数有专门且更详细的规定。 ⌋()

[SWS_Tm_00064] ⌈ 若底层 GPT 驱动服务返回 E_NOT_OK,则 ResetTimer, GetTimeSpanBusyWait 函数应报告错误 TM_E_HARDWARE_TIMER。 ⌋()

7.7 错误通知

请参阅 SWS_BSWGeneral 中"Error notification"章节。

8 API 规范

8.1 导入类型

本章列出从以下模块导入的所有类型:

[SWS_Tm_00031]

模块头文件导入类型
GptGpt.hGpt_PredefTimerType
Std_TypesStandardTypes.hStd_ReturnType
StandardTypes.hStd_VersionInfoType

⌋(SRS_BSW_00348)

8.2 类型定义

8.2.1 Tm_PredefTimer1us16bitType

[SWS_Tm_00032]

Name(名称):Tm_PredefTimer1us16bitType
Type(类型):Structure(结构体)
Range(范围):实现特定(Implementation specific)
Description(描述):时间服务预定义定时器 1us16bit 的数据类型。结构体包含参考时间。
Available via(可用途径):Tm.h

⌋(SRS_Tm_00001)

8.2.2 Tm_PredefTimer1us24bitType

[SWS_Tm_00033]

NameTm_PredefTimer1us24bitType
TypeStructure
Range实现特定
Description时间服务预定义定时器 1us24bit 的数据类型。结构体包含参考时间。
Available viaTm.h

⌋(SRS_Tm_00001)

8.2.3 Tm_PredefTimer1us32bitType

[SWS_Tm_00034]

NameTm_PredefTimer1us32bitType
TypeStructure
Range实现特定
Description时间服务预定义定时器 1us32bit 的数据类型。结构体包含参考时间。
Available viaTm.h

⌋(SRS_Tm_00001)

8.2.4 Tm_PredefTimer100us32bitType

[SWS_Tm_00035]

NameTm_PredefTimer100us32bitType
TypeStructure
Range实现特定
Description时间服务预定义定时器 100µs32bit 的数据类型。结构体包含参考时间。
Available viaTm.h

⌋(SRS_Tm_00001)

8.3 函数定义

8.3.1 Tm_GetVersionInfo

[SWS_Tm_00036]

Service name(服务名):Tm_GetVersionInfo
Syntax(语法):void Tm_GetVersionInfo(
  Std_VersionInfoType* VersionInfoPtr
)
Service ID [hex]0x1
Sync/AsyncSynchronous(同步)
Reentrancy(可重入性):Reentrant(可重入)
Parameters (in)(入参):None
Parameters (inout)None
Parameters (out)VersionInfoPtr指向存储本模块版本信息的位置的指针
Return value(返回值):None
Description返回本模块的版本信息
Available viaTm.h

⌋(SRS_BSW_00407)

[SWS_Tm_00037] ⌈ 若 Time Service 模块的开发错误检测已启用:当参数 VersionInfoPtr 为 null 指针时,函数 Tm_GetVersionInfo 应报告错误 TM_E_PARAM_POINTER。 ⌋(SRS_BSW_00323)

8.3.2 Tm_ResetTimer1us16bit

[SWS_Tm_00038]

Service nameTm_ResetTimer1us16bit
SyntaxStd_ReturnType Tm_ResetTimer1us16bit(
  Tm_PredefTimer1us16bitType* TimerPtr
)
Service ID [hex]0x2
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same timer instance(可重入,但对同一定时器实例不可)
Parameters (in)None
Parameters (inout)None
Parameters (out)TimerPtr指向由用户定义的定时器实例的指针
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description重置一个定时器实例(从用户视角)
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00004, SRS_BSW_00369)

8.3.3 Tm_GetTimeSpan1us16bit

[SWS_Tm_00039]

Service nameTm_GetTimeSpan1us16bit
SyntaxStd_ReturnType Tm_GetTimeSpan1us16bit(
  const Tm_PredefTimer1us16bitType* TimerPtr,
  uint16* TimeSpanPtr
)
Service ID [hex]0x3
Sync/AsyncSynchronous
ReentrancyReentrant
Parameters (in)TimerPtr指向由用户定义的定时器实例的指针
Parameters (inout)None
Parameters (out)TimeSpanPtr指向 RAM 中时间跨度目标数据的指针
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description返回时间差(当前时间 - 参考时间)
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00005, SRS_BSW_00369)

8.3.4 Tm_ShiftTimer1us16bit

[SWS_Tm_00040]

Service nameTm_ShiftTimer1us16bit
Syntaxvoid Tm_ShiftTimer1us16bit(
  Tm_PredefTimer1us16bitType* TimerPtr,
  uint16 TimeValue
)
Service ID [hex]0x4
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same timer instance
Parameters (in)TimeValue时间值(µs),参考时间应被平移该值
Parameters (inout)TimerPtr指向由用户定义的定时器实例的指针
Parameters (out)None
Return valueNone
Description平移定时器实例的参考时间
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00006)

8.3.5 Tm_SyncTimer1us16bit

[SWS_Tm_00041]

Service nameTm_SyncTimer1us16bit
Syntaxvoid Tm_SyncTimer1us16bit(
  Tm_PredefTimer1us16bitType* TimerDstPtr,
  const Tm_PredefTimer1us16bitType* TimerSrcPtr
)
Service ID [hex]0x5
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same destination timer instance
Parameters (in)TimerSrcPtr指向由用户定义的源定时器实例的指针
Parameters (inout)None
Parameters (out)TimerDstPtr指向由用户定义的目标定时器实例的指针
Return valueNone
Description同步两个定时器实例
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00007)

8.3.6 Tm_BusyWait1us16bit

[SWS_Tm_00042]

Service nameTm_BusyWait1us16bit
SyntaxStd_ReturnType Tm_BusyWait1us16bit(
  uint8 WaitingTimeMin
)
Service ID [hex]0x6
Sync/AsyncSynchronous
ReentrancyReentrant
Parameters (in)WaitingTimeMin最短等待时间(µs)
Parameters (inout)None
Parameters (out)None
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description通过轮询执行忙等待,保证最短等待时间
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00008)

:由于 BusyWait 服务基于轮询,BusyWait 服务的用户有责任避免非预期行为,见 §7.1.10。

8.3.7 Tm_ResetTimer1us24bit

[SWS_Tm_00043]

Service nameTm_ResetTimer1us24bit
SyntaxStd_ReturnType Tm_ResetTimer1us24bit(
  Tm_PredefTimer1us24bitType* TimerPtr
)
Service ID [hex]0x7
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same timer instance
Parameters (in)None
Parameters (inout)None
Parameters (out)TimerPtr指向由用户定义的定时器实例的指针
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description重置一个定时器实例(从用户视角)
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00004, SRS_BSW_00369)

8.3.8 Tm_GetTimeSpan1us24bit

[SWS_Tm_00044]

Service nameTm_GetTimeSpan1us24bit
SyntaxStd_ReturnType Tm_GetTimeSpan1us24bit(
  const Tm_PredefTimer1us24bitType* TimerPtr,
  uint32* TimeSpanPtr
)
Service ID [hex]0x8
Sync/AsyncSynchronous
ReentrancyReentrant
Parameters (in)TimerPtr指向由用户定义的定时器实例的指针
Parameters (inout)None
Parameters (out)TimeSpanPtr指向 RAM 中时间跨度目标数据的指针
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description返回时间差(当前时间 - 参考时间)
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00005, SRS_BSW_00369)

8.3.9 Tm_ShiftTimer1us24bit

[SWS_Tm_00045]

Service nameTm_ShiftTimer1us24bit
Syntaxvoid Tm_ShiftTimer1us24bit(
  Tm_PredefTimer1us24bitType* TimerPtr,
  uint32 TimeValue
)
Service ID [hex]0x9
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same timer instance
Parameters (in)TimeValue时间值(µs),参考时间应被平移该值
Range(范围):0 - 0xFFFFFF
Parameters (inout)TimerPtr指向由用户定义的定时器实例的指针
Parameters (out)None
Return valueNone
Description平移定时器实例的参考时间
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00006)

8.3.10 Tm_SyncTimer1us24bit

[SWS_Tm_00046]

Service nameTm_SyncTimer1us24bit
Syntaxvoid Tm_SyncTimer1us24bit(
  Tm_PredefTimer1us24bitType* TimerDstPtr,
  const Tm_PredefTimer1us24bitType* TimerSrcPtr
)
Service ID [hex]0xa
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same destination timer instance
Parameters (in)TimerSrcPtr指向由用户定义的源定时器实例的指针
Parameters (inout)None
Parameters (out)TimerDstPtr指向由用户定义的目标定时器实例的指针
Return valueNone
Description同步两个定时器实例
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00007)

8.3.11 Tm_BusyWait1us24bit

[SWS_Tm_00047]

Service nameTm_BusyWait1us24bit
SyntaxStd_ReturnType Tm_BusyWait1us24bit(
  uint8 WaitingTimeMin
)
Service ID [hex]0xb
Sync/AsyncSynchronous
ReentrancyReentrant
Parameters (in)WaitingTimeMin最短等待时间(µs)
Parameters (inout)None
Parameters (out)None
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description通过轮询执行忙等待,保证最短等待时间
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00008)

:由于 BusyWait 服务基于轮询,BusyWait 服务的用户有责任避免非预期行为,见 §7.1.10。

8.3.12 Tm_ResetTimer1us32bit

[SWS_Tm_00048]

Service nameTm_ResetTimer1us32bit
SyntaxStd_ReturnType Tm_ResetTimer1us32bit(
  Tm_PredefTimer1us32bitType* TimerPtr
)
Service ID [hex]0xc
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same timer instance
Parameters (in)None
Parameters (inout)None
Parameters (out)TimerPtr指向由用户定义的定时器实例的指针
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description重置一个定时器实例(从用户视角)
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00004, SRS_BSW_00369)

8.3.13 Tm_GetTimeSpan1us32bit

[SWS_Tm_00049]

Service nameTm_GetTimeSpan1us32bit
SyntaxStd_ReturnType Tm_GetTimeSpan1us32bit(
  const Tm_PredefTimer1us32bitType* TimerPtr,
  uint32* TimeSpanPtr
)
Service ID [hex]0xd
Sync/AsyncSynchronous
ReentrancyReentrant
Parameters (in)TimerPtr指向由用户定义的定时器实例的指针
Parameters (inout)None
Parameters (out)TimeSpanPtr指向 RAM 中时间跨度目标数据的指针
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description返回时间差(当前时间 - 参考时间)
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00005, SRS_BSW_00369)

8.3.14 Tm_ShiftTimer1us32bit

[SWS_Tm_00050]

Service nameTm_ShiftTimer1us32bit
Syntaxvoid Tm_ShiftTimer1us32bit(
  Tm_PredefTimer1us32bitType* TimerPtr,
  uint32 TimeValue
)
Service ID [hex]0xe
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same timer instance
Parameters (in)TimeValue时间值(µs),参考时间应被平移该值
Parameters (inout)TimerPtr指向由用户定义的定时器实例的指针
Parameters (out)None
Return valueNone
Description平移定时器实例的参考时间
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00006)

8.3.15 Tm_SyncTimer1us32bit

[SWS_Tm_00051]

Service nameTm_SyncTimer1us32bit
Syntaxvoid Tm_SyncTimer1us32bit(
  Tm_PredefTimer1us32bitType* TimerDstPtr,
  const Tm_PredefTimer1us32bitType* TimerSrcPtr
)
Service ID [hex]0xf
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same destination timer instance
Parameters (in)TimerSrcPtr指向由用户定义的源定时器实例的指针
Parameters (inout)None
Parameters (out)TimerDstPtr指向由用户定义的目标定时器实例的指针
Return valueNone
Description同步两个定时器实例
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00007)

8.3.16 Tm_BusyWait1us32bit

[SWS_Tm_00052]

Service nameTm_BusyWait1us32bit
SyntaxStd_ReturnType Tm_BusyWait1us32bit(
  uint8 WaitingTimeMin
)
Service ID [hex]0x10
Sync/AsyncSynchronous
ReentrancyReentrant
Parameters (in)WaitingTimeMin最短等待时间(µs)
Parameters (inout)None
Parameters (out)None
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description通过轮询执行忙等待,保证最短等待时间
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00008)

:由于 BusyWait 服务基于轮询,BusyWait 服务的用户有责任避免非预期行为,见 §7.1.10。

8.3.17 Tm_ResetTimer100us32bit

[SWS_Tm_00053]

Service nameTm_ResetTimer100us32bit
SyntaxStd_ReturnType Tm_ResetTimer100us32bit(
  Tm_PredefTimer100us32bitType* TimerPtr
)
Service ID [hex]0x11
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same timer instance
Parameters (in)None
Parameters (inout)None
Parameters (out)TimerPtr指向由用户定义的定时器实例的指针
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description重置一个定时器实例(从用户视角)
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00004, SRS_BSW_00369)

8.3.18 Tm_GetTimeSpan100us32bit

[SWS_Tm_00054]

Service nameTm_GetTimeSpan100us32bit
SyntaxStd_ReturnType Tm_GetTimeSpan100us32bit(
  const Tm_PredefTimer100us32bitType* TimerPtr,
  uint32* TimeSpanPtr
)
Service ID [hex]0x12
Sync/AsyncSynchronous
ReentrancyReentrant
Parameters (in)TimerPtr指向由用户定义的定时器实例的指针
Parameters (inout)None
Parameters (out)TimeSpanPtr指向 RAM 中时间跨度目标数据的指针
Return valueStd_ReturnTypeE_OK:底层 GPT 驱动服务已返回 E_OK,且未检测到开发错误
E_NOT_OK:底层 GPT 驱动服务已返回 E_NOT_OK,或检测到了开发错误
Description返回时间差(当前时间 - 参考时间)
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00005, SRS_BSW_00369)

8.3.19 Tm_ShiftTimer100us32bit

[SWS_Tm_00055]

Service nameTm_ShiftTimer100us32bit
Syntaxvoid Tm_ShiftTimer100us32bit(
  Tm_PredefTimer100us32bitType* TimerPtr,
  uint32 TimeValue
)
Service ID [hex]0x13
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same timer instance
Parameters (in)TimeValue时间值(单位 100 µs),参考时间应被平移该值
Parameters (inout)TimerPtr指向由用户定义的定时器实例的指针
Parameters (out)None
Return valueNone
Description平移定时器实例的参考时间
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00006)

8.3.20 Tm_SyncTimer100us32bit

[SWS_Tm_00056]

Service nameTm_SyncTimer100us32bit
Syntaxvoid Tm_SyncTimer100us32bit(
  Tm_PredefTimer100us32bitType* TimerDstPtr,
  const Tm_PredefTimer100us32bitType* TimerSrcPtr
)
Service ID [hex]0x14
Sync/AsyncSynchronous
ReentrancyReentrant but not for the same destination timer instance
Parameters (in)TimerSrcPtr指向由用户定义的源定时器实例的指针
Parameters (inout)None
Parameters (out)TimerDstPtr指向由用户定义的目标定时器实例的指针
Return valueNone
Description同步两个定时器实例
Available viaTm.h

⌋(SRS_Tm_00001, SRS_Tm_00007)

8.4 回调通知

无。

8.5 调度函数

无。

8.6 期望接口

本章列出从其他模块请求的所有接口。

8.6.1 强制接口

本章定义实现本模块核心功能所需的所有接口。

[SWS_Tm_00057]

API 函数头文件描述
Det_ReportRuntimeError Det.h 用于报告运行时错误的服务。若已配置 callout,则应调用此 callout。
Gpt_GetPredefTimerValue Gpt.h 返回所需 GPT 预定义定时器的当前值。

⌋(SRS_Tm_00002)

8.6.2 可选接口

本章定义实现本模块可选功能所需的所有接口。

[SWS_Tm_00060]

API 函数头文件描述
Det_ReportError Det.h 用于报告开发错误的服务。

⌋()

8.6.3 可配置接口

本章列出所有可配置目标函数(通常为回调函数)的接口。这些接口的名称通常不固定,因可配置而异。

无。

9 序列图

9.1 Tm 正常运行

图 4 — 序列图 "Tm_Normal_Operation"

下图展示了 Time Service 模块在典型场景下的完整调用序列:

  1. 用户调用 Tm_ResetTimer1us32bit(&Timer1) → Tm 模块调用 Gpt_GetPredefTimerValue(GPT_PREDEF_TIMER_1US_32BIT, &…),将 Timer1 的参考时间设置为当前 GPT 定时器值。
  2. 用户调用 Tm_SyncTimer1us32bit(&Timer2, &Timer1) → Timer2 的参考时间被设置为 Timer1 的参考时间。
  3. (标记点 1)用户调用 Tm_GetTimeSpan1us32bit(&Timer1, &TimeSpan1) → Tm 模块读取当前 GPT 值,TimeSpan1 = 当前时间 - Timer1 参考时间(自标记点 1 起经过的时间)。
  4. 用户调用 Tm_GetTimeSpan1us32bit(&Timer2, &TimeSpan2) → TimeSpan2 同样为自标记点 1 起经过的时间。
  5. 用户调用 Tm_ShiftTimer1us32bit(&Timer1, TimeSpan1) → Timer1 的参考时间被加上 TimeSpan1(即向前推进 TimeSpan1)。
  6. 用户调用 Tm_GetTimeSpan1us32bit(&Timer1, &TimeSpan3) → TimeSpan3 为自 ShiftTimer 调用后经过的时间。
  7. 用户调用 Tm_GetTimeSpan1us32bit(&Timer2, &TimeSpan4) → TimeSpan4 仍为自标记点 1 起经过的时间(Timer2 未被 Shift)。

三个交互对象:Tm User、Time Service 模块(Tm)、GPT 驱动模块(Gpt)。

10 配置规范

本章定义配置参数及其到容器的分组。10.1 节描述了基础规范,10.2 节规定了模块 GPT 的结构(容器)和参数,10.3 节规定了模块的发布信息。

:原文中 "Chapter 10.2 specifies the structure (containers) and the parameters of the module GPT" 为 AUTOSAR 模板的笔误,Time Service 模块的参数(而非 GPT 的)见下。

10.1 如何阅读本章

详情参阅 SWS_BSWGeneral 中"10.1 Introduction to configuration specification"章节。

10.2 容器与配置参数

以下各章汇总所有配置参数。参数的具体含义在第 7 章与第 8 章描述。

10.2.1 Tm

SWS Item: ECUC_Tm_00008

Module Name(模块名):Tm
Module Description(模块描述):Time Service 模块的配置
Post-Build Variant Support(构建后变体支持):false
Supported Config Variants(支持的配置变体):VARIANT-PRE-COMPILE

包含的容器:

容器名多重性作用域 / 依赖
TmGeneral1Time Service 模块的通用配置

图 5 — Tm 配置结构:容器 Tm 包含一个 TmGeneral 子容器;TmGeneral 包含 6 个布尔参数:TmDevErrorDetectTmEnablePredefTimer1us16bitTmEnablePredefTimer1us24bitTmEnablePredefTimer1us32bitTmEnablePredefTimer100us32bitTmVersionInfoApi

10.2.2 TmGeneral

SWS Item: ECUC_Tm_00001

Container Name(容器名):TmGeneral
Description(描述):Time Service 模块的通用配置
配置参数

SWS Item: ECUC_Tm_00002 — TmDevErrorDetect

NameTmDevErrorDetect
Parent ContainerTmGeneral
Description启用或关闭开发错误检测与通知。true:启用;false:关闭。
Multiplicity1
TypeEcucBooleanParamDef
Default valuefalse
Post-Build Variant Valuefalse
Value Configuration ClassPre-compile time: X (All Variants) | Link time: -- | Post-build time: --
Scope / Dependencyscope: local

SWS Item: ECUC_Tm_00003 — TmEnablePredefTimer1us16bit

NameTmEnablePredefTimer1us16bit
Parent ContainerTmGeneral
Description指定是否启用预定义定时器 1µs16bit(功能与 API 服务集合)。ON 或 OFF。
Multiplicity1
TypeEcucBooleanParamDef
Default value--(无)
Post-Build Variant Valuefalse
Value Configuration ClassPre-compile time: X (All Variants) | Link time: -- | Post-build time: --
Scope / Dependencyscope: ECU

SWS Item: ECUC_Tm_00004 — TmEnablePredefTimer1us24bit

NameTmEnablePredefTimer1us24bit
Parent ContainerTmGeneral
Description指定是否启用预定义定时器 1µs24bit(功能与 API 服务集合)。ON 或 OFF。
Multiplicity1
TypeEcucBooleanParamDef
Default value--
Post-Build Variant Valuefalse
Value Configuration ClassPre-compile time: X (All Variants) | Link time: -- | Post-build time: --
Scope / Dependencyscope: ECU

SWS Item: ECUC_Tm_00005 — TmEnablePredefTimer1us32bit

NameTmEnablePredefTimer1us32bit
Parent ContainerTmGeneral
Description指定是否启用预定义定时器 1µs32bit(功能与 API 服务集合)。ON 或 OFF。
Multiplicity1
TypeEcucBooleanParamDef
Default value--
Post-Build Variant Valuefalse
Value Configuration ClassPre-compile time: X (All Variants) | Link time: -- | Post-build time: --
Scope / Dependencyscope: ECU

SWS Item: ECUC_Tm_00006 — TmEnablePredefTimer100us32bit

NameTmEnablePredefTimer100us32bit
Parent ContainerTmGeneral
Description指定是否启用预定义定时器 100µs32bit(功能与 API 服务集合)。ON 或 OFF。
Multiplicity1
TypeEcucBooleanParamDef
Default value--
Post-Build Variant Valuefalse
Value Configuration ClassPre-compile time: X (All Variants) | Link time: -- | Post-build time: --
Scope / Dependencyscope: ECU

SWS Item: ECUC_Tm_00007 — TmVersionInfoApi

NameTmVersionInfoApi
Parent ContainerTmGeneral
Description从代码中添加 / 移除服务 Tm_GetVersionInfo()。ON 或 OFF。
Multiplicity1
TypeEcucBooleanParamDef
Default valuefalse
Post-Build Variant Valuefalse
Value Configuration ClassPre-compile time: X (All Variants) | Link time: -- | Post-build time: --
Scope / Dependencyscope: local

包含的容器:无。

10.3 发布信息

详情参阅 SWS_BSWGeneral 中"10.3 Published Information"章节。

11 不适用的需求

[SWS_Tm_00059] ⌈ 这些需求不适用于本规范。 ⌋

具体涉及 57 条 SRS_BSW_* 需求:SRS_BSW_00344, _00159, _00167, _00170, _00398, _00416, _00437, _00168, _00423, _00424, _00425, _00426, _00427, _00428, _00429, _00432, _00433, _00422, _00417, _00161, _00162, _00005, _00415, _00325, _00342, _00160, _00007, _00413, _00347, _00307, _00373, _00335, _00353, _00361, _00328, _00006, _00439, _00357, _00377, _00378, _00306, _00308, _00309, _00359, _00360, _00440, _00330, _00331, _00009, _00172, _00010, _00333, _00321, _00341, _00334