automotive-embedded-skills

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Automotive 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

按优先级划分的规则类别

PriorityCategoryImpactPrefix
1Memory Safety & ManagementCRITICAL
memory-
2MISRA C/C++ ComplianceCRITICAL
misra-
3AUTOSAR C++14 Guidelines (Classic & Adaptive)CRITICAL
autosar-
4Safety & Functional Safety (ISO 26262)HIGH
safety-
5Real-Time & Timing ConstraintsHIGH
realtime-
6Communication Protocols (CAN/LIN/Ethernet/IP/UDS)HIGH
comm-
7Concurrency & RTOS PatternsMEDIUM-HIGH
rtos-
8CAPL Scripting — CANoeMEDIUM-HIGH
capl-canoe-
9CAPL Scripting — vTESTstudioMEDIUM-HIGH
capl-vtest-
10Code Organization & ArchitectureMEDIUM
arch-
11Performance OptimizationMEDIUM
perf-
12Build, Compilation & Static AnalysisMEDIUM
build-
13Security & Cybersecurity (ISO 21434)HIGH
security-
14Testing & VerificationMEDIUM
test-
15Tool Integration (A2L/ODX/FIBEX)MEDIUM
integration-
优先级类别影响程度前缀
1内存安全与管理关键
memory-
2MISRA C/C++合规关键
misra-
3AUTOSAR C++14准则(经典版与自适应版)关键
autosar-
4安全与功能安全(ISO 26262)
safety-
5实时性与时序约束
realtime-
6通信协议(CAN/LIN/Ethernet/IP/UDS)
comm-
7并发与RTOS模式中高
rtos-
8CAPL脚本编写 — CANoe中高
capl-canoe-
9CAPL脚本编写 — vTESTstudio中高
capl-vtest-
10代码组织与架构
arch-
11性能优化
perf-
12构建、编译与静态分析
build-
13安全与网络安全(ISO 21434)
security-
14测试与验证
test-
15工具集成(A2L/ODX/FIBEX)
integration-

Quick Reference

快速参考

1. Memory Safety & Management (CRITICAL)

1. 内存安全与管理(关键)

  • memory-stack-over-heap
    - Prefer stack allocation over heap in embedded context
  • memory-static-allocation
    - Use static allocation for deterministic memory usage
  • memory-buffer-bounds
    - Always validate buffer boundaries before access
  • memory-pool-pattern
    - Use memory pool patterns for dynamic-like allocation
  • memory-no-malloc-in-rt
    - Never use malloc/free in real-time critical paths
  • memory-raii-cpp
    - Use RAII for resource management in C++ embedded code
  • memory-volatile-correctness
    - Use volatile correctly for hardware registers and shared data
  • memory-alignment
    - Ensure proper data structure alignment for target architecture
  • memory-zero-init
    - Always initialize variables, especially in safety-critical code
  • memory-stack-over-heap
    - 嵌入式场景下优先使用栈分配而非堆分配
  • memory-static-allocation
    - 使用静态分配以确保内存使用的确定性
  • memory-buffer-bounds
    - 访问缓冲区前始终验证边界
  • memory-pool-pattern
    - 使用内存池模式实现类动态分配
  • memory-no-malloc-in-rt
    - 绝不在实时关键路径中使用malloc/free
  • memory-raii-cpp
    - 在嵌入式C++代码中使用RAII进行资源管理
  • memory-volatile-correctness
    - 正确使用volatile访问硬件寄存器与共享数据
  • memory-alignment
    - 确保数据结构与目标架构的对齐要求一致
  • memory-zero-init
    - 始终初始化变量,尤其是在安全关键代码中

2. MISRA C/C++ Compliance (CRITICAL)

