logo资料库

基于MISRA C2012 C语言编程规范.docx

第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
资料共9页,剩余部分请下载后查看
C 语言编程方针 4. MATLAB 建模编程指导方针 参考:MAAM_Style_Guideline_Version3p00.pdf 5.C 语言编程指导方针 5.1 通用规则 5.2 注释规则 编程风格应遵循《Misra C 2012》 。 : 1.0.0 : Copyright 2017 NXP All Rights Reserved. Mcu_Cfg.c AUTOSAR Mcu - Data structures for the Mcu driver. 5.2.1 注释数量不低于代码数量的 20%。 5.2.2 代码只能通过“/* */”注释。 5.2.3 在 C 文件或头文件,应增加版本标示区。 /** * @file * @version 1.0.0 * * @brief * @details Precompile structure configuration for the driver initialization. * * @addtogroup MCU * @{ */ /*================================================================ ================================== * * * * * * * * * * S32K14x_MCAL_1_0_0_RTM_ASR_REL_4_2_REV_0002_20170824 * * * * ================================================================= =================================*/ /*================================================================ Autosar Version Autosar Revision Autosar Conf.Variant : SW Version Build Version : AUTOSAR 4.2 MCAL : ARM : MC : none Project Platform Peripheral Dependencies (c) Copyright 2006-2016 Freescale Semiconductor, Inc. : 4.2.2 : ASR_REL_4_2_REV_0002
================================== ================================================================= =================================*/ 5.2.4 函数前需增加函数注释标示区 /** * @brief This function returns the MSR register value (32 bits). * @details This function returns the MSR register value (32 bits). * * @param[in] * @return (32 bits). * * @pre None * @post None * */ void uint32 msr No input parameters This function returns the MSR register value 5.2.5 增加全局变量定义注释 The Mcu_RamSectionType specifies the identification (ID) The type shall be uint8, uint16 or uint32, based on best /** * @brief for a RAM section, configured via the configuration structure. * performance. * @implements Mcu_RamSectionType_typedef */ typedef uint32 Mcu_RamSectionType; 5.2.6 5.3.3 5.3 命名规则 5.3.1 通用命名规则 5.3.2 命名规则 英文字符(“A-Z or a-z”),数字(0-9)、下划杠(_). N -> v -> adj eg:u8_FailureIsActive; 5.3.4 全局变量命名规则 格式:g_([Data Type])_[ModuleName]_[Functional Name] Data Type :数据类型
ModuleName :C 文件名称,列如此全局变量是 CtCddDtcCheck.c 外部变量,ModuleName 就是 CtCddDtcCheck。 Functional Name :这个是实际的变量名称;可以又工程师定义,参照下面列表:
Functional Name :有几个部分组成,首字母应大写 5.3.3 局部变量命名规则 格式是: 、
Data Type ;Functional Name;参考 5.3.2 5.3.4 临时变量命名规则 Rule 5.3.7:字母“i,j,m,n,tmp…”在不产生错误或误解的情况下,是可以使用的。 Rule 5.3.8:只用字母和数字可以定义临时变量,临时变量都使用小写,并使用“_” 区分。 Rule 5.3.9:临时变量应遵循下面的格式: 5.3.5 常量、宏定义命名规则 Rule 5.3.11 定义常量、宏定义都使用大写([Module Name]例外),格式如下: Module Name 参考 5.3.2; [FUNCTIONAL NAME] 参考 5.3.2 中的 [Functional Name]; 另外:如果在头文件中定义常量、宏定义,[Module Name]应该加上即: [ModuleName]_[Functional Name]; ; 5.3.6 函数命名规则 格式: 5.3.7 结构体命名规则: [Data Type Definition] 参考 Table 5.2 ST:代表结构体,不能被改变。
Rule 5.3.15 全局结构体定义 Rule 5.3.16 定义局部结构体 格式如下: Rule 5.3.17 枚举 格式如下:
分享到:
收藏