84 lines
1.6 KiB
C
84 lines
1.6 KiB
C
/**
|
|
* @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
|