2. MISRA C/C++合规(关键)

  • misra-no-implicit-conversions
    - Avoid implicit type conversions
  • misra-single-exit-point
    - Prefer single function exit point for critical functions
  • misra-no-dynamic-memory
    - Avoid dynamic memory allocation (Rule 21.3)
  • misra-no-recursion
    - Avoid recursion in embedded context (Rule 17.2)
  • misra-switch-default
    - Always include default case in switch statements
  • misra-no-goto
    - Avoid goto except for error cleanup patterns in C
  • misra-boolean-expressions
    - Use explicit boolean comparisons
  • misra-pointer-arithmetic
    - Restrict pointer arithmetic to array indexing
  • misra-side-effects
    - Avoid side effects in conditional expressions
  • misra-no-implicit-conversions
    - 避免隐式类型转换
  • misra-single-exit-point
    - 关键函数优先使用单一出口点
  • misra-no-dynamic-memory
    - 避免动态内存分配(规则21.3)
  • misra-no-recursion
    - 嵌入式场景下避免递归(规则17.2)
  • misra-switch-default
    - switch语句中始终包含default分支
  • misra-no-goto
    - C语言中避免使用goto,除非用于错误清理模式
  • misra-boolean-expressions
    - 使用显式布尔比较
  • misra-pointer-arithmetic
    - 指针运算仅限于数组索引
  • misra-side-effects
    - 避免在条件表达式中产生副作用

3. AUTOSAR C++14 Guidelines (CRITICAL)

3. AUTOSAR C++14准则(关键)

  • autosar-smart-pointers
    - Use smart pointers instead of raw pointers for ownership
  • autosar-no-exceptions-rt
    - Avoid exceptions in real-time contexts, use Result types
  • autosar-const-correctness
    - Apply const-correctness throughout interfaces
  • autosar-override-final
    - Always use override/final for virtual function overrides
  • autosar-enum-class
    - Use enum class instead of plain enum
  • autosar-no-unions
    - Avoid unions, use std::variant when needed
  • autosar-braces-init
    - Prefer braced initialization to prevent narrowing
  • autosar-nodiscard
    - Use [[nodiscard]] for functions with important return values
  • autosar-smart-pointers
    - 使用智能指针而非裸指针管理所有权
  • autosar-no-exceptions-rt
    - 实时场景下避免使用异常,改用Result类型
  • autosar-const-correctness
    - 在接口中全面应用const正确性
  • autosar-override-final
    - 重写虚函数时始终使用override/final
  • autosar-enum-class
    - 使用enum class而非普通enum
  • autosar-no-unions
    - 避免使用联合体,必要时使用std::variant
  • autosar-braces-init
    - 优先使用大括号初始化以防止窄化转换
  • autosar-nodiscard
    - 对具有重要返回值的函数使用[[nodiscard]]

4. Safety & Functional Safety - ISO 26262 (HIGH)

4. 安全与功能安全 - ISO 26262(高)

  • safety-defensive-programming
    - Apply defensive programming at module boundaries
  • safety-error-detection
    - Implement error detection and plausibility checks
  • safety-redundant-checks
    - Use redundant checks for critical control paths
  • safety-watchdog-pattern
    - Implement watchdog monitoring patterns
  • safety-state-machine-integrity
    - Protect state machine transitions from corruption
  • safety-crc-validation
    - Validate data integrity with CRC for critical data
  • safety-safe-state
    - Always define and reach safe state on failure
  • safety-asil-decomposition
    - Follow ASIL decomposition patterns correctly
  • safety-defensive-programming
    - 在模块边界应用防御式编程
  • safety-error-detection
    - 实现错误检测与合理性检查
  • safety-redundant-checks
    - 对关键控制路径使用冗余检查
  • safety-watchdog-pattern
    - 实现看门狗监控模式
  • safety-state-machine-integrity
    - 保护状态机转换免受损坏
  • safety-crc-validation
    - 使用CRC验证关键数据的完整性
  • safety-safe-state
    - 故障发生时始终定义并进入安全状态
  • safety-asil-decomposition
    - 正确遵循ASIL分解模式

5. Real-Time & Timing Constraints (HIGH)

5. 实时性与时序约束(高)

  • realtime-deterministic-execution
    - Ensure deterministic execution time in cyclic tasks
  • realtime-wcet-awareness
    - Design with WCET (Worst-Case Execution Time) in mind
  • realtime-no-blocking-isr
    - Never block in interrupt service routines
  • realtime-priority-inversion
    - Prevent priority inversion with proper locking
  • realtime-cyclic-scheduling
    - Follow cyclic scheduling patterns correctly
  • realtime-interrupt-latency
    - Minimize interrupt latency and ISR execution time
  • realtime-deadline-monitoring
    - Implement deadline monitoring for critical tasks
  • realtime-deterministic-execution
    - 确保循环任务的执行时间具有确定性
  • realtime-wcet-awareness
    - 设计时考虑最坏情况执行时间(WCET)
  • realtime-no-blocking-isr
    - 绝不在中断服务程序中阻塞
  • realtime-priority-inversion
    - 使用适当的锁机制防止优先级反转
  • realtime-cyclic-scheduling
    - 正确遵循循环调度模式
  • realtime-interrupt-latency
    - 最小化中断延迟与ISR执行时间
  • realtime-deadline-monitoring
    - 为关键任务实现截止时间监控

