Skip to content

Module Design

This document describes in detail how each of the software modules works.

The following software module types are present in this collection of libraries:

  • Sensor Modules
  • Flash/Memory Modules
  • Communication wrappers

Sensor Modules

Sensor modules are the most commonly used type of software module in the Manikin CPR system. Each module follows a consistent structure and exposes a standardized public API.

API design

The diagram below illustrates the common structure and API of a sensor module:

Every sensor module implements the following functions:

Sensor module public api

[!NOTE]
This api design is based on the requirement that setting up and reading an sensor should not be a hassle. But the simplicity means that there was a concession on configurability. At this time within the Manikin project, there is no need for the additional sensor configurability. If requirements change (which will surely happen), it is possible to add an enum param to the sensor_ctx struct e.g. with specific configuration options for each sensor.

[!NOTE] It’s also important to note that these modules only provide raw sensor data without performing any processing. This design choice was driven by the need for functional decomposition and the goal of keeping the library as generic as possible. Since requirements frequently change, embedding logic directly into the sensor modules would make them harder to maintain, as any update would require changes to the entire module, something we aim to avoid.

init_sensor

Description Diagram
β€’ Validates input parameters.
β€’ If parameters are null or out of range.
   β€“ Returns MANIKIN_STATUS_ERR_NULL_PARAM.
β€’ If valid, checks for sensor presence.
β€’ If the sensor is present:
   β€“ Initializes with default settings (continuous mode).
   β€“ Returns MANIKIN_STATUS_OK.
β€’ If sensor is not present or init fails:
   β€“ Returns MANIKIN_STATUS_ERR_SENSOR_INIT_FAIL.
Sensor module init

read_sensor

Description Diagram
β€’ Validates input parameters.
β€’ If parameters are null or out of range.
   β€“ Returns MANIKIN_STATUS_ERR_NULL_PARAM.
β€’ If valid, checks I2C and sensor status register for faults.
β€’ If a fault is detected:
   β€“ Returns MANIKIN_STATUS_ERR_READ_FAIL.
β€’ If no faults are present:
   β€“ Reads result register.
   β€“ Writes data to passed-in byte array.
   β€“ Returns MANIKIN_STATUS_OK.
Sensor module init

[!NOTE]
The format and minimum required length of read_buf depend on the specific sensor. Refer to the sensor’s header file for detailed information.

deinit_sensor

Description Diagram
β€’ Validates input parameters.
β€’ If parameters are null or out of range.
   β€“ Returns MANIKIN_STATUS_ERR_NULL_PARAM.
β€’ If valid, checks for sensor presence.
β€’ If the sensor is present:
   β€“ Deinitializes sensor to idle/sleep mode.
   β€“ Returns MANIKIN_STATUS_OK.
β€’ If sensor is not present:
   β€“ Returns MANIKIN_STATUS_ERR_SENSOR_DEINIT_FAIL.
Sensor module deinit

πŸ“„ Flash/Memory Module

This module provides a driver interface for memory chips. The driver exposes a consistent API for initialization, status checking, reading, writing, sector erasing, and deinitialization.

API Design

Memory module public API

<memory_chip>_init()

Description Diagram
β€’ Validates input parameters.
β€’ If parameters are null or out of range.
   β€“ Returns MEMORY_CHIP_STATUS_ERR_NULL_PARAM.
β€’ If valid, read JEDEC ID.
β€’ If the chip present & JEDEC ID is valid:
   β€“ Resets device to known state.
   β€“ Returns MEMORY_CHIP_STATUS_OK.
β€’ If JEDEC ID is invalid or chip not present:
   β€“ Returns MEMORY_CHIP_STATUS_ERR_READ_FAIL.
Memory chip init

<memory_chip>_status()

Description Diagram
β€’ Validates input parameters.
β€’ If parameters are null or out of range.
   β€“ Returns MEMORY_CHIP_STATUS_ERR_NULL_PARAM.
β€’ If valid, checks for chip presence using JEDEC ID (no reset).
β€’ If chip is detected and JEDEC ID is valid:
   β€“ Returns MANIKIN_STATUS_OK.
β€’ If chip is not present or ID is invalid:
   β€“ Returns MANIKIN_STATUS_ERR_READ_FAIL.
Memory module status

<memory_chip>_write()

Description Diagram
β€’ Validates input parameters (data, addr, len).
β€’ If any parameter is invalid (e.g., null or zero length):
   β€“ Returns MANIKIN_MEMORY_RESULT_PARERR.
β€’ If parameters are valid, checks if chip is responsive.
β€’ If chip is not responding:
   β€“ Returns MANIKIN_MEMORY_RESULT_NOTRDY.
β€’ If chip is responsive, checks for write protection.
β€’ If write protection is enabled:
   β€“ Returns MANIKIN_MEMORY_RESULT_WRPRT.
β€’ If write protection is not enabled:
   β€“ Writes data to the specified address.
   β€“ Returns MANIKIN_MEMORY_RESULT_OK.
