From e603f9f3fe4c27cd999cec988799764730736586 Mon Sep 17 00:00:00 2001
From: Vladimir Zidar
Date: Mon, 5 Dec 2016 13:02:36 +0100
Subject: [PATCH 1/3] LP-444 Improved I2C alarm handling by monitoring error
count changes returned by PIOS_I2C_GetDiagnostics().
---
flight/modules/System/systemmod.c | 68 +++++++++++++++++++++++++++----
flight/pios/inc/pios_i2c.h | 10 +++++
flight/pios/stm32f0x/pios_i2c.c | 14 +++----
flight/pios/stm32f10x/pios_i2c.c | 14 +++----
flight/pios/stm32f4xx/pios_i2c.c | 14 +++----
5 files changed, 92 insertions(+), 28 deletions(-)
diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c
index 686578a77..fc5c91831 100644
--- a/flight/modules/System/systemmod.c
+++ b/flight/modules/System/systemmod.c
@@ -118,11 +118,20 @@ static void callbackSchedulerForEachCallback(int16_t callback_id, const struct p
static void updateStats();
static void updateSystemAlarms();
static void systemTask(void *parameters);
-#ifdef DIAG_I2C_WDG_STATS
static void updateI2Cstats();
+#ifdef DIAG_I2C_WDG_STATS
static void updateWDGstats();
#endif
+#ifdef PIOS_INCLUDE_I2C
+
+#define I2C_ERROR_ACTIVITY_TIMEOUT_SECONDS 2
+
+#define I2C_ERROR_ACTIVITY_TIMEOUT (I2C_ERROR_ACTIVITY_TIMEOUT_SECONDS * 1000 / SYSTEM_UPDATE_PERIOD_MS)
+
+static uint8_t i2c_error_activity[PIOS_I2C_ERROR_COUNT_NUMELEM];
+#endif
+
extern uintptr_t pios_uavo_settings_fs_id;
extern uintptr_t pios_user_fs_id;
@@ -234,10 +243,13 @@ static void systemTask(__attribute__((unused)) void *parameters)
NotificationUpdateStatus();
// Update the system statistics
updateStats();
+
+ // Update I2C stats
+ updateI2Cstats();
+
// Update the system alarms
updateSystemAlarms();
#ifdef DIAG_I2C_WDG_STATS
- updateI2Cstats();
updateWDGstats();
#endif
@@ -480,17 +492,36 @@ static void callbackSchedulerForEachCallback(int16_t callback_id, const struct p
#endif /* ifdef DIAG_TASKS */
/**
- * Called periodically to update the I2C statistics
+ * Called periodically (every SYSTEM_UPDATE_PERIOD_MS milliseconds) to update the I2C statistics
*/
-#ifdef DIAG_I2C_WDG_STATS
static void updateI2Cstats()
{
#if defined(PIOS_INCLUDE_I2C)
+ static uint8_t previous_error_counts[PIOS_I2C_ERROR_COUNT_NUMELEM];
+
+ struct pios_i2c_fault_history history;
+ uint8_t error_counts[PIOS_I2C_ERROR_COUNT_NUMELEM];
+
+ PIOS_I2C_GetDiagnostics(&history, error_counts);
+
+ // every time a counter changes, set activity timeout counter to ( I2C_ERROR_ACTIVITY_TIMEOUT ).
+ // every time a counter does not change, decrease activity counter.
+
+ for (uint8_t i = 0; i < PIOS_I2C_ERROR_COUNT_NUMELEM; i++) {
+ if (error_counts[i] != previous_error_counts[i]) {
+ i2c_error_activity[i] = I2C_ERROR_ACTIVITY_TIMEOUT;
+ } else if (i2c_error_activity[i] > 0) {
+ i2c_error_activity[i]--;
+ }
+
+ previous_error_counts[i] = error_counts[i];
+ }
+
+#ifdef DIAG_I2C_WDG_STATS
I2CStatsData i2cStats;
I2CStatsGet(&i2cStats);
- struct pios_i2c_fault_history history;
- PIOS_I2C_GetDiagnostics(&history, &i2cStats.event_errors);
+ memcpy(&i2cStats.event_errors, &error_counts, sizeof(error_counts));
for (uint8_t i = 0; (i < I2C_LOG_DEPTH) && (i < I2CSTATS_EVENT_LOG_NUMELEM); i++) {
i2cStats.evirq_log[i] = history.evirq[i];
@@ -500,9 +531,11 @@ static void updateI2Cstats()
}
i2cStats.last_error_type = history.type;
I2CStatsSet(&i2cStats);
-#endif
+#endif /* DIAG_I2C_WDG_STATS */
+#endif /* PIOS_INCLUDE_I2C */
}
+#ifdef DIAG_I2C_WDG_STATS
static void updateWDGstats()
{
WatchdogStatusData watchdogStatus;
@@ -663,6 +696,27 @@ static void updateSystemAlarms()
sysStats.ObjectManagerQueueID = objStats.lastQueueErrorID;
SystemStatsSet(&sysStats);
}
+
+#ifdef PIOS_INCLUDE_I2C
+ static const SystemAlarmsAlarmOptions i2c_alarm_by_error[] = {
+ [PIOS_I2C_BAD_EVENT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
+ [PIOS_I2C_FSM_FAULT_COUNT] = SYSTEMALARMS_ALARM_ERROR,
+ [PIOS_I2C_ERROR_INTERRUPT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
+ [PIOS_I2C_NACK_COUNTER] = SYSTEMALARMS_ALARM_CRITICAL,
+ [PIOS_I2C_TIMEOUT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
+ };
+
+ SystemAlarmsAlarmOptions i2c_alarm = SYSTEMALARMS_ALARM_OK;
+
+ for (uint8_t i = 0; i < PIOS_I2C_ERROR_COUNT_NUMELEM; i++) {
+ if ((i2c_error_activity[i] > 0) && (i2c_alarm < i2c_alarm_by_error[i])) {
+ i2c_alarm = i2c_alarm_by_error[i];
+ }
+ }
+
+ AlarmsSet(SYSTEMALARMS_ALARM_I2C, i2c_alarm);
+
+#endif /* PIOS_INCLUDE_I2C */
}
/**
diff --git a/flight/pios/inc/pios_i2c.h b/flight/pios/inc/pios_i2c.h
index d3c7ceb67..0c4c71431 100644
--- a/flight/pios/inc/pios_i2c.h
+++ b/flight/pios/inc/pios_i2c.h
@@ -63,6 +63,16 @@ struct pios_i2c_fault_history {
uint8_t state[I2C_LOG_DEPTH];
};
+enum pios_i2c_error_count {
+ PIOS_I2C_BAD_EVENT_COUNTER,
+ PIOS_I2C_FSM_FAULT_COUNT,
+ PIOS_I2C_ERROR_INTERRUPT_COUNTER,
+ PIOS_I2C_NACK_COUNTER,
+ PIOS_I2C_TIMEOUT_COUNTER,
+
+ PIOS_I2C_ERROR_COUNT_NUMELEM,
+};
+
/* Public Functions */
extern int32_t PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns);
extern int32_t PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns, void *callback);
diff --git a/flight/pios/stm32f0x/pios_i2c.c b/flight/pios/stm32f0x/pios_i2c.c
index b73355262..385c5295e 100644
--- a/flight/pios/stm32f0x/pios_i2c.c
+++ b/flight/pios/stm32f0x/pios_i2c.c
@@ -458,17 +458,17 @@ void PIOS_I2C_GetDiagnostics(struct pios_i2c_fault_history *data, uint8_t *count
{
#if defined(PIOS_I2C_DIAGNOSTICS)
memcpy(data, &i2c_adapter_fault_history, sizeof(i2c_adapter_fault_history));
- counts[0] = i2c_bad_event_counter;
- counts[1] = i2c_fsm_fault_count;
- counts[2] = i2c_error_interrupt_counter;
- counts[3] = i2c_nack_counter;
- counts[4] = i2c_timeout_counter;
+ counts[PIOS_I2C_BAD_EVENT_COUNTER] = i2c_bad_event_counter;
+ counts[PIOS_I2C_FSM_FAULT_COUNT] = i2c_fsm_fault_count;
+ counts[PIOS_I2C_ERROR_INTERRUPT_COUNTER] = i2c_error_interrupt_counter;
+ counts[PIOS_I2C_NACK_COUNTER] = i2c_nack_counter;
+ counts[PIOS_I2C_TIMEOUT_COUNTER] = i2c_timeout_counter;
#else
struct pios_i2c_fault_history i2c_adapter_fault_history;
- i2c_adapter_fault_history.type = PIOS_I2C_ERROR_EVENT;
+ i2c_adapter_fault_history.type = PIOS_I2C_ERROR_EVENT;
memcpy(data, &i2c_adapter_fault_history, sizeof(i2c_adapter_fault_history));
- counts[0] = counts[1] = counts[2] = 0;
+ memset(counts, 0, sizeof(*counts) * PIOS_I2C_ERROR_COUNT_NUMELEM);
#endif
}
diff --git a/flight/pios/stm32f10x/pios_i2c.c b/flight/pios/stm32f10x/pios_i2c.c
index 77f150ac0..e18edc2fe 100644
--- a/flight/pios/stm32f10x/pios_i2c.c
+++ b/flight/pios/stm32f10x/pios_i2c.c
@@ -857,17 +857,17 @@ void PIOS_I2C_GetDiagnostics(struct pios_i2c_fault_history *data, uint8_t *count
{
#if defined(PIOS_I2C_DIAGNOSTICS)
memcpy(data, &i2c_adapter_fault_history, sizeof(i2c_adapter_fault_history));
- counts[0] = i2c_bad_event_counter;
- counts[1] = i2c_fsm_fault_count;
- counts[2] = i2c_error_interrupt_counter;
- counts[3] = i2c_nack_counter;
- counts[4] = i2c_timeout_counter;
+ counts[PIOS_I2C_BAD_EVENT_COUNTER] = i2c_bad_event_counter;
+ counts[PIOS_I2C_FSM_FAULT_COUNT] = i2c_fsm_fault_count;
+ counts[PIOS_I2C_ERROR_INTERRUPT_COUNTER] = i2c_error_interrupt_counter;
+ counts[PIOS_I2C_NACK_COUNTER] = i2c_nack_counter;
+ counts[PIOS_I2C_TIMEOUT_COUNTER] = i2c_timeout_counter;
#else
struct pios_i2c_fault_history i2c_adapter_fault_history;
- i2c_adapter_fault_history.type = PIOS_I2C_ERROR_EVENT;
+ i2c_adapter_fault_history.type = PIOS_I2C_ERROR_EVENT;
memcpy(data, &i2c_adapter_fault_history, sizeof(i2c_adapter_fault_history));
- counts[0] = counts[1] = counts[2] = 0;
+ memset(counts, 0, sizeof(*counts) * PIOS_I2C_ERROR_COUNT_NUMELEM);
#endif
}
diff --git a/flight/pios/stm32f4xx/pios_i2c.c b/flight/pios/stm32f4xx/pios_i2c.c
index 60811fa13..2821f79be 100644
--- a/flight/pios/stm32f4xx/pios_i2c.c
+++ b/flight/pios/stm32f4xx/pios_i2c.c
@@ -952,17 +952,17 @@ void PIOS_I2C_GetDiagnostics(struct pios_i2c_fault_history *data, uint8_t *count
{
#if defined(PIOS_I2C_DIAGNOSTICS)
memcpy(data, &i2c_adapter_fault_history, sizeof(i2c_adapter_fault_history));
- counts[0] = i2c_bad_event_counter;
- counts[1] = i2c_fsm_fault_count;
- counts[2] = i2c_error_interrupt_counter;
- counts[3] = i2c_nack_counter;
- counts[4] = i2c_timeout_counter;
+ counts[PIOS_I2C_BAD_EVENT_COUNTER] = i2c_bad_event_counter;
+ counts[PIOS_I2C_FSM_FAULT_COUNT] = i2c_fsm_fault_count;
+ counts[PIOS_I2C_ERROR_INTERRUPT_COUNTER] = i2c_error_interrupt_counter;
+ counts[PIOS_I2C_NACK_COUNTER] = i2c_nack_counter;
+ counts[PIOS_I2C_TIMEOUT_COUNTER] = i2c_timeout_counter;
#else
struct pios_i2c_fault_history i2c_adapter_fault_history;
- i2c_adapter_fault_history.type = PIOS_I2C_ERROR_EVENT;
+ i2c_adapter_fault_history.type = PIOS_I2C_ERROR_EVENT;
memcpy(data, &i2c_adapter_fault_history, sizeof(i2c_adapter_fault_history));
- counts[0] = counts[1] = counts[2] = 0;
+ memset(counts, 0, sizeof(*counts) * PIOS_I2C_ERROR_COUNT_NUMELEM);
#endif
}
From 1207968362a63df8300bb9a4b1bad2c56eb59be6 Mon Sep 17 00:00:00 2001
From: Vladimir Zidar
Date: Mon, 5 Dec 2016 13:47:17 +0100
Subject: [PATCH 2/3] LP-444 Do not touch i2c alarm in case it is
uninitialised. This will keep the gcs field grey when I2C is not in use.
---
flight/modules/System/systemmod.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c
index fc5c91831..4a629f301 100644
--- a/flight/modules/System/systemmod.c
+++ b/flight/modules/System/systemmod.c
@@ -698,24 +698,25 @@ static void updateSystemAlarms()
}
#ifdef PIOS_INCLUDE_I2C
- static const SystemAlarmsAlarmOptions i2c_alarm_by_error[] = {
- [PIOS_I2C_BAD_EVENT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
- [PIOS_I2C_FSM_FAULT_COUNT] = SYSTEMALARMS_ALARM_ERROR,
- [PIOS_I2C_ERROR_INTERRUPT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
- [PIOS_I2C_NACK_COUNTER] = SYSTEMALARMS_ALARM_CRITICAL,
- [PIOS_I2C_TIMEOUT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
- };
+ if (AlarmsGet(SYSTEMALARMS_ALARM_I2C) != SYSTEMALARMS_ALARM_UNINITIALISED) {
+ static const SystemAlarmsAlarmOptions i2c_alarm_by_error[] = {
+ [PIOS_I2C_BAD_EVENT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
+ [PIOS_I2C_FSM_FAULT_COUNT] = SYSTEMALARMS_ALARM_ERROR,
+ [PIOS_I2C_ERROR_INTERRUPT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
+ [PIOS_I2C_NACK_COUNTER] = SYSTEMALARMS_ALARM_CRITICAL,
+ [PIOS_I2C_TIMEOUT_COUNTER] = SYSTEMALARMS_ALARM_ERROR,
+ };
- SystemAlarmsAlarmOptions i2c_alarm = SYSTEMALARMS_ALARM_OK;
+ SystemAlarmsAlarmOptions i2c_alarm = SYSTEMALARMS_ALARM_OK;
- for (uint8_t i = 0; i < PIOS_I2C_ERROR_COUNT_NUMELEM; i++) {
- if ((i2c_error_activity[i] > 0) && (i2c_alarm < i2c_alarm_by_error[i])) {
- i2c_alarm = i2c_alarm_by_error[i];
+ for (uint8_t i = 0; i < PIOS_I2C_ERROR_COUNT_NUMELEM; i++) {
+ if ((i2c_error_activity[i] > 0) && (i2c_alarm < i2c_alarm_by_error[i])) {
+ i2c_alarm = i2c_alarm_by_error[i];
+ }
}
+
+ AlarmsSet(SYSTEMALARMS_ALARM_I2C, i2c_alarm);
}
-
- AlarmsSet(SYSTEMALARMS_ALARM_I2C, i2c_alarm);
-
#endif /* PIOS_INCLUDE_I2C */
}
From 76c0f3f350a86731de27f3a9f55f52948cec27ad Mon Sep 17 00:00:00 2001
From: Laurent Lalanne
Date: Mon, 5 Dec 2016 15:22:05 +0100
Subject: [PATCH 3/3] LP-444 Update SystemHealth for I2C alarms and more.
---
flight/modules/System/systemmod.c | 3 ---
.../systemhealth/html/Attitude-Critical.html | 5 +++--
.../systemhealth/html/Attitude-Error.html | 3 ++-
.../systemhealth/html/Attitude-Warning.html | 16 ++++++++++++++++
.../plugins/systemhealth/html/GPS-Error.html | 6 +++---
.../systemhealth/html/I2C-Critical.html | 13 +++++++++++++
.../plugins/systemhealth/html/I2C-Error.html | 18 ++++++++++++++++++
.../systemhealth/html/Sensors-Critical.html | 7 +++----
.../html/Stabilization-Critical.html | 6 ++++--
.../systemhealth/html/Stabilization-Error.html | 17 +++++++++++++++++
.../html/Stabilization-Warning.html | 8 ++++++--
.../html/fr/Attitude-Critical.html | 5 +++--
.../systemhealth/html/fr/Attitude-Error.html | 1 +
.../systemhealth/html/fr/Attitude-Warning.html | 16 ++++++++++++++++
.../systemhealth/html/fr/GPS-Error.html | 6 +++---
.../systemhealth/html/fr/GPS-Warning.html | 2 +-
.../systemhealth/html/fr/I2C-Critical.html | 13 +++++++++++++
.../systemhealth/html/fr/I2C-Error.html | 18 ++++++++++++++++++
.../systemhealth/html/fr/Sensors-Critical.html | 4 ++--
.../html/fr/Stabilization-Critical.html | 6 ++++--
.../html/fr/Stabilization-Error.html | 17 +++++++++++++++++
.../html/fr/Stabilization-Warning.html | 8 ++++++--
.../src/plugins/systemhealth/systemhealth.qrc | 10 ++++++++++
23 files changed, 179 insertions(+), 29 deletions(-)
create mode 100644 ground/gcs/src/plugins/systemhealth/html/Attitude-Warning.html
create mode 100644 ground/gcs/src/plugins/systemhealth/html/I2C-Critical.html
create mode 100644 ground/gcs/src/plugins/systemhealth/html/I2C-Error.html
create mode 100644 ground/gcs/src/plugins/systemhealth/html/Stabilization-Error.html
create mode 100644 ground/gcs/src/plugins/systemhealth/html/fr/Attitude-Warning.html
create mode 100644 ground/gcs/src/plugins/systemhealth/html/fr/I2C-Critical.html
create mode 100644 ground/gcs/src/plugins/systemhealth/html/fr/I2C-Error.html
create mode 100644 ground/gcs/src/plugins/systemhealth/html/fr/Stabilization-Error.html
diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c
index 4a629f301..2cf86e751 100644
--- a/flight/modules/System/systemmod.c
+++ b/flight/modules/System/systemmod.c
@@ -124,11 +124,8 @@ static void updateWDGstats();
#endif
#ifdef PIOS_INCLUDE_I2C
-
#define I2C_ERROR_ACTIVITY_TIMEOUT_SECONDS 2
-
#define I2C_ERROR_ACTIVITY_TIMEOUT (I2C_ERROR_ACTIVITY_TIMEOUT_SECONDS * 1000 / SYSTEM_UPDATE_PERIOD_MS)
-
static uint8_t i2c_error_activity[PIOS_I2C_ERROR_COUNT_NUMELEM];
#endif
diff --git a/ground/gcs/src/plugins/systemhealth/html/Attitude-Critical.html b/ground/gcs/src/plugins/systemhealth/html/Attitude-Critical.html
index b7676c6dd..3a763a567 100644
--- a/ground/gcs/src/plugins/systemhealth/html/Attitude-Critical.html
+++ b/ground/gcs/src/plugins/systemhealth/html/Attitude-Critical.html
@@ -9,8 +9,9 @@
One of the following conditions may be present:
- - No data is received from the accelerometer
- - Waiting for good data from Magnetometer or GPS lock to perform module initialization.
+ - Waiting for the board to be steady before gyro init.
+ - No data is being received from the accelerometer.
+ - Waiting for good data from magnetometer or GPS lock to perform module initialization.
+ Attitude : Warning
+
+ One of the following conditions may be present:
+
+ - Waiting for the board to be steady before gyro init.
+
+
+
diff --git a/ground/gcs/src/plugins/systemhealth/html/Attitude-Error.html b/ground/gcs/src/plugins/systemhealth/html/Attitude-Error.html
index d1cbb4982..7ebc6ce75 100644
--- a/ground/gcs/src/plugins/systemhealth/html/Attitude-Error.html
+++ b/ground/gcs/src/plugins/systemhealth/html/Attitude-Error.html
@@ -9,8 +9,9 @@
diff --git a/ground/gcs/src/plugins/systemhealth/html/Attitude-Warning.html b/ground/gcs/src/plugins/systemhealth/html/Attitude-Warning.html
new file mode 100644
index 000000000..61ab7f9a3
--- /dev/null
+++ b/ground/gcs/src/plugins/systemhealth/html/Attitude-Warning.html
@@ -0,0 +1,16 @@
+
+