6. Communication Protocols (HIGH)

6. 通信协议(高)

CAN / LIN Bus:
  • comm-can-message-layout
    - Follow proper CAN/CAN FD message layout and DBC conventions
  • comm-can-error-handling
    - Handle CAN bus-off recovery and error frames
  • comm-can-fd-handling
    - Handle CAN FD extended data length and bit rate switching
  • comm-lin-schedule-table
    - Implement LIN schedule tables and response handling
  • comm-signal-timeout
    - Implement signal timeout monitoring with default values
  • comm-network-management
    - Follow NM (Network Management) state machine correctly
Automotive Ethernet / IP Stack:
  • comm-tcp-socket-lifecycle
    - Manage TCP socket lifecycle (connect, keepalive, graceful shutdown)
  • comm-udp-datagram-handling
    - Handle UDP datagrams for service discovery and streaming
  • comm-doip-implementation
    - Implement Diagnostics over IP (ISO 13400) activation and routing
  • comm-arp-table-management
    - Manage ARP tables and static ARP entries for deterministic networks
  • comm-icmp-handling
    - Handle ICMP for network diagnostics and reachability detection
  • comm-vlan-qos-priority
    - Configure VLAN tagging and QoS priority mapping (IEEE 802.1Q)
  • comm-dhcp-autoip
    - Implement IP address assignment (DHCP client, AutoIP fallback)
  • comm-someip-serialization
    - Use correct SOME/IP serialization for service-oriented communication
  • comm-someip-sd
    - Implement SOME/IP Service Discovery (offer, find, subscribe)
Diagnostics & Routing:
  • comm-uds-service-handler
    - Implement UDS diagnostic services with proper NRC handling
  • comm-gateway-routing
    - Implement proper message routing in gateway ECUs
CAN / LIN总线:
  • comm-can-message-layout
    - 遵循规范的CAN/CAN FD消息格式与DBC约定
  • comm-can-error-handling
    - 处理CAN总线离线恢复与错误帧
  • comm-can-fd-handling
    - 处理CAN FD扩展数据长度与比特率切换
  • comm-lin-schedule-table
    - 实现LIN调度表与响应处理
  • comm-signal-timeout
    - 实现信号超时监控并设置默认值
  • comm-network-management
    - 正确遵循网络管理(NM)状态机
汽车以太网 / IP栈:
  • comm-tcp-socket-lifecycle
    - 管理TCP套接字生命周期(连接、保活、优雅关闭)
  • comm-udp-datagram-handling
    - 处理用于服务发现与流传输的UDP数据报
  • comm-doip-implementation
    - 实现基于IP的诊断(ISO 13400)激活与路由
  • comm-arp-table-management
    - 管理ARP表与静态ARP条目以确保网络确定性
  • comm-icmp-handling
    - 处理ICMP用于网络诊断与可达性检测
  • comm-vlan-qos-priority
    - 配置VLAN标记与QoS优先级映射(IEEE 802.1Q)
  • comm-dhcp-autoip
    - 实现IP地址分配(DHCP客户端、AutoIP fallback)
  • comm-someip-serialization
    - 针对面向服务的通信使用正确的SOME/IP序列化方式
  • comm-someip-sd
    - 实现SOME/IP服务发现(提供、查找、订阅)
诊断与路由:
  • comm-uds-service-handler
    - 实现UDS诊断服务并正确处理NRC
  • comm-gateway-routing
    - 在网关ECU中实现正确的消息路由

7. Concurrency & RTOS Patterns (MEDIUM-HIGH)

