Skip to content

Safety API is designed to provide safety features when working with the Spin board.

To work with Spin API, include the following file in your code:

Note

#include <SafetyAPI.h>

API Reference

Class SafetyAPI

ClassList > SafetyAPI

Public Functions

Type Name
void disableSafetyApi ()
disable the safet API fault detection task
void enableSafetyApi ()
enable the safet API fault detection task
bool getChannelError (sensor_t sensors_error)
check if the sensor faced an error (went over/under threshold)
safety_reaction_t getChannelReaction ()
returns the reaction to do when encoutering an error.
float32_t getChannelThresholdMax (sensor_t sensors_threshold)
get the maximum threshold of the selected sensor
float32_t getChannelThresholdMin (sensor_t sensors_threshold)
get the minimum threshold of the selected sensor
bool getChannelWatch (sensor_t sensors_watch)
check if a sensor is being monitored or not.
void init_shield ()
Initializes thresholds min/max with the default value from the device tree, if values were stored and found in the flash they will be used instead. All the sensors will be monitored to detect potential faults in voltage/current.
void init_shield (sensor_t * sensors_watch, uint8_t sensors_watch_number)
Initializes thresholds min/max with the default value from the device tree, if values were stored and found in the flash they will be used instead. All the sensors will be monitored to detect potential faults in voltage/current.
int8_t retrieveThreshold (sensor_t sensor_threshold_retrieve)
store the current minimum and maximum threshold in the flash (non volatile memory)
void setChannelReaction (safety_reaction_t sensors_reaction)
Set the reaction to do if an error has been detected. Choose either open-circuit (both switches are opened and no power flows in the output) or short-circuit (high-side switch is opened, and low-side is closed maintaining the output in short-circuit)
int8_t setChannelThresholdMax (sensor_t * sensors_threshold, float32_t * threshold_max, uint8_t sensors_threshold_number)
set the maximum threshold for the sensors present in the list safety_sensors.
int8_t setChannelThresholdMin (sensor_t * sensors_threshold, float32_t * threshold_min, uint8_t sensors_threshold_number)
set the minimum threshold for the sensors present in the list safety_sensors.
int8_t setChannelWatch (sensor_t * sensors_watch, uint8_t sensors_watch_number)
Enables the monitoring of the selected sensors for safety.
int8_t storeThreshold (sensor_t sensor_threshold_store)
store the current minimum and maximum threshold in the flash (non volatile memory)
int8_t unsetChannelWatch (sensor_t * sensors_watch, uint8_t sensors_watch_number)
Disables the monitoring of the selected sensors for safety.

Public Functions Documentation

function disableSafetyApi

disable the safet API fault detection task

void SafetyAPI::disableSafetyApi () 

Returns:

none


function enableSafetyApi

enable the safet API fault detection task

void SafetyAPI::enableSafetyApi () 

Returns:

none


function getChannelError

check if the sensor faced an error (went over/under threshold)

bool SafetyAPI::getChannelError (
    sensor_t sensors_error
) 

Parameters:

  • sensors_error the sensor to check
  • V1_LOW
  • V2_LOW
  • V_HIGH
  • I1_LOW
  • I2_LOW
  • I_HIGH
  • TEMP_SENSOR
  • EXTRA_MEAS
  • ANALOG_COMM

Returns:

true if the sensor faced an error, false if not


function getChannelReaction

returns the reaction to do when encoutering an error.

safety_reaction_t SafetyAPI::getChannelReaction () 

Returns:

Open_Circuit or Short_Circuit


function getChannelThresholdMax

get the maximum threshold of the selected sensor

float32_t SafetyAPI::getChannelThresholdMax (
    sensor_t sensors_threshold
) 

Parameters:

  • sensors_threshold the sensor to check
  • V1_LOW
  • V2_LOW
  • V_HIGH
  • I1_LOW
  • I2_LOW
  • I_HIGH
  • TEMP_SENSOR
  • EXTRA_MEAS
  • ANALOG_COMM

Returns:

the maximum threshold


function getChannelThresholdMin

get the minimum threshold of the selected sensor

float32_t SafetyAPI::getChannelThresholdMin (
    sensor_t sensors_threshold
) 

Parameters:

  • sensors_threshold the sensor to check
  • V1_LOW
  • V2_LOW
  • V_HIGH
  • I1_LOW
  • I2_LOW
  • I_HIGH
  • TEMP_SENSOR
  • EXTRA_MEAS
  • ANALOG_COMM

Returns:

the minimum threshold


function getChannelWatch

check if a sensor is being monitored or not.

bool SafetyAPI::getChannelWatch (
    sensor_t sensors_watch
) 

Parameters:

  • sensors_watch the sensor to check
  • V1_LOW
  • V2_LOW
  • V_HIGH
  • I1_LOW
  • I2_LOW
  • I_HIGH
  • TEMP_SENSOR
  • EXTRA_MEAS
  • ANALOG_COMM

