Skip to main content

MISRA-C Compliance

For safety-critical deployments (automotive ECUs, medical devices, avionics), Timber provides a MISRA-C:2012 compliant code emitter.

Generating MISRA-C Code

from timber.codegen.misra_c import MisraCEmitter, check_misra_compliance
from timber.frontends.auto_detect import parse_model

ir = parse_model("model.json")
emitter = MisraCEmitter(ir)
files = emitter.emit()

# Write files
for filename, content in files.items():
with open(filename, "w") as f:
f.write(content)

Compliance Checking

report = check_misra_compliance(files)
print(f"Violations: {report.violations}")
print(f"Warnings: {report.warnings}")
print(f"Compliant: {report.is_compliant}")

# Detailed rule results
for rule in report.rules:
print(f" Rule {rule.id}: {'PASS' if rule.passed else 'FAIL'}{rule.description}")

Rules Checked

RuleDescriptionCategory
1.1No compiler extensionsRequired
10.1Unsigned integer suffix enforcementRequired
14.4Boolean conditionsRequired
15.7Else after if-else-ifRequired
17.7Return value usageRequired
20.7Macro expansionRequired
21.1No redefinition of standard identifiersRequired

Transformations Applied

The MISRA-C emitter wraps the standard C99 emitter and applies:

  1. Unsigned suffix enforcement — all unsigned literals get U suffix
  2. No compiler-specific extensions — pure ISO C
  3. Standard identifier protection — no redefinition of reserved names
  4. Compliance markers — generated headers include MISRA compliance declaration

Use Cases

  • Automotive — ADAS systems, engine control, autonomous driving
  • Medical devices — patient monitoring, diagnostic equipment
  • Avionics — flight control systems, navigation
  • Industrial — PLC controllers, safety-instrumented systems

Integration with Certification

The generated code, combined with the audit trail, provides documentation suitable for:

  • ISO 26262 (automotive)
  • IEC 62304 (medical software)
  • DO-178C (avionics)