7. 并发与RTOS模式(中高)

  • rtos-task-design
    - Design tasks with single responsibility and proper priority
  • rtos-critical-section
    - Minimize critical section duration
  • rtos-mutex-pattern
    - Use mutexes correctly, avoid nested locking
  • rtos-message-queue
    - Prefer message queues over shared memory for inter-task communication
  • rtos-no-priority-inversion
    - Use priority inheritance or ceiling protocols
  • rtos-isr-to-task
    - Defer ISR processing to task context via flags/queues
  • rtos-stack-sizing
    - Size task stacks correctly with safety margin
  • rtos-task-design
    - 设计具有单一职责与适当优先级的任务
  • rtos-critical-section
    - 最小化临界区持续时间
  • rtos-mutex-pattern
    - 正确使用互斥锁,避免嵌套锁定
  • rtos-message-queue
    - 优先使用消息队列而非共享内存进行任务间通信
  • rtos-no-priority-inversion
    - 使用优先级继承或天花板协议
  • rtos-isr-to-task
    - 通过标志/队列将ISR处理延迟到任务上下文
  • rtos-stack-sizing
    - 为任务栈设置正确的大小并预留安全余量

8. CAPL Scripting — CANoe (MEDIUM-HIGH)

8. CAPL脚本编写 — CANoe(中高)

  • capl-canoe-message-handler
    - Structure message handlers for readability and performance
  • capl-canoe-timer-pattern
    - Use timer patterns correctly for cyclic and one-shot operations
  • capl-canoe-test-structure
    - Structure test cases with proper setup/teardown/verification
  • capl-canoe-signal-access
    - Access signals via database symbols, not raw byte manipulation
  • capl-canoe-error-frame-handling
    - Handle error frames and bus-off conditions in simulation
  • capl-canoe-environment-variables
    - Use environment variables for panel interaction correctly
  • capl-canoe-diagnostic-testing
    - Implement diagnostic request/response testing patterns
  • capl-canoe-node-simulation
    - Design node simulation with proper state machines
  • capl-canoe-multi-channel
    - Multi-channel bus simulation (CAN+CAN, CAN+LIN, CAN+ETH)
  • capl-canoe-rbs-cyclic
    - Cyclic Rest Bus Simulation with counter/CRC generation
  • capl-canoe-rbs-reactive
    - Reactive RBS with Interaction Layer and state-dependent responses
  • capl-canoe-gateway-routing
    - Gateway simulation with signal/PDU/cross-protocol 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
    - 设计带有适当状态机的节点仿真
  • capl-canoe-multi-channel
    - 多通道总线仿真(CAN+CAN、CAN+LIN、CAN+ETH)
  • capl-canoe-rbs-cyclic
    - 循环式剩余总线仿真(RBS),包含计数器/CRC生成
  • capl-canoe-rbs-reactive
    - 响应式RBS,包含交互层与基于状态的响应
  • capl-canoe-gateway-routing
    - 网关仿真,包含信号/PDU/跨协议路由

8b. CAPL — Shared Patterns (MEDIUM-HIGH)

8b. CAPL — 通用模式(中高)

  • capl-signal-manipulation
    - Reusable signal manipulation library (ramp, sine, noise, step, sequence)
  • capl-signal-manipulation
    - �可复用的信号操作库(斜坡、正弦、噪声、阶跃、序列)

8c. CAPL — Fault Injection (HIGH)

8c. CAPL — 故障注入(高)

  • capl-fault-can
    - CAN/CAN FD fault injection (error frames, bus-off, signal stuck, timing)
  • capl-fault-lin
    - LIN fault injection (checksum, no-response, header, timing)
  • capl-fault-eth
    - Ethernet fault injection (link down, packet loss, latency, corruption)
  • capl-fault-can
    - CAN/CAN FD故障注入(错误帧、总线离线、信号卡滞、时序异常)
  • capl-fault-lin
    - LIN故障注入(校验和错误、无响应、头错误、时序异常)
  • capl-fault-eth
    - 以太网故障注入(链路断开、丢包、延迟、数据损坏)

8d. CAPL — External Integration (MEDIUM)

8d. CAPL — 外部集成(中)

  • capl-ext-dll-integration
    - CAPL DLL API, data exchange, thread safety, 32/64-bit
  • capl-ext-com-python
    - CANoe COM automation via Python
  • capl-ext-com-csharp
    - CANoe COM automation via C#
  • capl-ext-ci-cd
    - CI/CD integration (Jenkins, GitLab CI, headless execution)
  • capl-ext-dll-integration
    - CAPL DLL API、数据交换、线程安全、32/64位适配
  • capl-ext-com-python
    - 通过Python实现CANoe COM自动化
  • capl-ext-com-csharp
    - 通过C#实现CANoe COM自动化
  • capl-ext-ci-cd
    - CI/CD集成(Jenkins、GitLab CI、无头执行)

