AUTOSAR Classic General & Standard Types
Die Standard- und Plattformtypen definieren die grundlegenden C-Typen, Rückgabewerte und Kommunikationsdatenstrukturen der AUTOSAR Classic Architektur. Sie stellen hardwareunabhängige Portabilität für Basissoftware und Applikations-SW-Cs sicher.
集群指南人工智能生成
为所有 BSW 模块提供硬件无关的基础类型、状态返回值和通信缓冲区结构。
为所有 BSW 模块提供硬件无关的基础类型、状态返回值和通信缓冲区结构。
模块集群 General & Standard Types 通过头文件 Platform_Types.h、Std_Types.h 和 ComStack_Types.h 为 Classic Platform 的所有数据类型、状态反馈和通信缓冲区提供独立于硬件的基础(AUTOSAR_SRS_BSWGeneral 第62页)。它对字节序模型等基础架构特性、Std_ReturnType 等标准化返回值以及 PduInfoType 等通信结构进行了规范([SWS_Std_00005]、[SWS_COMTYPE_00008])。由于它由不含可执行代码的纯头文件定义组成,因此该集群既不需要运行时配置,也不具有专有任务或主动错误处理功能(SWS_StandardTypes 第27页)。
模块集群 General & Standard Types 包含三个基础头文件 platform(Platform_Types.h)、std(Std_Types.h)和 comstack(ComStack_Types.h)。作为纯类型定义,它们不包含任何可执行代码,亦无需配置(SWS_StandardTypes 第27页)。它们构成了全平台范围内独立于硬件的类型化基础,统一了编译器和硬件特性,并为所有 BSW 模块和 RTE 提供一致的数据结构(AUTOSAR_SRS_BSWGeneral 第62页)。
架构图:模块集群“General & Standard Types”带有导出类型接口的静态分层与包含架构。来源:AUTOSAR_SRS_BSWGeneral 第62页、[SWS_Std_00005]、[SWS_COMTYPE_00005]
包含层次结构逐步构建:Platform_Types.h 封装了平台专用特性,例如 C99 类型 boolean([SWS_Platform_00027])、通用缓冲区指针 ConstVoidPtr([SWS_Platform_91002])以及寄存器位顺序符号 CPU_BIT_ORDER([SWS_Platform_00038])和内存字节顺序符号 CPU_BYTE_ORDER([SWS_Platform_00039])。在此基础上,Std_Types.h 提供了通用标准常量(如 STD_ON/STD_OFF,[SWS_Std_00010])、通过 Std_VersionInfoType 实现的模块版本结构([SWS_Std_00015])以及包含 E_OK 和 E_NOT_OK 的基础状态系统 Std_ReturnType([SWS_Std_00005]、[SWS_Std_00006])。
针对 AUTOSAR 通信栈,ComStack_Types.h 定义了所有跨协议接口类型,例如 PduIdType([SWS_COMTYPE_00005])、NetworkHandleType([SWS_COMTYPE_00038])以及核心缓冲区结构 PduInfoType([SWS_COMTYPE_00008])。在分段传输协议(例如 CanTp 或 DoIP)中,返回类型 BufReq_ReturnType 与 RetryInfoType 共同控制 BSW 层之间的同步缓冲区预留和数据复制(SWS_DiagnosticCommunicationManager 第291页、[SWS_COMTYPE_00012])。
时序图:使用 ComStack_Types(PduInfoType、BufReq_ReturnType)的传输协议分段接收与缓冲区路径。来源:SWS_PDURouter 第112页、SWS_DiagnosticCommunicationManager 第273页、SWS_DiagnosticCommunicationManager 第274页
尽管该集群没有专有的错误处理或 DET 报告(SWS_StandardTypes 第27页),但 Std_ReturnType 规范了整个系统的错误处理结构:位 0 至 5(0x00 至 0x3F)保留用于标准错误和应用程序错误,而位 6 和 7 则专门由 RTE 占用([SWS_Std_00011]、AUTOSAR_CP_SWS_StandardTypes 第15页)。所有类型定义均针对多任务和中断上下文中的可重入使用进行了规范(SWS_CANInterface 第87页)。
系统架构 & 模块集群的角色
模块集群 General & Standard Types 构成了 AUTOSAR Classic Platform 在 R20-11 版本中的基础类型与硬件抽象基石。它由三个纯头文件模块 platform([SWS_Platform_00038])、std([SWS_Std_00005])和 comstack([SWS_COMTYPE_00005])组成。根据 BSW 架构,这些模块既不提供专有的可执行 C 代码,也不请求其他 BSW 驱动程序(SWS_StandardTypes 第27页)。它们的核心任务在于封装编译器和处理器相关性,提供全平台统一的基础类型,并为通信层建立标准化数据结构。
分层层次遵循严格的单向包含顺序:文件 Platform_Types.h 抽象了底层微控制器架构的特性(例如寄存器和内存布局以及 C99 基本类型),而 Std_Types.h 则基于此定义通用返回值和状态常量(AUTOSAR_SRS_BSWGeneral 第62页)。在此基础上,ComStack_Types.h 声明了针对 CAN、FlexRay、LIN 和 Ethernet 等网络,以及针对符合 ISO 15765-2 的传输协议和符合 ISO 14229 的诊断协议的所有跨总线和跨协议数据类型([SWS_COMTYPE_00008]、[SWS_COMTYPE_00011])。通过这种解耦,确保了运行时环境(RTE)和应用软件组件(SWC)等上层保持完全可移植(SWS_RTE 第818页)。
架构图:模块集群“General & Standard Types”带有导出类型接口的静态分层与包含架构。来源:AUTOSAR_SRS_BSWGeneral 第62页、[SWS_Std_00005]、[SWS_COMTYPE_00005]
各模块之间的交互配合与交互路径
集群内部的协作基于静态包含链:ComStack_Types.h 包含 Std_Types.h,而后者又引入了 Platform_Types.h(RS_BSWGeneral 第60页)。模块 platform 定义了诸如 boolean 等基础量,该量必须强制映射到 C99 基础类型 _Bool([SWS_Platform_00027]),并通过字面量 TRUE 和 FALSE 规范其严格的值分配([SWS_Platform_00034])。此外,还规范了通用缓冲区指针(如 ConstVoidPtr),用于向被调用的函数接口传递不可变传输缓冲区([SWS_Platform_91002])。
此外,platform 通过标准化预处理器符号协调了硬件端序:对于寄存器中的位顺序,CPU_BIT_ORDER 被设定为 MSB_FIRST 或 LSB_FIRST([SWS_Platform_00038]、[SWS_Platform_00048]、[SWS_Platform_00049])。物理内存中的字节顺序通过 CPU_BYTE_ORDER 控制,其中区分了 HIGH_BYTE_FIRST(大端,MSB 位于较低地址)与 LOW_BYTE_FIRST(小端,LSB 位于较低地址)([SWS_Platform_00039]、[SWS_Platform_00050]、[SWS_Platform_00051])。
结构图:大端(HIGH_BYTE_FIRST)与小端(LOW_BYTE_FIRST)下标量多字节值的内存映射。来源:AUTOSAR_CP_SWS_PlatformTypes 第16页、AUTOSAR_CP_SWS_PlatformTypes 第15页、[SWS_Platform_00050]、[SWS_Platform_00051]
在下一个抽象层级上,模块 std 定义了用于开关状态和逻辑电平的通用符号:针对物理电压电平的 STD_HIGH(0x01u)和 STD_LOW(0x00u)([SWS_Std_00007]),针对激活模式的 STD_ON(0x01u)和 STD_OFF(0x00u)([SWS_Std_00010]),以及针对逻辑执行状态的 STD_ACTIVE(0x01u)和 STD_IDLE(0x00u)([SWS_Std_00013])。针对报文协议和转换器,std 还提供了带有字面量 STD_MESSAGETYPE_REQUEST(0x00)和 STD_MESSAGETYPE_RESPONSE(0x01)的 Std_MessageTypeType([SWS_Std_91001]、[SWS_Std_00017]),以及用于提取协议头的函数指针类型 Std_ExtractProtocolHeaderFieldsType([SWS_Std_91003])。
模块 comstack 则利用 platform 和 std 的基础类型来组织通信栈中的整个缓冲区与数据交换。核心接口结构是 PduInfoType,它汇集了数据指针 SduDataPtr(uint8*)、元数据指针 MetaDataPtr 以及类型为 PduLengthType 的缓冲区长度 SduLength([SWS_COMTYPE_00008]、[SWS_COMTYPE_00011])。I-PDU 标识通过 PduIdType 进行([SWS_COMTYPE_00005])。为了管理整个通信通道和部分网络,comstack 定义了通道标识符 NetworkHandleType([SWS_COMTYPE_00038])以及部分网络标识符 PNCHandleType([SWS_COMTYPE_00036]),例如用于 ComM 和 Nm 的 Synchronized PNC Shutdown 中(SWS_COMManager 第171页)。
在分段传输协议传输(TP)中,缓冲区协商通过返回类型 BufReq_ReturnType 和结构 RetryInfoType 处理([SWS_COMTYPE_00012])。在 CanTp、PduR、DCM、DoIP 或 SecOC 等模块之间执行诸如 CopyTxData 或 CopyRxData 等同步复制调用时,BUFREQ_OK 指示复制过程成功,而 BUFREQ_E_BUSY 则通知暂时没有足够的缓冲区可用且可以重试(SWS_DiagnosticCommunicationManager 第291页、SWS_SecureOnboardCommunication 第76页)。通过带有诸如 TP_CONFPENDING 或 TP_DATACONF 等参数的 RetryInfoType,可确保数据保留在缓冲区中以供可能的重传,或在确认后释放(SWS_IntrusionDetectionSystemManager 第49页)。
时序图:使用 ComStack_Types(PduInfoType、BufReq_ReturnType)的传输协议分段接收与缓冲区路径。来源:SWS_PDURouter 第112页、SWS_DiagnosticCommunicationManager 第273页、SWS_DiagnosticCommunicationManager 第274页
同步、重入性与任务上下文
由于模块 platform、std 和 comstack 是不含可执行目标文件的纯头文件,因此它们自然不实现周期性 MainFunctions,也不具有专有任务上下文(SWS_StandardTypes 第27页)。然而,它们定义了跨层调用的函数的签名和类型约定。所有类型定义的设计均保证其能够无限制地以可重入且无状态的方式进行传递(SWS_CANInterface 第87页)。
这些类型的实际应用发生于高度异步和并发的环境中。使用 PduInfoType 和 PduIdType 的数据接收回调(如 CanIf_RxIndication 或 Dcm_CopyRxData)明确允许在中断上下文中执行(SWS_CANInterface 第164页、SWS_DiagnosticCommunicationManager 第274页)。与此相反,路由决策、缓冲区分配或周期性传输则在上层的周期性任务(例如 SoAd_MainFunction)中处理(SWS_SocketAdaptor 第104页)。由于诸如 PduInfoType 之类的指针结构可以在中断级和任务级之间共享,因此通过互斥区域(并发保护)实现线程安全同步的职责属于调用和实现该接口的 BSW 模块。
典型的生命周期和操作模式
纯类型定义不受运行时生命周期的约束,既没有初始化函数也没有关闭函数(SWS_StandardTypes 第27页)。它们必须在编译时在所有处理模块之前被静态包含。然而,它们构成了映射和监控其他 BSW 模块生命周期的规范框架:为了进行标准化的版本查询,std 规范了包含 vendorID、moduleID 以及软件版本状态(sw_major_version、sw_minor_version、sw_patch_version)的结构 Std_VersionInfoType([SWS_Std_00015])。
此外,诸如 NetworkHandleType 和 PNCHandleType 等类型在 Startup、正常运行、Sleep 和 Wakeup 等操作模式切换期间支持上层的网络和模式管理([SWS_COMTYPE_00036]、[SWS_COMTYPE_00038])。例如,ComM 根据这些标识符控制部分网络集群中的协调关闭和状态转换(SWS_COMManager 第171页、SWS_NetworkManagementInterface 第106页)。
错误处理、DET 跟踪与状态编码
该模块集群不提供专有的主动错误处理,既不向 DET 报告开发错误,也不向 DEM 报告生产错误(SWS_StandardTypes 第27页)。相反,它规范了全平台的反馈格式:基础类型 Std_ReturnType 基于 uint8,并在所有层中用作同步调用的标准结果([SWS_Std_00005]、BSWUMLModelModelingGuide 第28页)。默认情况下,E_OK(0x00u)表示执行成功,而 E_NOT_OK(0x01u)表示常规错误([SWS_Std_00006])。出于与 ISO 17356-3(OSEK OS)兼容性的考虑,E_OK 通过保护检查(STATUSTYPEDEFINED)防止重复定义(AUTOSAR_SRS_BSWGeneral 第62页)。
Std_ReturnType 的位布局遵循固定划分:位 0 至 5(范围 0x00 至 0x3F)保留用于标准化和模块特定的返回值,或客户端/服务器操作中应用程序特定的 ApplicationError 代码([SWS_Std_00011]、AUTOSAR_CP_SWS_StandardTypes 第15页)。模块特定的扩展在 UML 模型中作为构造型为 «extra_literals» 的类进行管理(BSWUMLModelModelingGuide 第33页)。位 6 和 7(取值范围 0x40、0x80、0xC0)严格保留用于 RTE 的基础架构错误状态(AUTOSAR_CP_SWS_StandardTypes 第15页)。针对 RTE 中的数据转换,std 还声明了由 errorCode([SWS_Std_00022])和 transformerClass([SWS_Std_00021])组成的结构 Std_TransformerError,借此可以在序列化或 E2E 保护过程中对错误链进行完整追溯。
本指南基于 AUTOSAR Classic Platform R20-11 版本针对 StandardTypes、PlatformTypes 和 CommunicationStackTypes 的规范性规范。
类型
booleanBufReq_ReturnTypeConstVoidPtrCPU_BIT_ORDERCPU_BYTE_ORDERCPU_TYPEE_OK / E_NOT_OKfloat32float64NetworkHandleTypePduIdTypePduInfoTypePduLengthTypePNCHandleTypeRetryInfoTypesint16sint16_leastsint32sint32_leastsint64sint8sint8_leastSTD_ACTIVE / STD_IDLEStd_ExtractProtocolHeaderFieldsTypeSTD_HIGH / STD_LOWStd_MessageResultTypeStd_MessageTypeSTD_ON / STD_OFFStd_ReturnTypeStd_TransformerClassStd_TransformerErrorStd_TransformerForwardStd_TransformerForwardCodeStd_VersionInfoTypeTpDataStateTypeTPParameterTypeTRUE_FALSEuint16uint16_leastuint32uint32_leastuint64uint8uint8_leastVoidPtr类型
booleanBufReq_ReturnTypeConstVoidPtrCPU_BIT_ORDERCPU_BYTE_ORDERCPU_TYPEE_OK / E_NOT_OKfloat32float64NetworkHandleTypePduIdTypePduInfoTypePduLengthTypePNCHandleTypeRetryInfoTypesint16sint16_leastsint32sint32_leastsint64sint8sint8_leastSTD_ACTIVE / STD_IDLEStd_ExtractProtocolHeaderFieldsTypeSTD_HIGH / STD_LOWStd_MessageResultTypeStd_MessageTypeSTD_ON / STD_OFFStd_ReturnTypeStd_TransformerClassStd_TransformerErrorStd_TransformerForwardStd_TransformerForwardCodeStd_VersionInfoTypeTpDataStateTypeTPParameterTypeTRUE_FALSEuint16uint16_leastuint32uint32_leastuint64uint8uint8_leastVoidPtr此版本没有元素数据
ComStack
Variables of this type shall be used to store the result of a buffer request.
typedef enum { BUFREQ_OK, BUFREQ_E_NOT_OK, BUFREQ_E_BUSY, BUFREQ_E_OVFL } BufReq_ReturnType;Variables of the type Network Handle Type shall be used to store the identifier of a communication channel.
typedef uint8 NetworkHandleType;Variables of this type shall be used to store the basic information about a PDU of any type, namely a pointer variable pointing to its SDU (payload), a pointer to Meta Data of the PDU, and the corresponding length of the SDU in byt es.
typedef struct { uint8* SduDataPtr; uint8* MetaDataPtr; PduLengthType SduLength; } PduInfoType;This type shall be used within the entire AUTOSAR Com Stack of an ECU except for bus drivers.
typedef uint16 PduLengthType;Used to store the identifier of a partial network cluster.
typedef uint8 PNCHandleType;Variables of this type shall be used to store the information about Tp buffer handling.
typedef struct { TpDataStateType TpDataState; PduLengthType TxTpDataCnt; } RetryInfoType;Variables of this type shall be used to store the state of TP buffer.
typedef enum { TP_DATACONF, TP_DATARETRY, TP_CONFPENDING } TpDataStateType;Specify the parameter to which the value has to be changed (BS or STmin).
typedef enum { TP_STMIN, TP_BS, TP_BC } TPParameterType;Platform
This standard AUTOSAR type shall only be used together with the definitions TRUE and FALSE.
typedef unsigned char boolean;This standard AUTOSAR type shall be a void pointer to const. Note: This type shall be used for buffers that are passed to the callee.
typedef const void* ConstVoidPtr;This symbol shall be defined as #define having one of the values MSB_FIRST or LSB_FIRST according to the platform.
This symbol shall be defined as #define having one of the values HIGH_BYTE_FIRST or LOW_ BYTE_FIRST according to the platform.
This symbol shall be defined as #define having one of the values CPU_TYPE_8, CPU_TYPE_16, CPU_TYPE_32 or CPU_TYPE_64 according to the platform.
This standard AUTOSAR type shall follow the 32-bit binary interchange format according to IEEE 754-2008 with encoding parameters specified in chapter 3.6, table 3.5, column "binary32".
typedef float float32;This standard AUTOSAR type shall follow the 64-bit binary interchange format according to IEEE 754-2008 with encoding parameters specified in chapter 3.6, table 3.5, column "binary64".
typedef double float64;This optimized AUTOSAR type shall be at least 16 bit signed.
typedef signed int sint16_least;This optimized AUTOSAR type shall be at least 32 bit signed.
typedef signed int sint32_least;This optimized AUTOSAR type shall be at least 8 bit signed.
typedef signed int sint8_least;The symbols TRUE and FALSE shall be defined as follows: #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif
This optimized AUTOSAR type shall be at least 16 bit unsigned.
typedef unsigned int uint16_least;This optimized AUTOSAR type shall be at least 32 bit unsigned.
typedef unsigned int uint32_least;This optimized AUTOSAR type shall be at least 8 bit unsigned.
typedef unsigned int uint8_least;Std
Because E_ OK is already defined within OSEK, the symbol E_ OK has to be shared. To avoid name clashes and redefinition problems, the symbols have to be defined in the following way (approved within implementation): #ifndef STATUSTYPEDEFINED #define STATUSTYPEDEFINED #define E_ OK 0x00u typedef unsigned char Status Type; /* OSEK compliance */ #endif #define E_ NOT_ OK 0x01u
#define E_OK 0x00u #define E_NOT_OK 0x01uThe symbols STD_ ACTIVE and STD_ IDLE shall be defined as follows: #define STD_ ACTIVE 0x01u /* Logical state active */ #define STD_ IDLE 0x00u /* Logical state idle */
#define STD_ACTIVE 0x01u #define STD_IDLE 0x00uType for the function pointer to extract the relevant protocol header fields of the message and the type of the message result of a transformer. - At the time being, this is limited to the types used for C/ S communication (i.e., REQUE ST and RESPONSE and OK and ERROR).
typedef Std_ReturnType (* Std_ExtractProtocolHeaderFieldsType)(const uint8* buffer, uint32 bufferLength, Std_MessageTypeType* messageType, Std_MessageResultType* messageResult);The symbols STD_ HIGH and STD_ LOW shall be defined as follows: #define STD_ HIGH 0x01u /* Physical state 5V or 3.3V */ #define STD_ LOW 0x00u /* Physical state 0V */
#define STD_HIGH 0x01u #define STD_LOW 0x00uThis type is used to encode different types of results for response messages. - Currently this encoding is limited to the distinction between OK and ERROR responses.
typedef uint8 Std_MessageResultType;This type is used to encode the different type of messages. - Currently this encoding is limited to the distinction between requests and responses in C/ S c ommunication.
The symbols STD_ ON and STD_ OFF shall be defined as follows: #define STD_ ON 0x01u #define STD_ OFF 0x00u
#define STD_ON 0x01u #define STD_OFF 0x00uThis type can be used as standard API return type which is shared between the RTE and the BSW modules. It shall be defined as follows: typedef uint8 Std_ Return Type;
typedef uint8 Std_ReturnType;-
typedef uint8 Std_TransformerClass;-
typedef uint8 Std_TransformerError;- Tags: atp.Status=draft
typedef uint8 Std_TransformerForward;- Tags: atp.Status=draft
typedef uint8 Std_TransformerForwardCode;Module im Cluster
Compiler Abstraction (Compiler)
AUTOSAR Classic Special Files-Modul Compiler Abstraction (Compiler, Spezifikation: AUTOSAR_SWS_CompilerAbstraction.pdf).
Communication Stack Types (ComStack_Types)
Standardized types, PDU identifiers, lengths, and buffer request types (PduIdType, PduLengthType, PduInfoType, BufReq_ReturnType) used across all communication layers.
Memory Mapping (MemMap)
AUTOSAR Classic Special Files-Modul Memory Mapping (MemMap, Spezifikation: AUTOSAR_CP_SWS_MemoryMapping.pdf, AUTOSAR_SWS_MemoryMapping.pdf).
Platform Types (Platform_Types)
Platform-specific fundamental data types (integers, booleans, floating-point numbers) mapped to CPU architecture primitives.
Standard Types (Std_Types)
Standard types, return codes (Std_ReturnType, E_OK, E_NOT_OK), version info structures, and error codes shared across the entire AUTOSAR architecture.
gemini-3.8-flash-low· 2026-10-13 · 德文原文