FW-HAL
Provide patterns for HAL design that enable testability, portability, and safety: clear interfaces, separation from application logic, and mockability.
Unsigned, install at your own risk
UnverifiedThis skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.
Install this skill
No account required. Pick your tool, or use the command that detects it for you.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install meddev-skills-fw-halManual setup by platform
Claude Code
~/.claude/skills/meddev-skills-fw-hal/SKILL.md
Instructions
Hardware Abstraction Layer (HAL) Design
Purpose
Provide patterns for HAL design that enable testability, portability, and safety: clear interfaces, separation from application logic, and mockability.
When to Apply
- Designing or refactoring drivers and HAL for peripherals.
- Porting to new MCUs/boards or enabling unit tests with mocks.
Requirements (testable)
- Interface Clarity: Define HAL interfaces with explicit types, ranges, and error codes; no hidden globals. Rationale: predictable use.
- Separation: Keep application logic free of direct register access; encapsulate hardware access in HAL modules. Rationale: portability and testability.
- Initialization Contracts: Provide explicit init/deinit; fail clearly on config errors; avoid partial init without reporting. Rationale: safe startup.
- Error Handling: HAL APIs return status; callers must handle; no silent failures. Rationale: reliability.
- Mock Support: Provide mock/fake implementations for unit tests; avoid static coupling that prevents substitution. Rationale: testability.
- Concurrency/ISR Safety: Document ISR-safe APIs; guard shared resources; avoid blocking in ISR-safe functions. Rationale: correctness under concurrency.
Recommended Practices
- Use narrow, capability-based interfaces (e.g.,
hal_uart_write,hal_uart_read). - Keep register definitions private; expose only needed abstractions.
- Version/config structures to allow forward-compatible changes.
- Provide compile-time selection of real vs mock HAL.
Patterns
HAL interface (header):
// REQ-HAL-IF-01; TEST-HAL-03
typedef enum { HAL_OK = 0, HAL_EINVAL, HAL_EIO, HAL_EBUSY } hal_status_t;
hal_status_t hal_uart_init(uint32_t baud);
hal_status_t hal_uart_write(const uint8_t *buf, size_t len, size_t *written);
hal_status_t hal_uart_read(uint8_t *buf, size_t len, size_t *read, uint32_t timeout_ms);
Mock implementation (test build):
// REQ-HAL-MOCK-02; TEST-HAL-05
static size_t mock_written;
hal_status_t hal_uart_write(const uint8_t *buf, size_t len, size_t *written) {
mock_written = len;
*written = len;
return HAL_OK;
}
Init with validation:
// REQ-HAL-INIT-03; TEST-HAL-07
hal_status_t hal_uart_init(uint32_t baud) {
if (baud < 1200 || baud > 921600) return HAL_EINVAL;
// configure hardware ...
return HAL_OK;
}
Anti-Patterns (risks)
- Application code directly accesses registers -> risk: untestable, tight coupling.
- HAL APIs that silently ignore errors -> risk: hidden failures.
- No mocks -> risk: unit tests blocked or using real hardware unintentionally.
- APIs with implicit globals or side effects -> risk: nondeterminism and test fragility.
Verification Checklist
- HAL interfaces defined with explicit types/ranges/error codes.
- Application code free of direct register access; uses HAL APIs.
- Init/deinit paths validate inputs and report errors.
- Errors propagated and handled by callers.
- Mock/fake HAL available and used in unit tests.
- ISR/concurrency characteristics documented; shared resources protected.
Traceability
- Map
REQ-HAL-###to tests (TEST-HAL-###) including mocks; link to portability requirements.
References
- MISRA C for interface clarity and header hygiene.
- IEC 62304 design segregation and testability expectations.
Changelog
- 1.0.0 (2026-01-04): Initial HAL design guidance with interfaces, mocks, and error handling.
Audit History
- 2026-01-04: Audit performed. Verified:
- HAL patterns follow industry best practices for testability
- Mock implementation examples are accurate
- Error handling patterns are sound
Security
Reviews (0)
Related skills
Browse all →More from Medical Device Skills
View source →More Build skills
Browse category →Frequently asked questions about FW-HAL
What does the FW-HAL skill do?
Provide patterns for HAL design that enable testability, portability, and safety: clear interfaces, separation from application logic, and mockability. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the FW-HAL skill?
Run `npx @skills-hub-ai/cli install meddev-skills-fw-hal` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/meddev-skills-fw-hal/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does FW-HAL work with?
FW-HAL runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the FW-HAL skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use FW-HAL after installing it?
In Claude Code, type `/meddev-skills-fw-hal` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the FW-HAL skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.