9. Code Organization & Architecture (MEDIUM)

9. 代码组织与架构(中)

  • arch-hal-abstraction
    - Use Hardware Abstraction Layer for portability
  • arch-module-interface
    - Design clean module interfaces with information hiding
  • arch-state-machine
    - Implement state machines with table-driven or state-pattern approach
  • arch-callback-pattern
    - Use callback patterns for decoupling layers
  • arch-config-separation
    - Separate configuration from logic (calibration parameters)
  • arch-layered-architecture
    - Follow layered architecture (MCAL, ECU-AL, BSW, SWC)
  • arch-hal-abstraction
    - 使用硬件抽象层(HAL)提升可移植性
  • arch-module-interface
    - 设计清晰的模块接口并实现信息隐藏
  • arch-state-machine
    - 使用表驱动或状态模式实现状态机
  • arch-callback-pattern
    - 使用回调模式实现层间解耦
  • arch-config-separation
    - 将配置与逻辑分离(校准参数)
  • arch-layered-architecture
    - 遵循分层架构(MCAL、ECU-AL、BSW、SWC)

10. Performance Optimization (MEDIUM)

10. 性能优化(中)

  • perf-loop-optimization
    - Optimize loop constructs for embedded targets
  • perf-lookup-table
    - Use lookup tables instead of runtime computation
  • perf-bitwise-operations
    - Use bitwise operations for flag and register manipulation
  • perf-cache-friendly
    - Organize data for CPU cache efficiency
  • perf-inline-critical
    - Inline small, critical functions
  • perf-fixed-point
    - Use fixed-point arithmetic instead of floating-point when possible
  • perf-dma-usage
    - Use DMA for bulk data transfers
  • perf-loop-optimization
    - 针对嵌入式目标优化循环结构
  • perf-lookup-table
    - 使用查找表替代运行时计算
  • perf-bitwise-operations
    - 使用位操作处理标志与寄存器
  • perf-cache-friendly
    - 组织数据以提升CPU缓存效率
  • perf-inline-critical
    - 内联小型关键函数
  • perf-fixed-point
    - 尽可能使用定点运算而非浮点运算
  • perf-dma-usage
    - 使用DMA进行批量数据传输

11. Build, Compilation & Static Analysis (MEDIUM)

11. 构建、编译与静态分析(中)

  • build-warnings-as-errors
    - Treat all compiler warnings as errors
  • build-static-analysis
    - Integrate static analysis (PC-lint, Polyspace, Coverity)
  • build-compiler-flags
    - Use appropriate compiler flags for safety and optimization
  • build-link-time-optimization
    - Use LTO for cross-module optimization
  • build-reproducible-builds
    - Ensure reproducible builds for traceability
  • build-warnings-as-errors
    - 将所有编译器警告视为错误
  • build-static-analysis
    - 集成静态分析工具(PC-lint、Polyspace、Coverity)
  • build-compiler-flags
    - 使用适合安全与优化要求的编译器标志
  • build-link-time-optimization
    - 使用LTO实现跨模块优化
  • build-reproducible-builds
    - 确保构建可复用以满足可追溯性要求

12. Testing & Verification (MEDIUM)

12. 测试与验证(中)

  • test-unit-test-pattern
    - Structure unit tests for embedded C/C++ (Unity, Google Test)
  • test-mock-hardware
    - Mock hardware dependencies for testability
  • test-boundary-values
    - Test boundary values and edge cases systematically
  • test-coverage-targets
    - Meet code coverage targets per ASIL level
  • test-integration-testing
    - Design integration tests for inter-module communication
  • test-hil-sil-pattern
    - Structure HIL/SIL test patterns for verification
  • test-unit-test-pattern
    - 结构化嵌入式C/C++单元测试(Unity、Google Test)
  • test-mock-hardware
    - 模拟硬件依赖以提升可测试性
  • test-boundary-values
    - 系统地测试边界值与边缘情况
  • test-coverage-targets
    - 满足对应ASIL等级的代码覆盖率要求
  • test-integration-testing
    - 设计模块间通信的集成测试
  • test-hil-sil-pattern
    - 结构化硬件在环(HIL)/软件在环(SIL)测试模式

13. Security & Cybersecurity — ISO 21434 (HIGH)

