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 ()
Disables the safety API fault detection task.
void enableSafetyApi ()
Enables the safety 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 encountering 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 initShield ()
Initializes thresholds min/max with the default value from the device tree.
void initShield (sensor_t * sensors_watch, uint8_t sensors_watch_number)
Initializes thresholds min/max with the default value from the device tree.
int8_t retrieveThreshold (sensor_t sensor_threshold_retrieve)
Retrieves the current minimum and maximum threshold stored in the flash (non volatile memory)
void setChannelReaction (safety_reaction_t sensors_reaction)
Set the reaction to do if an error has been detected.
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

Disables the safety API fault detection task.

void SafetyAPI::disableSafetyApi () 


function enableSafetyApi

Enables the safety API fault detection task.

void SafetyAPI::enableSafetyApi () 


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 within the possible names:

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 encountering 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 within the possible names:

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 within the possible names:

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 within the possible names:

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 initShield [1/2]

Initializes thresholds min/max with the default value from the device tree.

void SafetyAPI::initShield () 

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.


function initShield [2/2]

Initializes thresholds min/max with the default value from the device tree.

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

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.

Parameters:

  • sensors_watch A list of the sensors to watch. The variables names can be:

V1_LOW,V2_LOW, V_HIGH, I1_LOW,I2_LOW,I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM

Parameters:

  • sensors_watch_number The number of sensors present in the list sensors_watch.

function retrieveThreshold

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

int8_t SafetyAPI::retrieveThreshold (
    sensor_t sensor_threshold_retrieve
) 

Parameters:

  • sensor_threshold_retrieve the sensor to retrieve the threshold stored in the NVS within the possible names:

V1_LOW,V2_LOW, V_HIGH, I1_LOW,I2_LOW,I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM

Returns:

0 if parameters were correctly retrieved, 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.

void SafetyAPI::setChannelReaction (
    safety_reaction_t sensors_reaction
) 

Parameters:

  • sensors_reaction the reaction to do:

  • Open_Circuit: both switches are opened and no power flows to the output

  • Short_Circuit: high-side switch is opened, and low-side is closed maintaining the output in short-circuit. Useful in motor control.

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 watch. The variables names can be:

V1_LOW,V2_LOW, V_HIGH, I1_LOW,I2_LOW,I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM

Parameters:

  • 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 successful, 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 watch. The variables names can be:

V1_LOW,V2_LOW, V_HIGH, I1_LOW,I2_LOW,I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM

Parameters:

  • 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 successful, 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 names can be:

V1_LOW,V2_LOW, V_HIGH, I1_LOW,I2_LOW,I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM

Parameters:

  • sensors_watch_number The number of sensors present in the list sensors_watch.

Returns:

0 if successful, 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 to store the threshold in the NVS within the possible names:

V1_LOW,V2_LOW, V_HIGH, I1_LOW,I2_LOW,I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM

Parameters:

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

Returns:

0 if parameters were correctly 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 watch. The variables names can be:

V1_LOW,V2_LOW, V_HIGH, I1_LOW,I2_LOW,I_HIGH, TEMP_SENSOR, EXTRA_MEAS, ANALOG_COMM

Parameters:

  • sensors_watch_number The number of sensors present in the list sensors_watch.

Returns:

0 if successful, 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