Rail Controller Service

group Rail Controller Service

Driver for controlling power rails and monitoring consumption.

Note

This service should be polled periodically via rail_controller_update to ensure faults (like overcurrent events) are caught quickly.

group Types

Structures and Enums for rail status monitoring.

Enums

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_FAULT

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

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

Array of rail snapshots (length = NUM_POWER_RAILS)

bool initialized

True if controller has been initialized

group Public API

External interface for interacting with the Rail Controller Service.

Functions

void rail_controller_init(rail_controller_t *controller)

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 *controller, 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 *controller, 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

void rail_controller_update(rail_controller_t *controller)

Periodic update task.

Should be called in the main system loop.

This function:

  1. Reads the latest voltage/current data from sensors.

  2. Checks against safety thresholds.

  3. If an overcurrent is detected, it will automatically call

rail_controller_disable for the affected rail and set the status to RAIL_STATUS_OVERCURRENT.

Additionally, this function is used to update the current snapshot for all rails.

Parameters:

controller[in] The rail controller

rail_t rail_controller_get_rail(rail_controller_t *controller, power_rail_t rail)

Retrieve the latest telemetry for a specific rail.

Parameters:
  • rail[in] The rail ID to query.

  • controller[in] The rail controller

Returns:

rail_t A copy of the latest rail status structure.