13. 安全与网络安全 — ISO 21434(高)

  • security-secure-boot
    - Implement secure boot chain verification
  • security-secure-communication
    - Use TLS/DTLS for in-vehicle Ethernet communication
  • security-key-management
    - Handle cryptographic keys with proper storage and rotation
  • security-secure-diagnostics
    - Implement secure UDS authentication (0x29 service)
  • security-input-sanitization
    - Sanitize all external inputs (CAN, Ethernet, diagnostic)
  • security-secure-update
    - Implement secure OTA/reflash with signature verification
  • security-access-control
    - Enforce access control between security domains
  • security-crypto-usage
    - Use cryptographic primitives correctly (AES, HMAC, CMAC)
  • security-secure-boot
    - 实现安全启动链验证
  • security-secure-communication
    - 在车载以太网通信中使用TLS/DTLS
  • security-key-management
    - 正确处理加密密钥的存储与轮换
  • security-secure-diagnostics
    - 实现安全UDS认证(0x29服务)
  • security-input-sanitization
    - 对所有外部输入(CAN、以太网、诊断)进行清理
  • security-secure-update
    - 实现带有签名验证的安全OTA/重刷
  • security-access-control
    - 强制安全域间的访问控制
  • security-crypto-usage
    - 正确使用加密原语(AES、HMAC、CMAC)

14. MISRA Grouped Topics (CRITICAL)

14. MISRA分组主题(关键)

  • misra-type-system
    - Essential type model, implicit conversions, type casting (Rules 10-11)
  • misra-control-flow
    - Switch, goto, unreachable code, single exit (Rules 15-16)
  • misra-pointer-safety
    - Pointer arithmetic, null checks, conversions (Rules 18, 11)
  • misra-declarations
    - Variable scope, linkage, storage class (Rules 8)
  • misra-expressions
    - Side effects, precedence, boolean, sizeof (Rules 12-14)
  • misra-functions
    - Prototypes, parameters, return values, recursion ban (Rules 17)
  • misra-preprocessor
    - Macro safety, include guards, conditional compilation (Rules 20)
  • misra-standard-library
    - Banned functions, restricted headers (Rules 21-22)
  • misra-initialization
    - Variable/array/struct initialization (Rules 9)
  • misra-memory-model
    - Volatile, atomic access, memory barriers (Rules 19)
  • misra-concurrency
    - Thread safety, shared data access (Amendment 4)
  • misra-deviation-process
    - Deviation documentation, approval, common patterns
  • misra-type-system
    - 基础类型模型、隐式转换、类型转换(规则10-11)
  • misra-control-flow
    - 分支、goto、不可达代码、单一出口(规则15-16)
  • misra-pointer-safety
    - 指针运算、空检查、转换(规则18、11)
  • misra-declarations
    - 变量作用域、链接、存储类(规则8)
  • misra-expressions
    - 副作用、优先级、布尔运算、sizeof(规则12-14)
  • misra-functions
    - 原型、参数、返回值、递归禁用(规则17)
  • misra-preprocessor
    - 宏安全、包含保护、条件编译(规则20)
  • misra-standard-library
    - 禁用函数、受限头文件(规则21-22)
  • misra-initialization
    - 变量/数组/结构体初始化(规则9)
  • misra-memory-model
    - Volatile、原子访问、内存屏障(规则19)
  • misra-concurrency
    - 线程安全、共享数据访问(修正案4)
  • misra-deviation-process
    - 偏差文档、审批、常见模式

15. AUTOSAR Classic BSW Modules (HIGH)

15. AUTOSAR经典版BSW模块(高)

  • autosar-classic-ecum
    - EcuM startup/shutdown, sleep/wakeup
  • autosar-classic-bswm
    - BswM mode arbitration, action lists
  • autosar-classic-com
    - COM signal packing, transmission modes
  • autosar-classic-pdu-router
    - PDU Router routing paths, gateway
  • autosar-classic-dcm-dem
    - Dcm/Dem diagnostics, DTC management
  • autosar-classic-nvm
    - NvM block configuration, CRC, read/write
  • autosar-classic-os
    - AUTOSAR OS tasks, ISRs, resources, alarms
  • autosar-classic-canif-cantp
    - CanIf/CanTp callbacks, flow control
  • autosar-classic-ecum
    - EcuM启动/关闭、睡眠/唤醒
  • autosar-classic-bswm
    - BswM模式仲裁、动作列表
  • autosar-classic-com
    - COM信号打包、传输模式
  • autosar-classic-pdu-router
    - PDU路由器路径、网关
  • autosar-classic-dcm-dem
    - Dcm/Dem诊断、DTC管理
  • autosar-classic-nvm
    - NvM块配置、CRC、读/写
  • autosar-classic-os
    - AUTOSAR OS任务、ISR、资源、警报
  • autosar-classic-canif-cantp
    - CanIf/CanTp回调、流控制

