implement watchdog
This commit is contained in:
parent
d6d667a3c4
commit
e3f971bb18
12
306-controller_interface.X/app/can_message.c
Normal file
12
306-controller_interface.X/app/can_message.c
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @author Rémi Heredero
|
||||
* @version 1.0.0
|
||||
* @date August 2023
|
||||
* @file can_message.c
|
||||
*/
|
||||
|
||||
#include "../middleware/can_interface.h"
|
||||
|
||||
void CM_controller_alive(void* p) {
|
||||
CAN_Send(0x0, 0xF, 0);
|
||||
}
|
29
306-controller_interface.X/app/can_message.h
Normal file
29
306-controller_interface.X/app/can_message.h
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @author Rémi Heredero
|
||||
* @version 1.0.0
|
||||
* @date August 2023
|
||||
* @file can_message.h
|
||||
*/
|
||||
|
||||
#ifndef CAN_MESSAGE_H
|
||||
#define CAN_MESSAGE_H
|
||||
|
||||
|
||||
/*
|
||||
S R M
|
||||
1 0 F CONTROL_ALIVE - - - -
|
||||
1 2 0 JOY_SETUP Mode Param1 Param2 aliveTime
|
||||
1 3 0 DISPLAY_SETUP reset - - aliveTime
|
||||
1 3 2 DISPLAY_SPEED valH valL - -
|
||||
1 3 3 DISPLAY_DIRECTION direction - - -
|
||||
1 4 0 DRIVE_SETUP Reset/init speedTime stopTime aliveTime
|
||||
1 4 1 DRIVE_POWER valH valL - -
|
||||
1 5 0 STEERING_SETUP Reset/init homing setCenter aliveTime
|
||||
1 5 1 STEERING_SET valHH valH valL valLL
|
||||
1 6 0 SETUP_CONTROL batteryVoltTime batteryCurrentTime batteryEnergyTime aliveTime
|
||||
*/
|
||||
|
||||
void CM_controller_alive(void* p);
|
||||
|
||||
#endif /* CAN_MESSAGE_H */
|
||||
|
@ -30,6 +30,10 @@ LED* l8() {
|
||||
return &theFactory.l8_;
|
||||
}
|
||||
|
||||
WATCHDOG* WDcontroller(){
|
||||
return &theFactory.WDcontroller_;
|
||||
}
|
||||
|
||||
|
||||
//initialize all objects
|
||||
void Factory_init() {
|
||||
@ -54,6 +58,13 @@ void Factory_init() {
|
||||
CAN_init();
|
||||
CAN_setSender(1);
|
||||
LED_off(l1());
|
||||
|
||||
// TODO init EPROM interface
|
||||
|
||||
// TODO init watchdog with EPROM CST
|
||||
WATCHDOG_init(WDcontroller());
|
||||
CAR_CST.CONTROL_ALIVE_TIME = 10;
|
||||
WATCHDOG_setTime(WDcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
|
||||
}
|
||||
|
||||
void foo(uint8_t a, uint8_t b, uint32_t c){
|
||||
@ -69,9 +80,12 @@ void foo(uint8_t a, uint8_t b, uint32_t c){
|
||||
void Factory_build() {
|
||||
ECAN_SetRXBnInterruptHandler(CAN_newMsg);
|
||||
CAN_onReceiveCan(foo);
|
||||
|
||||
WATCHDOG_onAlive(WDcontroller(), CM_controller_alive, NULL);
|
||||
}
|
||||
|
||||
//start all state machines
|
||||
void Factory_start() {
|
||||
CAN_startBehaviour();
|
||||
WATCHDOG_startBehaviour(WDcontroller());
|
||||
}
|
||||
|
@ -12,9 +12,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../car.h"
|
||||
#include "../can_message.h"
|
||||
#include "../../board/led/led.h"
|
||||
#include "../../board/button/button.h"
|
||||
#include "../../middleware/alive_checker.h"
|
||||
#include "../../middleware/can_interface.h"
|
||||
#include "../../middleware/watchdog.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
@ -26,6 +30,8 @@ typedef struct {
|
||||
LED l6_;
|
||||
LED l7_;
|
||||
LED l8_;
|
||||
|
||||
WATCHDOG WDcontroller_;
|
||||
|
||||
} Factory;
|
||||
|
||||
@ -44,5 +50,7 @@ LED* l6();
|
||||
LED* l7();
|
||||
LED* l8();
|
||||
|
||||
WATCHDOG* WDcontroller();
|
||||
|
||||
|
||||
#endif
|
90
306-controller_interface.X/middleware/watchdog.c
Normal file
90
306-controller_interface.X/middleware/watchdog.c
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* @author Rémi Heredero
|
||||
* @version 1.0.0
|
||||
* @date August 2023
|
||||
* @file watchdog.c
|
||||
*/
|
||||
|
||||
#include "watchdog.h"
|
||||
|
||||
void WATCHDOG_init(WATCHDOG* me){
|
||||
me->state = STWD_INIT;
|
||||
me->time = 10;
|
||||
me->alive.f = NULL;
|
||||
}
|
||||
|
||||
void WATCHDOG_startBehaviour(WATCHDOG* me){
|
||||
POST(me, &WATCHDOG_processEvent, evWDinit, 0, 0);
|
||||
}
|
||||
|
||||
bool WATCHDOG_processEvent(Event* ev) {
|
||||
bool processed = false;
|
||||
WATCHDOG* me = (WATCHDOG*)Event_getTarget(ev);
|
||||
WATCHDOG_STATES oldState = me->state;
|
||||
evIDT evid = Event_getId(ev);
|
||||
uint64_t data = Event_getData(ev);
|
||||
|
||||
switch (me->state) { // onState
|
||||
case STWD_INIT:
|
||||
if (ev->id == evWDinit) {
|
||||
me->state = STWD_ALIVE;
|
||||
WATCHDOG_emitPoll(me, 10*me->time, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case STWD_ALIVE:
|
||||
if (ev->id == evWDpoll) {
|
||||
WATCHDOG_emitPoll(me, 10*me->time, 0);
|
||||
if (me->alive.f != NULL) {
|
||||
me->alive.f(me->alive.p);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(oldState != me->state){
|
||||
switch (oldState) { // onExit
|
||||
case STWD_INIT:
|
||||
break;
|
||||
|
||||
case STWD_ALIVE:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (me->state) { // onEntry
|
||||
case STWD_INIT:
|
||||
break;
|
||||
|
||||
case STWD_ALIVE:
|
||||
break;
|
||||
}
|
||||
|
||||
processed = true;
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
/*************
|
||||
* Callbacks *
|
||||
*************/
|
||||
|
||||
void WATCHDOG_onAlive(WATCHDOG* me, WATCHDOG_CALLBACK_FUNCTION f, void* p) {
|
||||
me->alive.f = f;
|
||||
me->alive.p = p;
|
||||
}
|
||||
|
||||
/************
|
||||
* EMITTERS *
|
||||
************/
|
||||
|
||||
void WATCHDOG_emitPoll(WATCHDOG* me, uint16_t t, int64_t data) {
|
||||
POST(me, &WATCHDOG_processEvent, evWDpoll, t, data);
|
||||
}
|
||||
|
||||
/***********
|
||||
* SETTERS *
|
||||
***********/
|
||||
|
||||
void WATCHDOG_setTime(WATCHDOG* me, uint8_t v) {
|
||||
me->time = v;
|
||||
}
|
83
306-controller_interface.X/middleware/watchdog.h
Normal file
83
306-controller_interface.X/middleware/watchdog.h
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @author Rémi Heredero
|
||||
* @version 1.0.0
|
||||
* @date August 2023
|
||||
* @file watchdog.h
|
||||
*/
|
||||
#ifndef WATCHDOG_H
|
||||
#define WATCHDOG_H
|
||||
|
||||
#include "../xf/xf.h"
|
||||
|
||||
typedef enum {
|
||||
STWD_INIT,
|
||||
STWD_ALIVE
|
||||
} WATCHDOG_STATES;
|
||||
|
||||
typedef enum {
|
||||
evWDinit = 20,
|
||||
evWDpoll
|
||||
} WATCHDOG_EVENTS;
|
||||
|
||||
typedef void (*WATCHDOG_CALLBACK_FUNCTION)(void*);
|
||||
typedef struct {
|
||||
WATCHDOG_CALLBACK_FUNCTION f; // function
|
||||
void* p; // param(s)
|
||||
} WATCHDOG_CALLBACK;
|
||||
|
||||
typedef struct {
|
||||
WATCHDOG_STATES state;
|
||||
uint8_t time;
|
||||
WATCHDOG_CALLBACK alive;
|
||||
} WATCHDOG;
|
||||
|
||||
/**
|
||||
* Initialize the WATCHDOG
|
||||
* @param me the WATCHDOG itself
|
||||
*/
|
||||
void WATCHDOG_init(WATCHDOG* me);
|
||||
|
||||
/**
|
||||
* Start the WATCHDOG state machine
|
||||
* @param me the WATCHDOG itself
|
||||
*/
|
||||
void WATCHDOG_startBehaviour(WATCHDOG* me);
|
||||
|
||||
/**
|
||||
* Process the event
|
||||
* @param ev the event to process
|
||||
* @return true if the event is processed
|
||||
*/
|
||||
bool WATCHDOG_processEvent(Event* ev);
|
||||
|
||||
/*************
|
||||
* Callbacks *
|
||||
*************/
|
||||
|
||||
/**
|
||||
* Set the callback function to call when the WATCHDOG is entering state alive
|
||||
* @param me the WATCHDOG itself
|
||||
* @param f the function to call
|
||||
* @param p the param(s) to pass to the function
|
||||
*/
|
||||
void WATCHDOG_onAlive(WATCHDOG* me, WATCHDOG_CALLBACK_FUNCTION f, void* p);
|
||||
|
||||
/************
|
||||
* EMITTERS *
|
||||
************/
|
||||
|
||||
/**
|
||||
* Emit the poll event
|
||||
* @param me the WATCHDOG itself
|
||||
* @param t time to wait in ms before triggering event
|
||||
* @param data data to put on the event for XF
|
||||
*/
|
||||
void WATCHDOG_emitPoll(WATCHDOG* me, uint16_t t, int64_t data);
|
||||
|
||||
/***********
|
||||
* SETTERS *
|
||||
***********/
|
||||
|
||||
void WATCHDOG_setTime(WATCHDOG* me, uint8_t v);
|
||||
|
||||
#endif
|
@ -7,6 +7,7 @@
|
||||
<logicalFolder name="app" displayName="app" projectFiles="true">
|
||||
<itemPath>app/factory/factory.h</itemPath>
|
||||
<itemPath>app/car.h</itemPath>
|
||||
<itemPath>app/can_message.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="board" displayName="board" projectFiles="true">
|
||||
<itemPath>board/led/led.h</itemPath>
|
||||
@ -25,6 +26,7 @@
|
||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||
<itemPath>middleware/can_interface.h</itemPath>
|
||||
<itemPath>middleware/alive_checker.h</itemPath>
|
||||
<itemPath>middleware/watchdog.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||
<itemPath>xf/event.h</itemPath>
|
||||
@ -41,6 +43,7 @@
|
||||
projectFiles="true">
|
||||
<logicalFolder name="app" displayName="app" projectFiles="true">
|
||||
<itemPath>app/factory/factory.c</itemPath>
|
||||
<itemPath>app/can_message.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="board" displayName="board" projectFiles="true">
|
||||
<itemPath>board/led/led.c</itemPath>
|
||||
@ -59,6 +62,7 @@
|
||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||
<itemPath>middleware/can_interface.c</itemPath>
|
||||
<itemPath>middleware/alive_checker.c</itemPath>
|
||||
<itemPath>middleware/watchdog.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||
<itemPath>xf/event.c</itemPath>
|
||||
@ -210,6 +214,7 @@
|
||||
<property key="debugoptions.debug-startup" value="Use system settings"/>
|
||||
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
|
||||
<property key="debugoptions.useswbreakpoints" value="false"/>
|
||||
<property key="firmware.download.all" value="false"/>
|
||||
<property key="hwtoolclock.frcindebug" value="false"/>
|
||||
<property key="memories.aux" value="false"/>
|
||||
<property key="memories.bootflash" value="true"/>
|
||||
@ -240,7 +245,7 @@
|
||||
<property key="programoptions.programcalmem" value="false"/>
|
||||
<property key="programoptions.programuserotp" value="false"/>
|
||||
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
|
||||
<property key="programoptions.usehighvoltageonmclr" value="false"/>
|
||||
<property key="programoptions.usehighvoltageonmclr" value="true"/>
|
||||
<property key="programoptions.uselvpprogramming" value="false"/>
|
||||
<property key="voltagevalue" value="5.0"/>
|
||||
</PICkit3PlatformTool>
|
||||
@ -285,7 +290,7 @@
|
||||
<property key="programoptions.programcalmem" value="false"/>
|
||||
<property key="programoptions.programuserotp" value="false"/>
|
||||
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
|
||||
<property key="programoptions.usehighvoltageonmclr" value="false"/>
|
||||
<property key="programoptions.usehighvoltageonmclr" value="true"/>
|
||||
<property key="programoptions.uselvpprogramming" value="false"/>
|
||||
<property key="voltagevalue" value="5.0"/>
|
||||
</Tool>
|
||||
|
Reference in New Issue
Block a user