/** * @author Rémi Heredero * @version 1.0.0 * @date August 2023 * @file can_interface.h */ #ifndef CANINTERFACE_H #define CANINTERFACE_H #include "../xf/xf.h" typedef enum { STCA_INIT, STCA_WAIT, STCA_READ } CANINTERFACE_STATES; typedef enum { evCAinit = 10, // TODO change this number (< 256) evCAnewMsg, evCAdone } CANINTERFACE_EVENTS; typedef void (*CANINTERFACE_CALLBACK_FUNCTION)(void*); typedef void (*CANINTERFACE_CALLBACK_CAN)(uint32_t, uint32_t); typedef struct { CANINTERFACE_CALLBACK_FUNCTION f; // function void* p; // param(s) } CANINTERFACE_CALLBACK; typedef struct { CANINTERFACE_STATES state; CANINTERFACE_CALLBACK wait; CANINTERFACE_CALLBACK read; CANINTERFACE_CALLBACK_CAN processCan; } CANINTERFACE; CANINTERFACE CANINTERFACE_myself; /** * Initialize the CANINTERFACE * @param me the CANINTERFACE itself */ void CANINTERFACE_init(); /** * Start the CANINTERFACE state machine * @param me the CANINTERFACE itself */ void CANINTERFACE_startBehaviour(); /** * Handler for receiving new can message during. * This function is done during interrupt */ void CANINTERFACE_newMsg(); /** * Process the event * @param ev the event to process * @return true if the event is processed */ bool CANINTERFACE_processEvent(Event* ev); /************* * Callbacks * *************/ /** * Set the callback function to call when the CANINTERFACE is entering state wait * @param me the CANINTERFACE itself * @param f the function to call * @param p the param(s) to pass to the function */ void CANINTERFACE_onWait(CANINTERFACE_CALLBACK_FUNCTION f, void* p); /** * Set the callback function to call when the CANINTERFACE is entering state read * @param me the CANINTERFACE itself * @param f the function to call * @param p the param(s) to pass to the function */ void CANINTERFACE_onRead(CANINTERFACE_CALLBACK_FUNCTION f, void* p); /** * Set the callback function to call when the CANINTERFACE is entering state read * @param f the function to call */ void CANINTERFACE_onProcessCan(CANINTERFACE_CALLBACK_CAN f); /************ * EMITTERS * ************/ /** * Emit the NewMsg event * @param me the CANINTERFACE itself * @param t time to wait in ms before triggering event */void CANINTERFACE_emitNewMsg(uint16_t t); #endif