16. AUTOSAR Adaptive ara:: APIs (HIGH)

16. AUTOSAR自适应版ara:: APIs(高)

  • autosar-adaptive-ara-com
    - ara::com proxy/skeleton, service discovery
  • autosar-adaptive-ara-core
    - ara::core Result<T,E>, ErrorCode, Future
  • autosar-adaptive-ara-exec
    - ara::exec process lifecycle, function groups
  • autosar-adaptive-ara-diag
    - ara::diag diagnostic services
  • autosar-adaptive-ara-log
    - ara::log logging patterns
  • autosar-adaptive-ara-phm
    - ara::phm health management, supervision
  • autosar-adaptive-ara-per
    - ara::per persistency, key-value storage
  • autosar-adaptive-ara-com
    - ara::com代理/骨架、服务发现
  • autosar-adaptive-ara-core
    - ara::core Result<T,E>、ErrorCode、Future
  • autosar-adaptive-ara-exec
    - ara::exec进程生命周期、功能组
  • autosar-adaptive-ara-diag
    - ara::diag诊断服务
  • autosar-adaptive-ara-log
    - ara::log日志模式
  • autosar-adaptive-ara-phm
    - ara::phm健康管理、监控
  • autosar-adaptive-ara-per
    - ara::per持久化、键值存储

17. ECU Boot Sequence (HIGH)

17. ECU启动序列(高)

  • boot-baremetal-startup
    - Bare-metal boot: startup → C runtime → main
  • boot-autosar-classic-startup
    - Classic AUTOSAR EcuM/BswM boot
  • boot-autosar-adaptive-startup
    - Adaptive Execution Manager boot
  • boot-bootloader-reprogramming
    - UDS flash download sequence
  • boot-secure-boot-chain
    - Secure boot with HSM verification
  • boot-baremetal-startup
    - 裸机启动:启动程序 → C运行时 → main
  • boot-autosar-classic-startup
    - 经典版AUTOSAR EcuM/BswM启动
  • boot-autosar-adaptive-startup
    - 自适应版执行管理器启动
  • boot-bootloader-reprogramming
    - UDS闪存下载序列
  • boot-secure-boot-chain
    - 带有HSM验证的安全启动

18. NVM Management (HIGH)

18. NVM管理(高)

  • nvm-autosar-block-config
    - AUTOSAR NvM blocks, CRC, redundancy
  • nvm-fee-ea-abstraction
    - Fee/Ea Flash EEPROM Emulation
  • nvm-baremetal-flash
    - Bare-metal Flash/EEPROM patterns
  • nvm-wear-leveling
    - Wear leveling strategies for automotive lifetime
  • nvm-autosar-block-config
    - AUTOSAR NvM块、CRC、冗余
  • nvm-fee-ea-abstraction
    - Fee/Ea Flash EEPROM仿真
  • nvm-baremetal-flash
    - 裸机Flash/EEPROM模式
  • nvm-wear-leveling
    - 满足汽车生命周期要求的损耗均衡策略

19. Power Management (MEDIUM)

19. 电源管理(中)

  • power-ecum-sleep-wakeup
    - EcuM sleep/wakeup state machine
  • power-partial-networking
    - Partial networking, selective transceiver wakeup
  • power-bswm-shutdown
    - BswM ordered shutdown action lists
  • power-clock-peripheral
    - Clock gating and peripheral power-down
  • power-low-power-modes
    - MCU low-power modes (SLEEP, STANDBY, STOP)
  • power-ecum-sleep-wakeup
    - EcuM睡眠/唤醒状态机
  • power-partial-networking
    - 部分网络、选择性收发器唤醒
  • power-bswm-shutdown
    - BswM有序关闭动作列表
  • power-clock-peripheral
    - 时钟门控与外设断电
  • power-low-power-modes
    - MCU低功耗模式(SLEEP、STANDBY、STOP)

