/safety-critical:safety-critical-patternsfrom safety-critical
Provides MISRA-compliant C patterns: fixed-width types, single-exit functions, suppression comments, March-C RAM test, and CRC protection for safety-critical firmware.
Ships in safety-critical. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
MISRA C compliance and safety-critical firmware patterns.
MISRA mandates explicit types. Use <stdint.h> types throughout.
/* Non-compliant (implicit types): */
int i;
unsigned char flags;
/* MISRA compliant: */
#include <stdint.h>
#include <stdbool.h>
int32_t i;
uint8_t flags;
bool enable;
/* Rule 7.1: Octal constants */
/* VIOLATION: */
uint8_t val = 010; /* Octal 8, not decimal 10 */
/* COMPLIANT: */
uint8_t val = 0x08U;
/* Rule 7.2: Unsigned constants must have U suffix */
/* VIOLATION: */
uint32_t x = 100;
/* COMPLIANT: */
uint32_t x = 100U;
MISRA 15.5: a function shall have a single point of exit.
/* NON-COMPLIANT: multiple returns */
int32_t process(uint8_t *buf, uint32_t len)
{
if (buf == NULL) { return -1; }
if (len == 0U) { return -2; }
/* process */
return 0;
}
/* COMPLIANT: single exit */
int32_t process(uint8_t *buf, uint32_t len)
{
int32_t result = 0;
if (buf == NULL) {
result = -1;
} else if (len == 0U) {
result = -2;
} else {
/* process */
result = 0;
}
return result;
}
This is advisory in MISRA 2012 (was required in MISRA 2004), but required for DO-178C DAL-A.
When a violation is justified, document it with a suppression comment and deviation record.
/* MISRA C:2012 Rule 11.5 Deviation:
Reason: CMSIS HAL requires void* for peripheral handle cast.
Risk: Low — type verified by HAL layer.
Reviewed by: J.Smith, 2024-03-15, ref: DEV-2024-011 */
/*lint -e9087 */ /* PC-lint suppression */
void *handle = (void *)&hspi1; /* PRQA S 0306 */ /* Polyspace suppression */
/*lint +e9087 */
Deviation records must be maintained in a deviation log linked to each suppression.
March-C tests SRAM integrity at startup (required for IEC 61508 SIL 2+).
/* March-C+ algorithm: detects stuck-at faults, coupling faults */
bool ram_march_c_test(uint32_t *start, uint32_t *end)
{
volatile uint32_t *p;
/* Phase 1: write 0 ascending */
for (p = start; p < end; p++) { *p = 0U; }
/* Phase 2: read 0, write 1 ascending */
for (p = start; p < end; p++) {
if (*p != 0U) { return false; }
*p = 0xFFFFFFFFU;
}
/* Phase 3: read 1, write 0 ascending */
for (p = start; p < end; p++) {
if (*p != 0xFFFFFFFFU) { return false; }
*p = 0U;
}
/* Phase 4: read 0, write 1 descending */
p = end;
do {
p--;
if (*p != 0U) { return false; }
*p = 0xFFFFFFFFU;
} while (p > start);
/* Phase 5: read 1, write 0 descending */
p = end;
do {
p--;
if (*p != 0xFFFFFFFFU) { return false; }
*p = 0U;
} while (p > start);
/* Phase 6: read 0 */
for (p = start; p < end; p++) {
if (*p != 0U) { return false; }
}
return true;
}
Call from startup before .bss zero-fill (test RAM before relying on it).
For data stored in NVM or transmitted over interfaces, verify integrity:
/* CRC-8 of a configuration structure */
uint8_t crc8_compute(const uint8_t *data, uint32_t len)
{
uint8_t crc = 0xFFU;
while (len--) {
crc ^= *data++;
for (uint8_t i = 0U; i < 8U; i++) {
crc = (crc & 0x80U) ? ((crc << 1U) ^ 0x07U) : (crc << 1U);
}
}
return crc;
}
typedef struct __attribute__((packed)) {
uint16_t setpoint_tenths;
uint8_t mode;
uint8_t flags;
uint8_t crc; /* CRC-8 of previous 4 bytes */
} config_t;
bool config_is_valid(const config_t *cfg)
{
return cfg->crc == crc8_compute((const uint8_t *)cfg,
sizeof(config_t) - 1U);
}
goto without justification: MISRA 15.2 permits goto only for forward jumps within same function. Never use for error path unwinding when single-exit applies.assert in production code that compiles to nothing with NDEBUG: safety-critical code must use static_assert or a runtime assertion that does not disappear.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
misra-c, functional-safety, firmware, embedded-c, iec-61508, do-178c
npx claudepluginhub ormus-solutions/libreembed-claude-code --plugin safety-criticalOther plugins' skills for the same job