Memory chip write

<memory_chip>_read()

Description Diagram
β€’ Validates input parameters (data, addr, len).
β€’ If any parameter is invalid (e.g., null or zero length):
   β€“ Returns MANIKIN_MEMORY_RESULT_PARERR.
β€’ If parameters are valid, checks if chip is responsive.
β€’ If chip is not responding:
   β€“ Returns MANIKIN_MEMORY_RESULT_NOTRDY.
β€’ If chip is responsive, checks for write protection.
β€’ If write protection is enabled:
   β€“ Returns MANIKIN_MEMORY_RESULT_WRPRT.
β€’ If write protection is not enabled:
   β€“ Reads data from the specified address.
   β€“ Returns MANIKIN_MEMORY_RESULT_OK.
Memory chip read

<memory_chip>_erase_sector()

Description Diagram
β€’ Validates the sector_number parameter.
β€’ If parameter is invalid or out of range:
   β€“ Returns MANIKIN_MEMORY_RESULT_PARERR.
β€’ If parameter is valid, checks if chip is responsive.
β€’ If chip is not responding:
   β€“ Returns MANIKIN_MEMORY_RESULT_NOTRDY.
β€’ If chip is responsive, checks for write protection.
β€’ If write protection is enabled:
   β€“ Returns MANIKIN_MEMORY_RESULT_WRPRT.
β€’ If write protection is not enabled:
   β€“ Erases the specified 4KB sector.
   β€“ Returns MANIKIN_MEMORY_RESULT_OK.
Memory chip erase

<memory_chip>_deinit()

Description Diagram
β€’ Validates input parameters.
β€’ If parameters are null or out of range:
   β€“ Returns MANIKIN_CHIP_STATUS_ERR_NULL_PARAM.
β€’ If parameters are valid, checks for chip presence.
β€’ If the chip is present:
   β€“ Resets device and clears internal state.
   β€“ Returns MANIKIN_STATUS_OK.
β€’ If chip is not present:
   β€“ Returns MANIKIN_STATUS_ERR_WRITE_FAIL.
Memory chip deinit

πŸ“„ I2C Peripheral Module

This module provides a platform-agnostic driver interface for I2C communication. It wraps low-level hardware access in a consistent API used throughout the Manikin CPR system.


Public API

I2C module public API

Function Descriptions

manikin_i2c_init()

Description Diagram
β€’ Validates I2C instance and baud-rate parameters.
β€’ If parameters are invalid:
   β€“ Returns MANIKIN_STATUS_ERR_NULL_PARAM or MANIKIN_STATUS_ERR_INVALID_I2C_BAUD.
β€’ If valid:
   β€“ Initializes I2C with 7-bit addressing and 1 stop-bit.
   β€“ Returns MANIKIN_STATUS_OK.
I2C module init

manikin_i2c_check_device_address()

Description Diagram
β€’ Checks the presence of an I2C device at a given address.
β€’ Sends an I2C ping.
   β€“ Returns 1 if device responds.
   β€“ Returns 0 if no device is found.
I2C module check_device_address

manikin_i2c_write_reg() / write_reg16()

Description Diagram
β€’ Validates parameters.
β€’ If invalid:
   β€“ Returns MANIKIN_STATUS_ERR_NULL_PARAM.
β€’ Writes 8-bit or 16-bit data to I2C register.
   β€“ Returns MANIKIN_STATUS_OK on success.
I2C module write reg

manikin_i2c_read_reg() / read_reg16()

Description Diagram
β€’ Validates parameters.
β€’ If invalid:
   β€“ Returns MANIKIN_STATUS_ERR_NULL_PARAM.
β€’ Reads 8-bit or 16-bit data from I2C register.
   β€“ Stores data to provided pointer.
   β€“ Returns MANIKIN_STATUS_OK.
I2C module read reg

manikin_i2c_read_bytes()

Description Diagram
β€’ Reads multiple bytes from an I2C device.
β€’ Saves data to provided buffer.
   β€“ Returns number of bytes successfully read.
I2C module read bytes

manikin_i2c_write_bytes()

Description Diagram
β€’ Writes multiple bytes from a buffer to I2C device.
   β€“ Returns number of bytes successfully written.
I2C module write bytes

manikin_i2c_deinit()

Description Diagram
β€’ Validates I2C instance pointer.
β€’ If invalid:
   β€“ Returns MANIKIN_STATUS_ERR_NULL_PARAM.
β€’ If valid:
   β€“ Deinitializes I2C peripheral.
   β€“ Returns MANIKIN_STATUS_OK.
I2C module deinit

Design Rationale

This driver avoids unnecessary abstraction and complexity to preserve deterministic timing, hardware safety, and MISRA compliance.

As with other modules in the Manikin Software Library: - No dynamic allocation - No function pointers or runtime interfaces - No object-oriented abstractions

The design keeps the code minimal, traceable, and suitable for high-reliability systems.