20. Automotive Ethernet Deep-Dive (HIGH)

20. 汽车以太网深度解析(高)

  • eth-tsn-time-sync
    - TSN time synchronization (IEEE 802.1AS / gPTP)
  • eth-tsn-traffic-shaping
    - TSN traffic shaping (IEEE 802.1Qbv)
  • eth-tsn-stream-filtering
    - TSN stream filtering (IEEE 802.1Qci)
  • eth-switch-configuration
    - Automotive Ethernet switch configuration
  • eth-avb-streaming
    - AVB Audio/Video streaming
  • eth-tsn-time-sync
    - TSN时间同步(IEEE 802.1AS / gPTP)
  • eth-tsn-traffic-shaping
    - TSN流量整形(IEEE 802.1Qbv)
  • eth-tsn-stream-filtering
    - TSN流过滤(IEEE 802.1Qci)
  • eth-switch-configuration
    - 汽车以太网交换机配置
  • eth-avb-streaming
    - AVB音频/视频流

21. Compiler & Static Analysis (HIGH)

21. 编译器与静态分析(高)

  • build-gcc-warnings
    - GCC warning flags for automotive
  • build-clang-analysis
    - Clang-Tidy and Clang Static Analyzer
  • build-greenhills-safety
    - GreenHills safety-qualified compiler
  • analysis-pclint-config
    - PC-lint MISRA configuration
  • analysis-polyspace
    - Polyspace Bug Finder / Code Prover
  • analysis-coverity
    - Coverity embedded checkers
  • analysis-cppcheck
    - cppcheck with MISRA addon
  • analysis-parasoft
    - Parasoft C/C++test
  • analysis-ldra
    - LDRA traceability and coverage
  • build-gcc-warnings
    - 适用于汽车领域的GCC警告标志
  • build-clang-analysis
    - Clang-Tidy与Clang静态分析器
  • build-greenhills-safety
    - GreenHills安全认证编译器
  • analysis-pclint-config
    - PC-lint MISRA配置
  • analysis-polyspace
    - Polyspace Bug Finder / Code Prover
  • analysis-coverity
    - Coverity嵌入式检查器
  • analysis-cppcheck
    - 带有MISRA插件的cppcheck
  • analysis-parasoft
    - Parasoft C/C++test
  • analysis-ldra
    - LDRA可追溯性与覆盖率

22. vTESTstudio CAPL (MEDIUM-HIGH)

22. vTESTstudio CAPL(中高)

  • capl-vtest-test-unit
    - Test unit/group/fixture structure
  • capl-vtest-data-driven
    - Data-driven testing with parameters
  • capl-vtest-xml-module
    - XML test module integration
  • capl-vtest-verdict-reporting
    - Verdict and reporting patterns
  • capl-vtest-stimulus-response
    - Stimulus/response timing validation
  • capl-vtest-test-unit
    - 测试单元/组/夹具结构
  • capl-vtest-data-driven
    - 带参数的数据驱动测试
  • capl-vtest-xml-module
    - XML测试模块集成
  • capl-vtest-verdict-reporting
    - verdict与报告模式
  • capl-vtest-stimulus-response
    - 刺激/响应时序验证

23. Tool Integration (MEDIUM)

23. 工具集成(中)

  • integration-a2l-calibration
    - Generate and maintain A2L/ASAP2 calibration descriptions
  • integration-odx-diagnostic
    - Structure ODX/PDX diagnostic descriptions correctly
  • integration-fibex-network
    - Maintain FIBEX network description files
  • integration-dbc-arxml-sync
    - Keep DBC/ARXML and code signal definitions synchronized
  • integration-xcp-calibration
    - Implement XCP (Universal Measurement and Calibration Protocol)
  • integration-autosar-arxml
    - Generate and parse AUTOSAR ARXML configuration correctly
  • integration-a2l-calibration
    - 生成与维护A2L/ASAP2校准描述
  • integration-odx-diagnostic
    - 正确结构化ODX/PDX诊断描述
  • integration-fibex-network
    - 维护FIBEX网络描述文件
  • integration-dbc-arxml-sync
    - 保持DBC/ARXML与代码信号定义同步
  • integration-xcp-calibration
    - 实现XCP(通用测量与校准协议)
  • integration-autosar-arxml
    - 正确生成与解析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.md
Each 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