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

100 lines
3.1 KiB
C

/* 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>
#include <stdint.h>
#include <stddef.h>
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;
};
/**
* @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);
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);
enum analog_monitor_status safety_controller_get_analog_mon_value(enum analog_value_monitor monitor, float *value);
int safety_controller_get_flag(enum safety_flag flag, bool *status, bool try_ack);
int safety_controller_ack_flag(enum safety_flag flag);
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);
#endif /* __SAFETY_CONTROLLER_H__ */
/** @} */