Ajout d'un systeme de panic pour tracer des erreurs irrecuperables

This commit is contained in:
dimercur 2023-10-11 18:01:04 +02:00
parent 64b8f9fe08
commit 1d27411326
7 changed files with 142 additions and 6 deletions

View file

@ -16,6 +16,8 @@
#include "batterie.h"
#include "messages.h"
#include "panic.h"
typedef enum {
stateStartup=0,
stateIdle,
@ -179,9 +181,11 @@ void APPLICATION_MainThread(void* params) {
case MSG_ID_BAT_ADC_ERR:
/* depart en panic: error 2 */
PANIC_Raise(panic_adc_err);
break;
case MSG_ID_BAT_CHARGE_ERR:
/* depart en panic: error 3 */
PANIC_Raise(panic_charger_err);
break;
case MSG_ID_BAT_CHARGE_COMPLETE:
case MSG_ID_BAT_CHARGE_LOW:
@ -382,7 +386,7 @@ void APPLICATION_TransitionToNewState(APPLICATION_State new_state) {
systemTimeout.watchdogEnabled=0;
break;
case stateWatchdogDisable:
ledState = leds_erreur_1;
ledState = leds_watchdog_expired;
LEDS_Set(ledState);
systemTimeout.watchdogEnabled=0;
@ -440,7 +444,7 @@ void vTimerTimeoutCallback( TimerHandle_t xTimer ) {
systemTimeout.watchdogMissedCnt++;
if (systemTimeout.watchdogMissedCnt>=(APPLICATION_WATCHDOG_MISSED_MAX/100))
APPLICATION_TransitionToNewState(stateWatchdogDisable);
APPLICATION_TransitionToNewState(stateWatchdogDisable); /* TODO: Reprendre pour en faire un envoi de message */
}
}
}

View file

@ -45,8 +45,8 @@ uint8_t BUTTON_Inactivity=1; //start with button on/off inactive
void BATTERIE_VoltageThread(void* params);
void BATTERIE_Init(void) {
task_handler = NULL;
charger_thread_handler = NULL;
//task_handler = NULL;
//charger_thread_handler = NULL;
/* Create the task without using any dynamic memory allocation. */
xHandleBatterie = xTaskCreateStatic(

View file

@ -68,9 +68,11 @@
#define LED_PATTERN_DIGIT_C 31
#define LED_PATTERN_DIGIT_L 32
#define LED_PATTERN_DIGIT_B 33
#define LED_PATTERN_DIGIT_UNKNOWN 34
#define LED_PATTERN_WDT_EXP_1 34
#define LED_PATTERN_WDT_EXP_2 35
#define LED_PATTERN_DIGIT_UNKNOWN 36
#define LED_MAX_PATTERNS 35
#define LED_MAX_PATTERNS 37
/*
* Relation entre segment et nom
@ -131,6 +133,8 @@ uint16_t LEDS_Patterns [LED_MAX_PATTERNS][4]= {
{ LED_SEG_D_Pin, LED_SEG_A_Pin|LED_SEG_B_Pin|LED_SEG_C_Pin, LED_SEG_E_Pin|LED_SEG_F_Pin|LED_SEG_G_Pin|LED_SEG_DP_Pin, 0}, // C
{ 0, LED_SEG_A_Pin|LED_SEG_B_Pin|LED_SEG_C_Pin, LED_SEG_D_Pin|LED_SEG_E_Pin|LED_SEG_F_Pin|LED_SEG_G_Pin|LED_SEG_DP_Pin, 0},// L
{ LED_SEG_F_Pin|LED_SEG_G_Pin, LED_SEG_A_Pin|LED_SEG_B_Pin|LED_SEG_C_Pin, LED_SEG_D_Pin|LED_SEG_E_Pin|LED_SEG_DP_Pin, 0}, // b
{ LED_SEG_E_Pin, LED_SEG_B_Pin, LED_SEG_D_Pin|LED_SEG_F_Pin|LED_SEG_G_Pin|LED_SEG_DP_Pin, LED_SEG_A_Pin|LED_SEG_C_Pin}, // Watchdog expired 1
{ LED_SEG_F_Pin, LED_SEG_C_Pin, LED_SEG_D_Pin|LED_SEG_E_Pin|LED_SEG_G_Pin|LED_SEG_DP_Pin, LED_SEG_A_Pin|LED_SEG_B_Pin}, // Watchdog expired 2
{ LED_SEG_D_Pin|LED_SEG_E_Pin|LED_SEG_G_Pin, LED_SEG_B_Pin, LED_SEG_F_Pin|LED_SEG_DP_Pin, LED_SEG_A_Pin|LED_SEG_C_Pin} // ?
};
@ -350,6 +354,14 @@ void LEDS_ActionThread(void* params) {
cnt=0;
break;
case leds_watchdog_expired:
if (cnt<3)
LEDS_ShowPattern(LED_PATTERN_WDT_EXP_1);
else if (cnt<6)
LEDS_ShowPattern(LED_PATTERN_WDT_EXP_2);
else
cnt=0;
break;
case leds_erreur_1:
if (cnt<5)
LEDS_ShowPattern(LED_PATTERN_ERROR);

View file

@ -23,6 +23,7 @@ typedef enum {
leds_bat_charge_med,
leds_bat_charge_high,
leds_bat_charge_complete,
leds_watchdog_expired,
leds_erreur_1,
leds_erreur_2,
leds_erreur_3,

View file

@ -0,0 +1,94 @@
/*
* panic.c
*
* Created on: Oct 11, 2023
* Author: dimercur
*/
#include "application.h"
#include "timers.h"
#include "panic.h"
#include "leds.h"
void PANIC_StopTasksAndWait(void);
void MOTEURS_DesactiveAlim(void);
extern TaskHandle_t xHandleLedsHandler;
extern TaskHandle_t xHandleLedsAction;
extern TaskHandle_t xHandleBatterie;
extern TimerHandle_t xHandleTimerButton;
extern TaskHandle_t xHandleApplicationMain;
extern TimerHandle_t xHandleTimerTimeout;
extern TaskHandle_t xHandleMoteurs;
extern TaskHandle_t xHandleMoteursAsservissement;
extern TaskHandle_t xHandleXbeeTXHandler;
extern TaskHandle_t xHandleXbeeRX;
void PANIC_Raise(PANIC_Typedef panicId) {
switch (panicId) {
case panic_adc_err:
LEDS_Set(leds_erreur_1);
break;
case panic_charger_err:
LEDS_Set(leds_erreur_2);
break;
case panic_malloc:
LEDS_Set(leds_erreur_3);
break;
default:
LEDS_Set(leds_erreur_5);
break;
}
PANIC_StopTasksAndWait();
}
void PANIC_StopTasksAndWait(void){
TaskHandle_t currentTask;
currentTask = xTaskGetCurrentTaskHandle();
/* Arret des timers */
xTimerStop(xHandleTimerButton,0);
xTimerStop(xHandleTimerTimeout,0);
/* Arret des taches
* On n'arrete toute les taches sauf celle en cours !
*
* a la fin, on arrete la tache en cours
*
* on n'arrete jamais les leds, sinon plus d'animation !!
*/
if (currentTask != xHandleXbeeRX)
vTaskSuspend(xHandleXbeeRX);
if (currentTask != xHandleXbeeTXHandler)
vTaskSuspend(xHandleXbeeTXHandler);
if (currentTask != xHandleMoteurs)
vTaskSuspend(xHandleMoteurs);
if (currentTask != xHandleMoteursAsservissement)
vTaskSuspend(xHandleMoteursAsservissement);
if (currentTask != xHandleBatterie)
vTaskSuspend(xHandleBatterie);
if (currentTask != xHandleApplicationMain)
vTaskSuspend(xHandleApplicationMain);
/* Stop des alim moteurs */
MOTEURS_DesactiveAlim();
/* disable XBEE */
HAL_GPIO_WritePin(XBEE_RESET_GPIO_Port, XBEE_RESET_Pin, GPIO_PIN_RESET);
/* Stop la tache courante */
vTaskSuspend(currentTask);
while (1) {
__WFE(); /* Attente infinie */
}
}

View file

@ -0,0 +1,19 @@
/*
* panic.h
*
* Created on: Oct 11, 2023
* Author: dimercur
*/
#ifndef PANIC_H_
#define PANIC_H_
typedef enum {
panic_charger_err=1, // erreur 1
panic_adc_err, // erreur 2
panic_malloc // erreur 3
} PANIC_Typedef;
void PANIC_Raise(PANIC_Typedef panicId);
#endif /* PANIC_H_ */

View file

@ -33,6 +33,8 @@
#include "cmsis_os.h"
#include "panic.h"
/* Variables */
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
@ -55,6 +57,10 @@ void* malloc(size_t size)
// We simply wrap the FreeRTOS call into a standard form
ptr = pvPortMalloc(size);
Counter_Malloc++;
if (ptr==NULL) { /* plus assez de memoire dynamique*/
PANIC_Raise(panic_malloc);
}
} // else NULL if there was an error
return ptr;