AUTOSAR CP software coding specification

AUTOSAR CP software coding specification

For embedded programmers, the MISRAC specification is very important to provide them with some suggestions, so that they can gradually establish some good programming habits and programming ideas, and gradually abandon those potentially risky programming. Behavior, write more secure and robust code.

General principles:
1. Safety first
2. Simplicity is the beauty
3. Choose the appropriate style and keep it consistent with the original style of the code (eg HAL, BSP, MCL, OS, AutoSar, HandWrite)

Four commonly used encoding methods:

  • underscore nomenclature,
  • CamelCase,
  • Big CamelCase
  • Hungarian notation

Suggestion: Since the basic software is mainly developed using AUTOSAR software commonly used in the industry, it is more appropriate to use the AUTOSAR style to write code in the basic style


1 header file

For the C language, the design of the header file reflects most of the system design. Internally as the interface between modules, externally can provide the necessary interface in the form of lib+*.h.

Principle 1.1 Header files are suitable for placing declarations of interfaces, not implementations.
Description: The header file is the external interface of the module (Module) or unit (Unit). External declarations, such as function declarations, macro definitions, and type definitions provided externally, should be placed in the header file.
Principle 1.2 Header documents should have a single responsibility.
Explanation: The header file is too complicated, and the dependency is too complicated, which is the main reason for the long compilation time. In many existing codes, the header files are too large, there are too many responsibilities, and the circular dependency problem may lead to the use of a macro in .c

Guess you like

Origin blog.csdn.net/qq_44992918/article/details/128051938