1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

Merged in mindnever/librepilot/LP-444-Improve_I2C_Alarms (pull request #361)

LP-444 - Improved I2C Alarms
This commit is contained in:
Philippe Renon 2016-12-11 19:13:39 +01:00
commit a189f9b012
27 changed files with 269 additions and 54 deletions

View File

@ -118,11 +118,17 @@ 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 +240,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 +489,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 +528,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 +693,28 @@ static void updateSystemAlarms()
sysStats.ObjectManagerQueueID = objStats.lastQueueErrorID;
SystemStatsSet(&sysStats);
}
#ifdef PIOS_INCLUDE_I2C
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;
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 */
}
/**

View File

@ -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);

View File

@ -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;
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
}

View File

@ -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;
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
}

View File

@ -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;
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
}

View File

@ -9,8 +9,9 @@
<p>
One of the following conditions may be present:
<ul>
<li>No data is received from the accelerometer</li>
<li>Waiting for good data from Magnetometer or GPS lock to perform module initialization.</li>
<li>Waiting for the board to be steady before gyro init.</li>
<li>No data is being received from the accelerometer.</li>
<li>Waiting for good data from magnetometer or GPS lock to perform module initialization.</li>
</ul>
</p>
</body>

View File

@ -9,8 +9,9 @@
<p>
One of the following conditions may be present:
<ul>
<li>Waiting for the board to be steady before gyro init.</li>
<li>Failed to get an update from the accelerometer or gyros.</li>
<li>Attitude Estimation Algorithm set to "GPS Navigation (INS13)" and no Magnetometer : please set HomeLocation.</li>
<li>Attitude Estimation Algorithm set to "GPS Navigation (INS13)" and no magnetometer : please set HomeLocation.</li>
</ul>
</p>
</body>

View File

@ -0,0 +1,16 @@
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<h1>Attitude : Warning</h1>
<p>
One of the following conditions may be present:
<ul>
<li>Waiting for the board to be steady before gyro init.</li>
</ul>
</p>
</body>
</html>

View File

@ -9,9 +9,9 @@
<p>
The GPS has timed out, one of the following conditions may be present:
<ul>
<li>there is no GPS plugged in</li>
<li>GPS is not powered using an external source (+5V)</li>
<li>there is a hardware issue with wiring</li>
<li>There is no GPS plugged in.</li>
<li>GPS is not powered using an external source. (+5V)</li>
<li>GPS device is not properly wired.</li>
</ul>
</p>
</body>

View File

@ -0,0 +1,13 @@
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<h1>I2C: Critical</h1>
<p>
I2C port is working but there are acknowledgement errors.
</p>
</body>
</html>

View File

@ -0,0 +1,18 @@
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<h1>I2C: Error</h1>
<p>
The I2C has timed out, one of the following conditions may be present:
<ul>
<li>I2C device is not connected.</li>
<li>I2C device is not powered using an external source. (+5V)</li>
<li>I2C device is not properly wired.</li>
</ul>
</p>
</body>
</html>

View File

@ -9,10 +9,9 @@
<p>
One of the following conditions may be present:
<ul>
<li>Either the accelerometer, gyro or magnetometer tests failed.</li>
<li>The accelerometer, gyro or magnetometer test failed.</li>
<li>Timed out waiting for data from the accelerometer or gyro.</li>
</ul>
</p>
</body>
</html>

View File

@ -9,8 +9,10 @@
<p>
One of the following conditions may be present:
<ul>
<li>Something is wrong with the Stabilization module</li>
<li>Waiting for good data from the Magnetometer or for GPS lock to perform module initialization.</li>
<li>Waiting for the board to be steady before gyro init.</li>
<li>Rate loop skipped more than 4 executions.</li>
<li>Missed 3 gyro updates.</li>
<li>Waiting for good data from the magnetometer or for GPS lock to perform module initialization.</li>
</ul>
</p>
</body>

View File

@ -0,0 +1,17 @@
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<h1>Stabilization: Error</h1>
<p>
One of the following conditions may be present:
<ul>
<li>Something is wrong with Stabilization module.</li>
<li>Gyro didn't update at all!</li>
</ul>
</p>
</body>
</html>

View File

@ -7,7 +7,11 @@
<body>
<h1>Stabilization: Warning</h1>
<p>
Timed out waiting for an attitude update.
One of the following conditions may be present:
<ul>
<li>Rate loop skipped more than 2 executions.</li>
<li>Missed one gyro update.</li>
</ul>
</p>
</body>
</html>

View File

@ -9,8 +9,9 @@
<p>
Une des conditions suivantes semble présente :
<ul>
<li>Pas de données reçues en provenance des accéléromètres</li>
<li>En attente de données correctes du Magnétomètre ou d'une position GPS pour initialiser le module.</li>
<li>En attente d'une carte sans mouvement pour initialiser les gyros.</li>
<li>Pas de données reçues en provenance des accéléromètres.</li>
<li>En attente de données correctes du magnétomètre ou d'une position GPS pour initialiser le module.</li>
</ul>
</p>
</body>

View File

@ -9,6 +9,7 @@
<p>
Une des conditions suivantes semble présente :
<ul>
<li>En attente d'une carte sans mouvement pour initialiser les gyros.</li>
<li>Échec de l'acquisition en provenance des accéléromètres ou gyroscopes.</li>
<li>Algorithme d'évaluation de l'attitude réglé à "GPS Navigation (INS13)" et pas de magnétomètre : veuillez fixer la position Home.</li>
</ul>

View File

@ -0,0 +1,16 @@
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<h1>Attitude : Avertissement</h1>
<p>
Une des conditions suivantes semble présente :
<ul>
<li>En attente d'une carte sans mouvement pour initialiser les gyros.</li>
</ul>
</p>
</body>
</html>

View File

@ -9,9 +9,9 @@
<p>
Le GPS a expiré pour une des raisons suivantes :
<ul>
<li>il n'y a pas de GPS branché</li>
<li>le GPS n'est pas alimenté avec une source d'alimentation extérieure (+5V)</li>
<li>il y a un problème avec le câblage</li>
<li>Il n'y a pas de GPS branché</li>
<li>Le GPS n'est pas alimenté avec une source d'alimentation extérieure (+5V)</li>
<li>Il y a un problème avec le câblage</li>
</ul>
</p>
</body>

View File

@ -5,7 +5,7 @@
<style></style>
</head>
<body>
<h1>GPS: Avertissement</h1>
<h1>GPS : Avertissement</h1>
<p>
Le GPS a un fix et la navigation peut être utilisée. Cependant, la précision de la position est très faible (l'indication est &lt; 7 satellites)
</p>

View File

@ -0,0 +1,13 @@
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<h1>I2C : Critique</h1>
<p>
Le port I2C fonctionne mais il y a des erreurs d'ack.
</p>
</body>
</html>

View File

@ -0,0 +1,18 @@
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<h1>I2C : Erreur</h1>
<p>
Le port I2C a expiré pour une des raisons suivantes :
<ul>
<li>Le composant I2C n'est pas branché.</li>
<li>Le composant I2C n'est pas alimenté avec une source d'alimentation extérieure. (+5V)</li>
<li>Il y a un problème avec le câblage.</li>
</ul>
</p>
</body>
</html>

View File

@ -9,8 +9,10 @@
<p>
Une des conditions suivantes semble présente :
<ul>
<li>Quelque chose ne va pas avec le module de stabilisation</li>
<li>En attente de données correctes du Magnétomètre ou d'une position GPS pour initialiser le module.</li>
<li>En attente d'une carte sans mouvement pour initialiser les gyros.</li>
<li>La boucle Rate a été ignorée plus de quatre fois.</li>
<li>Manqué trois mises à jour du gyro.</li>
<li>En attente de données correctes du magnétomètre ou d'une position GPS pour initialiser le module.</li>
</ul>
</p>
</body>

View File

@ -0,0 +1,17 @@
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<h1>Stabilisation : Erreur</h1>
<p>
Une des conditions suivantes semble présente :
<ul>
<li>Quelque chose ne va pas avec le module Stabilisation.</li>
<li>Aucune mise à jour des gyros !</li>
</ul>
</p>
</body>
</html>

View File

@ -5,9 +5,13 @@
<style></style>
</head>
<body>
<h1>Stabilisation: Avertissement</h1>
<h1>Stabilisation : Avertissement</h1>
<p>
Délai d'attente d'une mise à jour de l'attitude dépassé.
Une des conditions suivantes semble présente :
<ul>
<li>La boucle Rate a été ignorée plus de deux fois.</li>
<li>Manqué une mise à jour du gyro.</li>
</ul>
</p>
</body>
</html>

View File

@ -11,6 +11,7 @@
<file>html/EventSystem-Warning.html</file>
<file>html/FlightTime-Critical.html</file>
<file>html/AlarmOK.html</file>
<file>html/Attitude-Warning.html</file>
<file>html/Attitude-Critical.html</file>
<file>html/Attitude-Error.html</file>
<file>html/Battery-Critical.html</file>
@ -20,10 +21,14 @@
<file>html/GPS-Error.html</file>
<file>html/GPS-Warning.html</file>
<file>html/Guidance-Warning.html</file>
<file>html/I2C-Critical.html</file>
<file>html/I2C-Error.html</file>
<file>html/OutOfMemory-Critical.html</file>
<file>html/OutOfMemory-Warning.html</file>
<file>html/Sensors-Critical.html</file>
<file>html/Stabilization-Warning.html</file>
<file>html/Stabilization-Critical.html</file>
<file>html/Stabilization-Error.html</file>
<file>html/StackOverflow-Critical.html</file>
<file>html/Telemetry-Error.html</file>
<file>html/SystemConfiguration-Critical.html</file>
@ -48,6 +53,7 @@
<file alias="html/EventSystem-Warning.html">html/fr/EventSystem-Warning.html</file>
<file alias="html/FlightTime-Critical.html">html/fr/FlightTime-Critical.html</file>
<file alias="html/AlarmOK.html">html/fr/AlarmOK.html</file>
<file alias="html/Attitude-Warning.html">html/fr/Attitude-Warning.html</file>
<file alias="html/Attitude-Critical.html">html/fr/Attitude-Critical.html</file>
<file alias="html/Attitude-Error.html">html/fr/Attitude-Error.html</file>
<file alias="html/Battery-Critical.html">html/fr/Battery-Critical.html</file>
@ -57,10 +63,14 @@
<file alias="html/GPS-Error.html">html/fr/GPS-Error.html</file>
<file alias="html/GPS-Warning.html">html/fr/GPS-Warning.html</file>
<file alias="html/Guidance-Warning.html">html/fr/Guidance-Warning.html</file>
<file alias="html/I2C-Critical.html">html/fr/I2C-Critical.html</file>
<file alias="html/I2C-Error.html">html/fr/I2C-Error.html</file>
<file alias="html/OutOfMemory-Critical.html">html/fr/OutOfMemory-Critical.html</file>
<file alias="html/OutOfMemory-Warning.html">html/fr/OutOfMemory-Warning.html</file>
<file alias="html/Sensors-Critical.html">html/fr/Sensors-Critical.html</file>
<file alias="html/Stabilization-Warning.html">html/fr/Stabilization-Warning.html</file>
<file alias="html/Stabilization-Critical.html">html/fr/Stabilization-Critical.html</file>
<file alias="html/Stabilization-Error.html">html/fr/Stabilization-Error.html</file>
<file alias="html/StackOverflow-Critical.html">html/fr/StackOverflow-Critical.html</file>
<file alias="html/Telemetry-Error.html">html/fr/Telemetry-Error.html</file>
<file alias="html/SystemConfiguration-Critical.html">html/fr/SystemConfiguration-Critical.html</file>