Rail Controller Service

group Rail Controller Service

Driver for controlling power rails and monitoring consumption.

Note

The application that consumes this service should subscribe to faults (like overcurrent events) to ensure they are caught quickly.

group Types

Structures and Enums for rail status monitoring.

Defines

RAIL_CONTROLLER_SERVICE_ID
RAIL_CONTROLLER_EVENT_FAULT_DETECTED
RAIL_CONTROLLER_EVENT_OVERCURRENT_DETECTED
RAIL_CONTROLLER_EVENT_UNDERVOLTAGE_DETECTED
RAIL_CONTROLLER_EVENT_OVERVOLTAGE_DETECTED
RAIL_CONTROLLER_EVENT_RAIL_FAULT_DETECTED

Enums

enum rail_controller_id_t

Values:

enumerator RAIL_CONTROLLER_FAULT_DETECTED

Published when a critical fault is detected. Payload: rail_controller_t (Snapshot at time of failure)

enumerator RAIL_CONTROLLER_OVERCURRENT_DETECTED

Published when an overcurrent is detected on a single rail. Payload: rail_t (Snapshot at time of failure)

enumerator RAIL_CONTROLLER_UNDERVOLTAGE_DETECTED

Published when an undervoltage event is detected on a single rail. Payload: rail_t (Snapshot at time of failure)

enumerator RAIL_CONTROLLER_OVERVOLTAGE_DETECTED

Published when an overvoltage event is detected on a single rail. Payload: rail_t (Snapshot at time of failure)

enumerator RAIL_CONTROLLER_RAIL_FAULT_DETECTED

Published when a critical fault is detected on a single rail. Payload: rail_t (Snapshot at time of failure)

enumerator RAIL_CONTROLLER_TELEMETRY

Telemetry snapshot of one rail. Published for each rail Payload: rail_t (Snapshot)

enum rail_status_t

Operational health status of a power rail.

Values:

enumerator RAIL_STATUS_OK

Rail is operating nominally.

enumerator RAIL_STATUS_DISABLED

Rail is intentionally disabled.

enumerator RAIL_STATUS_OVERCURRENT

Rail was shut down due to current limit violation.

enumerator RAIL_STATUS_UNDERVOLTAGE

Rail voltage is below expected threshold

enumerator RAIL_STATUS_OVERVOLTAGE
enumerator RAIL_STATUS_FAULT

<Rail voltage is above expected threshold Generic fault or hardware failure

struct rail_t
#include <rail_controller.h>

Snapshot for a specific power rail.

Returned by rail_controller_get_rail for system monitoring.

Public Members

power_rail_t rail_id

The rail this structure represents

float voltage

Output voltage in volts

float current

Current in amps

rail_status_t status

Current rail status

bool enabled

True if the switch is currently turned on

struct rail_controller_t
#include <rail_controller.h>

Container for all power rail state.

Holds snapshots for all rails and initialization status. Must be initialized with rail_controller_init before use.

Public Members

rail_t rails[NUM_POWER_RAILS]

Array of rail snapshots (length = NUM_POWER_RAILS)

bool initialized

True if controller has been initialized

uint32_t tick_counter

Internal counter for update loop

uint32_t telemetry_tick_counter

Internal counter for telemetry

group Public API

External interface for interacting with the Rail Controller Service.

Functions

void rail_controller_init(rail_controller_t *manager)

Initialize the Rail Controller hardware.

Configures GPIO pins for load switches as outputs (defaulting to OFF) and initializes any I2C/ADC interfaces required for current monitoring.

Note

This function is idempotent.

Parameters:

[controller] – The rail controller

void rail_controller_enable(rail_controller_t *manager, power_rail_t rail)

Turn ON a specific power rail.

Note

This function returns immediately. The rail voltage may take some time to stabilize.

Parameters:
  • rail[in] The unique ID of the rail to enable (defined in eps_config.h).

  • controller[in] The rail controller

void rail_controller_disable(rail_controller_t *manager, power_rail_t rail)

Turn OFF a specific power rail.

Parameters:
  • rail[in] The unique ID of the rail to disable.

  • controller[in] The rail controller