WIP CAN sender
This commit is contained in:
parent
146fc9011e
commit
6734467031
@ -52,7 +52,7 @@ void Factory_build() {
|
|||||||
ButtonSM_setObserver(bsm(), blc(), &BLControl_onButton);
|
ButtonSM_setObserver(bsm(), blc(), &BLControl_onButton);
|
||||||
|
|
||||||
ECAN_SetRXBnInterruptHandler(CANINTERFACE_newMsg);
|
ECAN_SetRXBnInterruptHandler(CANINTERFACE_newMsg);
|
||||||
CANINTERFACE_onProcessCan(foo);
|
//CANINTERFACE_onProcessCan(foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//start all state machines
|
//start all state machines
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
void CANINTERFACE_init(){
|
void CANINTERFACE_init(){
|
||||||
CANINTERFACE_myself.wait.f = NULL;
|
CANINTERFACE_myself.wait.f = NULL;
|
||||||
CANINTERFACE_myself.read.f = NULL;
|
CANINTERFACE_myself.read.f = NULL;
|
||||||
CANINTERFACE_myself.processCan = NULL;
|
//CANINTERFACE_myself.processCan = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANINTERFACE_startBehaviour(){
|
void CANINTERFACE_startBehaviour(){
|
||||||
|
107
306-controller_interface.X/middleware/can/can_sender.c
Normal file
107
306-controller_interface.X/middleware/can/can_sender.c
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
* @author Rémi Heredero
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date August 2023
|
||||||
|
* @file can_sender.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "can_sender.h"
|
||||||
|
|
||||||
|
void CAN_SENDER_init(CAN_SENDER* me){
|
||||||
|
me->state = STCS_INIT;
|
||||||
|
me->sendingTime = 1;
|
||||||
|
me->wait.f = NULL;
|
||||||
|
me->send.f = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAN_SENDER_startBehaviour(CAN_SENDER* me){
|
||||||
|
POST(me, &CAN_SENDER_processEvent, evCSinit, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CAN_SENDER_processEvent(Event* ev) {
|
||||||
|
bool processed = false;
|
||||||
|
CAN_SENDER* me = (CAN_SENDER*)Event_getTarget(ev);
|
||||||
|
CAN_SENDER_STATES oldState = me->state;
|
||||||
|
evIDT evid = Event_getId(ev);
|
||||||
|
|
||||||
|
switch (me->state) { // onState
|
||||||
|
case STCS_INIT:
|
||||||
|
if (ev->id == evCSinit) {
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCS_WAIT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCS_SEND:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(oldState != me->state){
|
||||||
|
switch (oldState) { // onExit
|
||||||
|
case STCS_INIT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCS_WAIT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCS_SEND:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (me->state) { // onEntry
|
||||||
|
case STCS_INIT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCS_WAIT:
|
||||||
|
if (me->wait.f != NULL) {
|
||||||
|
me->wait.f(me->wait.p);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCS_SEND:
|
||||||
|
if (me->send.f != NULL) {
|
||||||
|
me->send.f(me->send.p);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
processed = true;
|
||||||
|
}
|
||||||
|
return processed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************
|
||||||
|
* Callbacks *
|
||||||
|
*************/
|
||||||
|
|
||||||
|
void CAN_SENDER_onWait(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p) {
|
||||||
|
me->wait.f = f;
|
||||||
|
me->wait.p = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAN_SENDER_onSend(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p) {
|
||||||
|
me->send.f = f;
|
||||||
|
me->send.p = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************
|
||||||
|
* EMITTERS *
|
||||||
|
************/
|
||||||
|
|
||||||
|
void CAN_SENDER_emitSend(CAN_SENDER* me, uint16_t t) {
|
||||||
|
POST(me, &CAN_SENDER_processEvent, evCSsend, t, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAN_SENDER_emitDone(CAN_SENDER* me, uint16_t t) {
|
||||||
|
POST(me, &CAN_SENDER_processEvent, evCSdone, t, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********
|
||||||
|
* SETTERS *
|
||||||
|
***********/
|
||||||
|
|
||||||
|
void CAN_SENDER_setSendingTime(CAN_SENDER* me, uint8_t v) {
|
||||||
|
me->sendingTime = v;
|
||||||
|
}
|
105
306-controller_interface.X/middleware/can/can_sender.h
Normal file
105
306-controller_interface.X/middleware/can/can_sender.h
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/**
|
||||||
|
* @author Rémi Heredero
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date August 2023
|
||||||
|
* @file can_sender.h
|
||||||
|
*/
|
||||||
|
#ifndef CAN_SENDER_H
|
||||||
|
#define CAN_SENDER_H
|
||||||
|
|
||||||
|
#include "../../xf/xf.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
STCS_INIT,
|
||||||
|
STCS_WAIT,
|
||||||
|
STCS_SEND
|
||||||
|
} CAN_SENDER_STATES;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
evCSinit = 15, // TODO change this number (< 256)
|
||||||
|
evCSsend,
|
||||||
|
evCSdone
|
||||||
|
} CAN_SENDER_EVENTS;
|
||||||
|
|
||||||
|
typedef void (*CAN_SENDER_CALLBACK_FUNCTION)(void*);
|
||||||
|
typedef struct {
|
||||||
|
CAN_SENDER_CALLBACK_FUNCTION f; // function
|
||||||
|
void* p; // param(s)
|
||||||
|
} CAN_SENDER_CALLBACK;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CAN_SENDER_STATES state;
|
||||||
|
uint8_t sendingTime;
|
||||||
|
CAN_SENDER_CALLBACK wait;
|
||||||
|
CAN_SENDER_CALLBACK send;
|
||||||
|
} CAN_SENDER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the CAN_SENDER
|
||||||
|
* @param me the CAN_SENDER itself
|
||||||
|
*/
|
||||||
|
void CAN_SENDER_init(CAN_SENDER* me);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the CAN_SENDER state machine
|
||||||
|
* @param me the CAN_SENDER itself
|
||||||
|
*/
|
||||||
|
void CAN_SENDER_startBehaviour(CAN_SENDER* me);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the event
|
||||||
|
* @param ev the event to process
|
||||||
|
* @return true if the event is processed
|
||||||
|
*/
|
||||||
|
bool CAN_SENDER_processEvent(Event* ev);
|
||||||
|
|
||||||
|
/*************
|
||||||
|
* Callbacks *
|
||||||
|
*************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the callback function to call when the CAN_SENDER is entering state wait
|
||||||
|
* @param me the CAN_SENDER itself
|
||||||
|
* @param f the function to call
|
||||||
|
* @param p the param(s) to pass to the function
|
||||||
|
*/
|
||||||
|
void CAN_SENDER_onWait(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the callback function to call when the CAN_SENDER is entering state send
|
||||||
|
* @param me the CAN_SENDER itself
|
||||||
|
* @param f the function to call
|
||||||
|
* @param p the param(s) to pass to the function
|
||||||
|
*/
|
||||||
|
void CAN_SENDER_onSend(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p);
|
||||||
|
|
||||||
|
/************
|
||||||
|
* EMITTERS *
|
||||||
|
************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit the send event
|
||||||
|
* @param me the CAN_SENDER itself
|
||||||
|
* @param t time to wait in ms before triggering event
|
||||||
|
*/
|
||||||
|
void CAN_SENDER_emitSend(CAN_SENDER* me, uint16_t t);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit the done event
|
||||||
|
* @param me the CAN_SENDER itself
|
||||||
|
* @param t time to wait in ms before triggering event
|
||||||
|
*/
|
||||||
|
void CAN_SENDER_emitDone(CAN_SENDER* me, uint16_t t);
|
||||||
|
|
||||||
|
/***********
|
||||||
|
* SETTERS *
|
||||||
|
***********/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param me
|
||||||
|
* @param v
|
||||||
|
*/
|
||||||
|
void CAN_SENDER_setSendingTime(CAN_SENDER* me, uint8_t v);
|
||||||
|
|
||||||
|
#endif
|
@ -31,7 +31,10 @@
|
|||||||
<itemPath>mcc_generated_files/memory.h</itemPath>
|
<itemPath>mcc_generated_files/memory.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||||
<itemPath>middleware/can_interface.h</itemPath>
|
<logicalFolder name="f1" displayName="can" projectFiles="true">
|
||||||
|
<itemPath>middleware/can/can_interface.h</itemPath>
|
||||||
|
<itemPath>middleware/can/can_sender.h</itemPath>
|
||||||
|
</logicalFolder>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||||
<itemPath>xf/event.h</itemPath>
|
<itemPath>xf/event.h</itemPath>
|
||||||
@ -73,7 +76,10 @@
|
|||||||
<itemPath>mcc_generated_files/memory.c</itemPath>
|
<itemPath>mcc_generated_files/memory.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||||
<itemPath>middleware/can_interface.c</itemPath>
|
<logicalFolder name="f1" displayName="can" projectFiles="true">
|
||||||
|
<itemPath>middleware/can/can_interface.c</itemPath>
|
||||||
|
<itemPath>middleware/can/can_sender.c</itemPath>
|
||||||
|
</logicalFolder>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||||
<itemPath>xf/event.c</itemPath>
|
<itemPath>xf/event.c</itemPath>
|
||||||
|
Reference in New Issue
Block a user