reflow-oven-control-sw/stm-firmware/include/reflow-controller/safety/safety-controller.h

114 lines
3.5 KiB
C
Raw Normal View History

/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @addtogroup safety-controller
* @{
*/
#ifndef __SAFETY_CONTROLLER_H__
#define __SAFETY_CONTROLLER_H__
#include <reflow-controller/safety/safety-config.h>
#include <stdbool.h>
2020-07-27 21:29:15 +02:00
#include <stdint.h>
#include <stddef.h>
2020-07-09 22:31:42 +02:00
enum analog_monitor_status {ANALOG_MONITOR_OK = 0,
ANALOG_MONITOR_ERROR,
ANALOG_MONITOR_INACTIVE,
ANALOG_MONITOR_OVER,
ANALOG_MONITOR_UNDER};
struct analog_monitor_info {
float value;
float min;
float max;
enum analog_monitor_status status;
uint64_t timestamp;
};
struct timing_monitor_info {
uint64_t last_run;
uint64_t min;
uint64_t max;
bool enabled;
uint64_t delta;
};
/**
* @brief Initialize the safety controller
*
* After a call to this function the controller is iniotlaized and the watchdog is set up.
* You have to call safety_controller_handle
* If this function fails, it will hang, because errors in the safety controller are not recoverable
*/
void safety_controller_init();
/**
* @brief Handle the safety controller.
* @note This function must be executed periodically in order to prevent the watchdog from resetting the firmware
* @return 0 if successful
*/
int safety_controller_handle();
int safety_controller_report_error(enum safety_flag flag);
int safety_controller_report_error_with_key(enum safety_flag flag, uint32_t key);
void safety_controller_report_timing(enum timing_monitor monitor);
2020-07-09 22:31:42 +02:00
void safety_controller_report_analog_value(enum analog_value_monitor monitor, float value);
int safety_controller_enable_timing_mon(enum timing_monitor monitor, bool enable);
2020-07-09 22:31:42 +02:00
enum analog_monitor_status safety_controller_get_analog_mon_value(enum analog_value_monitor monitor, float *value);
2020-07-26 21:40:09 +02:00
int safety_controller_get_flag(enum safety_flag flag, bool *status, bool try_ack);
int safety_controller_ack_flag(enum safety_flag flag);
2020-07-09 22:31:42 +02:00
2020-07-27 21:29:15 +02:00
int safety_controller_ack_flag_with_key(enum safety_flag flag, uint32_t key);
bool safety_controller_get_flags_by_mask(enum safety_flag mask);
uint32_t safety_controller_get_flag_count();
uint32_t safety_controller_get_analog_monitor_count();
int safety_controller_get_flag_name_by_index(uint32_t index, char *buffer, size_t buffsize);
int safety_controller_get_flag_by_index(uint32_t index, bool *status, enum safety_flag *flag_enum);
int safety_controller_get_analog_mon_by_index(uint32_t index, struct analog_monitor_info *info);
int safety_controller_get_analog_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize);
int safety_controller_get_timing_mon_by_index(uint32_t index, struct timing_monitor_info *info);
int safety_controller_get_timing_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize);
uint32_t safety_controller_get_timing_monitor_count();
#endif /* __SAFETY_CONTROLLER_H__ */
/** @} */