Returns:

true if the sensor is being monitored, false if not


function init_shield [1/2]

Initializes thresholds min/max with the default value from the device tree, if values were stored and found in the flash they will be used instead. All the sensors will be monitored to detect potential faults in voltage/current.

void SafetyAPI::init_shield () 

Returns:

none


function init_shield [2/2]

Initializes thresholds min/max with the default value from the device tree, if values were stored and found in the flash they will be used instead. All the sensors will be monitored to detect potential faults in voltage/current.

void SafetyAPI::init_shield (
    sensor_t * sensors_watch,
    uint8_t sensors_watch_number
) 

Parameters:

  • sensors_watch A list of the sensors to watch. The variables in the list can be : V1_LOW, V2_LOW, V_HIGH, I1_LOW, I2_LOW, I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM
  • sensors_watch_number The number of sensors present in the list sensors_watch.

Returns:

none


function retrieveThreshold

store the current minimum and maximum threshold in the flash (non volatile memory)

int8_t SafetyAPI::retrieveThreshold (
    sensor_t sensor_threshold_retrieve
) 

Parameters:

  • sensor_threshold_retrieve the sensor for which we store the threshold in the NVS

Returns:

0 if parameters were correcly retreived, negative value if there was an error: -1: NVS is empty -2: NVS contains data, but their version doesn't match current version -3: NVS data is corrupted -4: NVS contains data, but not for the requested sensor


function setChannelReaction

Set the reaction to do if an error has been detected. Choose either open-circuit (both switches are opened and no power flows in the output) or short-circuit (high-side switch is opened, and low-side is closed maintaining the output in short-circuit)

void SafetyAPI::setChannelReaction (
    safety_reaction_t sensors_reaction
) 

Parameters:

  • sensors_reaction the reaction to do
  • Open_Circuit
  • Short_Circuit

Returns:

none


function setChannelThresholdMax

set the maximum threshold for the sensors present in the list safety_sensors.

int8_t SafetyAPI::setChannelThresholdMax (
    sensor_t * sensors_threshold,
    float32_t * threshold_max,
    uint8_t sensors_threshold_number
) 

Parameters:

  • sensors_threshold A list of the sensors to set the threshold. The variables in the list can be : V1_LOW, V2_LOW, V_HIGH, I1_LOW, I2_LOW, I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM
  • threshold_max A list of the maximum threshold to apply to the sensors in safety_sensors.
  • sensors_threshold_number the number of sensors present in the list sensor_threshold

Returns:

0 if sucessfull, or -1 if not.


function setChannelThresholdMin

set the minimum threshold for the sensors present in the list safety_sensors.

int8_t SafetyAPI::setChannelThresholdMin (
    sensor_t * sensors_threshold,
    float32_t * threshold_min,
    uint8_t sensors_threshold_number
) 

Parameters:

  • sensors_threshold A list of the sensors to set the threshold. The variables in the list can be : V1_LOW, V2_LOW, V_HIGH, I1_LOW, I2_LOW, I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM
  • threshold_min A list of the minimum threshold to apply to the sensors in safety_sensors.
  • sensors_threshold_number the number of sensors present in the list sensor_threshold

Returns:

0 if sucessfull, or -1 if not.


function setChannelWatch

Enables the monitoring of the selected sensors for safety.

int8_t SafetyAPI::setChannelWatch (
    sensor_t * sensors_watch,
    uint8_t sensors_watch_number
) 

Parameters:

  • sensors_watch A list of the sensors to watch. The variables in the list can be : V1_LOW, V2_LOW, V_HIGH, I1_LOW, I2_LOW, I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM
  • sensors_watch_number The number of sensors present in the list sensors_watch.

Returns:

0 if sucessfull, or -1 if there was an error


function storeThreshold

store the current minimum and maximum threshold in the flash (non volatile memory)

int8_t SafetyAPI::storeThreshold (
    sensor_t sensor_threshold_store
) 

Parameters:

  • sensor_threshold_store the sensor for which we store the threshold in the NVS

Returns:

0 if parameters were correcly stored, -1 if there was an error.


function unsetChannelWatch

Disables the monitoring of the selected sensors for safety.

int8_t SafetyAPI::unsetChannelWatch (
    sensor_t * sensors_watch,
    uint8_t sensors_watch_number
) 

Parameters:

  • sensors_watch A list of the sensors to unwatch. The variables in the list can be : V1_LOW, V2_LOW, V_HIGH, I1_LOW, I2_LOW, I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM
  • sensors_watch_number The number of sensors present in the list sensors_watch.

Returns:

0 if sucessfull, or -1 if there was an error



The documentation for this class was generated from the following file docs/core/zephyr/modules/owntech_safety_api/zephyr/public_api/SafetyAPI.h