Skip to content
Skills Library
Programming · Building & coding

meddev-hardware-abstraction

/meddev-hardware-abstraction

Provide patterns for HAL design that enable testability, portability, and safety: clear interfaces, separation from application logic, and mockability. Use when working on hardware abstraction in medical device software.

Licence
MIT
Last repository change
19.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 19.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Provide patterns for HAL design that enable testability, portability, and safety: clear interfaces, separation from application logic, and mockability. Use when working on hardware abstraction in medical device software.

Original author description

Provide patterns for HAL design that enable testability, portability, and safety: clear interfaces, separation from application logic, and mockability. Use when working on hardware abstraction in medical device software.

How it works

  1. Purpose
  2. When to Apply
  3. Requirements (testable)
  4. Recommended Practices
  5. Patterns
  6. Anti-Patterns (risks)
  7. Verification Checklist
  8. Traceability
  9. References
  10. Changelog
Original SKILL.md headings · 86 lines, 492 words
SKILL.md preview
---
name: meddev-hardware-abstraction
description: 'Provide patterns for HAL design that enable testability, portability, and safety: clear interfaces, separation from application logic, and mockability. Use when working on hardware abstraction in medical device software.'
license: MIT
metadata:
  skill_id: FW-HAL
  version: 1.0.0
  last_updated: '2026-01-04'
  applies_to: Class A, Class B, Class C
  jurisdiction: Global
  prerequisites: FW-EMBEDDED-C
  category: firmware
---

# 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)
1. Interface Clarity: Define HAL interfaces with explicit types, ranges, and error codes; no hidden globals. Rationale: predictable use.
2. Separation: Keep application logic free of direct register access; encapsulate hardware access in HAL modules. Rationale: portability and testability.
3. Initialization Contracts: Provide explicit init/deinit; fail clearly on config errors; avoid partial init without reporting. Rationale: safe startup.
4. Error Handling: HAL APIs return status; callers must handle; no silent failures. Rationale: reliability.
5. Mock Support: Provide mock/fake implementations for unit tests; avoid static coupling that prevents substitution. Rationale: testability.
6. 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):
```c
// 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):
```c
// 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:
```c
// 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

Versions

The database has no other skills named meddev-hardware-abstraction.

Database snapshot: 13.11.2026 · package version 6fdc23ad8884 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100meddev-hardware-in-loop
    Validate software with real or representative hardware, sensors, actuators, and timing, to uncover integration and safety issues not visible in simulation. Use when working on hardware in loop in medical device software.
  • 100meddev-fault-tolerance
    Provide patterns for detecting, containing, and recovering from faults in medical device software, scaled to safety class. Use when working on fault tolerance in medical device software.
  • 100embedded-stm32
    Best practices for embedded C/C++ development on STM32 microcontrollers using the HAL, covering peripherals, DMA, interrupts, memory constraints, and hardware-focused testing. Use when writing STM32 HAL code, configuring peripherals generated by STM32CubeMX, working with…
  • 100rust-embedded
    Design, implement, review, and validate embedded Rust firmware, including no_std, targets, runtime and startup, embedded-hal drivers, interrupts, DMA, shared state, async executors, hardware mocks, cross-compilation, flashing, and hardware acceptance evidence. Use when users ask…
  • 100embedded-firmware-from-hardware
    Build and review maintainable embedded MCU firmware from schematic, PCB, netlist, pin-map, BOM, Keil/C51/MDK projects, vendor demo code, or hardware debug evidence. Use when Codex must convert hardware design knowledge into firmware architecture, BSP/HAL code, pin configuration,…
  • 100raspberry-pi-rust-embedded
    Production-grade embedded Rust guidelines for Raspberry Pi (bare-metal no_std and Linux embedded std/rppal/embedded-hal). Use when developing low-latency hardware control apps, embedded Rust drivers, Linux GPIO/SPI/I2C/UART software, real-time interrupt handlers, and memory-safe…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.