diff --git a/306-controller_interface.X/app/can_message.c b/306-controller_interface.X/app/can_message.c
index 05f929a..2e5cca0 100644
--- a/306-controller_interface.X/app/can_message.c
+++ b/306-controller_interface.X/app/can_message.c
@@ -37,7 +37,7 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){
CAR_CST.CONTROL_ALIVE_TIME = tmpData.separate.byte3;
MEM_write_1_byte(MEMADD_CONTROL_STEERING_MODE, CAR_CST.CONTROL_STEERING_MODE);
MEM_write_1_byte(MEMADD_CONTROL_ALIVE_TIME, CAR_CST.CONTROL_ALIVE_TIME);
- WATCHDOG_setTime(WDcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
+ ALIVE_setAliveTime(ALcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
}
if(idMsg == 0x1) { // CONTROL_SPEED_FACTOR
@@ -78,7 +78,7 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){
MEM_write_1_byte(MEMADD_JOYSTICK_PARAM2, CAR_CST.JOYSTICK_PARAM2);
MEM_write_1_byte(MEMADD_JOYSTICK_ALIVE_TIME, CAR_CST.JOYSTICK_ALIVE_TIME);
- ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
+ ALIVE_setAliveTime(ALjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
CM_JOY_SETUP(NULL);
}
@@ -107,15 +107,15 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){
if(idMsg == 0xF) { // JOY_ALIVE
// - - - -
- ALIVE_CHECKER_ISALIVE(ACjoy());
- if(ACjoy()->state == STAC_DEAD){
+ ALIVE_ISALIVE(ALjoy());
+ if(ALjoy()->state == STAL_DEAD){
CAR_CST.JOYSTICK_MODE = MEM_read_1_byte(MEMADD_JOYSTICK_MODE);
CAR_CST.JOYSTICK_PARAM1 = MEM_read_1_byte(MEMADD_JOYSTICK_PARAM1);
CAR_CST.JOYSTICK_PARAM2 = MEM_read_1_byte(MEMADD_JOYSTICK_PARAM2);
CAR_CST.JOYSTICK_ALIVE_TIME = MEM_read_1_byte(MEMADD_JOYSTICK_ALIVE_TIME);
- ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
- ALIVE_CHECKER_emitBorn(ACjoy(), 0, 0);
- ALIVE_CHECKER_emitReady(ACjoy(), 100, 0);
+ ALIVE_setAliveTime(ALjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
+ ALIVE_emitBorn(ALjoy(), 0, 0);
+ ALIVE_emitReady(ALjoy(), 100, 0);
}
}
break;
diff --git a/306-controller_interface.X/app/factory/factory.c b/306-controller_interface.X/app/factory/factory.c
index 11b5ec4..fe819c8 100644
--- a/306-controller_interface.X/app/factory/factory.c
+++ b/306-controller_interface.X/app/factory/factory.c
@@ -30,12 +30,12 @@ LED* l8() {
return &theFactory.l8_;
}
-WATCHDOG* WDcontroller(){
- return &theFactory.WDcontroller_;
+ALIVE* ALcontroller(){
+ return &theFactory.ALcontroller_;
}
-ALIVE_CHECKER* ACjoy() {
- return &theFactory.ACjoy_;
+ALIVE* ALjoy(){
+ return &theFactory.ALjoy_;
}
@@ -67,10 +67,10 @@ void Factory_init() {
MEM_init();
// TODO init watchdog with EPROM CST
- WATCHDOG_init(WDcontroller());
- WATCHDOG_setTime(WDcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
+ ALIVE_init(ALcontroller());
+ ALIVE_setAliveTime(ALcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
- ALIVE_CHECKER_init(ACjoy());
+ ALIVE_init(ALjoy());
}
//connect objects if required
@@ -78,20 +78,22 @@ void Factory_build() {
ECAN_SetRXBnInterruptHandler(CAN_newMsg);
CAN_onReceiveCan(CM_processIncome);
- WATCHDOG_onAlive(WDcontroller(), CM_CONTROLLER_ALIVE, NULL);
- ALIVE_CHECKER_onSetup(ACjoy(), CM_JOY_SETUP, NULL);
- ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
- ALIVE_CHECKER_onBorn(ACjoy(), LED_on, l1());
- ALIVE_CHECKER_onDead(ACjoy(), LED_off, l1());
+ ALIVE_onAlive(ALcontroller(), CM_CONTROLLER_ALIVE, NULL);
+
+ ALIVE_onSetup(ALjoy(), CM_JOY_SETUP, NULL);
+ ALIVE_setAliveTime(ALjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
+ ALIVE_onBorn(ALjoy(), LED_on, l1());
+ ALIVE_onDead(ALjoy(), LED_off, l1());
}
//start all state machines
void Factory_start() {
CAN_startBehaviour();
- WATCHDOG_startBehaviour(WDcontroller());
- ALIVE_CHECKER_startBehaviour(ACjoy());
- ALIVE_CHECKER_emitBorn(ACjoy(), 100, 0);
- ALIVE_CHECKER_emitReady(ACjoy(), 200, 0);
+
+ ALIVE_startBehaviourSender(ALcontroller());
+ ALIVE_startBehaviourChecker(ALjoy());
+ ALIVE_emitBorn(ALjoy(), 100, 0);
+ ALIVE_emitReady(ALjoy(), 200, 0);
}
diff --git a/306-controller_interface.X/app/factory/factory.h b/306-controller_interface.X/app/factory/factory.h
index b847d38..bcbc830 100644
--- a/306-controller_interface.X/app/factory/factory.h
+++ b/306-controller_interface.X/app/factory/factory.h
@@ -16,9 +16,8 @@
#include "../can_message.h"
#include "../../board/led/led.h"
#include "../../board/button/button.h"
-#include "../../middleware/alive_checker.h"
+#include "../../middleware/alive.h"
#include "../../middleware/can_interface.h"
-#include "../../middleware/watchdog.h"
#include "../../middleware/eeprom.h"
@@ -32,8 +31,8 @@ typedef struct {
LED l7_;
LED l8_;
- WATCHDOG WDcontroller_;
- ALIVE_CHECKER ACjoy_;
+ ALIVE ALcontroller_;
+ ALIVE ALjoy_;
} Factory;
@@ -52,8 +51,8 @@ LED* l6();
LED* l7();
LED* l8();
-WATCHDOG* WDcontroller();
-ALIVE_CHECKER* ACjoy();
+ALIVE* ALcontroller();
+ALIVE* ALjoy();
#endif
\ No newline at end of file
diff --git a/306-controller_interface.X/main.c b/306-controller_interface.X/main.c
index 6a05435..d81327c 100644
--- a/306-controller_interface.X/main.c
+++ b/306-controller_interface.X/main.c
@@ -10,8 +10,6 @@ void main(void)
// Initialize the device
SYSTEM_Initialize();
- // Enable the Global Interrupts
- INTERRUPT_GlobalInterruptEnable();
// Disable the Global Interrupts
// INTERRUPT_GlobalInterruptDisable();
@@ -29,6 +27,8 @@ void main(void)
// TMR0 is interrupting. Important: Set the TICKINTERVAL define in
//the xf.h file to the same value as the TMR0 value.
TMR0_SetInterruptHandler(XF_decrementAndQueueTimers);
+ // Enable the Global Interrupts
+ INTERRUPT_GlobalInterruptEnable();
while (1)
{
diff --git a/306-controller_interface.X/middleware/alive.c b/306-controller_interface.X/middleware/alive.c
new file mode 100644
index 0000000..146e9f3
--- /dev/null
+++ b/306-controller_interface.X/middleware/alive.c
@@ -0,0 +1,259 @@
+/**
+ * @author Rémi Heredero
+ * @version 1.0.0
+ * @date August 2023
+ * @file alive.c
+ */
+
+#include "alive.h"
+
+void ALIVE_init(ALIVE* me){
+ me->state = STAL_INIT;
+ me->isAlive = false;
+ me->checker = false;
+ me->sender = false;
+ me->haveBreak = true;
+ me->aliveTime = 10;
+ me->setup.f = NULL;
+ me->born.f = NULL;
+ me->wait.f = NULL;
+ me->dead.f = NULL;
+ me->alive.f = NULL;
+ me->break_cb.f = NULL;
+}
+
+void ALIVE_startBehaviourChecker(ALIVE* me){
+ POST(me, &ALIVE_processEvent, evALinitChecker, 0, 0);
+}
+
+void ALIVE_startBehaviourSender(ALIVE* me){
+ POST(me, &ALIVE_processEvent, evALinitSender, 0, 0);
+}
+
+bool ALIVE_processEvent(Event* ev) {
+ bool processed = false;
+ ALIVE* me = (ALIVE*)Event_getTarget(ev);
+ ALIVE_STATES oldState = me->state;
+ evIDT evid = Event_getId(ev);
+ uint64_t data = Event_getData(ev);
+
+ switch (me->state) { // onState
+ case STAL_INIT:
+ if (ev->id == evALinitChecker) {
+ me->state = STAL_SETUP;
+ }
+ if (ev->id == evALinitSender) {
+ me->state = STAL_ALIVE;
+ ALIVE_emitPoll(me, me->aliveTime*10, 0);
+ }
+ break;
+
+ case STAL_SETUP:
+ if (ev->id == evALborn) {
+ me->state = STAL_BORN;
+ }
+ break;
+
+ case STAL_BORN:
+ if (ev->id == evALready) {
+ me->state = STAL_WAIT;
+ ALIVE_emitPoll(me, me->aliveTime*10, 0);
+ }
+ break;
+
+ case STAL_WAIT:
+ if (ev->id == evALpoll) {
+
+ if (me->aliveTime == 0) {
+ if (me->haveBreak){
+ me->state = STAL_BREAK;
+ }
+ } else if (me->isAlive){
+ me->state = STAL_WAIT;
+ ALIVE_emitPoll(me, me->aliveTime*10, 0);
+ } else {
+ me->state = STAL_DEAD;
+ }
+ me->isAlive = false;
+
+ }
+ break;
+
+ case STAL_DEAD:
+ if (ev->id == evALborn) {
+ me->state = STAL_BORN;
+ }
+ break;
+
+ case STAL_ALIVE:
+ if (ev->id == evALpoll) {
+ if (me->alive.f != NULL) {
+ me->alive.f(me->alive.p);
+ }
+ if (me->aliveTime == 0) {
+ if (me->haveBreak){
+ me->state == STAL_BREAK;
+ }
+ } else {
+ ALIVE_emitPoll(me, me->aliveTime*10, 0);
+ }
+ }
+ break;
+
+ case STAL_BREAK:
+ if (ev->id == evALstart) {
+ ALIVE_emitPoll(me, me->aliveTime*10, 0);
+ if (me->checker) {
+ me->state = STAL_WAIT;
+ }
+ if (me->sender) {
+ me->state = STAL_ALIVE;
+ }
+ }
+ break;
+ }
+
+ if(oldState != me->state){
+ switch (oldState) { // onExit
+ case STAL_INIT:
+ break;
+
+ case STAL_SETUP:
+ break;
+
+ case STAL_BORN:
+ break;
+
+ case STAL_WAIT:
+ break;
+
+ case STAL_DEAD:
+ break;
+
+ case STAL_ALIVE:
+ break;
+
+ case STAL_BREAK:
+ break;
+ }
+
+ switch (me->state) { // onEntry
+ case STAL_INIT:
+ break;
+
+ case STAL_SETUP:
+ if (me->setup.f != NULL) {
+ me->setup.f(me->setup.p);
+ }
+ break;
+
+ case STAL_BORN:
+ if (me->born.f != NULL) {
+ me->born.f(me->born.p);
+ }
+ break;
+
+ case STAL_WAIT:
+ if (me->wait.f != NULL) {
+ me->wait.f(me->wait.p);
+ }
+ break;
+
+ case STAL_DEAD:
+ if (me->dead.f != NULL) {
+ me->dead.f(me->dead.p);
+ }
+ break;
+
+ case STAL_ALIVE:
+ break;
+
+ case STAL_BREAK:
+ if (me->break_cb.f != NULL) {
+ me->break_cb.f(me->break_cb.p);
+ }
+ break;
+ }
+
+ processed = true;
+ }
+ return processed;
+}
+
+/*************
+ * Callbacks *
+ *************/
+
+void ALIVE_onSetup(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) {
+ me->setup.f = f;
+ me->setup.p = p;
+}
+
+void ALIVE_onBorn(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) {
+ me->born.f = f;
+ me->born.p = p;
+}
+
+void ALIVE_onWait(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) {
+ me->wait.f = f;
+ me->wait.p = p;
+}
+
+void ALIVE_onDead(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) {
+ me->dead.f = f;
+ me->dead.p = p;
+}
+
+void ALIVE_onAlive(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) {
+ me->alive.f = f;
+ me->alive.p = p;
+}
+
+void ALIVE_onBreak(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) {
+ me->break_cb.f = f;
+ me->break_cb.p = p;
+}
+
+/************
+ * EMITTERS *
+ ************/
+
+void ALIVE_emitInitSender(ALIVE* me, uint16_t t, int64_t data) {
+ POST(me, &ALIVE_processEvent, evALinitSender, t, data);
+}
+
+void ALIVE_emitBorn(ALIVE* me, uint16_t t, int64_t data) {
+ POST(me, &ALIVE_processEvent, evALborn, t, data);
+}
+
+void ALIVE_emitReady(ALIVE* me, uint16_t t, int64_t data) {
+ POST(me, &ALIVE_processEvent, evALready, t, data);
+}
+
+void ALIVE_emitPoll(ALIVE* me, uint16_t t, int64_t data) {
+ POST(me, &ALIVE_processEvent, evALpoll, t, data);
+}
+
+void ALIVE_emitStart(ALIVE* me, uint16_t t, int64_t data) {
+ POST(me, &ALIVE_processEvent, evALstart, t, data);
+}
+
+/***********
+ * SETTERS *
+ ***********/
+
+void ALIVE_setIsAlive(ALIVE* me, bool v) {
+ me->isAlive = v;
+}
+
+void ALIVE_setHaveBreak(ALIVE* me, bool v) {
+ me->haveBreak = v;
+}
+
+void ALIVE_setAliveTime(ALIVE* me, uint8_t v) {
+ me->aliveTime = v;
+}
+
+void ALIVE_ISALIVE(ALIVE* me) {
+ ALIVE_setIsAlive(me, true);
+}
diff --git a/306-controller_interface.X/middleware/alive.h b/306-controller_interface.X/middleware/alive.h
new file mode 100644
index 0000000..749d9a9
--- /dev/null
+++ b/306-controller_interface.X/middleware/alive.h
@@ -0,0 +1,178 @@
+/**
+ * @author Rémi Heredero
+ * @version 1.0.0
+ * @date August 2023
+ * @file alive.h
+ */
+#ifndef ALIVE_H
+#define ALIVE_H
+
+#include "../xf/xf.h"
+
+typedef enum {
+ STAL_INIT,
+ STAL_SETUP,
+ STAL_BORN,
+ STAL_WAIT,
+ STAL_DEAD,
+ STAL_ALIVE,
+ STAL_BREAK
+} ALIVE_STATES;
+
+typedef enum {
+ evALinitChecker = 15,
+ evALinitSender,
+ evALborn,
+ evALready,
+ evALpoll,
+ evALstart
+} ALIVE_EVENTS;
+
+typedef void (*ALIVE_CALLBACK_FUNCTION)(void*);
+typedef struct {
+ ALIVE_CALLBACK_FUNCTION f; // function
+ void* p; // param(s)
+} ALIVE_CALLBACK;
+
+typedef struct {
+ ALIVE_STATES state;
+ bool isAlive;
+ bool checker;
+ bool sender;
+ bool haveBreak;
+ uint8_t aliveTime;
+ ALIVE_CALLBACK setup;
+ ALIVE_CALLBACK born;
+ ALIVE_CALLBACK wait;
+ ALIVE_CALLBACK dead;
+ ALIVE_CALLBACK alive;
+ ALIVE_CALLBACK break_cb;
+} ALIVE;
+
+/**
+ * Initialize the ALIVE
+ * @param me the ALIVE itself
+ */
+void ALIVE_init(ALIVE* me);
+
+/**
+ * Start the ALIVE state machine for checker part
+ * @param me the ALIVE itself
+ */
+void ALIVE_startBehaviourChecker(ALIVE* me);
+
+/**
+ * Start the ALIVE state machine for sender part
+ * @param me the ALIVE itself
+ */
+void ALIVE_startBehaviourSender(ALIVE* me);
+
+/**
+ * Process the event
+ * @param ev the event to process
+ * @return true if the event is processed
+ */
+bool ALIVE_processEvent(Event* ev);
+
+/*************
+ * Callbacks *
+ *************/
+
+/**
+ * Set the callback function to call when the ALIVE is entering state setup
+ * @param me the ALIVE itself
+ * @param f the function to call
+ * @param p the param(s) to pass to the function
+ */
+void ALIVE_onSetup(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p);
+
+/**
+ * Set the callback function to call when the ALIVE is entering state born
+ * @param me the ALIVE itself
+ * @param f the function to call
+ * @param p the param(s) to pass to the function
+ */
+void ALIVE_onBorn(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p);
+
+/**
+ * Set the callback function to call when the ALIVE is entering state wait
+ * @param me the ALIVE itself
+ * @param f the function to call
+ * @param p the param(s) to pass to the function
+ */
+void ALIVE_onWait(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p);
+
+/**
+ * Set the callback function to call when the ALIVE is entering state dead
+ * @param me the ALIVE itself
+ * @param f the function to call
+ * @param p the param(s) to pass to the function
+ */
+void ALIVE_onDead(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p);
+
+/**
+ * Set the callback function to call when the ALIVE is entering state alive
+ * @param me the ALIVE itself
+ * @param f the function to call
+ * @param p the param(s) to pass to the function
+ */
+void ALIVE_onAlive(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p);
+
+/**
+ * Set the callback function to call when the ALIVE is entering state break
+ * @param me the ALIVE itself
+ * @param f the function to call
+ * @param p the param(s) to pass to the function
+ */
+void ALIVE_onBreak(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p);
+
+/************
+ * EMITTERS *
+ ************/
+
+/**
+ * Emit the born event
+ * @param me the ALIVE itself
+ * @param t time to wait in ms before triggering event
+ * @param data data to put on the event for XF
+ */
+void ALIVE_emitBorn(ALIVE* me, uint16_t t, int64_t data);
+
+/**
+ * Emit the ready event
+ * @param me the ALIVE itself
+ * @param t time to wait in ms before triggering event
+ * @param data data to put on the event for XF
+ */
+void ALIVE_emitReady(ALIVE* me, uint16_t t, int64_t data);
+
+/**
+ * Emit the poll event
+ * @param me the ALIVE itself
+ * @param t time to wait in ms before triggering event
+ * @param data data to put on the event for XF
+ */
+void ALIVE_emitPoll(ALIVE* me, uint16_t t, int64_t data);
+
+/**
+ * Emit the start event
+ * @param me the ALIVE itself
+ * @param t time to wait in ms before triggering event
+ * @param data data to put on the event for XF
+ */
+void ALIVE_emitStart(ALIVE* me, uint16_t t, int64_t data);
+
+
+/***********
+ * SETTERS *
+ ***********/
+
+void ALIVE_setIsAlive(ALIVE* me, bool v);
+
+void ALIVE_setHaveBreak(ALIVE* me, bool v);
+
+void ALIVE_setAliveTime(ALIVE* me, uint8_t v);
+
+void ALIVE_ISALIVE(ALIVE* me);
+
+#endif
diff --git a/306-controller_interface.X/middleware/alive_checker.c b/306-controller_interface.X/middleware/alive_checker.c
deleted file mode 100644
index 00466a4..0000000
--- a/306-controller_interface.X/middleware/alive_checker.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * @author Rémi Heredero
- * @version 1.0.0
- * @date August 2023
- * @file alive_checker.c
- */
-
-#include "alive_checker.h"
-
-void ALIVE_CHECKER_init(ALIVE_CHECKER* me){
- me->state = STAC_INIT;
- me->isAlive = false;
- me->aliveTime = 10;
- me->setup.f = NULL;
- me->born.f = NULL;
- me->wait.f = NULL;
- me->dead.f = NULL;
-}
-
-void ALIVE_CHECKER_startBehaviour(ALIVE_CHECKER* me){
- POST(me, &ALIVE_CHECKER_processEvent, evACinit, 0, 0);
-}
-
-bool ALIVE_CHECKER_processEvent(Event* ev) {
- bool processed = false;
- ALIVE_CHECKER* me = (ALIVE_CHECKER*)Event_getTarget(ev);
- ALIVE_CHECKER_STATES oldState = me->state;
- evIDT evid = Event_getId(ev);
- uint64_t data = Event_getData(ev);
-
- switch (me->state) { // onState
- case STAC_INIT:
- if (ev->id == evACinit) {
- me->state = STAC_SETUP;
- }
- break;
-
- case STAC_SETUP:
- if (ev->id == evACborn) {
- me->state = STAC_BORN;
- }
- break;
-
- case STAC_BORN:
- if (ev->id == evACready) {
- me->state = STAC_WAIT;
- ALIVE_CHECKER_emitPoll(me, me->aliveTime*10, 0);
- }
- break;
-
- case STAC_WAIT:
- if (ev->id == evACpoll) {
- if (me->isAlive) {
- me->state = STAC_WAIT;
- ALIVE_CHECKER_emitPoll(me, me->aliveTime*10, 0);
- } else {
- me->state = STAC_DEAD;
- }
- me->isAlive = false;
- }
- break;
-
- case STAC_DEAD:
- if(ev->id == evACborn) {
- me->state = STAC_BORN;
- }
- break;
- }
-
- if(oldState != me->state){
- switch (oldState) { // onExit
- case STAC_INIT:
- break;
-
- case STAC_SETUP:
- break;
-
- case STAC_BORN:
- break;
-
- case STAC_WAIT:
- break;
-
- case STAC_DEAD:
- break;
- }
-
- switch (me->state) { // onEntry
- case STAC_INIT:
- break;
-
- case STAC_SETUP:
- if (me->setup.f != NULL) {
- me->setup.f(me->setup.p);
- }
- break;
-
- case STAC_BORN:
- if (me->born.f != NULL) {
- me->born.f(me->born.p);
- }
- break;
-
- case STAC_WAIT:
- if (me->wait.f != NULL) {
- me->wait.f(me->wait.p);
- }
- break;
-
- case STAC_DEAD:
- if (me->dead.f != NULL) {
- me->dead.f(me->dead.p);
- }
- break;
- }
-
- processed = true;
- }
- return processed;
-}
-
-/*************
- * Callbacks *
- *************/
-
-void ALIVE_CHECKER_onSetup(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p) {
- me->setup.f = f;
- me->setup.p = p;
-}
-
-void ALIVE_CHECKER_onBorn(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p) {
- me->born.f = f;
- me->born.p = p;
-}
-
-void ALIVE_CHECKER_onWait(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p) {
- me->wait.f = f;
- me->wait.p = p;
-}
-
-void ALIVE_CHECKER_onDead(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p) {
- me->dead.f = f;
- me->dead.p = p;
-}
-
-/************
- * EMITTERS *
- ************/
-
-void ALIVE_CHECKER_emitBorn(ALIVE_CHECKER* me, uint16_t t, int64_t data) {
- POST(me, &ALIVE_CHECKER_processEvent, evACborn, t, data);
-}
-
-void ALIVE_CHECKER_emitReady(ALIVE_CHECKER* me, uint16_t t, int64_t data) {
- POST(me, &ALIVE_CHECKER_processEvent, evACready, t, data);
-}
-
-void ALIVE_CHECKER_emitPoll(ALIVE_CHECKER* me, uint16_t t, int64_t data) {
- POST(me, &ALIVE_CHECKER_processEvent, evACpoll, t, data);
-}
-
-/***********
- * SETTERS *
- ***********/
-
-void ALIVE_CHECKER_setAliveTime(ALIVE_CHECKER* me, uint8_t v) {
- me->aliveTime = v;
-}
-
-void ALIVE_CHECKER_setIsAlive(ALIVE_CHECKER* me, bool v) {
- me->isAlive = v;
-}
-
-void ALIVE_CHECKER_ISALIVE(ALIVE_CHECKER* me) {
- ALIVE_CHECKER_setIsAlive(me, true);
-}
diff --git a/306-controller_interface.X/middleware/alive_checker.h b/306-controller_interface.X/middleware/alive_checker.h
deleted file mode 100644
index 6b57ac7..0000000
--- a/306-controller_interface.X/middleware/alive_checker.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * @author Rémi Heredero
- * @version 1.0.0
- * @date August 2023
- * @file alive_checker.h
- */
-#ifndef ALIVE_CHECKER_H
-#define ALIVE_CHECKER_H
-
-#include "../xf/xf.h"
-
-typedef enum {
- STAC_INIT,
- STAC_SETUP,
- STAC_BORN,
- STAC_WAIT,
- STAC_DEAD
-} ALIVE_CHECKER_STATES;
-
-typedef enum {
- evACinit = 15,
- evACborn,
- evACready,
- evACpoll
-} ALIVE_CHECKER_EVENTS;
-
-typedef void (*ALIVE_CHECKER_CALLBACK_FUNCTION)(void*);
-typedef struct {
- ALIVE_CHECKER_CALLBACK_FUNCTION f; // function
- void* p; // param(s)
-} ALIVE_CHECKER_CALLBACK;
-
-typedef struct {
- ALIVE_CHECKER_STATES state;
- bool isAlive;
- uint8_t aliveTime;
- ALIVE_CHECKER_CALLBACK setup;
- ALIVE_CHECKER_CALLBACK born;
- ALIVE_CHECKER_CALLBACK wait;
- ALIVE_CHECKER_CALLBACK dead;
-} ALIVE_CHECKER;
-
-/**
- * Initialize the ALIVE_CHECKER
- * @param me the ALIVE_CHECKER itself
- */
-void ALIVE_CHECKER_init(ALIVE_CHECKER* me);
-
-/**
- * Start the ALIVE_CHECKER state machine
- * @param me the ALIVE_CHECKER itself
- */
-void ALIVE_CHECKER_startBehaviour(ALIVE_CHECKER* me);
-
-/**
- * Process the event
- * @param ev the event to process
- * @return true if the event is processed
- */
-bool ALIVE_CHECKER_processEvent(Event* ev);
-
-/*************
- * Callbacks *
- *************/
-
-/**
- * Set the callback function to call when the ALIVE_CHECKER is entering state setup
- * @param me the ALIVE_CHECKER itself
- * @param f the function to call
- * @param p the param(s) to pass to the function
- */
-void ALIVE_CHECKER_onSetup(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p);
-
-/**
- * Set the callback function to call when the ALIVE_CHECKER is entering state born
- * @param me the ALIVE_CHECKER itself
- * @param f the function to call
- * @param p the param(s) to pass to the function
- */
-void ALIVE_CHECKER_onBorn(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p);
-
-/**
- * Set the callback function to call when the ALIVE_CHECKER is entering state wait
- * @param me the ALIVE_CHECKER itself
- * @param f the function to call
- * @param p the param(s) to pass to the function
- */
-void ALIVE_CHECKER_onWait(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p);
-
-/**
- * Set the callback function to call when the ALIVE_CHECKER is entering state dead
- * @param me the ALIVE_CHECKER itself
- * @param f the function to call
- * @param p the param(s) to pass to the function
- */
-void ALIVE_CHECKER_onDead(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p);
-
-/************
- * EMITTERS *
- ************/
-
-/**
- * Emit the born event
- * @param me the ALIVE_CHECKER itself
- * @param t time to wait in ms before triggering event
- * @param data data to put on the event for XF
- */
-void ALIVE_CHECKER_emitBorn(ALIVE_CHECKER* me, uint16_t t, int64_t data);
-
-/**
- * Emit the ready event
- * @param me the ALIVE_CHECKER itself
- * @param t time to wait in ms before triggering event
- * @param data data to put on the event for XF
- */
-void ALIVE_CHECKER_emitReady(ALIVE_CHECKER* me, uint16_t t, int64_t data);
-
-/**
- * Emit the poll event
- * @param me the ALIVE_CHECKER itself
- * @param t time to wait in ms before triggering event
- * @param data data to put on the event for XF
- */
-void ALIVE_CHECKER_emitPoll(ALIVE_CHECKER* me, uint16_t t, int64_t data);
-
-/***********
- * SETTERS *
- ***********/
-
-void ALIVE_CHECKER_setAliveTime(ALIVE_CHECKER* me, uint8_t v);
-void ALIVE_CHECKER_setIsAlive(ALIVE_CHECKER* me, bool v);
-void ALIVE_CHECKER_ISALIVE(ALIVE_CHECKER* me); // Use this one when you receive CAN message
-
-#endif
diff --git a/306-controller_interface.X/middleware/watchdog.c b/306-controller_interface.X/middleware/watchdog.c
deleted file mode 100644
index 5840bf5..0000000
--- a/306-controller_interface.X/middleware/watchdog.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * @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;
-}
diff --git a/306-controller_interface.X/middleware/watchdog.h b/306-controller_interface.X/middleware/watchdog.h
deleted file mode 100644
index ed2d184..0000000
--- a/306-controller_interface.X/middleware/watchdog.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * @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
diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml
index 81887fd..28707ef 100644
--- a/306-controller_interface.X/nbproject/configurations.xml
+++ b/306-controller_interface.X/nbproject/configurations.xml
@@ -26,8 +26,7 @@
middleware/can_interface.h
- middleware/alive_checker.h
- middleware/watchdog.h
+ middleware/alive.h
xf/event.h
@@ -63,8 +62,7 @@
middleware/can_interface.c
- middleware/alive_checker.c
- middleware/watchdog.c
+ middleware/alive.c
xf/event.c
@@ -94,7 +92,7 @@
PICkit3PlatformTool
XC8
2.41
- 2
+ 3
diff --git a/UML/alive.pdf b/UML/alive.pdf
index 75b99e5..47870de 100644
Binary files a/UML/alive.pdf and b/UML/alive.pdf differ
diff --git a/UML/alive.uxf b/UML/alive.uxf
index e54aa37..f68ad3c 100644
--- a/UML/alive.uxf
+++ b/UML/alive.uxf
@@ -1,13 +1,13 @@
- 15
+ 14
UMLSpecialState
- 510
- 30
- 30
- 30
+ 714
+ 28
+ 56
+ 56
type=initial
@@ -15,47 +15,48 @@
Relation
- 510
- 45
- 90
- 105
+ 462
+ 70
+ 308
+ 154
lt=->
-evInit
- 10.0;10.0;10.0;50.0
+evInitChecker
+ 200.0;10.0;200.0;50.0;10.0;50.0;10.0;90.0
UMLState
- 390
- 120
- 285
- 90
+ 350
+ 196
+ 266
+ 112
SETUP
--
-/entry: sendParamsOnCan
+/entry: sendParamsOnCan
+/entry: checker = true
Relation
- 510
- 195
- 105
- 105
+ 462
+ 294
+ 98
+ 98
lt=->
-evBorn
+m1=evBorn
10.0;10.0;10.0;50.0
UMLState
- 390
- 270
- 285
- 90
+ 350
+ 364
+ 266
+ 84
BORN
--
@@ -65,10 +66,10 @@ evBorn
UMLState
- 390
- 420
- 285
- 120
+ 350
+ 504
+ 266
+ 112
WAIT
--
@@ -80,22 +81,22 @@ isAlive = false
Relation
- 510
- 345
- 120
- 105
+ 462
+ 434
+ 112
+ 98
lt=->
-evReady
+m1=evReady
10.0;10.0;10.0;50.0
UMLState
- 390
- 720
- 285
- 90
+ 350
+ 784
+ 266
+ 84
DEAD
--
@@ -105,94 +106,166 @@ evReady
Relation
- 510
- 525
- 105
- 105
-
- lt=->
-evPoll
- 10.0;10.0;10.0;50.0
-
-
- UMLSpecialState
-
- 495
- 600
- 60
- 60
-
- type=decision
-
-
-
- Relation
-
- 510
- 645
- 90
- 105
-
- lt=->
-m1=[else]
- 10.0;10.0;10.0;50.0
-
-
- Relation
-
- 315
- 465
+ 280
+ 546
210
- 210
+ 182
lt=->
-m1=[isAlive]
- 120.0;110.0;10.0;110.0;10.0;10.0;50.0;10.0
+m1=evPoll\n[isAlive]
+ 80.0;50.0;80.0;110.0;10.0;110.0;10.0;10.0;50.0;10.0
Relation
- 660
- 135
- 210
- 405
+ 224
+ 392
+ 336
+ 560
lt=->
-evDisable
- 10.0;250.0;60.0;250.0;60.0;10.0;10.0;10.0
-
-
- Relation
-
- 255
- 300
- 300
- 600
-
- lt=->
-evBorn
+m1=evBorn
180.0;340.0;180.0;380.0;10.0;380.0;10.0;10.0;90.0;10.0
Relation
- 660
- 495
- 120
- 315
+ 462
+ 602
+ 112
+ 210
- lt=-
- 10.0;190.0;60.0;190.0;60.0;10.0
+ lt=->
+m1=evPoll\n[default]
+ 10.0;10.0;10.0;130.0
Relation
- 660
- 315
- 120
- 45
+ 728
+ 70
+ 308
+ 154
- lt=-
- 10.0;10.0;60.0;10.0
+ lt=->
+evInitSender
+ 10.0;10.0;10.0;50.0;200.0;50.0;200.0;90.0
+
+
+ Relation
+
+ 784
+ 252
+ 224
+ 140
+
+ lt=->
+m1=evPoll\n[else]
+ 100.0;40.0;100.0;70.0;10.0;70.0;10.0;10.0;60.0;10.0
+
+
+ UMLNote
+
+ 784
+ 28
+ 140
+ 56
+
+ read time on
+EPROM
+
+
+
+ UMLState
+
+ 868
+ 196
+ 266
+ 112
+
+ ALIVE
+--
+\entry: sender = true
+--
+sendAliveOnCan
+
+
+
+ UMLState
+
+ 868
+ 518
+ 266
+ 84
+
+ lt=..
+BREAK
+-..
+
+
+
+
+ Relation
+
+ 994
+ 294
+ 210
+ 252
+
+ lt=..>
+m1=evPoll\n[time==0]\n[haveBreak]
+ 60.0;10.0;60.0;110.0;10.0;110.0;10.0;160.0
+
+
+ Relation
+
+ 560
+ 546
+ 336
+ 182
+
+ lt=..>
+m1=evPoll\n[time==0]\n[haveBreak]
+ 10.0;50.0;10.0;110.0;90.0;110.0;170.0;10.0;220.0;10.0
+
+
+ Relation
+
+ 602
+ 546
+ 420
+ 182
+
+ lt=..>
+m1=evStart\n[checker]
+ 220.0;40.0;220.0;110.0;140.0;110.0;60.0;10.0;10.0;10.0
+
+
+ Relation
+
+ 1078
+ 252
+ 182
+ 476
+
+ lt=..>
+m1=evStart\n[sender]
+ 10.0;250.0;10.0;320.0;110.0;320.0;110.0;10.0;40.0;10.0
+
+
+ UMLNote
+
+ 868
+ 728
+ 266
+ 154
+
+ lt=..
+break part can be disable
+with setHaveBreak(false)
+
+not all childrens have a break
+for time at 0
+
diff --git a/UML/can_sequence.png b/UML/can_sequence.png
new file mode 100644
index 0000000..22a7e70
Binary files /dev/null and b/UML/can_sequence.png differ