Fix ADC measurement to run at 1000 Hz and fix wrong error handling for PT1000 Watchdog. Add function for flags to shell
This commit is contained in:
@@ -59,7 +59,7 @@ float safety_adc_convert_channel(enum safety_adc_meas_channel channel, uint16_t
|
||||
|
||||
switch (channel) {
|
||||
case SAFETY_ADC_MEAS_TEMP:
|
||||
converted_val = (((float)channel / 4095.0f * 2500.0f - SAFETY_ADC_TEMP_NOM_MV) /
|
||||
converted_val = (((float)analog_value / 4095.0f * 2500.0f - SAFETY_ADC_TEMP_NOM_MV) /
|
||||
SAFETY_ADC_TEMP_MV_SLOPE) + SAFETY_ADC_TEMP_NOM;
|
||||
break;
|
||||
case SAFETY_ADC_MEAS_VREF:
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <helper-macros/helper-macros.h>
|
||||
#include <reflow-controller/systick.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
struct error_flag {
|
||||
const char *name;
|
||||
@@ -87,9 +88,9 @@ static volatile struct error_flag flags[] = {
|
||||
};
|
||||
|
||||
static volatile struct timing_mon timings[] = {
|
||||
TIM_MON_ENTRY(ERR_TIMING_PID, 1, 800, ERR_FLAG_TIMING_PID),
|
||||
TIM_MON_ENTRY(ERR_TIMING_MEAS_ADC, 1, 50, ERR_FLAG_TIMING_MEAS_ADC),
|
||||
TIM_MON_ENTRY(ERR_TIMING_SAFETY_ADC, 1, 250, ERR_FLAG_SAFETY_ADC),
|
||||
TIM_MON_ENTRY(ERR_TIMING_PID, 2, 1000, ERR_FLAG_TIMING_PID),
|
||||
TIM_MON_ENTRY(ERR_TIMING_MEAS_ADC, 0, 50, ERR_FLAG_TIMING_MEAS_ADC),
|
||||
TIM_MON_ENTRY(ERR_TIMING_SAFETY_ADC, 10, SAFETY_CONTROLLER_ADC_DELAY_MS + 70, ERR_FLAG_SAFETY_ADC),
|
||||
};
|
||||
|
||||
static volatile struct analog_mon analog_mons[] = {
|
||||
@@ -209,7 +210,7 @@ void safety_controller_report_timing(enum timing_monitor monitor)
|
||||
tim = find_timing_mon(monitor);
|
||||
if (tim) {
|
||||
if (tim->enabled) {
|
||||
if (!systick_ticks_have_passed(tim->last, tim->min_delta)) {
|
||||
if (!systick_ticks_have_passed(tim->last, tim->min_delta) && tim->min_delta > 0U) {
|
||||
safety_controller_report_error(tim->associated_flag);
|
||||
}
|
||||
}
|
||||
@@ -261,11 +262,15 @@ static void safety_controller_check_stack()
|
||||
static void safety_controller_handle_safety_adc()
|
||||
{
|
||||
static enum safety_adc_meas_channel current_channel = SAFETY_ADC_MEAS_TEMP;
|
||||
static uint64_t last_result_timestamp = 0;
|
||||
int poll_result;
|
||||
uint16_t result;
|
||||
float analog_value;
|
||||
|
||||
poll_result = safety_adc_poll_result(&result);
|
||||
if (!systick_ticks_have_passed(last_result_timestamp, SAFETY_CONTROLLER_ADC_DELAY_MS) && poll_result != 1)
|
||||
return;
|
||||
|
||||
if (poll_result) {
|
||||
if (poll_result == -1) {
|
||||
switch (current_channel) {
|
||||
@@ -278,9 +283,9 @@ static void safety_controller_handle_safety_adc()
|
||||
current_channel = SAFETY_ADC_MEAS_TEMP;
|
||||
break;
|
||||
}
|
||||
|
||||
safety_adc_trigger_meas(current_channel);
|
||||
} else if (poll_result == 1) {
|
||||
last_result_timestamp = systick_get_global_tick();
|
||||
analog_value = safety_adc_convert_channel(current_channel, result);
|
||||
safety_controller_report_timing(ERR_TIMING_SAFETY_ADC);
|
||||
switch (current_channel) {
|
||||
@@ -441,4 +446,42 @@ bool safety_controller_get_flags_by_mask(enum safety_flag mask)
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t safety_controller_get_flag_count()
|
||||
{
|
||||
return COUNT_OF(flags);
|
||||
}
|
||||
|
||||
int safety_controller_get_flag_name_by_index(uint32_t index, char *buffer, size_t buffsize)
|
||||
{
|
||||
if (index >= COUNT_OF(flags))
|
||||
return -1;
|
||||
|
||||
if (buffsize == 0 || !buffer)
|
||||
return -1000;
|
||||
|
||||
strncpy(buffer, flags[index].name, buffsize);
|
||||
buffer[buffsize - 1] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safety_controller_get_flag_by_index(uint32_t index, bool *status, enum safety_flag *flag_enum)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (!status && !flag_enum)
|
||||
return -1000;
|
||||
|
||||
if (index < COUNT_OF(flags)) {
|
||||
if (status)
|
||||
*status = flags[index].error_state;
|
||||
if (flag_enum)
|
||||
*flag_enum = flags[index].flag;
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
Reference in New Issue
Block a user