automotive-embedded-skills
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAutomotive Embedded C/C++/CAPL Best Practices
汽车嵌入式系统C/C++/CAPL最佳实践
Comprehensive coding guidelines for automotive embedded software development in C, C++, and CAPL. Contains 180+ rules across 23 categories, prioritized by safety impact and industry compliance requirements (MISRA C:2012, MISRA C++:2023, AUTOSAR C++14 Classic & Adaptive, ISO 26262, ISO 21434). Covers full automotive communication stack (CAN/LIN/Ethernet/IP/TSN), cybersecurity, diagnostics, CAPL simulation/testing/fault injection, AUTOSAR BSW modules, boot/NVM/power management, compiler toolchains, static analysis tools, and CI/CD integration.
本指南是针对汽车嵌入式软件开发的C、C++和CAPL全面编码规范,涵盖23个类别下的180+条规则,根据安全影响和行业合规要求(MISRA C:2012、MISRA C++:2023、AUTOSAR C++14经典版与自适应版、ISO 26262、ISO 21434)划分优先级。内容覆盖完整的汽车通信栈(CAN/LIN/Ethernet/IP/TSN)、网络安全、诊断、CAPL仿真/测试/故障注入、AUTOSAR BSW模块、启动/非易失性存储器(NVM)/电源管理、编译器工具链、静态分析工具以及CI/CD集成。
When to Apply
适用场景
Reference these guidelines when:
- Writing new embedded C/C++ modules for automotive ECUs
- Implementing or reviewing CAN/LIN/Ethernet communication stacks
- Writing CAPL scripts for CANoe/CANalyzer simulation and testing
- Refactoring code for MISRA C/C++ or AUTOSAR C++14 compliance
- Designing safety-critical software (ASIL A-D per ISO 26262)
- Implementing RTOS task management and inter-task communication
- Reviewing code for memory safety, timing, and determinism
- Working with diagnostic protocols (UDS, OBD-II, DoIP)
- Implementing Automotive Ethernet (TCP, UDP, SOME/IP, DoIP, VLAN)
- Addressing cybersecurity requirements (ISO 21434, secure boot, TLS)
- Integrating with calibration/diagnostic tools (A2L, ODX, XCP)
- Optimizing for resource-constrained microcontrollers (RAM, Flash, CPU)
在以下场景中可参考本指南:
- 为汽车ECU编写新的嵌入式C/C++模块
- 实现或评审CAN/LIN/Ethernet通信栈
- 为CANoe/CANalyzer仿真与测试编写CAPL脚本
- 重构代码以符合MISRA C/C++或AUTOSAR C++14规范
- 设计安全关键软件(符合ISO 26262的ASIL A-D等级)
- 实现RTOS任务管理与任务间通信
- 评审代码的内存安全性、时序性与确定性
- 处理诊断协议(UDS、OBD-II、DoIP)
- 实现汽车以太网(TCP、UDP、SOME/IP、DoIP、VLAN)
- 满足网络安全要求(ISO 21434、安全启动、TLS)
- 与校准/诊断工具集成(A2L、ODX、XCP)
- 针对资源受限的微控制器优化代码(RAM、Flash、CPU)
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Memory Safety & Management | CRITICAL | |
| 2 | MISRA C/C++ Compliance | CRITICAL | |
| 3 | AUTOSAR C++14 Guidelines (Classic & Adaptive) | CRITICAL | |
| 4 | Safety & Functional Safety (ISO 26262) | HIGH | |
| 5 | Real-Time & Timing Constraints | HIGH | |
| 6 | Communication Protocols (CAN/LIN/Ethernet/IP/UDS) | HIGH | |
| 7 | Concurrency & RTOS Patterns | MEDIUM-HIGH | |
| 8 | CAPL Scripting — CANoe | MEDIUM-HIGH | |
| 9 | CAPL Scripting — vTESTstudio | MEDIUM-HIGH | |
| 10 | Code Organization & Architecture | MEDIUM | |
| 11 | Performance Optimization | MEDIUM | |
| 12 | Build, Compilation & Static Analysis | MEDIUM | |
| 13 | Security & Cybersecurity (ISO 21434) | HIGH | |
| 14 | Testing & Verification | MEDIUM | |
| 15 | Tool Integration (A2L/ODX/FIBEX) | MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 内存安全与管理 | 关键 | |
| 2 | MISRA C/C++合规 | 关键 | |
| 3 | AUTOSAR C++14准则(经典版与自适应版) | 关键 | |
| 4 | 安全与功能安全(ISO 26262) | 高 | |
| 5 | 实时性与时序约束 | 高 | |
| 6 | 通信协议(CAN/LIN/Ethernet/IP/UDS) | 高 | |
| 7 | 并发与RTOS模式 | 中高 | |
| 8 | CAPL脚本编写 — CANoe | 中高 | |
| 9 | CAPL脚本编写 — vTESTstudio | 中高 | |
| 10 | 代码组织与架构 | 中 | |
| 11 | 性能优化 | 中 | |
| 12 | 构建、编译与静态分析 | 中 | |
| 13 | 安全与网络安全(ISO 21434) | 高 | |
| 14 | 测试与验证 | 中 | |
| 15 | 工具集成(A2L/ODX/FIBEX) | 中 | |
Quick Reference
快速参考
1. Memory Safety & Management (CRITICAL)
1. 内存安全与管理(关键)
- - Prefer stack allocation over heap in embedded context
memory-stack-over-heap - - Use static allocation for deterministic memory usage
memory-static-allocation - - Always validate buffer boundaries before access
memory-buffer-bounds - - Use memory pool patterns for dynamic-like allocation
memory-pool-pattern - - Never use malloc/free in real-time critical paths
memory-no-malloc-in-rt - - Use RAII for resource management in C++ embedded code
memory-raii-cpp - - Use volatile correctly for hardware registers and shared data
memory-volatile-correctness - - Ensure proper data structure alignment for target architecture
memory-alignment - - Always initialize variables, especially in safety-critical code
memory-zero-init
- - 嵌入式场景下优先使用栈分配而非堆分配
memory-stack-over-heap - - 使用静态分配以确保内存使用的确定性
memory-static-allocation - - 访问缓冲区前始终验证边界
memory-buffer-bounds - - 使用内存池模式实现类动态分配
memory-pool-pattern - - 绝不在实时关键路径中使用malloc/free
memory-no-malloc-in-rt - - 在嵌入式C++代码中使用RAII进行资源管理
memory-raii-cpp - - 正确使用volatile访问硬件寄存器与共享数据
memory-volatile-correctness - - 确保数据结构与目标架构的对齐要求一致
memory-alignment - - 始终初始化变量,尤其是在安全关键代码中
memory-zero-init
2. MISRA C/C++ Compliance (CRITICAL)
2. MISRA C/C++合规(关键)
- - Avoid implicit type conversions
misra-no-implicit-conversions - - Prefer single function exit point for critical functions
misra-single-exit-point - - Avoid dynamic memory allocation (Rule 21.3)
misra-no-dynamic-memory - - Avoid recursion in embedded context (Rule 17.2)
misra-no-recursion - - Always include default case in switch statements
misra-switch-default - - Avoid goto except for error cleanup patterns in C
misra-no-goto - - Use explicit boolean comparisons
misra-boolean-expressions - - Restrict pointer arithmetic to array indexing
misra-pointer-arithmetic - - Avoid side effects in conditional expressions
misra-side-effects
- - 避免隐式类型转换
misra-no-implicit-conversions - - 关键函数优先使用单一出口点
misra-single-exit-point - - 避免动态内存分配(规则21.3)
misra-no-dynamic-memory - - 嵌入式场景下避免递归(规则17.2)
misra-no-recursion - - switch语句中始终包含default分支
misra-switch-default - - C语言中避免使用goto,除非用于错误清理模式
misra-no-goto - - 使用显式布尔比较
misra-boolean-expressions - - 指针运算仅限于数组索引
misra-pointer-arithmetic - - 避免在条件表达式中产生副作用
misra-side-effects
3. AUTOSAR C++14 Guidelines (CRITICAL)
3. AUTOSAR C++14准则(关键)
- - Use smart pointers instead of raw pointers for ownership
autosar-smart-pointers - - Avoid exceptions in real-time contexts, use Result types
autosar-no-exceptions-rt - - Apply const-correctness throughout interfaces
autosar-const-correctness - - Always use override/final for virtual function overrides
autosar-override-final - - Use enum class instead of plain enum
autosar-enum-class - - Avoid unions, use std::variant when needed
autosar-no-unions - - Prefer braced initialization to prevent narrowing
autosar-braces-init - - Use [[nodiscard]] for functions with important return values
autosar-nodiscard
- - 使用智能指针而非裸指针管理所有权
autosar-smart-pointers - - 实时场景下避免使用异常,改用Result类型
autosar-no-exceptions-rt - - 在接口中全面应用const正确性
autosar-const-correctness - - 重写虚函数时始终使用override/final
autosar-override-final - - 使用enum class而非普通enum
autosar-enum-class - - 避免使用联合体,必要时使用std::variant
autosar-no-unions - - 优先使用大括号初始化以防止窄化转换
autosar-braces-init - - 对具有重要返回值的函数使用[[nodiscard]]
autosar-nodiscard
4. Safety & Functional Safety - ISO 26262 (HIGH)
4. 安全与功能安全 - ISO 26262(高)
- - Apply defensive programming at module boundaries
safety-defensive-programming - - Implement error detection and plausibility checks
safety-error-detection - - Use redundant checks for critical control paths
safety-redundant-checks - - Implement watchdog monitoring patterns
safety-watchdog-pattern - - Protect state machine transitions from corruption
safety-state-machine-integrity - - Validate data integrity with CRC for critical data
safety-crc-validation - - Always define and reach safe state on failure
safety-safe-state - - Follow ASIL decomposition patterns correctly
safety-asil-decomposition
- - 在模块边界应用防御式编程
safety-defensive-programming - - 实现错误检测与合理性检查
safety-error-detection - - 对关键控制路径使用冗余检查
safety-redundant-checks - - 实现看门狗监控模式
safety-watchdog-pattern - - 保护状态机转换免受损坏
safety-state-machine-integrity - - 使用CRC验证关键数据的完整性
safety-crc-validation - - 故障发生时始终定义并进入安全状态
safety-safe-state - - 正确遵循ASIL分解模式
safety-asil-decomposition
5. Real-Time & Timing Constraints (HIGH)
5. 实时性与时序约束(高)
- - Ensure deterministic execution time in cyclic tasks
realtime-deterministic-execution - - Design with WCET (Worst-Case Execution Time) in mind
realtime-wcet-awareness - - Never block in interrupt service routines
realtime-no-blocking-isr - - Prevent priority inversion with proper locking
realtime-priority-inversion - - Follow cyclic scheduling patterns correctly
realtime-cyclic-scheduling - - Minimize interrupt latency and ISR execution time
realtime-interrupt-latency - - Implement deadline monitoring for critical tasks
realtime-deadline-monitoring
- - 确保循环任务的执行时间具有确定性
realtime-deterministic-execution - - 设计时考虑最坏情况执行时间(WCET)
realtime-wcet-awareness - - 绝不在中断服务程序中阻塞
realtime-no-blocking-isr - - 使用适当的锁机制防止优先级反转
realtime-priority-inversion - - 正确遵循循环调度模式
realtime-cyclic-scheduling - - 最小化中断延迟与ISR执行时间
realtime-interrupt-latency - - 为关键任务实现截止时间监控
realtime-deadline-monitoring
6. Communication Protocols (HIGH)
6. 通信协议(高)
CAN / LIN Bus:
- - Follow proper CAN/CAN FD message layout and DBC conventions
comm-can-message-layout - - Handle CAN bus-off recovery and error frames
comm-can-error-handling - - Handle CAN FD extended data length and bit rate switching
comm-can-fd-handling - - Implement LIN schedule tables and response handling
comm-lin-schedule-table - - Implement signal timeout monitoring with default values
comm-signal-timeout - - Follow NM (Network Management) state machine correctly
comm-network-management
Automotive Ethernet / IP Stack:
- - Manage TCP socket lifecycle (connect, keepalive, graceful shutdown)
comm-tcp-socket-lifecycle - - Handle UDP datagrams for service discovery and streaming
comm-udp-datagram-handling - - Implement Diagnostics over IP (ISO 13400) activation and routing
comm-doip-implementation - - Manage ARP tables and static ARP entries for deterministic networks
comm-arp-table-management - - Handle ICMP for network diagnostics and reachability detection
comm-icmp-handling - - Configure VLAN tagging and QoS priority mapping (IEEE 802.1Q)
comm-vlan-qos-priority - - Implement IP address assignment (DHCP client, AutoIP fallback)
comm-dhcp-autoip - - Use correct SOME/IP serialization for service-oriented communication
comm-someip-serialization - - Implement SOME/IP Service Discovery (offer, find, subscribe)
comm-someip-sd
Diagnostics & Routing:
- - Implement UDS diagnostic services with proper NRC handling
comm-uds-service-handler - - Implement proper message routing in gateway ECUs
comm-gateway-routing
CAN / LIN总线:
- - 遵循规范的CAN/CAN FD消息格式与DBC约定
comm-can-message-layout - - 处理CAN总线离线恢复与错误帧
comm-can-error-handling - - 处理CAN FD扩展数据长度与比特率切换
comm-can-fd-handling - - 实现LIN调度表与响应处理
comm-lin-schedule-table - - 实现信号超时监控并设置默认值
comm-signal-timeout - - 正确遵循网络管理(NM)状态机
comm-network-management
汽车以太网 / IP栈:
- - 管理TCP套接字生命周期(连接、保活、优雅关闭)
comm-tcp-socket-lifecycle - - 处理用于服务发现与流传输的UDP数据报
comm-udp-datagram-handling - - 实现基于IP的诊断(ISO 13400)激活与路由
comm-doip-implementation - - 管理ARP表与静态ARP条目以确保网络确定性
comm-arp-table-management - - 处理ICMP用于网络诊断与可达性检测
comm-icmp-handling - - 配置VLAN标记与QoS优先级映射(IEEE 802.1Q)
comm-vlan-qos-priority - - 实现IP地址分配(DHCP客户端、AutoIP fallback)
comm-dhcp-autoip - - 针对面向服务的通信使用正确的SOME/IP序列化方式
comm-someip-serialization - - 实现SOME/IP服务发现(提供、查找、订阅)
comm-someip-sd
诊断与路由:
- - 实现UDS诊断服务并正确处理NRC
comm-uds-service-handler - - 在网关ECU中实现正确的消息路由
comm-gateway-routing
7. Concurrency & RTOS Patterns (MEDIUM-HIGH)
7. 并发与RTOS模式(中高)
- - Design tasks with single responsibility and proper priority
rtos-task-design - - Minimize critical section duration
rtos-critical-section - - Use mutexes correctly, avoid nested locking
rtos-mutex-pattern - - Prefer message queues over shared memory for inter-task communication
rtos-message-queue - - Use priority inheritance or ceiling protocols
rtos-no-priority-inversion - - Defer ISR processing to task context via flags/queues
rtos-isr-to-task - - Size task stacks correctly with safety margin
rtos-stack-sizing
- - 设计具有单一职责与适当优先级的任务
rtos-task-design - - 最小化临界区持续时间
rtos-critical-section - - 正确使用互斥锁,避免嵌套锁定
rtos-mutex-pattern - - 优先使用消息队列而非共享内存进行任务间通信
rtos-message-queue - - 使用优先级继承或天花板协议
rtos-no-priority-inversion - - 通过标志/队列将ISR处理延迟到任务上下文
rtos-isr-to-task - - 为任务栈设置正确的大小并预留安全余量
rtos-stack-sizing
8. CAPL Scripting — CANoe (MEDIUM-HIGH)
8. CAPL脚本编写 — CANoe(中高)
- - Structure message handlers for readability and performance
capl-canoe-message-handler - - Use timer patterns correctly for cyclic and one-shot operations
capl-canoe-timer-pattern - - Structure test cases with proper setup/teardown/verification
capl-canoe-test-structure - - Access signals via database symbols, not raw byte manipulation
capl-canoe-signal-access - - Handle error frames and bus-off conditions in simulation
capl-canoe-error-frame-handling - - Use environment variables for panel interaction correctly
capl-canoe-environment-variables - - Implement diagnostic request/response testing patterns
capl-canoe-diagnostic-testing - - Design node simulation with proper state machines
capl-canoe-node-simulation - - Multi-channel bus simulation (CAN+CAN, CAN+LIN, CAN+ETH)
capl-canoe-multi-channel - - Cyclic Rest Bus Simulation with counter/CRC generation
capl-canoe-rbs-cyclic - - Reactive RBS with Interaction Layer and state-dependent responses
capl-canoe-rbs-reactive - - Gateway simulation with signal/PDU/cross-protocol routing
capl-canoe-gateway-routing
- - 结构化消息处理程序以提升可读性与性能
capl-canoe-message-handler - - 正确使用定时器模式实现循环与一次性操作
capl-canoe-timer-pattern - - 结构化测试用例,包含适当的设置/清理/验证步骤
capl-canoe-test-structure - - 通过数据库符号访问信号,而非直接操作原始字节
capl-canoe-signal-access - - 在仿真中处理错误帧与总线离线情况
capl-canoe-error-frame-handling - - 正确使用环境变量实现面板交互
capl-canoe-environment-variables - - 实现诊断请求/响应测试模式
capl-canoe-diagnostic-testing - - 设计带有适当状态机的节点仿真
capl-canoe-node-simulation - - 多通道总线仿真(CAN+CAN、CAN+LIN、CAN+ETH)
capl-canoe-multi-channel - - 循环式剩余总线仿真(RBS),包含计数器/CRC生成
capl-canoe-rbs-cyclic - - 响应式RBS,包含交互层与基于状态的响应
capl-canoe-rbs-reactive - - 网关仿真,包含信号/PDU/跨协议路由
capl-canoe-gateway-routing
8b. CAPL — Shared Patterns (MEDIUM-HIGH)
8b. CAPL — 通用模式(中高)
- - Reusable signal manipulation library (ramp, sine, noise, step, sequence)
capl-signal-manipulation
- - �可复用的信号操作库(斜坡、正弦、噪声、阶跃、序列)
capl-signal-manipulation
8c. CAPL — Fault Injection (HIGH)
8c. CAPL — 故障注入(高)
- - CAN/CAN FD fault injection (error frames, bus-off, signal stuck, timing)
capl-fault-can - - LIN fault injection (checksum, no-response, header, timing)
capl-fault-lin - - Ethernet fault injection (link down, packet loss, latency, corruption)
capl-fault-eth
- - CAN/CAN FD故障注入(错误帧、总线离线、信号卡滞、时序异常)
capl-fault-can - - LIN故障注入(校验和错误、无响应、头错误、时序异常)
capl-fault-lin - - 以太网故障注入(链路断开、丢包、延迟、数据损坏)
capl-fault-eth
8d. CAPL — External Integration (MEDIUM)
8d. CAPL — 外部集成(中)
- - CAPL DLL API, data exchange, thread safety, 32/64-bit
capl-ext-dll-integration - - CANoe COM automation via Python
capl-ext-com-python - - CANoe COM automation via C#
capl-ext-com-csharp - - CI/CD integration (Jenkins, GitLab CI, headless execution)
capl-ext-ci-cd
- - CAPL DLL API、数据交换、线程安全、32/64位适配
capl-ext-dll-integration - - 通过Python实现CANoe COM自动化
capl-ext-com-python - - 通过C#实现CANoe COM自动化
capl-ext-com-csharp - - CI/CD集成(Jenkins、GitLab CI、无头执行)
capl-ext-ci-cd
9. Code Organization & Architecture (MEDIUM)
9. 代码组织与架构(中)
- - Use Hardware Abstraction Layer for portability
arch-hal-abstraction - - Design clean module interfaces with information hiding
arch-module-interface - - Implement state machines with table-driven or state-pattern approach
arch-state-machine - - Use callback patterns for decoupling layers
arch-callback-pattern - - Separate configuration from logic (calibration parameters)
arch-config-separation - - Follow layered architecture (MCAL, ECU-AL, BSW, SWC)
arch-layered-architecture
- - 使用硬件抽象层(HAL)提升可移植性
arch-hal-abstraction - - 设计清晰的模块接口并实现信息隐藏
arch-module-interface - - 使用表驱动或状态模式实现状态机
arch-state-machine - - 使用回调模式实现层间解耦
arch-callback-pattern - - 将配置与逻辑分离(校准参数)
arch-config-separation - - 遵循分层架构(MCAL、ECU-AL、BSW、SWC)
arch-layered-architecture
10. Performance Optimization (MEDIUM)
10. 性能优化(中)
- - Optimize loop constructs for embedded targets
perf-loop-optimization - - Use lookup tables instead of runtime computation
perf-lookup-table - - Use bitwise operations for flag and register manipulation
perf-bitwise-operations - - Organize data for CPU cache efficiency
perf-cache-friendly - - Inline small, critical functions
perf-inline-critical - - Use fixed-point arithmetic instead of floating-point when possible
perf-fixed-point - - Use DMA for bulk data transfers
perf-dma-usage
- - 针对嵌入式目标优化循环结构
perf-loop-optimization - - 使用查找表替代运行时计算
perf-lookup-table - - 使用位操作处理标志与寄存器
perf-bitwise-operations - - 组织数据以提升CPU缓存效率
perf-cache-friendly - - 内联小型关键函数
perf-inline-critical - - 尽可能使用定点运算而非浮点运算
perf-fixed-point - - 使用DMA进行批量数据传输
perf-dma-usage
11. Build, Compilation & Static Analysis (MEDIUM)
11. 构建、编译与静态分析(中)
- - Treat all compiler warnings as errors
build-warnings-as-errors - - Integrate static analysis (PC-lint, Polyspace, Coverity)
build-static-analysis - - Use appropriate compiler flags for safety and optimization
build-compiler-flags - - Use LTO for cross-module optimization
build-link-time-optimization - - Ensure reproducible builds for traceability
build-reproducible-builds
- - 将所有编译器警告视为错误
build-warnings-as-errors - - 集成静态分析工具(PC-lint、Polyspace、Coverity)
build-static-analysis - - 使用适合安全与优化要求的编译器标志
build-compiler-flags - - 使用LTO实现跨模块优化
build-link-time-optimization - - 确保构建可复用以满足可追溯性要求
build-reproducible-builds
12. Testing & Verification (MEDIUM)
12. 测试与验证(中)
- - Structure unit tests for embedded C/C++ (Unity, Google Test)
test-unit-test-pattern - - Mock hardware dependencies for testability
test-mock-hardware - - Test boundary values and edge cases systematically
test-boundary-values - - Meet code coverage targets per ASIL level
test-coverage-targets - - Design integration tests for inter-module communication
test-integration-testing - - Structure HIL/SIL test patterns for verification
test-hil-sil-pattern
- - 结构化嵌入式C/C++单元测试(Unity、Google Test)
test-unit-test-pattern - - 模拟硬件依赖以提升可测试性
test-mock-hardware - - 系统地测试边界值与边缘情况
test-boundary-values - - 满足对应ASIL等级的代码覆盖率要求
test-coverage-targets - - 设计模块间通信的集成测试
test-integration-testing - - 结构化硬件在环(HIL)/软件在环(SIL)测试模式
test-hil-sil-pattern
13. Security & Cybersecurity — ISO 21434 (HIGH)
13. 安全与网络安全 — ISO 21434(高)
- - Implement secure boot chain verification
security-secure-boot - - Use TLS/DTLS for in-vehicle Ethernet communication
security-secure-communication - - Handle cryptographic keys with proper storage and rotation
security-key-management - - Implement secure UDS authentication (0x29 service)
security-secure-diagnostics - - Sanitize all external inputs (CAN, Ethernet, diagnostic)
security-input-sanitization - - Implement secure OTA/reflash with signature verification
security-secure-update - - Enforce access control between security domains
security-access-control - - Use cryptographic primitives correctly (AES, HMAC, CMAC)
security-crypto-usage
- - 实现安全启动链验证
security-secure-boot - - 在车载以太网通信中使用TLS/DTLS
security-secure-communication - - 正确处理加密密钥的存储与轮换
security-key-management - - 实现安全UDS认证(0x29服务)
security-secure-diagnostics - - 对所有外部输入(CAN、以太网、诊断)进行清理
security-input-sanitization - - 实现带有签名验证的安全OTA/重刷
security-secure-update - - 强制安全域间的访问控制
security-access-control - - 正确使用加密原语(AES、HMAC、CMAC)
security-crypto-usage
14. MISRA Grouped Topics (CRITICAL)
14. MISRA分组主题(关键)
- - Essential type model, implicit conversions, type casting (Rules 10-11)
misra-type-system - - Switch, goto, unreachable code, single exit (Rules 15-16)
misra-control-flow - - Pointer arithmetic, null checks, conversions (Rules 18, 11)
misra-pointer-safety - - Variable scope, linkage, storage class (Rules 8)
misra-declarations - - Side effects, precedence, boolean, sizeof (Rules 12-14)
misra-expressions - - Prototypes, parameters, return values, recursion ban (Rules 17)
misra-functions - - Macro safety, include guards, conditional compilation (Rules 20)
misra-preprocessor - - Banned functions, restricted headers (Rules 21-22)
misra-standard-library - - Variable/array/struct initialization (Rules 9)
misra-initialization - - Volatile, atomic access, memory barriers (Rules 19)
misra-memory-model - - Thread safety, shared data access (Amendment 4)
misra-concurrency - - Deviation documentation, approval, common patterns
misra-deviation-process
- - 基础类型模型、隐式转换、类型转换(规则10-11)
misra-type-system - - 分支、goto、不可达代码、单一出口(规则15-16)
misra-control-flow - - 指针运算、空检查、转换(规则18、11)
misra-pointer-safety - - 变量作用域、链接、存储类(规则8)
misra-declarations - - 副作用、优先级、布尔运算、sizeof(规则12-14)
misra-expressions - - 原型、参数、返回值、递归禁用(规则17)
misra-functions - - 宏安全、包含保护、条件编译(规则20)
misra-preprocessor - - 禁用函数、受限头文件(规则21-22)
misra-standard-library - - 变量/数组/结构体初始化(规则9)
misra-initialization - - Volatile、原子访问、内存屏障(规则19)
misra-memory-model - - 线程安全、共享数据访问(修正案4)
misra-concurrency - - 偏差文档、审批、常见模式
misra-deviation-process
15. AUTOSAR Classic BSW Modules (HIGH)
15. AUTOSAR经典版BSW模块(高)
- - EcuM startup/shutdown, sleep/wakeup
autosar-classic-ecum - - BswM mode arbitration, action lists
autosar-classic-bswm - - COM signal packing, transmission modes
autosar-classic-com - - PDU Router routing paths, gateway
autosar-classic-pdu-router - - Dcm/Dem diagnostics, DTC management
autosar-classic-dcm-dem - - NvM block configuration, CRC, read/write
autosar-classic-nvm - - AUTOSAR OS tasks, ISRs, resources, alarms
autosar-classic-os - - CanIf/CanTp callbacks, flow control
autosar-classic-canif-cantp
- - EcuM启动/关闭、睡眠/唤醒
autosar-classic-ecum - - BswM模式仲裁、动作列表
autosar-classic-bswm - - COM信号打包、传输模式
autosar-classic-com - - PDU路由器路径、网关
autosar-classic-pdu-router - - Dcm/Dem诊断、DTC管理
autosar-classic-dcm-dem - - NvM块配置、CRC、读/写
autosar-classic-nvm - - AUTOSAR OS任务、ISR、资源、警报
autosar-classic-os - - CanIf/CanTp回调、流控制
autosar-classic-canif-cantp
16. AUTOSAR Adaptive ara:: APIs (HIGH)
16. AUTOSAR自适应版ara:: APIs(高)
- - ara::com proxy/skeleton, service discovery
autosar-adaptive-ara-com - - ara::core Result<T,E>, ErrorCode, Future
autosar-adaptive-ara-core - - ara::exec process lifecycle, function groups
autosar-adaptive-ara-exec - - ara::diag diagnostic services
autosar-adaptive-ara-diag - - ara::log logging patterns
autosar-adaptive-ara-log - - ara::phm health management, supervision
autosar-adaptive-ara-phm - - ara::per persistency, key-value storage
autosar-adaptive-ara-per
- - ara::com代理/骨架、服务发现
autosar-adaptive-ara-com - - ara::core Result<T,E>、ErrorCode、Future
autosar-adaptive-ara-core - - ara::exec进程生命周期、功能组
autosar-adaptive-ara-exec - - ara::diag诊断服务
autosar-adaptive-ara-diag - - ara::log日志模式
autosar-adaptive-ara-log - - ara::phm健康管理、监控
autosar-adaptive-ara-phm - - ara::per持久化、键值存储
autosar-adaptive-ara-per
17. ECU Boot Sequence (HIGH)
17. ECU启动序列(高)
- - Bare-metal boot: startup → C runtime → main
boot-baremetal-startup - - Classic AUTOSAR EcuM/BswM boot
boot-autosar-classic-startup - - Adaptive Execution Manager boot
boot-autosar-adaptive-startup - - UDS flash download sequence
boot-bootloader-reprogramming - - Secure boot with HSM verification
boot-secure-boot-chain
- - 裸机启动:启动程序 → C运行时 → main
boot-baremetal-startup - - 经典版AUTOSAR EcuM/BswM启动
boot-autosar-classic-startup - - 自适应版执行管理器启动
boot-autosar-adaptive-startup - - UDS闪存下载序列
boot-bootloader-reprogramming - - 带有HSM验证的安全启动
boot-secure-boot-chain
18. NVM Management (HIGH)
18. NVM管理(高)
- - AUTOSAR NvM blocks, CRC, redundancy
nvm-autosar-block-config - - Fee/Ea Flash EEPROM Emulation
nvm-fee-ea-abstraction - - Bare-metal Flash/EEPROM patterns
nvm-baremetal-flash - - Wear leveling strategies for automotive lifetime
nvm-wear-leveling
- - AUTOSAR NvM块、CRC、冗余
nvm-autosar-block-config - - Fee/Ea Flash EEPROM仿真
nvm-fee-ea-abstraction - - 裸机Flash/EEPROM模式
nvm-baremetal-flash - - 满足汽车生命周期要求的损耗均衡策略
nvm-wear-leveling
19. Power Management (MEDIUM)
19. 电源管理(中)
- - EcuM sleep/wakeup state machine
power-ecum-sleep-wakeup - - Partial networking, selective transceiver wakeup
power-partial-networking - - BswM ordered shutdown action lists
power-bswm-shutdown - - Clock gating and peripheral power-down
power-clock-peripheral - - MCU low-power modes (SLEEP, STANDBY, STOP)
power-low-power-modes
- - EcuM睡眠/唤醒状态机
power-ecum-sleep-wakeup - - 部分网络、选择性收发器唤醒
power-partial-networking - - BswM有序关闭动作列表
power-bswm-shutdown - - 时钟门控与外设断电
power-clock-peripheral - - MCU低功耗模式(SLEEP、STANDBY、STOP)
power-low-power-modes
20. Automotive Ethernet Deep-Dive (HIGH)
20. 汽车以太网深度解析(高)
- - TSN time synchronization (IEEE 802.1AS / gPTP)
eth-tsn-time-sync - - TSN traffic shaping (IEEE 802.1Qbv)
eth-tsn-traffic-shaping - - TSN stream filtering (IEEE 802.1Qci)
eth-tsn-stream-filtering - - Automotive Ethernet switch configuration
eth-switch-configuration - - AVB Audio/Video streaming
eth-avb-streaming
- - TSN时间同步(IEEE 802.1AS / gPTP)
eth-tsn-time-sync - - TSN流量整形(IEEE 802.1Qbv)
eth-tsn-traffic-shaping - - TSN流过滤(IEEE 802.1Qci)
eth-tsn-stream-filtering - - 汽车以太网交换机配置
eth-switch-configuration - - AVB音频/视频流
eth-avb-streaming
21. Compiler & Static Analysis (HIGH)
21. 编译器与静态分析(高)
- - GCC warning flags for automotive
build-gcc-warnings - - Clang-Tidy and Clang Static Analyzer
build-clang-analysis - - GreenHills safety-qualified compiler
build-greenhills-safety - - PC-lint MISRA configuration
analysis-pclint-config - - Polyspace Bug Finder / Code Prover
analysis-polyspace - - Coverity embedded checkers
analysis-coverity - - cppcheck with MISRA addon
analysis-cppcheck - - Parasoft C/C++test
analysis-parasoft - - LDRA traceability and coverage
analysis-ldra
- - 适用于汽车领域的GCC警告标志
build-gcc-warnings - - Clang-Tidy与Clang静态分析器
build-clang-analysis - - GreenHills安全认证编译器
build-greenhills-safety - - PC-lint MISRA配置
analysis-pclint-config - - Polyspace Bug Finder / Code Prover
analysis-polyspace - - Coverity嵌入式检查器
analysis-coverity - - 带有MISRA插件的cppcheck
analysis-cppcheck - - Parasoft C/C++test
analysis-parasoft - - LDRA可追溯性与覆盖率
analysis-ldra
22. vTESTstudio CAPL (MEDIUM-HIGH)
22. vTESTstudio CAPL(中高)
- - Test unit/group/fixture structure
capl-vtest-test-unit - - Data-driven testing with parameters
capl-vtest-data-driven - - XML test module integration
capl-vtest-xml-module - - Verdict and reporting patterns
capl-vtest-verdict-reporting - - Stimulus/response timing validation
capl-vtest-stimulus-response
- - 测试单元/组/夹具结构
capl-vtest-test-unit - - 带参数的数据驱动测试
capl-vtest-data-driven - - XML测试模块集成
capl-vtest-xml-module - - verdict与报告模式
capl-vtest-verdict-reporting - - 刺激/响应时序验证
capl-vtest-stimulus-response
23. Tool Integration (MEDIUM)
23. 工具集成(中)
- - Generate and maintain A2L/ASAP2 calibration descriptions
integration-a2l-calibration - - Structure ODX/PDX diagnostic descriptions correctly
integration-odx-diagnostic - - Maintain FIBEX network description files
integration-fibex-network - - Keep DBC/ARXML and code signal definitions synchronized
integration-dbc-arxml-sync - - Implement XCP (Universal Measurement and Calibration Protocol)
integration-xcp-calibration - - Generate and parse AUTOSAR ARXML configuration correctly
integration-autosar-arxml
- - 生成与维护A2L/ASAP2校准描述
integration-a2l-calibration - - 正确结构化ODX/PDX诊断描述
integration-odx-diagnostic - - 维护FIBEX网络描述文件
integration-fibex-network - - 保持DBC/ARXML与代码信号定义同步
integration-dbc-arxml-sync - - 实现XCP(通用测量与校准协议)
integration-xcp-calibration - - 正确生成与解析AUTOSAR ARXML配置
integration-autosar-arxml
How to Use
使用方法
Read individual rule files for detailed explanations and code examples:
rules/memory-stack-over-heap.md
rules/misra-no-recursion.md
rules/capl-message-handler.mdEach rule file contains:
- Brief explanation of why it matters in automotive embedded context
- Incorrect code example with explanation
- Correct code example with explanation
- Relevant standard references (MISRA, AUTOSAR, ISO 26262)
- Additional context and impact on safety/performance
阅读单个规则文件获取详细说明与代码示例:
rules/memory-stack-over-heap.md
rules/misra-no-recursion.md
rules/capl-message-handler.md每个规则文件包含:
- 该规则在汽车嵌入式场景中重要性的简要说明
- 错误代码示例及解释
- 正确代码示例及解释
- 相关标准参考(MISRA、AUTOSAR、ISO 26262)
- 额外上下文信息及对安全/性能的影响
Full Compiled Document
完整编译文档
For the complete guide with all rules expanded:
AGENTS.md包含所有扩展规则的完整指南:
AGENTS.md