From 102d4e199279e4c7214818c69ef82da1bfa3d167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 22 Aug 2023 15:53:38 +0200 Subject: [PATCH 01/14] can receive part done --- 306-controller_interface.X/factory/factory.c | 15 +- 306-controller_interface.X/factory/factory.h | 1 + .../mcc_generated_files/ecan.h | 8 +- .../middleware/can_interface.c | 123 ++++++++++++++++ .../middleware/can_interface.h | 101 +++++++++++++ .../nbproject/configurations.xml | 91 +++++++++++- 306-controller_interface.X/ss22ep.mc3 | 18 +-- UML/can.uxf | 134 ++++++++++++++++++ 8 files changed, 472 insertions(+), 19 deletions(-) create mode 100644 306-controller_interface.X/middleware/can_interface.c create mode 100644 306-controller_interface.X/middleware/can_interface.h create mode 100644 UML/can.uxf diff --git a/306-controller_interface.X/factory/factory.c b/306-controller_interface.X/factory/factory.c index 600f8bb..d1c1920 100644 --- a/306-controller_interface.X/factory/factory.c +++ b/306-controller_interface.X/factory/factory.c @@ -36,14 +36,23 @@ void Factory_init() Button_initHW(b()); ButtonSM_init(bsm(),b()); BLControl_init(blc()); + + CANINTERFACE_init(); + ; } +void foo(uint32_t a, uint32_t b){ + +} + //connect objects if required -void Factory_build() -{ - ButtonSM_setObserver(bsm(), blc(), &BLControl_onButton); +void Factory_build() { + ButtonSM_setObserver(bsm(), blc(), &BLControl_onButton); + + ECAN_SetRXBnInterruptHandler(CANINTERFACE_newMsg); + CANINTERFACE_onProcessCan(foo); } //start all state machines diff --git a/306-controller_interface.X/factory/factory.h b/306-controller_interface.X/factory/factory.h index 4d630a9..ff0752d 100644 --- a/306-controller_interface.X/factory/factory.h +++ b/306-controller_interface.X/factory/factory.h @@ -11,6 +11,7 @@ #include "../board/button/button.h" #include "../board/button/buttonsm.h" #include "../app/blcontrol.h" +#include "../middleware/can_interface.h" #define BID 1 diff --git a/306-controller_interface.X/mcc_generated_files/ecan.h b/306-controller_interface.X/mcc_generated_files/ecan.h index f619bfa..407ce8b 100644 --- a/306-controller_interface.X/mcc_generated_files/ecan.h +++ b/306-controller_interface.X/mcc_generated_files/ecan.h @@ -70,10 +70,10 @@ typedef union { uint8_t data1; uint8_t data2; uint8_t data3; - uint8_t data4; - uint8_t data5; - uint8_t data6; - uint8_t data7; + uint8_t data4; // uselesss + uint8_t data5; // uselesss + uint8_t data6; // uselesss + uint8_t data7; // uselesss uint8_t rtr; } frame; uint8_t array[15]; diff --git a/306-controller_interface.X/middleware/can_interface.c b/306-controller_interface.X/middleware/can_interface.c new file mode 100644 index 0000000..65fa2d1 --- /dev/null +++ b/306-controller_interface.X/middleware/can_interface.c @@ -0,0 +1,123 @@ +/** + * @author Rémi Heredero + * @version 1.0.0 + * @date August 2023 + * @file can_interface.c + */ + +#include "can_interface.h" + +void CANINTERFACE_init(){ + CANINTERFACE_myself.wait.f = NULL; + CANINTERFACE_myself.read.f = NULL; + CANINTERFACE_myself.processCan = NULL; +} + +void CANINTERFACE_startBehaviour(){ + POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAinit, 0, 0); +} + +void CANINTERFACE_newMsg() { + uint64_t data; + uCAN_MSG canMsg; + CAN_receive(&canMsg); + data = canMsg.frame.id; + data = data<<32; + data = canMsg.frame.data0; + data = data<<8; + data = canMsg.frame.data1; + data = data<<8; + data = canMsg.frame.data2; + data = data<<8; + data = canMsg.frame.data3; + POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAinit, 0, data); +} + +bool CANINTERFACE_processEvent(Event* ev) { + bool processed = false; + CANINTERFACE* me = (CANINTERFACE*)Event_getTarget(ev); + CANINTERFACE_STATES oldState = me->state; + evIDT evid = Event_getId(ev); + + uint64_t data = Event_getData(ev); + uint32_t canData = (uint32_t) data; + data = data>>8; + uint32_t canId = (uint32_t) data; + + switch (me->state) { // onState + case STCA_INIT: + if (ev->id == evCAinit) { + + } + break; + + case STCA_WAIT: + break; + + case STCA_READ: + break; + } + + if(oldState != me->state){ + switch (oldState) { // onExit + case STCA_INIT: + break; + + case STCA_WAIT: + break; + + case STCA_READ: + break; + } + + switch (me->state) { // onEntry + case STCA_INIT: + break; + + case STCA_WAIT: + if (me->wait.f != NULL) { + me->wait.f(me->wait.p); + } + break; + + case STCA_READ: + if (me->read.f != NULL) { + me->read.f(me->read.p); + } + + if (me->processCan != NULL) { + me->processCan(canId, canData); + } + break; + } + + processed = true; + } + return processed; +} + +/************* + * Callbacks * + *************/ + +void CANINTERFACE_onWait(CANINTERFACE_CALLBACK_FUNCTION f, void* p) { + CANINTERFACE_myself.wait.f = f; + CANINTERFACE_myself.wait.p = p; +} + +void CANINTERFACE_onRead(CANINTERFACE_CALLBACK_FUNCTION f, void* p) { + CANINTERFACE_myself.read.f = f; + CANINTERFACE_myself.read.p = p; +} + +void CANINTERFACE_onProcessCan(CANINTERFACE_CALLBACK_CAN f) { + CANINTERFACE_myself.processCan = f; +} + +/************ + * EMITTERS * + ************/ + +void CANINTERFACE_emitNewMsg(uint16_t t) { + POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, t, 0); +} diff --git a/306-controller_interface.X/middleware/can_interface.h b/306-controller_interface.X/middleware/can_interface.h new file mode 100644 index 0000000..fe5281f --- /dev/null +++ b/306-controller_interface.X/middleware/can_interface.h @@ -0,0 +1,101 @@ +/** + * @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 diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index 4e1f9cf..f88848a 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -31,6 +31,7 @@ mcc_generated_files/memory.h + middleware/can_interface.h xf/event.h @@ -72,6 +73,7 @@ mcc_generated_files/memory.c + middleware/can_interface.c xf/event.c @@ -103,7 +105,7 @@ PIC18F26K83 - PICkit3PlatformTool + noID XC8 2.41 3 @@ -169,7 +171,7 @@ - + @@ -219,10 +221,93 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/306-controller_interface.X/ss22ep.mc3 b/306-controller_interface.X/ss22ep.mc3 index 25fb154..9f4cf09 100644 --- a/306-controller_interface.X/ss22ep.mc3 +++ b/306-controller_interface.X/ss22ep.mc3 @@ -1948,7 +1948,7 @@ - {"dataArray":[{"DMA Channels":{"data":{"isDisable":"true","options":"--NONE--","text":"DMA CHANNEL1","value":"false"},"id":"DMA Channels_rowCount_0"},"Src Module":{"data":{"isDisable":"true","options":"--NONE--,TMR0,ECAN,MEMORY","text":"--NONE--","value":"--NONE--"},"id":"Src Module_rowCount_0"},"Src Region":{"data":{"isDisable":"true","options":"SFR#disabled,GPR#enabled,Program Flash#enabled,Data EEPROM#enabled","text":"GPR","value":"GPR"},"id":"Src Region_rowCount_0"},"Src SFR":{"Src SFR":{"isDisable":"true","options":"","text":"","value":""},"data":{"isDisable":"true","options":"","text":"","value":""},"id":"Src SFR_rowCount_0"},"Src VarName":{"data":{"isDisable":"true","options":"","text":"SrcVarName0","value":"SrcVarName0"},"Src VarName":{"isDisable":"true","options":"","text":"SrcVarName0","value":"SrcVarName0"},"id":"Src VarName_rowCount_0"},"Src VarSize":{"data":{"isDisable":"true","options":"","text":"10","value":"10"},"id":"Src VarSize_rowCount_0","Src VarSize":{"isDisable":"true","options":"","text":"10","value":"10"}},"Src Address":{"data":{"isDisable":"true","options":"","text":"Enter Address0","value":"Enter Address0"},"id":"Src Address_rowCount_0","Src Address":{"isDisable":"true","options":"","text":"Enter Address0","value":"Enter Address0"}},"Src Mode":{"Src Mode":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"data":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"id":"Src Mode_rowCount_0"},"Src Message Size":{"data":{"isDisable":"true","options":"","text":"1","value":"1"},"Src Message Size":{"isDisable":"true","options":"","text":"1","value":"1"},"id":"Src Message Size_rowCount_0"},"Dst Module":{"data":{"isDisable":"true","options":"--NONE--,TMR0,ECAN,MEMORY","text":"--NONE--","value":"--NONE--"},"id":"Dst Module_rowCount_0"},"Dst Region":{"data":{"isDisable":"true","options":"SFR,GPR","text":"GPR","value":"GPR"},"id":"Dst Region_rowCount_0"},"Dst SFR":{"Dst SFR":{"isDisable":"true","options":"","text":"","value":""},"data":{"isDisable":"true","options":"","text":"","value":""},"id":"Dst SFR_rowCount_0"},"Dst VarName":{"data":{"isDisable":"true","options":"","text":"DstVarName0","value":"DstVarName0"},"Dst VarName":{"isDisable":"true","options":"","text":"DstVarName0","value":"DstVarName0"},"id":"Dst VarName_rowCount_0"},"Dst VarSize":{"data":{"isDisable":"true","options":"","text":"10","value":"10"},"id":"Dst VarSize_rowCount_0","Dst VarSize":{"isDisable":"true","options":"","text":"10","value":"10"}},"Dst Mode":{"data":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"Dst Mode":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"id":"Dst Mode_rowCount_0"},"Dst Message Size":{"data":{"isDisable":"true","options":"","text":"1","value":"1"},"Dst Message Size":{"isDisable":"true","options":"","text":"1","value":"1"},"id":"Dst Message Size_rowCount_0"},"Start Trigger":{"Start Trigger":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"data":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"id":"Start Trigger_rowCount_0"},"Abort Trigger":{"data":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"id":"Abort Trigger_rowCount_0","Abort Trigger":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"}}},{"DMA Channels":{"data":{"isDisable":"true","options":"--NONE--","text":"DMA CHANNEL2","value":"false"},"id":"DMA Channels_rowCount_1"},"Src Module":{"data":{"isDisable":"true","options":"--NONE--,TMR0,ECAN,MEMORY","text":"--NONE--","value":"--NONE--"},"id":"Src Module_rowCount_1"},"Src Region":{"data":{"isDisable":"true","options":"SFR#disabled,GPR#enabled,Program Flash#enabled,Data EEPROM#enabled","text":"GPR","value":"GPR"},"id":"Src Region_rowCount_1"},"Src SFR":{"Src SFR":{"isDisable":"true","options":"","text":"","value":""},"data":{"isDisable":"true","options":"","text":"","value":""},"id":"Src SFR_rowCount_1"},"Src VarName":{"data":{"isDisable":"true","options":"","text":"SrcVarName1","value":"SrcVarName1"},"Src VarName":{"isDisable":"true","options":"","text":"SrcVarName1","value":"SrcVarName1"},"id":"Src VarName_rowCount_1"},"Src VarSize":{"data":{"isDisable":"true","options":"","text":"10","value":"10"},"id":"Src VarSize_rowCount_1","Src VarSize":{"isDisable":"true","options":"","text":"10","value":"10"}},"Src Address":{"data":{"isDisable":"true","options":"","text":"Enter Address1","value":"Enter Address1"},"id":"Src Address_rowCount_1","Src Address":{"isDisable":"true","options":"","text":"Enter Address1","value":"Enter Address1"}},"Src Mode":{"Src Mode":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"data":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"id":"Src Mode_rowCount_1"},"Src Message Size":{"data":{"isDisable":"true","options":"","text":"1","value":"1"},"Src Message Size":{"isDisable":"true","options":"","text":"1","value":"1"},"id":"Src Message Size_rowCount_1"},"Dst Module":{"data":{"isDisable":"true","options":"--NONE--,TMR0,ECAN,MEMORY","text":"--NONE--","value":"--NONE--"},"id":"Dst Module_rowCount_1"},"Dst Region":{"data":{"isDisable":"true","options":"SFR,GPR","text":"GPR","value":"GPR"},"id":"Dst Region_rowCount_1"},"Dst SFR":{"Dst SFR":{"isDisable":"true","options":"","text":"","value":""},"data":{"isDisable":"true","options":"","text":"","value":""},"id":"Dst SFR_rowCount_1"},"Dst VarName":{"data":{"isDisable":"true","options":"","text":"DstVarName1","value":"DstVarName1"},"Dst VarName":{"isDisable":"true","options":"","text":"DstVarName1","value":"DstVarName1"},"id":"Dst VarName_rowCount_1"},"Dst VarSize":{"data":{"isDisable":"true","options":"","text":"10","value":"10"},"id":"Dst VarSize_rowCount_1","Dst VarSize":{"isDisable":"true","options":"","text":"10","value":"10"}},"Dst Mode":{"data":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"Dst Mode":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"id":"Dst Mode_rowCount_1"},"Dst Message Size":{"data":{"isDisable":"true","options":"","text":"1","value":"1"},"Dst Message Size":{"isDisable":"true","options":"","text":"1","value":"1"},"id":"Dst Message Size_rowCount_1"},"Start Trigger":{"Start Trigger":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"data":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"id":"Start Trigger_rowCount_1"},"Abort Trigger":{"data":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"id":"Abort Trigger_rowCount_1","Abort Trigger":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"}}}],"type":"tableDynamicControls","key":"dmaTable"} + {"dataArray":[{"DMA Channels":{"data":{"isDisable":"true","options":"--NONE--","text":"DMA CHANNEL1","value":"false"},"id":"DMA Channels_rowCount_0"},"Src Module":{"data":{"isDisable":"true","options":"--NONE--,ECAN,TMR0,MEMORY","text":"--NONE--","value":"--NONE--"},"id":"Src Module_rowCount_0"},"Src Region":{"data":{"isDisable":"true","options":"SFR#disabled,GPR#enabled,Program Flash#enabled,Data EEPROM#enabled","text":"GPR","value":"GPR"},"id":"Src Region_rowCount_0"},"Src SFR":{"Src SFR":{"isDisable":"true","options":"","text":"","value":""},"data":{"isDisable":"true","options":"","text":"","value":""},"id":"Src SFR_rowCount_0"},"Src VarName":{"data":{"isDisable":"true","options":"","text":"SrcVarName0","value":"SrcVarName0"},"Src VarName":{"isDisable":"true","options":"","text":"SrcVarName0","value":"SrcVarName0"},"id":"Src VarName_rowCount_0"},"Src VarSize":{"data":{"isDisable":"true","options":"","text":"10","value":"10"},"id":"Src VarSize_rowCount_0","Src VarSize":{"isDisable":"true","options":"","text":"10","value":"10"}},"Src Address":{"data":{"isDisable":"true","options":"","text":"Enter Address0","value":"Enter Address0"},"id":"Src Address_rowCount_0","Src Address":{"isDisable":"true","options":"","text":"Enter Address0","value":"Enter Address0"}},"Src Mode":{"Src Mode":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"data":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"id":"Src Mode_rowCount_0"},"Src Message Size":{"data":{"isDisable":"true","options":"","text":"1","value":"1"},"Src Message Size":{"isDisable":"true","options":"","text":"1","value":"1"},"id":"Src Message Size_rowCount_0"},"Dst Module":{"data":{"isDisable":"true","options":"--NONE--,ECAN,TMR0,MEMORY","text":"--NONE--","value":"--NONE--"},"id":"Dst Module_rowCount_0"},"Dst Region":{"data":{"isDisable":"true","options":"SFR,GPR","text":"GPR","value":"GPR"},"id":"Dst Region_rowCount_0"},"Dst SFR":{"Dst SFR":{"isDisable":"true","options":"","text":"","value":""},"data":{"isDisable":"true","options":"","text":"","value":""},"id":"Dst SFR_rowCount_0"},"Dst VarName":{"data":{"isDisable":"true","options":"","text":"DstVarName0","value":"DstVarName0"},"Dst VarName":{"isDisable":"true","options":"","text":"DstVarName0","value":"DstVarName0"},"id":"Dst VarName_rowCount_0"},"Dst VarSize":{"data":{"isDisable":"true","options":"","text":"10","value":"10"},"id":"Dst VarSize_rowCount_0","Dst VarSize":{"isDisable":"true","options":"","text":"10","value":"10"}},"Dst Mode":{"data":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"Dst Mode":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"id":"Dst Mode_rowCount_0"},"Dst Message Size":{"data":{"isDisable":"true","options":"","text":"1","value":"1"},"Dst Message Size":{"isDisable":"true","options":"","text":"1","value":"1"},"id":"Dst Message Size_rowCount_0"},"Start Trigger":{"Start Trigger":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"data":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"id":"Start Trigger_rowCount_0"},"Abort Trigger":{"data":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"id":"Abort Trigger_rowCount_0","Abort Trigger":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"}}},{"DMA Channels":{"data":{"isDisable":"true","options":"--NONE--","text":"DMA CHANNEL2","value":"false"},"id":"DMA Channels_rowCount_1"},"Src Module":{"data":{"isDisable":"true","options":"--NONE--,ECAN,TMR0,MEMORY","text":"--NONE--","value":"--NONE--"},"id":"Src Module_rowCount_1"},"Src Region":{"data":{"isDisable":"true","options":"SFR#disabled,GPR#enabled,Program Flash#enabled,Data EEPROM#enabled","text":"GPR","value":"GPR"},"id":"Src Region_rowCount_1"},"Src SFR":{"Src SFR":{"isDisable":"true","options":"","text":"","value":""},"data":{"isDisable":"true","options":"","text":"","value":""},"id":"Src SFR_rowCount_1"},"Src VarName":{"data":{"isDisable":"true","options":"","text":"SrcVarName1","value":"SrcVarName1"},"Src VarName":{"isDisable":"true","options":"","text":"SrcVarName1","value":"SrcVarName1"},"id":"Src VarName_rowCount_1"},"Src VarSize":{"data":{"isDisable":"true","options":"","text":"10","value":"10"},"id":"Src VarSize_rowCount_1","Src VarSize":{"isDisable":"true","options":"","text":"10","value":"10"}},"Src Address":{"data":{"isDisable":"true","options":"","text":"Enter Address1","value":"Enter Address1"},"id":"Src Address_rowCount_1","Src Address":{"isDisable":"true","options":"","text":"Enter Address1","value":"Enter Address1"}},"Src Mode":{"Src Mode":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"data":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"id":"Src Mode_rowCount_1"},"Src Message Size":{"data":{"isDisable":"true","options":"","text":"1","value":"1"},"Src Message Size":{"isDisable":"true","options":"","text":"1","value":"1"},"id":"Src Message Size_rowCount_1"},"Dst Module":{"data":{"isDisable":"true","options":"--NONE--,ECAN,TMR0,MEMORY","text":"--NONE--","value":"--NONE--"},"id":"Dst Module_rowCount_1"},"Dst Region":{"data":{"isDisable":"true","options":"SFR,GPR","text":"GPR","value":"GPR"},"id":"Dst Region_rowCount_1"},"Dst SFR":{"Dst SFR":{"isDisable":"true","options":"","text":"","value":""},"data":{"isDisable":"true","options":"","text":"","value":""},"id":"Dst SFR_rowCount_1"},"Dst VarName":{"data":{"isDisable":"true","options":"","text":"DstVarName1","value":"DstVarName1"},"Dst VarName":{"isDisable":"true","options":"","text":"DstVarName1","value":"DstVarName1"},"id":"Dst VarName_rowCount_1"},"Dst VarSize":{"data":{"isDisable":"true","options":"","text":"10","value":"10"},"id":"Dst VarSize_rowCount_1","Dst VarSize":{"isDisable":"true","options":"","text":"10","value":"10"}},"Dst Mode":{"data":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"Dst Mode":{"isDisable":"true","options":"decremented,incremented,unchanged","text":"unchanged","value":"unchanged"},"id":"Dst Mode_rowCount_1"},"Dst Message Size":{"data":{"isDisable":"true","options":"","text":"1","value":"1"},"Dst Message Size":{"isDisable":"true","options":"","text":"1","value":"1"},"id":"Dst Message Size_rowCount_1"},"Start Trigger":{"Start Trigger":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"data":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"id":"Start Trigger_rowCount_1"},"Abort Trigger":{"data":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"},"id":"Abort Trigger_rowCount_1","Abort Trigger":{"isDisable":"true","options":"AD,ADT,CAN_ERRIF,CAN_IRXIF,CAN_RXB0IF\/FIFOIF,CAN_RXB1IF\/RXBnIF,CAN_TXB0IF,CAN_TXB1IF,CAN_TXB2IF\/TXBnIF,CAN_WAKIF,CCP1,CCP2,CCP3,CCP4,CLC1,CLC2,CLC3,CLC4,CMP1,CMP2,CRC,CSW,CWG1,CWG2,CWG3,DMA1A,DMA1DCNT,DMA1OR,DMA1SCNT,DMA2A,DMA2DCNT,DMA2OR,DMA2SCNT,I2C1,I2C1E,I2C1RX,I2C1TX,I2C2,I2C2E,I2C2RX,I2C2TX,INT0,INT1,INT2,IOC,LVD,NCO,NVM,None,OSF,SCAN,SMT1,SMT1PRA,SMT1PWA,SMT2,SMT2PRA,SMT2PWA,SPI1,SPI1RX,SPI1TX,TMR0,TMR1,TMR1G,TMR2,TMR3,TMR3G,TMR4,TMR5,TMR5G,TMR6,U1,U1E,U1RX,U1TX,U2,U2E,U2RX,U2TX,ZCD","text":"None","value":"None"}}}],"type":"tableDynamicControls","key":"dmaTable"} @@ -11696,11 +11696,11 @@ - IO_RA5 + - IO_RA6 + @@ -11800,11 +11800,11 @@ - input + disabled - output + disabled @@ -14352,7 +14352,7 @@ - 223 + 255 @@ -14720,7 +14720,7 @@ - 191 + 255 @@ -14788,7 +14788,7 @@ - digital + analog @@ -15848,7 +15848,7 @@ - output + input diff --git a/UML/can.uxf b/UML/can.uxf new file mode 100644 index 0000000..3a06625 --- /dev/null +++ b/UML/can.uxf @@ -0,0 +1,134 @@ + + + 15 + + UMLSpecialState + + 465 + 165 + 30 + 30 + + type=initial + + + + UMLState + + 405 + 255 + 150 + 60 + + STCA_WAIT + + + + Relation + + 465 + 180 + 90 + 105 + + lt=-> +evInit + + 10.0;10.0;10.0;50.0 + + + Relation + + 465 + 300 + 180 + 105 + + lt=-> +evCaNewMsg + 10.0;10.0;10.0;50.0 + + + UMLState + + 330 + 375 + 285 + 105 + + STCA_READ +- +-. +/entry: processCan + + + + Relation + + 495 + 270 + 225 + 360 + + lt=-> +m1=[queue empty] + + 10.0;210.0;130.0;210.0;130.0;10.0;40.0;10.0 + + + UMLSpecialState + + 450 + 555 + 60 + 60 + + type=decision + + + + Relation + + 465 + 465 + 45 + 120 + + lt=-> + + 10.0;10.0;10.0;60.0 + + + Relation + + 225 + 390 + 255 + 240 + + lt=-> +m1=[else] + + 150.0;130.0;10.0;130.0;10.0;10.0;70.0;10.0 + + + UMLNote + + 750 + 300 + 615 + 270 + + _*How to use*_ + +*In Factory_build: * +ECAN_SetRXBnInterruptHandler(CANINTERFACE_newMsg); +CANINTERFACE_onProcessCan(&processCan); + +*Somewhere:* +void processCan(uint32_t canId, uint32_t canData) { + ..... +} + + + From 146fc9011e144f4376cd5c30cae6082b3bb4626d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 22 Aug 2023 16:56:01 +0200 Subject: [PATCH 02/14] fix can receive part for SM --- 306-controller_interface.X/factory/factory.h | 2 +- .../middleware/{ => can}/can_interface.c | 15 +++++++++++++-- .../middleware/{ => can}/can_interface.h | 15 +++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) rename 306-controller_interface.X/middleware/{ => can}/can_interface.c (85%) rename 306-controller_interface.X/middleware/{ => can}/can_interface.h (90%) diff --git a/306-controller_interface.X/factory/factory.h b/306-controller_interface.X/factory/factory.h index ff0752d..fa65abc 100644 --- a/306-controller_interface.X/factory/factory.h +++ b/306-controller_interface.X/factory/factory.h @@ -11,7 +11,7 @@ #include "../board/button/button.h" #include "../board/button/buttonsm.h" #include "../app/blcontrol.h" -#include "../middleware/can_interface.h" +#include "../middleware/can/can_interface.h" #define BID 1 diff --git a/306-controller_interface.X/middleware/can_interface.c b/306-controller_interface.X/middleware/can/can_interface.c similarity index 85% rename from 306-controller_interface.X/middleware/can_interface.c rename to 306-controller_interface.X/middleware/can/can_interface.c index 65fa2d1..b48d487 100644 --- a/306-controller_interface.X/middleware/can_interface.c +++ b/306-controller_interface.X/middleware/can/can_interface.c @@ -30,7 +30,7 @@ void CANINTERFACE_newMsg() { data = canMsg.frame.data2; data = data<<8; data = canMsg.frame.data3; - POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAinit, 0, data); + POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, 0, data); } bool CANINTERFACE_processEvent(Event* ev) { @@ -47,14 +47,21 @@ bool CANINTERFACE_processEvent(Event* ev) { switch (me->state) { // onState case STCA_INIT: if (ev->id == evCAinit) { - + me->state = STCA_WAIT; } break; case STCA_WAIT: + if (ev->id == evCAnewMsg) { + me->state = STCA_READ; + CANINTERFACE_emitDone(0); + } break; case STCA_READ: + if (ev->id == evCAdone) { + me->state = STCA_WAIT; + } break; } @@ -121,3 +128,7 @@ void CANINTERFACE_onProcessCan(CANINTERFACE_CALLBACK_CAN f) { void CANINTERFACE_emitNewMsg(uint16_t t) { POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, t, 0); } + +void CANINTERFACE_emitDone(uint16_t t) { + POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAdone, t, 0); +} diff --git a/306-controller_interface.X/middleware/can_interface.h b/306-controller_interface.X/middleware/can/can_interface.h similarity index 90% rename from 306-controller_interface.X/middleware/can_interface.h rename to 306-controller_interface.X/middleware/can/can_interface.h index fe5281f..5508af3 100644 --- a/306-controller_interface.X/middleware/can_interface.h +++ b/306-controller_interface.X/middleware/can/can_interface.h @@ -7,7 +7,7 @@ #ifndef CANINTERFACE_H #define CANINTERFACE_H -#include "../xf/xf.h" +#include "../../xf/xf.h" typedef enum { STCA_INIT, @@ -45,7 +45,6 @@ void CANINTERFACE_init(); /** * Start the CANINTERFACE state machine - * @param me the CANINTERFACE itself */ void CANINTERFACE_startBehaviour(); @@ -68,7 +67,6 @@ bool CANINTERFACE_processEvent(Event* ev); /** * 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 */ @@ -76,7 +74,6 @@ 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 */ @@ -94,8 +91,14 @@ void CANINTERFACE_onProcessCan(CANINTERFACE_CALLBACK_CAN f); /** * 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); + */ +void CANINTERFACE_emitNewMsg(uint16_t t); + +/** + * Emit the Done event + * @param t time to wait in ms before triggering event + */ +void CANINTERFACE_emitDone(uint16_t t); #endif From 67344670314d41a81992da1f9bfa1ffa9634bf8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 22 Aug 2023 17:50:49 +0200 Subject: [PATCH 03/14] WIP CAN sender --- 306-controller_interface.X/factory/factory.c | 2 +- .../middleware/can/can_interface.c | 2 +- .../middleware/can/can_sender.c | 107 ++++++++++++++++++ .../middleware/can/can_sender.h | 105 +++++++++++++++++ .../nbproject/configurations.xml | 10 +- 5 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 306-controller_interface.X/middleware/can/can_sender.c create mode 100644 306-controller_interface.X/middleware/can/can_sender.h diff --git a/306-controller_interface.X/factory/factory.c b/306-controller_interface.X/factory/factory.c index d1c1920..f0f5b58 100644 --- a/306-controller_interface.X/factory/factory.c +++ b/306-controller_interface.X/factory/factory.c @@ -52,7 +52,7 @@ void Factory_build() { ButtonSM_setObserver(bsm(), blc(), &BLControl_onButton); ECAN_SetRXBnInterruptHandler(CANINTERFACE_newMsg); - CANINTERFACE_onProcessCan(foo); + //CANINTERFACE_onProcessCan(foo); } //start all state machines diff --git a/306-controller_interface.X/middleware/can/can_interface.c b/306-controller_interface.X/middleware/can/can_interface.c index b48d487..4ac0fce 100644 --- a/306-controller_interface.X/middleware/can/can_interface.c +++ b/306-controller_interface.X/middleware/can/can_interface.c @@ -10,7 +10,7 @@ void CANINTERFACE_init(){ CANINTERFACE_myself.wait.f = NULL; CANINTERFACE_myself.read.f = NULL; - CANINTERFACE_myself.processCan = NULL; + //CANINTERFACE_myself.processCan = NULL; } void CANINTERFACE_startBehaviour(){ diff --git a/306-controller_interface.X/middleware/can/can_sender.c b/306-controller_interface.X/middleware/can/can_sender.c new file mode 100644 index 0000000..1de392d --- /dev/null +++ b/306-controller_interface.X/middleware/can/can_sender.c @@ -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; +} diff --git a/306-controller_interface.X/middleware/can/can_sender.h b/306-controller_interface.X/middleware/can/can_sender.h new file mode 100644 index 0000000..633cec3 --- /dev/null +++ b/306-controller_interface.X/middleware/can/can_sender.h @@ -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 diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index f88848a..b7db225 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -31,7 +31,10 @@ mcc_generated_files/memory.h - middleware/can_interface.h + + middleware/can/can_interface.h + middleware/can/can_sender.h + xf/event.h @@ -73,7 +76,10 @@ mcc_generated_files/memory.c - middleware/can_interface.c + + middleware/can/can_interface.c + middleware/can/can_sender.c + xf/event.c From d5c30dfea4d46e00abd0278cb856a49c574919d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 22 Aug 2023 17:51:19 +0200 Subject: [PATCH 04/14] WIP can sender --- UML/can.uxf | 142 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 116 insertions(+), 26 deletions(-) diff --git a/UML/can.uxf b/UML/can.uxf index 3a06625..835b6d9 100644 --- a/UML/can.uxf +++ b/UML/can.uxf @@ -4,8 +4,8 @@ UMLSpecialState - 465 - 165 + 450 + 150 30 30 @@ -15,8 +15,8 @@ UMLState - 405 - 255 + 390 + 240 150 60 @@ -26,33 +26,33 @@ Relation - 465 - 180 - 90 + 450 + 165 + 120 105 lt=-> -evInit +evCAinit 10.0;10.0;10.0;50.0 Relation - 465 - 300 - 180 + 450 + 285 + 165 105 lt=-> -evCaNewMsg +evCAnewMsg 10.0;10.0;10.0;50.0 UMLState - 330 - 375 + 315 + 360 285 105 @@ -65,8 +65,8 @@ evCaNewMsg Relation - 495 - 270 + 480 + 255 225 360 @@ -78,8 +78,8 @@ m1=[queue empty] UMLSpecialState - 450 - 555 + 435 + 540 60 60 @@ -89,20 +89,20 @@ m1=[queue empty] Relation - 465 - 465 - 45 + 450 + 450 + 135 120 lt=-> - +evCAdone 10.0;10.0;10.0;60.0 Relation - 225 - 390 + 210 + 375 255 240 @@ -114,8 +114,8 @@ m1=[else] UMLNote - 750 - 300 + 90 + 630 615 270 @@ -131,4 +131,94 @@ void processCan(uint32_t canId, uint32_t canData) { } + + Relation + + 900 + 225 + 90 + 105 + + lt=-> +evInit + + 10.0;10.0;10.0;50.0 + + + UMLSpecialState + + 900 + 210 + 30 + 30 + + type=initial + + + + UMLState + + 840 + 300 + 150 + 60 + + STCS_WAIT + + + + UMLState + + 810 + 420 + 210 + 90 + + STCS_SEND +-- +-. +/entry sendCan + + + + Relation + + 900 + 345 + 135 + 105 + + lt=-> +evCSsend + + 10.0;10.0;10.0;50.0 + + + Relation + + 900 + 315 + 270 + 270 + + lt=-> +evCSdone + + 10.0;130.0;10.0;160.0;100.0;160.0;100.0;10.0;60.0;10.0 + + + UMLNote + + 765 + 630 + 645 + 150 + + _*How to use*_ + +CANSENDER_send(uint32_t id, uint32_t data); +or +CANSENDER_send(CANSENDER *me, uint8_t id, uint32_t data); + + From ff9137a026db61ff4e064b1f08b0cad674827aac Mon Sep 17 00:00:00 2001 From: Klagarge Date: Wed, 23 Aug 2023 07:29:12 +0200 Subject: [PATCH 05/14] WIP can sender - template done --- .../middleware/can/can_sender.c | 52 ++++++++++---- .../middleware/can/can_sender.h | 67 ++++++++++--------- .../nbproject/configurations.xml | 15 ----- UML/can.uxf | 16 +++-- 4 files changed, 85 insertions(+), 65 deletions(-) diff --git a/306-controller_interface.X/middleware/can/can_sender.c b/306-controller_interface.X/middleware/can/can_sender.c index 1de392d..71163be 100644 --- a/306-controller_interface.X/middleware/can/can_sender.c +++ b/306-controller_interface.X/middleware/can/can_sender.c @@ -7,34 +7,56 @@ #include "can_sender.h" -void CAN_SENDER_init(CAN_SENDER* me){ +void CANSENDER_init(CANSENDER* 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); +void CANSENDER_startBehaviour(CANSENDER* me){ + POST(me, &CANSENDER_processEvent, evCSinit, 0, 0); } -bool CAN_SENDER_processEvent(Event* ev) { +bool CANSENDER_processEvent(Event* ev) { bool processed = false; - CAN_SENDER* me = (CAN_SENDER*)Event_getTarget(ev); - CAN_SENDER_STATES oldState = me->state; + CANSENDER* me = (CANSENDER*)Event_getTarget(ev); + CANSENDER_STATES oldState = me->state; evIDT evid = Event_getId(ev); + uint64_t data = Event_getData(ev); switch (me->state) { // onState case STCS_INIT: if (ev->id == evCSinit) { - + CANSENDER.state = STCS_WAIT; } break; case STCS_WAIT: + if (ev->id == evCSsend) { + CANSENDER.state = STCS_SEND; + } break; case STCS_SEND: + if (ev->id == evCSdone) { + CANSENDER.state = STCS_WAIT; + } + + uCAN_MSG canMsg; + canMsg.frame.data0 = (uint8_t) data; + data = data >> 8; + canMsg.frame.data1 = (uint8_t) data; + data = data >> 8; + canMsg.frame.data2 = (uint8_t) data; + data = data >> 8; + canMsg.frame.data3 = (uint8_t) data; + data = data >> 8; + canMsg.frame.id = (uint32_t) data; + CAN_transmit(&canMsg); + + CANSENDER_emitDone(me, 0); + break; } @@ -76,12 +98,12 @@ bool CAN_SENDER_processEvent(Event* ev) { * Callbacks * *************/ -void CAN_SENDER_onWait(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p) { +void CANSENDER_onWait(CANSENDER* me, CANSENDER_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) { +void CANSENDER_onSend(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p) { me->send.f = f; me->send.p = p; } @@ -90,18 +112,20 @@ void CAN_SENDER_onSend(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p) * EMITTERS * ************/ -void CAN_SENDER_emitSend(CAN_SENDER* me, uint16_t t) { - POST(me, &CAN_SENDER_processEvent, evCSsend, t, 0); +void CANSENDER_emitSend(CANSENDER* me, uint16_t t) { + POST(me, &CANSENDER_processEvent, evCSsend, t, 0); } -void CAN_SENDER_emitDone(CAN_SENDER* me, uint16_t t) { - POST(me, &CAN_SENDER_processEvent, evCSdone, t, 0); +void CANSENDER_emitDone(CANSENDER* me, uint16_t t) { + POST(me, &CANSENDER_processEvent, evCSdone, t, 0); } +CANSENDER_sendCanMsg(CANSENDER* me, uint8_t id, uint32_t data) + /*********** * SETTERS * ***********/ -void CAN_SENDER_setSendingTime(CAN_SENDER* me, uint8_t v) { +void CANSENDER_setSendingTime(CANSENDER* me, uint8_t v) { me->sendingTime = v; } diff --git a/306-controller_interface.X/middleware/can/can_sender.h b/306-controller_interface.X/middleware/can/can_sender.h index 633cec3..3703e49 100644 --- a/306-controller_interface.X/middleware/can/can_sender.h +++ b/306-controller_interface.X/middleware/can/can_sender.h @@ -4,8 +4,8 @@ * @date August 2023 * @file can_sender.h */ -#ifndef CAN_SENDER_H -#define CAN_SENDER_H +#ifndef CANSENDER_H +#define CANSENDER_H #include "../../xf/xf.h" @@ -13,65 +13,65 @@ typedef enum { STCS_INIT, STCS_WAIT, STCS_SEND -} CAN_SENDER_STATES; +} CANSENDER_STATES; typedef enum { evCSinit = 15, // TODO change this number (< 256) evCSsend, evCSdone -} CAN_SENDER_EVENTS; +} CANSENDER_EVENTS; -typedef void (*CAN_SENDER_CALLBACK_FUNCTION)(void*); +typedef void (*CANSENDER_CALLBACK_FUNCTION)(void*); typedef struct { - CAN_SENDER_CALLBACK_FUNCTION f; // function + CANSENDER_CALLBACK_FUNCTION f; // function void* p; // param(s) -} CAN_SENDER_CALLBACK; +} CANSENDER_CALLBACK; typedef struct { - CAN_SENDER_STATES state; + CANSENDER_STATES state; uint8_t sendingTime; - CAN_SENDER_CALLBACK wait; - CAN_SENDER_CALLBACK send; -} CAN_SENDER; + CANSENDER_CALLBACK wait; + CANSENDER_CALLBACK send; +} CANSENDER; /** - * Initialize the CAN_SENDER - * @param me the CAN_SENDER itself + * Initialize the CANSENDER + * @param me the CANSENDER itself */ -void CAN_SENDER_init(CAN_SENDER* me); +void CANSENDER_init(CANSENDER* me); /** - * Start the CAN_SENDER state machine - * @param me the CAN_SENDER itself + * Start the CANSENDER state machine + * @param me the CANSENDER itself */ -void CAN_SENDER_startBehaviour(CAN_SENDER* me); +void CANSENDER_startBehaviour(CANSENDER* me); /** * Process the event * @param ev the event to process * @return true if the event is processed */ -bool CAN_SENDER_processEvent(Event* ev); +bool CANSENDER_processEvent(Event* ev); /************* * Callbacks * *************/ /** - * Set the callback function to call when the CAN_SENDER is entering state wait - * @param me the CAN_SENDER itself + * Set the callback function to call when the CANSENDER is entering state wait + * @param me the CANSENDER 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); +void CANSENDER_onWait(CANSENDER* me, CANSENDER_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 + * Set the callback function to call when the CANSENDER is entering state send + * @param me the CANSENDER 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); +void CANSENDER_onSend(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p); /************ * EMITTERS * @@ -79,18 +79,22 @@ void CAN_SENDER_onSend(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p); /** * Emit the send event - * @param me the CAN_SENDER itself + * @param me the CANSENDER itself * @param t time to wait in ms before triggering event */ -void CAN_SENDER_emitSend(CAN_SENDER* me, uint16_t t); +void CANSENDER_emitSend(CANSENDER* me, uint16_t t); /** * Emit the done event - * @param me the CAN_SENDER itself + * @param me the CANSENDER itself * @param t time to wait in ms before triggering event */ - void CAN_SENDER_emitDone(CAN_SENDER* me, uint16_t t); - + void CANSENDER_emitDone(CANSENDER* me, uint16_t t); + + void CANSENDER_sendCanMsg(CANSENDER* me, uint8_t id, uint32_t data); + void sendCanMsg(uint32_t id, uint32_t data); + + /*********** * SETTERS * ***********/ @@ -100,6 +104,9 @@ void CAN_SENDER_emitSend(CAN_SENDER* me, uint16_t t); * @param me * @param v */ -void CAN_SENDER_setSendingTime(CAN_SENDER* me, uint8_t v); +void CANSENDER_setSendingTime(CANSENDER* me, uint8_t v); + +void CANSENDER_seSender(CANSENDER* me, uint8_t s); +void CANSENDER_setRecipient(CANSENDER* me, uint8_t r); #endif diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index b7db225..cc66702 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -319,21 +319,6 @@ - - - - - - - - - - - - - - - diff --git a/UML/can.uxf b/UML/can.uxf index 835b6d9..d40dc6b 100644 --- a/UML/can.uxf +++ b/UML/can.uxf @@ -1,5 +1,5 @@ - + 15 UMLSpecialState @@ -211,14 +211,18 @@ evCSdone 765 630 - 645 - 150 + 705 + 270 _*How to use*_ -CANSENDER_send(uint32_t id, uint32_t data); -or -CANSENDER_send(CANSENDER *me, uint8_t id, uint32_t data); +*Like a static class:* +sendCanMsg(uint32_t id, uint32_t data); + +*Or like an Object: * +CANSENDER_seSender(CANSENDER* me, uint8_t s); +CANSENDER_setRecipient(CANSENDER* me, uint8_t r); +CANSENDER_sendCanMsg(CANSENDER* me, uint8_t id, uint32_t data); From 21f9cb7f623452db80c264a36ba0824a4bcc7696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 23 Aug 2023 13:45:34 +0200 Subject: [PATCH 06/14] finish devleop can interface not yet tested --- 306-controller_interface.X/app/blcontrol.c | 25 --- 306-controller_interface.X/app/blcontrol.h | 19 -- .../app/factory/factory.c | 70 ++++++ .../app/factory/factory.h | 48 ++++ 306-controller_interface.X/{ => app}/main.c | 4 +- .../board/button/button.c | 169 ++++++++++---- .../board/button/button.h | 104 +++++++-- .../board/button/buttonsm.c | 129 ----------- .../board/button/buttonsm.h | 69 ------ 306-controller_interface.X/board/led/led.c | 85 +++---- 306-controller_interface.X/board/led/led.h | 54 +++-- 306-controller_interface.X/factory/factory.c | 62 ----- 306-controller_interface.X/factory/factory.h | 42 ---- .../mcc_generated_files/pin_manager.c | 11 +- .../mcc_generated_files/pin_manager.h | 208 +++++++++++++---- .../middleware/can/can_interface.c | 134 ----------- .../middleware/can/can_interface.h | 104 --------- .../middleware/can/can_sender.c | 131 ----------- .../middleware/can/can_sender.h | 112 --------- .../middleware/can_interface.c | 127 +++++++++++ .../middleware/can_interface.h | 99 ++++++++ .../nbproject/configurations.xml | 53 ++--- 306-controller_interface.X/ss22ep.mc3 | 212 +++++++++--------- 23 files changed, 927 insertions(+), 1144 deletions(-) delete mode 100644 306-controller_interface.X/app/blcontrol.c delete mode 100644 306-controller_interface.X/app/blcontrol.h create mode 100644 306-controller_interface.X/app/factory/factory.c create mode 100644 306-controller_interface.X/app/factory/factory.h rename 306-controller_interface.X/{ => app}/main.c (93%) delete mode 100644 306-controller_interface.X/board/button/buttonsm.c delete mode 100644 306-controller_interface.X/board/button/buttonsm.h delete mode 100644 306-controller_interface.X/factory/factory.c delete mode 100644 306-controller_interface.X/factory/factory.h delete mode 100644 306-controller_interface.X/middleware/can/can_interface.c delete mode 100644 306-controller_interface.X/middleware/can/can_interface.h delete mode 100644 306-controller_interface.X/middleware/can/can_sender.c delete mode 100644 306-controller_interface.X/middleware/can/can_sender.h create mode 100644 306-controller_interface.X/middleware/can_interface.c create mode 100644 306-controller_interface.X/middleware/can_interface.h diff --git a/306-controller_interface.X/app/blcontrol.c b/306-controller_interface.X/app/blcontrol.c deleted file mode 100644 index 60efb4f..0000000 --- a/306-controller_interface.X/app/blcontrol.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "blcontrol.h" -#include "../mcc_generated_files/mcc.h" -#include "../factory/factory.h" -//private methods - -void BLControl_init(BLControl* me) -{ - //nothing to do yet -} - -void BLControl_onButton(void * me, uint8_t buttonId, bool pressed) -{ - BLControl* realMe = (BLControl*)me; - if (buttonId == BID) - { - if (pressed) - { - LED_on(l()); - } - else - { - LED_off(l()); - } - } -} diff --git a/306-controller_interface.X/app/blcontrol.h b/306-controller_interface.X/app/blcontrol.h deleted file mode 100644 index 6b0e053..0000000 --- a/306-controller_interface.X/app/blcontrol.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef BLCONTROL_DEF -#define BLCONTROL_DEF - -#include -#include -#include "../xf/xf.h" -#include "../board/button/buttonsm.h" - -struct BLControl_ -{ - -}; - -typedef struct BLControl_ BLControl; - -void BLControl_init(BLControl* me); -void BLControl_onButton(void* me, uint8_t buttonId, bool pressed); - -#endif diff --git a/306-controller_interface.X/app/factory/factory.c b/306-controller_interface.X/app/factory/factory.c new file mode 100644 index 0000000..3b149bb --- /dev/null +++ b/306-controller_interface.X/app/factory/factory.c @@ -0,0 +1,70 @@ +#include "factory.h" + + +//the factory object containing all objects of our system +static Factory theFactory; + +//all the getters +LED* l1() { + return &theFactory.l1_; +} +LED* l2() { + return &theFactory.l2_; +} +LED* l3() { + return &theFactory.l3_; +} +LED* l4() { + return &theFactory.l4_; +} +LED* l5() { + return &theFactory.l5_; +} +LED* l6() { + return &theFactory.l6_; +} +LED* l7() { + return &theFactory.l7_; +} +LED* l8() { + return &theFactory.l8_; +} + + +//initialize all objects +void Factory_init() { + LED_init(l1(), 1); + LED_init(l2(), 2); + LED_init(l3(), 3); + LED_init(l4(), 4); + LED_init(l5(), 5); + LED_init(l6(), 6); + LED_init(l7(), 7); + LED_init(l8(), 8); + + LED_initHW(l1()); + LED_initHW(l2()); + LED_initHW(l3()); + LED_initHW(l4()); + LED_initHW(l5()); + LED_initHW(l6()); + LED_initHW(l7()); + LED_initHW(l8()); + + CAN_init(); +} + +void foo(uint8_t a, uint8_t b, uint32_t c){ + +} + +//connect objects if required +void Factory_build() { + ECAN_SetRXBnInterruptHandler(CAN_newMsg); + CAN_onReceiveCan(foo); +} + +//start all state machines +void Factory_start() { + CAN_startBehaviour(); +} diff --git a/306-controller_interface.X/app/factory/factory.h b/306-controller_interface.X/app/factory/factory.h new file mode 100644 index 0000000..737a8e3 --- /dev/null +++ b/306-controller_interface.X/app/factory/factory.h @@ -0,0 +1,48 @@ +/** + * @author Rémi Heredero + * @version. 0.0.0 + * @date August 2023 + * @file factory.h + */ + + +#ifndef FACTORY_H +#define FACTORY_H + +#include +#include + +#include "../../board/led/led.h" +#include "../../board/button/button.h" +#include "../../middleware/can_interface.h" + + +typedef struct { + LED l1_; + LED l2_; + LED l3_; + LED l4_; + LED l5_; + LED l6_; + LED l7_; + LED l8_; + +} Factory; + + +void Factory_init(); +void Factory_build(); +void Factory_start(); + +//these are global getters for our objects +LED* l1(); +LED* l2(); +LED* l3(); +LED* l4(); +LED* l5(); +LED* l6(); +LED* l7(); +LED* l8(); + + +#endif \ No newline at end of file diff --git a/306-controller_interface.X/main.c b/306-controller_interface.X/app/main.c similarity index 93% rename from 306-controller_interface.X/main.c rename to 306-controller_interface.X/app/main.c index 1c5d0ae..f8f2218 100644 --- a/306-controller_interface.X/main.c +++ b/306-controller_interface.X/app/main.c @@ -1,5 +1,5 @@ -#include "mcc_generated_files/mcc.h" -#include "xf/xf.h" +#include "../mcc_generated_files/mcc.h" +#include "../xf/xf.h" #include "factory/factory.h" /* diff --git a/306-controller_interface.X/board/button/button.c b/306-controller_interface.X/board/button/button.c index 158cf00..a227b8c 100644 --- a/306-controller_interface.X/board/button/button.c +++ b/306-controller_interface.X/board/button/button.c @@ -1,66 +1,137 @@ +/** + * @author Rémi Heredero (remi@heredero.ch) + * @version. 1.0.0 + * @date 2023-06-15 + */ #include "button.h" #include "../../mcc_generated_files/pin_manager.h" +#include "../../app/factory/factory.h" -void Button_init(Button* me, uint8_t id, bool isPullUp) -{ +/** + * @brief Initialize the button + * + * @param me The object to initialize + * @param id The id of the button + */ +void BUTTON_init(BUTTON* me, uint8_t id) { me->id = id; - me->isPullUp = isPullUp; + me->state = ST_PBINIT; + me->press.fCallBack = NULL; + me->release.fCallBack = NULL; } /** - * @brief Initialize the Driver + * @brief Initialize the hardware of the button * + * @param me The object to initialize */ -void Button_initHW(Button* me) -{ -} - -//read the state of the button -//maybe you have to adjust the -//low level calls -uint8_t Button_read(Button* me) -{ - uint8_t value = LOW; - switch (me->id) - { +void BUTTON_initHW(BUTTON* me) { + switch (me->id) { case 1: - value = IO_RA7_GetValue(); - break; + INPUT1_SetDigitalInput(); + break; case 2: - break; + INPUT2_SetDigitalInput(); + break; case 3: - break; - case 4: - break; - case 5: - break; - case 6: - break; - case 7: - break; - case 8: - break; - case 9: - break; - case 10: - break; + INPUT3_SetDigitalInput(); + break; + default: + break; } - if (me->isPullUp == true) - { - value=value==LOW?HIGH:LOW; - } - return value; - } - -//id getter -uint8_t Button_getId(Button* me) -{ - return me->id; } -//id setter -void Button_setId(Button* me, uint8_t id) -{ - me->id = id; +/** + * @brief Check if the button is pressed + * The function returns true if the button is pressed, false otherwise + * + * @param me The object to check + * @return true if the button is pressed + * @return false if the button is not pressed + */ +bool BUTTON_isPressed(BUTTON* me) { + switch (me->id) { + case 1: + return INPUT1_GetValue(); + break; + case 2: + return INPUT2_GetValue(); + break; + case 3: + return INPUT3_GetValue(); + break; + default: + return false; + break; + } +} + +void BUTTON_startBehaviour(BUTTON* me) { + POST(me, &BUTTON_processEvent, evPBInit, 0, 0); +} + +bool BUTTON_processEvent(Event * ev) { + bool processed = false; + BUTTON* me = (BUTTON*)Event_getTarget(ev); + BUTTON_STATES oldState = me->state; + evIDT evid = Event_getId(ev); + + switch(me->state){ + case ST_PBINIT: + if (evid == evPBInit) { + POST(me, &BUTTON_processEvent, evPBPoll, 0, 0); + if(BUTTON_isPressed(me)) { + me->state = ST_PBPRESSED; + } else { + me->state = ST_PBRELEASED; + } + } + break; + case ST_PBRELEASED: + if(evid == evPBPoll) { + POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0); + if(BUTTON_isPressed(me)) { + me->state = ST_PBPRESSED; + } + } + + break; + case ST_PBPRESSED: + if(evid == evPBPoll) { + POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0); + if(!BUTTON_isPressed(me)){ + me->state = ST_PBRELEASED; + } + + } + break; + } + + if(oldState != me->state) { + switch(me->state){ + case ST_PBINIT: + break; + case ST_PBRELEASED: + if(me->release.fCallBack != NULL) me->release.fCallBack(me->release.param); + break; + case ST_PBPRESSED: + if(me->press.fCallBack != NULL) me->press.fCallBack(me->press.param); + break; + } + processed = true; + } + return processed; +} + +void BUTTON_setEventFunctions(BUTTON* me, buttonCallBack fPress, buttonCallBack fRelease) { + me->press = fPress; + me->release = fRelease; +} + +buttonCallBack BUTTON_defineCallBack(fButtonCallback f, void* param){ + buttonCallBack c; + c.fCallBack = f; + c.param = param; + return c; } \ No newline at end of file diff --git a/306-controller_interface.X/board/button/button.h b/306-controller_interface.X/board/button/button.h index de76a35..c3cfbf0 100644 --- a/306-controller_interface.X/board/button/button.h +++ b/306-controller_interface.X/board/button/button.h @@ -1,25 +1,97 @@ -#ifndef Button_ONCE -#define Button_ONCE +/** + * @author Rémi Heredero (remi@heredero.ch) + * @version. 1.0.0 + * @date 2023-06-15 + */ +#ifndef BUTTON_H +#define BUTTON_H #include #include +#include "../../xf/xf.h" -/* - * this is the declaration of the Button class +#define PB_POLL_TIME 20 // Poll time for BUTTON + +typedef enum { + ST_PBINIT, + ST_PBRELEASED, + ST_PBPRESSED +} BUTTON_STATES; + +typedef enum { + evPBInit=50, + evPBPoll +} BUTTON_EVENTS; + +// Calback function +typedef void (*fButtonCallback)(void*); +typedef struct { + fButtonCallback fCallBack; + void* param; +} buttonCallBack; + +typedef struct { + uint8_t id; // Id of the button + BUTTON_STATES state; // Actual state + buttonCallBack press; // Callback for the rising edge of the button + buttonCallBack release; // Callback for the falling edge of the button +} BUTTON; + +/** + * @brief Initialize the button + * + * @param me button itself + * @param id The id of the button */ +void BUTTON_init(BUTTON* me, uint8_t id); -struct Button_ -{ - uint8_t id; - bool isPullUp; -}; +/** + * @brief Initialize the hardware of the button + * + * @param me button itself + */ +void BUTTON_initHW(BUTTON* me); -typedef struct Button_ Button; +/** + * @brief Set both callback event functions + * + * @param me button itself + * @param fPress callback function when the button have a rising edge + * @param release callback function whent the have a falling edge + */ +void BUTTON_setEventFunctions(BUTTON* me, buttonCallBack fPress, buttonCallBack release); -void Button_init(Button* me, uint8_t id, bool isPullUp); -void Button_initHW(Button* me); -uint8_t Button_read(Button* me); -void Button_setId(Button* me, uint8_t id); -uint8_t Button_getId(Button* me); +/** + * @brief Check if the button is pressed + * The function returns true if the button is pressed, false otherwise + * + * @param me button itself + * @return true if the button is pressed + * @return false if the button is not pressed + */ +bool BUTTON_isPressed(BUTTON* me); -#endif +/** + * @biref Start state machine of the BUTTON + * + * @param me the button itself + */ +void BUTTON_startBehaviour(BUTTON* me); + +/** + * @brief State machine of the BUTTON + * + * @param ev event to process on the state machine + */ +bool BUTTON_processEvent(Event* ev); + +/** + * @brief Define a callback for BUTTON + * + * @param f callback function + * @param param callback parameter for the function + * @return the callback struct + */ +buttonCallBack BUTTON_defineCallBack(fButtonCallback f, void* param); + +#endif /* BUTTON_H */ \ No newline at end of file diff --git a/306-controller_interface.X/board/button/buttonsm.c b/306-controller_interface.X/board/button/buttonsm.c deleted file mode 100644 index 05e7fb9..0000000 --- a/306-controller_interface.X/board/button/buttonsm.c +++ /dev/null @@ -1,129 +0,0 @@ -#include "buttonsm.h" - -/* - * this is the init method of the ButtonSM class - */ -void ButtonSM_init(ButtonSM* me, Button* button) -{ - me->state = ST_BSMINIT; - me->button = button; - - me->actualState = ST_BSMINIT; - me->observer = NULL; - me->observerCB = NULL; -} - -/* - * this is the state machine method of the ButtonSM class - */ -bool ButtonSM_processEvent(Event* ev) -{ - ButtonSM* me = (ButtonSM*)ev->target; - bool processed = false; - BSMState oldState = me->state; - - switch (me->state) - { - case ST_BSMINIT: - if (Event_getId(ev) == evBSMInit) - { - me->state = ST_BSMWAIT; - } - break; - case ST_BSMWAIT: - if (Event_getId(ev) == evBSMPollTM) - { - me->state = ST_BSMPOLL; - } - break; - case ST_BSMPOLL: - if (Event_getId(ev) == evBSMDefault) - { - if (Button_read(me->button)==HIGH) - { - me->state = ST_BSMPRESSED; - } - else - { - me->state = ST_BSMRELEASED; - } - } - break; - case ST_BSMPRESSED: - if (Event_getId(ev) == evBSMDefault) - { - me->state = ST_BSMWAIT; - } - break; - case ST_BSMRELEASED: - if (Event_getId(ev) == evBSMDefault) - { - me->state = ST_BSMWAIT; - } - break; - } - if (oldState != me->state) - { - processed = true; - switch (me->state) - { - case ST_BSMINIT: - break; - case ST_BSMWAIT: - POST(me, &ButtonSM_processEvent, evBSMPollTM,POLLTM,0); - break; - case ST_BSMPOLL: - POST(me, &ButtonSM_processEvent, evBSMDefault,0,0); - break; - case ST_BSMPRESSED: - POST(me, &ButtonSM_processEvent, evBSMDefault,0,0); - if (me->actualState != ST_BSMPRESSED) - { - if (me->observerCB != NULL) - { - me->observerCB(me->observer,Button_getId(me->button),true); - me->actualState = ST_BSMPRESSED; - } - } - break; - case ST_BSMRELEASED: - POST(me, &ButtonSM_processEvent, evBSMDefault,0,0); - if (me->actualState != ST_BSMRELEASED) - { - if (me->observerCB != NULL) - { - me->observerCB(me->observer,Button_getId(me->button),false); - me->actualState = ST_BSMRELEASED; - } - } - break; - } - } - return processed; -} - -/* - * this is the start method for the - * state machine of the ButtonSM class - */ -void ButtonSM_startBehaviour(ButtonSM* me) -{ - POST(me, &ButtonSM_processEvent, evBSMInit,0,0); - me->actualState = Button_read(me->button)==HIGH?ST_BSMPRESSED:ST_BSMRELEASED; -} - -/* - * this is the method to set the object and the - * call back method of the ButtonSM class - * this method will be called whenever the - * button changes its state - * as parameters to the callback method will be passed - * the object address, the button id and its state - * if the call back method does not belong to a class, - * then the object address must be set to NULL - */ -void ButtonSM_setObserver(ButtonSM* me, void* observer, buttonObserverCBT observerCB) -{ - me->observer = observer; - me->observerCB = observerCB; -} \ No newline at end of file diff --git a/306-controller_interface.X/board/button/buttonsm.h b/306-controller_interface.X/board/button/buttonsm.h deleted file mode 100644 index 9353774..0000000 --- a/306-controller_interface.X/board/button/buttonsm.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef BUTTONSM_DEF -#define BUTTONSM_DEF - -#include -#include -#include "../../xf/xf.h" -#include "button.h" - -/* - * these are the events of the - * button state machine - * be sure to make the first event - * in the enumeration different from 0 - */ -typedef enum BSMEvent -{ - evBSMInit = 10, - evBSMDefault, - evBSMPollTM -} BSMEvent; - -/* - * these are the states of the - * button state machine - */ -typedef enum BSMSTate_ -{ - ST_BSMINIT, - ST_BSMWAIT, - ST_BSMPOLL, - ST_BSMPRESSED, - ST_BSMRELEASED -} BSMState; - -/* - * the associated button will be polled - * each 50 ms. do not make this time - * shorter than TICKINTERVAL - */ -#define POLLTM 50 - -/* - * this is the prototype type of the callback function - * that will be called when the associated button - * changes from released to pressed or inverse. - */ -typedef void (*buttonObserverCBT)(void*, uint8_t, bool); - -/* - * this is the declaration of the ButtonSM class - */ -struct ButtonSM_ -{ - BSMState state; - Button* button; - BSMState actualState; - - buttonObserverCBT observerCB; - void* observer; -}; - -typedef struct ButtonSM_ ButtonSM; - - -void ButtonSM_init(ButtonSM* me, Button* button); -void ButtonSM_startBehaviour(ButtonSM* me); -bool ButtonSM_processEvent(Event* ev); -void ButtonSM_setObserver(ButtonSM* me, void* observer, buttonObserverCBT observerCB); -#endif diff --git a/306-controller_interface.X/board/led/led.c b/306-controller_interface.X/board/led/led.c index cc4a4ba..c91bc4e 100644 --- a/306-controller_interface.X/board/led/led.c +++ b/306-controller_interface.X/board/led/led.c @@ -1,8 +1,13 @@ +/** + * @author Rémi Heredero (remi@heredero.ch) + * @version. 1.0.0 + * @date 2023-06-15 + */ + #include "led.h" #include "../../mcc_generated_files/pin_manager.h" -void LED_init(LED* me, uint8_t id) -{ +void LED_init(LED* me, uint8_t id) { me->id = id; } @@ -10,94 +15,68 @@ void LED_init(LED* me, uint8_t id) * @brief Initialize the Driver * */ -void LED_initHW(LED* me) -{ +void LED_initHW(LED* me) { LED_off(me); } -/* - * for the on and the off methods: - * if the output is push pull, it depends if the - * load is connect to ground or vcc. - * in this case, the load is connected to vcc, - * so on and off are inverted. Change the code as it - * is convenient for your hardware - */ - - -//switch on the led -//maybe you have to adjust your -//low level calls -void LED_on(LED* me) -{ - switch (me->id) - { +void LED_on(void* me) { + LED* l = (LED*) me; + switch (l->id) { case 1: - IO_RB0_SetLow(); + OUTPUT1_SetHigh(); break; case 2: + OUTPUT2_SetHigh(); break; case 3: + OUTPUT3_SetHigh(); break; case 4: + OUTPUT4_SetHigh(); break; case 5: + OUTPUT5_SetHigh(); break; case 6: + OUTPUT6_SetHigh(); break; case 7: + OUTPUT7_SetHigh(); break; case 8: - break; - case 9: - break; - case 10: - break; + OUTPUT8_SetHigh(); + break; } } -//switch off the led -//maybe you have to adjust your -//low level calls -void LED_off(LED* me) -{ - switch (me->id) - { +void LED_off(void* me) { + LED* l = (LED*) me; + switch (l->id) { case 1: - IO_RB0_SetHigh(); + OUTPUT1_SetLow(); break; case 2: + OUTPUT2_SetLow(); break; case 3: + OUTPUT3_SetLow(); break; case 4: + OUTPUT4_SetLow(); break; case 5: + OUTPUT5_SetLow(); break; case 6: + OUTPUT6_SetLow(); break; case 7: + OUTPUT7_SetLow(); break; case 8: - break; - case 9: - break; - case 10: + OUTPUT8_SetLow(); break; - } - + } } -void LED_setState(LED* me, uint8_t state) -{ - if (state == HIGH) - { - LED_on(me); - } - - if (state == LOW) - { - LED_off(me); - } -} \ No newline at end of file diff --git a/306-controller_interface.X/board/led/led.h b/306-controller_interface.X/board/led/led.h index 1bc5873..5255053 100644 --- a/306-controller_interface.X/board/led/led.h +++ b/306-controller_interface.X/board/led/led.h @@ -1,23 +1,43 @@ -#ifndef LED_ONCE -#define LED_ONCE +/** + * @author Rémi Heredero (remi@heredero.ch) + * @version. 1.0.0 + * @date 2023-06-15 + */ + +#ifndef LED_H +#define LED_H #include -/* - * this is the declaration of the Led class +// LED struct +typedef struct { + uint8_t id; // The id of the LED +}LED; + +/** + * Initialize the led + * @param me the led itself + * @param id the id of the led */ -struct LED_ -{ - //has a gpo - uint8_t id; -}; - -typedef struct LED_ LED; - void LED_init(LED* me, uint8_t id); -void LED_initHW(LED* me); -void LED_on(LED* me); -void LED_off(LED* me); -void LED_setState(LED* me,uint8_t state); -#endif +/** + * Initializing the led + * @param me the led itself + */ +void LED_initHW(LED* me); + +/** + * Turn On the led + * @param me the led itself + */ +void LED_on(void* me); + +/** + * Turn Off the led + * @param me the led itself + */ +void LED_off(void* me); + +#endif /* LED_H */ + diff --git a/306-controller_interface.X/factory/factory.c b/306-controller_interface.X/factory/factory.c deleted file mode 100644 index f0f5b58..0000000 --- a/306-controller_interface.X/factory/factory.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "factory.h" - - -//the factory object containing all objects of our system -static Factory theFactory; - - -//all the getters -LED* l() -{ - return &theFactory.l_; -} - -Button* b() -{ - return &theFactory.b_; -} - -ButtonSM* bsm() -{ - return &theFactory.bsm_; -} - -BLControl* blc() -{ - return &theFactory.blc_; -} - - -//initialize all objects -void Factory_init() -{ - LED_init(l(),LID); - LED_initHW(l()); - Button_init(b(),BID, true); - Button_initHW(b()); - ButtonSM_init(bsm(),b()); - BLControl_init(blc()); - - CANINTERFACE_init(); - -; - -} - -void foo(uint32_t a, uint32_t b){ - -} - -//connect objects if required -void Factory_build() { - ButtonSM_setObserver(bsm(), blc(), &BLControl_onButton); - - ECAN_SetRXBnInterruptHandler(CANINTERFACE_newMsg); - //CANINTERFACE_onProcessCan(foo); -} - -//start all state machines -void Factory_start() -{ - ButtonSM_startBehaviour(bsm()); -} diff --git a/306-controller_interface.X/factory/factory.h b/306-controller_interface.X/factory/factory.h deleted file mode 100644 index fa65abc..0000000 --- a/306-controller_interface.X/factory/factory.h +++ /dev/null @@ -1,42 +0,0 @@ -/* this is the Factory class */ - - -#ifndef FACTORY_ONCE -#define FACTORY_ONCE - -#include -#include - -#include "../board/led/led.h" -#include "../board/button/button.h" -#include "../board/button/buttonsm.h" -#include "../app/blcontrol.h" -#include "../middleware/can/can_interface.h" - - -#define BID 1 -#define LID 1 - -void bObs(void*, uint8_t,bool); - -struct Factory_ -{ - LED l_; - Button b_; - ButtonSM bsm_; - BLControl blc_; -}; - -typedef struct Factory_ Factory; - -void Factory_init(); -void Factory_build(); -void Factory_start(); - -//these are global getters for our objects -LED* l(); -Button* b(); -ButtonSM* bsm(); -BLControl* blc(); - -#endif \ No newline at end of file diff --git a/306-controller_interface.X/mcc_generated_files/pin_manager.c b/306-controller_interface.X/mcc_generated_files/pin_manager.c index 87f781b..b9c898e 100644 --- a/306-controller_interface.X/mcc_generated_files/pin_manager.c +++ b/306-controller_interface.X/mcc_generated_files/pin_manager.c @@ -64,16 +64,16 @@ void PIN_MANAGER_Initialize(void) /** TRISx registers */ - TRISA = 0xFF; - TRISB = 0xFE; + TRISA = 0x00; + TRISB = 0xF6; TRISC = 0xFF; /** ANSELx registers */ ANSELC = 0xFF; - ANSELB = 0xF6; - ANSELA = 0x7F; + ANSELB = 0xEE; + ANSELA = 0x00; /** WPUx registers @@ -112,7 +112,8 @@ void PIN_MANAGER_Initialize(void) - CANRXPPS = 0x0B; //RB3->ECAN:CANRX; + CANRXPPS = 0x0C; //RB4->ECAN:CANRX; + RB3PPS = 0x33; //RB3->ECAN:CANTX0; } void PIN_MANAGER_IOC(void) diff --git a/306-controller_interface.X/mcc_generated_files/pin_manager.h b/306-controller_interface.X/mcc_generated_files/pin_manager.h index f6407c3..a4d0d24 100644 --- a/306-controller_interface.X/mcc_generated_files/pin_manager.h +++ b/306-controller_interface.X/mcc_generated_files/pin_manager.h @@ -65,45 +65,165 @@ #define PULL_UP_ENABLED 1 #define PULL_UP_DISABLED 0 -// get/set IO_RA7 aliases -#define IO_RA7_TRIS TRISAbits.TRISA7 -#define IO_RA7_LAT LATAbits.LATA7 -#define IO_RA7_PORT PORTAbits.RA7 -#define IO_RA7_WPU WPUAbits.WPUA7 -#define IO_RA7_OD ODCONAbits.ODCA7 -#define IO_RA7_ANS ANSELAbits.ANSELA7 -#define IO_RA7_SetHigh() do { LATAbits.LATA7 = 1; } while(0) -#define IO_RA7_SetLow() do { LATAbits.LATA7 = 0; } while(0) -#define IO_RA7_Toggle() do { LATAbits.LATA7 = ~LATAbits.LATA7; } while(0) -#define IO_RA7_GetValue() PORTAbits.RA7 -#define IO_RA7_SetDigitalInput() do { TRISAbits.TRISA7 = 1; } while(0) -#define IO_RA7_SetDigitalOutput() do { TRISAbits.TRISA7 = 0; } while(0) -#define IO_RA7_SetPullup() do { WPUAbits.WPUA7 = 1; } while(0) -#define IO_RA7_ResetPullup() do { WPUAbits.WPUA7 = 0; } while(0) -#define IO_RA7_SetPushPull() do { ODCONAbits.ODCA7 = 0; } while(0) -#define IO_RA7_SetOpenDrain() do { ODCONAbits.ODCA7 = 1; } while(0) -#define IO_RA7_SetAnalogMode() do { ANSELAbits.ANSELA7 = 1; } while(0) -#define IO_RA7_SetDigitalMode() do { ANSELAbits.ANSELA7 = 0; } while(0) +// get/set OUTPUT1 aliases +#define OUTPUT1_TRIS TRISAbits.TRISA0 +#define OUTPUT1_LAT LATAbits.LATA0 +#define OUTPUT1_PORT PORTAbits.RA0 +#define OUTPUT1_WPU WPUAbits.WPUA0 +#define OUTPUT1_OD ODCONAbits.ODCA0 +#define OUTPUT1_ANS ANSELAbits.ANSELA0 +#define OUTPUT1_SetHigh() do { LATAbits.LATA0 = 1; } while(0) +#define OUTPUT1_SetLow() do { LATAbits.LATA0 = 0; } while(0) +#define OUTPUT1_Toggle() do { LATAbits.LATA0 = ~LATAbits.LATA0; } while(0) +#define OUTPUT1_GetValue() PORTAbits.RA0 +#define OUTPUT1_SetDigitalInput() do { TRISAbits.TRISA0 = 1; } while(0) +#define OUTPUT1_SetDigitalOutput() do { TRISAbits.TRISA0 = 0; } while(0) +#define OUTPUT1_SetPullup() do { WPUAbits.WPUA0 = 1; } while(0) +#define OUTPUT1_ResetPullup() do { WPUAbits.WPUA0 = 0; } while(0) +#define OUTPUT1_SetPushPull() do { ODCONAbits.ODCA0 = 0; } while(0) +#define OUTPUT1_SetOpenDrain() do { ODCONAbits.ODCA0 = 1; } while(0) +#define OUTPUT1_SetAnalogMode() do { ANSELAbits.ANSELA0 = 1; } while(0) +#define OUTPUT1_SetDigitalMode() do { ANSELAbits.ANSELA0 = 0; } while(0) -// get/set IO_RB0 aliases -#define IO_RB0_TRIS TRISBbits.TRISB0 -#define IO_RB0_LAT LATBbits.LATB0 -#define IO_RB0_PORT PORTBbits.RB0 -#define IO_RB0_WPU WPUBbits.WPUB0 -#define IO_RB0_OD ODCONBbits.ODCB0 -#define IO_RB0_ANS ANSELBbits.ANSELB0 -#define IO_RB0_SetHigh() do { LATBbits.LATB0 = 1; } while(0) -#define IO_RB0_SetLow() do { LATBbits.LATB0 = 0; } while(0) -#define IO_RB0_Toggle() do { LATBbits.LATB0 = ~LATBbits.LATB0; } while(0) -#define IO_RB0_GetValue() PORTBbits.RB0 -#define IO_RB0_SetDigitalInput() do { TRISBbits.TRISB0 = 1; } while(0) -#define IO_RB0_SetDigitalOutput() do { TRISBbits.TRISB0 = 0; } while(0) -#define IO_RB0_SetPullup() do { WPUBbits.WPUB0 = 1; } while(0) -#define IO_RB0_ResetPullup() do { WPUBbits.WPUB0 = 0; } while(0) -#define IO_RB0_SetPushPull() do { ODCONBbits.ODCB0 = 0; } while(0) -#define IO_RB0_SetOpenDrain() do { ODCONBbits.ODCB0 = 1; } while(0) -#define IO_RB0_SetAnalogMode() do { ANSELBbits.ANSELB0 = 1; } while(0) -#define IO_RB0_SetDigitalMode() do { ANSELBbits.ANSELB0 = 0; } while(0) +// get/set OUTPUT2 aliases +#define OUTPUT2_TRIS TRISAbits.TRISA1 +#define OUTPUT2_LAT LATAbits.LATA1 +#define OUTPUT2_PORT PORTAbits.RA1 +#define OUTPUT2_WPU WPUAbits.WPUA1 +#define OUTPUT2_OD ODCONAbits.ODCA1 +#define OUTPUT2_ANS ANSELAbits.ANSELA1 +#define OUTPUT2_SetHigh() do { LATAbits.LATA1 = 1; } while(0) +#define OUTPUT2_SetLow() do { LATAbits.LATA1 = 0; } while(0) +#define OUTPUT2_Toggle() do { LATAbits.LATA1 = ~LATAbits.LATA1; } while(0) +#define OUTPUT2_GetValue() PORTAbits.RA1 +#define OUTPUT2_SetDigitalInput() do { TRISAbits.TRISA1 = 1; } while(0) +#define OUTPUT2_SetDigitalOutput() do { TRISAbits.TRISA1 = 0; } while(0) +#define OUTPUT2_SetPullup() do { WPUAbits.WPUA1 = 1; } while(0) +#define OUTPUT2_ResetPullup() do { WPUAbits.WPUA1 = 0; } while(0) +#define OUTPUT2_SetPushPull() do { ODCONAbits.ODCA1 = 0; } while(0) +#define OUTPUT2_SetOpenDrain() do { ODCONAbits.ODCA1 = 1; } while(0) +#define OUTPUT2_SetAnalogMode() do { ANSELAbits.ANSELA1 = 1; } while(0) +#define OUTPUT2_SetDigitalMode() do { ANSELAbits.ANSELA1 = 0; } while(0) + +// get/set OUTPUT3 aliases +#define OUTPUT3_TRIS TRISAbits.TRISA2 +#define OUTPUT3_LAT LATAbits.LATA2 +#define OUTPUT3_PORT PORTAbits.RA2 +#define OUTPUT3_WPU WPUAbits.WPUA2 +#define OUTPUT3_OD ODCONAbits.ODCA2 +#define OUTPUT3_ANS ANSELAbits.ANSELA2 +#define OUTPUT3_SetHigh() do { LATAbits.LATA2 = 1; } while(0) +#define OUTPUT3_SetLow() do { LATAbits.LATA2 = 0; } while(0) +#define OUTPUT3_Toggle() do { LATAbits.LATA2 = ~LATAbits.LATA2; } while(0) +#define OUTPUT3_GetValue() PORTAbits.RA2 +#define OUTPUT3_SetDigitalInput() do { TRISAbits.TRISA2 = 1; } while(0) +#define OUTPUT3_SetDigitalOutput() do { TRISAbits.TRISA2 = 0; } while(0) +#define OUTPUT3_SetPullup() do { WPUAbits.WPUA2 = 1; } while(0) +#define OUTPUT3_ResetPullup() do { WPUAbits.WPUA2 = 0; } while(0) +#define OUTPUT3_SetPushPull() do { ODCONAbits.ODCA2 = 0; } while(0) +#define OUTPUT3_SetOpenDrain() do { ODCONAbits.ODCA2 = 1; } while(0) +#define OUTPUT3_SetAnalogMode() do { ANSELAbits.ANSELA2 = 1; } while(0) +#define OUTPUT3_SetDigitalMode() do { ANSELAbits.ANSELA2 = 0; } while(0) + +// get/set OUTPUT4 aliases +#define OUTPUT4_TRIS TRISAbits.TRISA3 +#define OUTPUT4_LAT LATAbits.LATA3 +#define OUTPUT4_PORT PORTAbits.RA3 +#define OUTPUT4_WPU WPUAbits.WPUA3 +#define OUTPUT4_OD ODCONAbits.ODCA3 +#define OUTPUT4_ANS ANSELAbits.ANSELA3 +#define OUTPUT4_SetHigh() do { LATAbits.LATA3 = 1; } while(0) +#define OUTPUT4_SetLow() do { LATAbits.LATA3 = 0; } while(0) +#define OUTPUT4_Toggle() do { LATAbits.LATA3 = ~LATAbits.LATA3; } while(0) +#define OUTPUT4_GetValue() PORTAbits.RA3 +#define OUTPUT4_SetDigitalInput() do { TRISAbits.TRISA3 = 1; } while(0) +#define OUTPUT4_SetDigitalOutput() do { TRISAbits.TRISA3 = 0; } while(0) +#define OUTPUT4_SetPullup() do { WPUAbits.WPUA3 = 1; } while(0) +#define OUTPUT4_ResetPullup() do { WPUAbits.WPUA3 = 0; } while(0) +#define OUTPUT4_SetPushPull() do { ODCONAbits.ODCA3 = 0; } while(0) +#define OUTPUT4_SetOpenDrain() do { ODCONAbits.ODCA3 = 1; } while(0) +#define OUTPUT4_SetAnalogMode() do { ANSELAbits.ANSELA3 = 1; } while(0) +#define OUTPUT4_SetDigitalMode() do { ANSELAbits.ANSELA3 = 0; } while(0) + +// get/set OUTPUT5 aliases +#define OUTPUT5_TRIS TRISAbits.TRISA4 +#define OUTPUT5_LAT LATAbits.LATA4 +#define OUTPUT5_PORT PORTAbits.RA4 +#define OUTPUT5_WPU WPUAbits.WPUA4 +#define OUTPUT5_OD ODCONAbits.ODCA4 +#define OUTPUT5_ANS ANSELAbits.ANSELA4 +#define OUTPUT5_SetHigh() do { LATAbits.LATA4 = 1; } while(0) +#define OUTPUT5_SetLow() do { LATAbits.LATA4 = 0; } while(0) +#define OUTPUT5_Toggle() do { LATAbits.LATA4 = ~LATAbits.LATA4; } while(0) +#define OUTPUT5_GetValue() PORTAbits.RA4 +#define OUTPUT5_SetDigitalInput() do { TRISAbits.TRISA4 = 1; } while(0) +#define OUTPUT5_SetDigitalOutput() do { TRISAbits.TRISA4 = 0; } while(0) +#define OUTPUT5_SetPullup() do { WPUAbits.WPUA4 = 1; } while(0) +#define OUTPUT5_ResetPullup() do { WPUAbits.WPUA4 = 0; } while(0) +#define OUTPUT5_SetPushPull() do { ODCONAbits.ODCA4 = 0; } while(0) +#define OUTPUT5_SetOpenDrain() do { ODCONAbits.ODCA4 = 1; } while(0) +#define OUTPUT5_SetAnalogMode() do { ANSELAbits.ANSELA4 = 1; } while(0) +#define OUTPUT5_SetDigitalMode() do { ANSELAbits.ANSELA4 = 0; } while(0) + +// get/set OUTPUT6 aliases +#define OUTPUT6_TRIS TRISAbits.TRISA5 +#define OUTPUT6_LAT LATAbits.LATA5 +#define OUTPUT6_PORT PORTAbits.RA5 +#define OUTPUT6_WPU WPUAbits.WPUA5 +#define OUTPUT6_OD ODCONAbits.ODCA5 +#define OUTPUT6_ANS ANSELAbits.ANSELA5 +#define OUTPUT6_SetHigh() do { LATAbits.LATA5 = 1; } while(0) +#define OUTPUT6_SetLow() do { LATAbits.LATA5 = 0; } while(0) +#define OUTPUT6_Toggle() do { LATAbits.LATA5 = ~LATAbits.LATA5; } while(0) +#define OUTPUT6_GetValue() PORTAbits.RA5 +#define OUTPUT6_SetDigitalInput() do { TRISAbits.TRISA5 = 1; } while(0) +#define OUTPUT6_SetDigitalOutput() do { TRISAbits.TRISA5 = 0; } while(0) +#define OUTPUT6_SetPullup() do { WPUAbits.WPUA5 = 1; } while(0) +#define OUTPUT6_ResetPullup() do { WPUAbits.WPUA5 = 0; } while(0) +#define OUTPUT6_SetPushPull() do { ODCONAbits.ODCA5 = 0; } while(0) +#define OUTPUT6_SetOpenDrain() do { ODCONAbits.ODCA5 = 1; } while(0) +#define OUTPUT6_SetAnalogMode() do { ANSELAbits.ANSELA5 = 1; } while(0) +#define OUTPUT6_SetDigitalMode() do { ANSELAbits.ANSELA5 = 0; } while(0) + +// get/set OUTPUT7 aliases +#define OUTPUT7_TRIS TRISAbits.TRISA6 +#define OUTPUT7_LAT LATAbits.LATA6 +#define OUTPUT7_PORT PORTAbits.RA6 +#define OUTPUT7_WPU WPUAbits.WPUA6 +#define OUTPUT7_OD ODCONAbits.ODCA6 +#define OUTPUT7_ANS ANSELAbits.ANSELA6 +#define OUTPUT7_SetHigh() do { LATAbits.LATA6 = 1; } while(0) +#define OUTPUT7_SetLow() do { LATAbits.LATA6 = 0; } while(0) +#define OUTPUT7_Toggle() do { LATAbits.LATA6 = ~LATAbits.LATA6; } while(0) +#define OUTPUT7_GetValue() PORTAbits.RA6 +#define OUTPUT7_SetDigitalInput() do { TRISAbits.TRISA6 = 1; } while(0) +#define OUTPUT7_SetDigitalOutput() do { TRISAbits.TRISA6 = 0; } while(0) +#define OUTPUT7_SetPullup() do { WPUAbits.WPUA6 = 1; } while(0) +#define OUTPUT7_ResetPullup() do { WPUAbits.WPUA6 = 0; } while(0) +#define OUTPUT7_SetPushPull() do { ODCONAbits.ODCA6 = 0; } while(0) +#define OUTPUT7_SetOpenDrain() do { ODCONAbits.ODCA6 = 1; } while(0) +#define OUTPUT7_SetAnalogMode() do { ANSELAbits.ANSELA6 = 1; } while(0) +#define OUTPUT7_SetDigitalMode() do { ANSELAbits.ANSELA6 = 0; } while(0) + +// get/set OUTPUT8 aliases +#define OUTPUT8_TRIS TRISAbits.TRISA7 +#define OUTPUT8_LAT LATAbits.LATA7 +#define OUTPUT8_PORT PORTAbits.RA7 +#define OUTPUT8_WPU WPUAbits.WPUA7 +#define OUTPUT8_OD ODCONAbits.ODCA7 +#define OUTPUT8_ANS ANSELAbits.ANSELA7 +#define OUTPUT8_SetHigh() do { LATAbits.LATA7 = 1; } while(0) +#define OUTPUT8_SetLow() do { LATAbits.LATA7 = 0; } while(0) +#define OUTPUT8_Toggle() do { LATAbits.LATA7 = ~LATAbits.LATA7; } while(0) +#define OUTPUT8_GetValue() PORTAbits.RA7 +#define OUTPUT8_SetDigitalInput() do { TRISAbits.TRISA7 = 1; } while(0) +#define OUTPUT8_SetDigitalOutput() do { TRISAbits.TRISA7 = 0; } while(0) +#define OUTPUT8_SetPullup() do { WPUAbits.WPUA7 = 1; } while(0) +#define OUTPUT8_ResetPullup() do { WPUAbits.WPUA7 = 0; } while(0) +#define OUTPUT8_SetPushPull() do { ODCONAbits.ODCA7 = 0; } while(0) +#define OUTPUT8_SetOpenDrain() do { ODCONAbits.ODCA7 = 1; } while(0) +#define OUTPUT8_SetAnalogMode() do { ANSELAbits.ANSELA7 = 1; } while(0) +#define OUTPUT8_SetDigitalMode() do { ANSELAbits.ANSELA7 = 0; } while(0) // get/set RB3 procedures #define RB3_SetHigh() do { LATBbits.LATB3 = 1; } while(0) @@ -117,6 +237,18 @@ #define RB3_SetAnalogMode() do { ANSELBbits.ANSELB3 = 1; } while(0) #define RB3_SetDigitalMode() do { ANSELBbits.ANSELB3 = 0; } while(0) +// get/set RB4 procedures +#define RB4_SetHigh() do { LATBbits.LATB4 = 1; } while(0) +#define RB4_SetLow() do { LATBbits.LATB4 = 0; } while(0) +#define RB4_Toggle() do { LATBbits.LATB4 = ~LATBbits.LATB4; } while(0) +#define RB4_GetValue() PORTBbits.RB4 +#define RB4_SetDigitalInput() do { TRISBbits.TRISB4 = 1; } while(0) +#define RB4_SetDigitalOutput() do { TRISBbits.TRISB4 = 0; } while(0) +#define RB4_SetPullup() do { WPUBbits.WPUB4 = 1; } while(0) +#define RB4_ResetPullup() do { WPUBbits.WPUB4 = 0; } while(0) +#define RB4_SetAnalogMode() do { ANSELBbits.ANSELB4 = 1; } while(0) +#define RB4_SetDigitalMode() do { ANSELBbits.ANSELB4 = 0; } while(0) + /** @Param none diff --git a/306-controller_interface.X/middleware/can/can_interface.c b/306-controller_interface.X/middleware/can/can_interface.c deleted file mode 100644 index 4ac0fce..0000000 --- a/306-controller_interface.X/middleware/can/can_interface.c +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @author Rémi Heredero - * @version 1.0.0 - * @date August 2023 - * @file can_interface.c - */ - -#include "can_interface.h" - -void CANINTERFACE_init(){ - CANINTERFACE_myself.wait.f = NULL; - CANINTERFACE_myself.read.f = NULL; - //CANINTERFACE_myself.processCan = NULL; -} - -void CANINTERFACE_startBehaviour(){ - POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAinit, 0, 0); -} - -void CANINTERFACE_newMsg() { - uint64_t data; - uCAN_MSG canMsg; - CAN_receive(&canMsg); - data = canMsg.frame.id; - data = data<<32; - data = canMsg.frame.data0; - data = data<<8; - data = canMsg.frame.data1; - data = data<<8; - data = canMsg.frame.data2; - data = data<<8; - data = canMsg.frame.data3; - POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, 0, data); -} - -bool CANINTERFACE_processEvent(Event* ev) { - bool processed = false; - CANINTERFACE* me = (CANINTERFACE*)Event_getTarget(ev); - CANINTERFACE_STATES oldState = me->state; - evIDT evid = Event_getId(ev); - - uint64_t data = Event_getData(ev); - uint32_t canData = (uint32_t) data; - data = data>>8; - uint32_t canId = (uint32_t) data; - - switch (me->state) { // onState - case STCA_INIT: - if (ev->id == evCAinit) { - me->state = STCA_WAIT; - } - break; - - case STCA_WAIT: - if (ev->id == evCAnewMsg) { - me->state = STCA_READ; - CANINTERFACE_emitDone(0); - } - break; - - case STCA_READ: - if (ev->id == evCAdone) { - me->state = STCA_WAIT; - } - break; - } - - if(oldState != me->state){ - switch (oldState) { // onExit - case STCA_INIT: - break; - - case STCA_WAIT: - break; - - case STCA_READ: - break; - } - - switch (me->state) { // onEntry - case STCA_INIT: - break; - - case STCA_WAIT: - if (me->wait.f != NULL) { - me->wait.f(me->wait.p); - } - break; - - case STCA_READ: - if (me->read.f != NULL) { - me->read.f(me->read.p); - } - - if (me->processCan != NULL) { - me->processCan(canId, canData); - } - break; - } - - processed = true; - } - return processed; -} - -/************* - * Callbacks * - *************/ - -void CANINTERFACE_onWait(CANINTERFACE_CALLBACK_FUNCTION f, void* p) { - CANINTERFACE_myself.wait.f = f; - CANINTERFACE_myself.wait.p = p; -} - -void CANINTERFACE_onRead(CANINTERFACE_CALLBACK_FUNCTION f, void* p) { - CANINTERFACE_myself.read.f = f; - CANINTERFACE_myself.read.p = p; -} - -void CANINTERFACE_onProcessCan(CANINTERFACE_CALLBACK_CAN f) { - CANINTERFACE_myself.processCan = f; -} - -/************ - * EMITTERS * - ************/ - -void CANINTERFACE_emitNewMsg(uint16_t t) { - POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, t, 0); -} - -void CANINTERFACE_emitDone(uint16_t t) { - POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAdone, t, 0); -} diff --git a/306-controller_interface.X/middleware/can/can_interface.h b/306-controller_interface.X/middleware/can/can_interface.h deleted file mode 100644 index 5508af3..0000000 --- a/306-controller_interface.X/middleware/can/can_interface.h +++ /dev/null @@ -1,104 +0,0 @@ -/** - * @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 - */ -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 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 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 t time to wait in ms before triggering event - */ -void CANINTERFACE_emitNewMsg(uint16_t t); - -/** - * Emit the Done event - * @param t time to wait in ms before triggering event - */ -void CANINTERFACE_emitDone(uint16_t t); - -#endif diff --git a/306-controller_interface.X/middleware/can/can_sender.c b/306-controller_interface.X/middleware/can/can_sender.c deleted file mode 100644 index 71163be..0000000 --- a/306-controller_interface.X/middleware/can/can_sender.c +++ /dev/null @@ -1,131 +0,0 @@ -/** - * @author Rémi Heredero - * @version 1.0.0 - * @date August 2023 - * @file can_sender.c - */ - -#include "can_sender.h" - -void CANSENDER_init(CANSENDER* me){ - me->state = STCS_INIT; - me->sendingTime = 1; - me->wait.f = NULL; - me->send.f = NULL; -} - -void CANSENDER_startBehaviour(CANSENDER* me){ - POST(me, &CANSENDER_processEvent, evCSinit, 0, 0); -} - -bool CANSENDER_processEvent(Event* ev) { - bool processed = false; - CANSENDER* me = (CANSENDER*)Event_getTarget(ev); - CANSENDER_STATES oldState = me->state; - evIDT evid = Event_getId(ev); - uint64_t data = Event_getData(ev); - - switch (me->state) { // onState - case STCS_INIT: - if (ev->id == evCSinit) { - CANSENDER.state = STCS_WAIT; - } - break; - - case STCS_WAIT: - if (ev->id == evCSsend) { - CANSENDER.state = STCS_SEND; - } - break; - - case STCS_SEND: - if (ev->id == evCSdone) { - CANSENDER.state = STCS_WAIT; - } - - uCAN_MSG canMsg; - canMsg.frame.data0 = (uint8_t) data; - data = data >> 8; - canMsg.frame.data1 = (uint8_t) data; - data = data >> 8; - canMsg.frame.data2 = (uint8_t) data; - data = data >> 8; - canMsg.frame.data3 = (uint8_t) data; - data = data >> 8; - canMsg.frame.id = (uint32_t) data; - CAN_transmit(&canMsg); - - CANSENDER_emitDone(me, 0); - - 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 CANSENDER_onWait(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p) { - me->wait.f = f; - me->wait.p = p; -} - -void CANSENDER_onSend(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p) { - me->send.f = f; - me->send.p = p; -} - -/************ - * EMITTERS * - ************/ - -void CANSENDER_emitSend(CANSENDER* me, uint16_t t) { - POST(me, &CANSENDER_processEvent, evCSsend, t, 0); -} - -void CANSENDER_emitDone(CANSENDER* me, uint16_t t) { - POST(me, &CANSENDER_processEvent, evCSdone, t, 0); -} - -CANSENDER_sendCanMsg(CANSENDER* me, uint8_t id, uint32_t data) - -/*********** - * SETTERS * - ***********/ - -void CANSENDER_setSendingTime(CANSENDER* me, uint8_t v) { - me->sendingTime = v; -} diff --git a/306-controller_interface.X/middleware/can/can_sender.h b/306-controller_interface.X/middleware/can/can_sender.h deleted file mode 100644 index 3703e49..0000000 --- a/306-controller_interface.X/middleware/can/can_sender.h +++ /dev/null @@ -1,112 +0,0 @@ -/** - * @author Rémi Heredero - * @version 1.0.0 - * @date August 2023 - * @file can_sender.h - */ -#ifndef CANSENDER_H -#define CANSENDER_H - -#include "../../xf/xf.h" - -typedef enum { - STCS_INIT, - STCS_WAIT, - STCS_SEND -} CANSENDER_STATES; - -typedef enum { - evCSinit = 15, // TODO change this number (< 256) - evCSsend, - evCSdone -} CANSENDER_EVENTS; - -typedef void (*CANSENDER_CALLBACK_FUNCTION)(void*); -typedef struct { - CANSENDER_CALLBACK_FUNCTION f; // function - void* p; // param(s) -} CANSENDER_CALLBACK; - -typedef struct { - CANSENDER_STATES state; - uint8_t sendingTime; - CANSENDER_CALLBACK wait; - CANSENDER_CALLBACK send; -} CANSENDER; - -/** - * Initialize the CANSENDER - * @param me the CANSENDER itself - */ -void CANSENDER_init(CANSENDER* me); - -/** - * Start the CANSENDER state machine - * @param me the CANSENDER itself - */ -void CANSENDER_startBehaviour(CANSENDER* me); - -/** - * Process the event - * @param ev the event to process - * @return true if the event is processed - */ -bool CANSENDER_processEvent(Event* ev); - -/************* - * Callbacks * - *************/ - -/** - * Set the callback function to call when the CANSENDER is entering state wait - * @param me the CANSENDER itself - * @param f the function to call - * @param p the param(s) to pass to the function - */ -void CANSENDER_onWait(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p); - -/** - * Set the callback function to call when the CANSENDER is entering state send - * @param me the CANSENDER itself - * @param f the function to call - * @param p the param(s) to pass to the function - */ -void CANSENDER_onSend(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p); - -/************ - * EMITTERS * - ************/ - -/** - * Emit the send event - * @param me the CANSENDER itself - * @param t time to wait in ms before triggering event - */ -void CANSENDER_emitSend(CANSENDER* me, uint16_t t); - -/** - * Emit the done event - * @param me the CANSENDER itself - * @param t time to wait in ms before triggering event - */ - void CANSENDER_emitDone(CANSENDER* me, uint16_t t); - - void CANSENDER_sendCanMsg(CANSENDER* me, uint8_t id, uint32_t data); - void sendCanMsg(uint32_t id, uint32_t data); - - -/*********** - * SETTERS * - ***********/ - -/** - * - * @param me - * @param v - */ -void CANSENDER_setSendingTime(CANSENDER* me, uint8_t v); - -void CANSENDER_seSender(CANSENDER* me, uint8_t s); -void CANSENDER_setRecipient(CANSENDER* me, uint8_t r); - -#endif diff --git a/306-controller_interface.X/middleware/can_interface.c b/306-controller_interface.X/middleware/can_interface.c new file mode 100644 index 0000000..2656dc9 --- /dev/null +++ b/306-controller_interface.X/middleware/can_interface.c @@ -0,0 +1,127 @@ +/** + * @author Rémi Heredero + * @version 1.0.0 + * @date August 2023 + * @file can_interface.c + */ + +#include "can_interface.h" + +void CAN_init(){ + CAN_myself.receiveCan = NULL; + CAN_myself.sender = 0; +} + +void CAN_startBehaviour(){ + POST(&CAN_myself, &CAN_processEvent, evCAinit, 0, 0); +} + +bool CAN_processEvent(Event* ev) { + bool processed = false; + CAN* me = (CAN*)Event_getTarget(ev); + CAN_STATES oldState = me->state; + evIDT evid = Event_getId(ev); + + uint64_t data = Event_getData(ev); + + + switch (me->state) { // onState + case STCA_INIT: + if (ev->id == evCAinit) { + me->state = STCA_PROCESS; + } + break; + + case STCA_PROCESS: + + // New message arrive + if (ev->id == evCAnewMsg) { + if (me->receiveCan != NULL) { + uint32_t canData = (uint32_t) data; + data = data>>32; + uint8_t idMsg = (uint8_t) data; + data = data>>4; + uint8_t idRecipient = (uint8_t) data; + data = data>>4; + uint8_t idSender = (uint8_t) data; + me->receiveCan(idSender, idMsg, canData); + } + } + + // Send a message + if (ev->id == evCAsend) { + uCAN_MSG canMsg; + canMsg.frame.idType = 0; // I don't understand what is it + canMsg.frame.dlc = 8; // 8 bytes to send + canMsg.frame.rtr = 0; // no remote frame + canMsg.frame.data0 = (uint8_t) data; + data = data >> 8; + canMsg.frame.data1 = (uint8_t) data; + data = data >> 8; + canMsg.frame.data2 = (uint8_t) data; + data = data >> 8; + canMsg.frame.data3 = (uint8_t) data; + data = data >> 8; + canMsg.frame.id = (uint32_t) data; + CAN_transmit(&canMsg); + } + break; + } + + if(oldState != me->state){ + switch (oldState) { // onExit + case STCA_INIT: + break; + + case STCA_PROCESS: + break; + } + + switch (me->state) { // onEntry + case STCA_INIT: + break; + + case STCA_PROCESS: + break; + } + + processed = true; + } + return processed; +} + +/************* + * Callbacks * + *************/ + +void CAN_onReceiveCan(CAN_CALLBACK f) { + CAN_myself.receiveCan = f; +} + +/************ + * EMITTERS * + ************/ + +void CAN_newMsg() { + uint64_t data; + uCAN_MSG canMsg; + CAN_receive(&canMsg); + data = canMsg.frame.id; + data = data<<32; + data = canMsg.frame.data0; + data = data<<8; + data = canMsg.frame.data1; + data = data<<8; + data = canMsg.frame.data2; + data = data<<8; + data = canMsg.frame.data3; + POST(&CAN_myself, &CAN_processEvent, evCAnewMsg, 0, data); +} + +void CAN_Send(uint8_t idRecipient, uint8_t idMsg, uint32_t data) { + uint64_t tmpData = CAN_myself.sender; + tmpData = (tmpData<<4) | idRecipient; + tmpData = (tmpData<<4) | idMsg; + tmpData = (tmpData<<32) | data; + POST(&CAN_myself, &CAN_processEvent, evCAsend, 0, tmpData); +} diff --git a/306-controller_interface.X/middleware/can_interface.h b/306-controller_interface.X/middleware/can_interface.h new file mode 100644 index 0000000..d08b1cb --- /dev/null +++ b/306-controller_interface.X/middleware/can_interface.h @@ -0,0 +1,99 @@ +/** + * @author Rémi Heredero + * @version 1.0.0 + * @date August 2023 + * @file can_interface.h + */ +#ifndef CAN_H +#define CAN_H + +#include "../xf/xf.h" + +typedef enum { + STCA_INIT, + STCA_PROCESS +} CAN_STATES; + +typedef enum { + evCAinit = 10, // TODO change this number (< 256) + evCAnewMsg, + evCAsend +} CAN_EVENTS; + +typedef void (*CAN_CALLBACK)(uint8_t, uint8_t, uint32_t); + +typedef struct { + CAN_STATES state; + uint8_t sender; + CAN_CALLBACK receiveCan; +} CAN; + +CAN CAN_myself; + +/** + * Initialize the CAN + * @param me the CAN itself + */ +void CAN_init(); + +/** + * Start the CAN state machine + */ +void CAN_startBehaviour(); + + +/** + * Process the event + * @param ev the event to process + * @return true if the event is processed + */ +bool CAN_processEvent(Event* ev); + +/************* + * Callbacks * + *************/ + + +/** + * Set the callback function to call when the CAN is entering state read + * @param f the function to call + */ +void CAN_onReceiveCan(CAN_CALLBACK f); + +/************ + * EMITTERS * + ************/ + +/** + * Handler for receiving new can message during. + * This function is done during interrupt + */ +void CAN_newMsg(); + +/** + * Put a new can message on the queue + * @param idRecipient id for the recipient + * @param idMsg id for the message + * @param data 4 bytes of data to send + */ +void CAN_Send(uint8_t idRecipient, uint8_t idMsg, uint32_t data); + +/*********** + * SETTERS * + ***********/ + +/** + * Set the sender of this firmware + * @param idSender id of the sender + * 1 CONTROL + * 2 JOYSTICK + * 3 DISPLAY + * 4 DRIVE + * 5 STEERING + * 6 SUPPLY + * 7 UNDEFINED YET + * 0 BROADCAST/DEBUG + */ +void CAN_setSender(uint8_t idSender); + +#endif diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index cc66702..9db35d3 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -5,19 +5,10 @@ displayName="Header Files" projectFiles="true"> - app/blcontrol.h + app/factory/factory.h - - board/button/buttonsm.h - board/button/button.h - - - board/led/led.h - - - - factory/factory.h + board/led/led.h mcc_generated_files/memory.h - - middleware/can/can_interface.h - middleware/can/can_sender.h - + middleware/can_interface.h xf/event.h @@ -50,19 +38,11 @@ displayName="Source Files" projectFiles="true"> - app/blcontrol.c + app/factory/factory.c + app/main.c - - board/button/button.c - board/button/buttonsm.c - - - board/led/led.c - - - - factory/factory.c + board/led/led.c mcc_generated_files/memory.c - - middleware/can/can_interface.c - middleware/can/can_sender.c - + middleware/can_interface.c xf/event.c xf/xf.c - main.c + + + + + + + + + + + + + + + diff --git a/306-controller_interface.X/ss22ep.mc3 b/306-controller_interface.X/ss22ep.mc3 index 9f4cf09..33d9ca8 100644 --- a/306-controller_interface.X/ss22ep.mc3 +++ b/306-controller_interface.X/ss22ep.mc3 @@ -11676,35 +11676,35 @@ - + OUTPUT1 - + OUTPUT2 - + OUTPUT3 - + OUTPUT4 - + OUTPUT5 - + OUTPUT6 - + OUTPUT7 - + OUTPUT8 @@ -11780,35 +11780,35 @@ - disabled + output - disabled + output - disabled + output - disabled + output - disabled + output - disabled + output - disabled + output - disabled + output @@ -11884,35 +11884,35 @@ - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled @@ -11980,35 +11980,35 @@ - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled - disabled + enabled @@ -14352,11 +14352,11 @@ - 255 + 0 - 246 + 238 @@ -14364,7 +14364,7 @@ - 11 + 12 @@ -14588,11 +14588,11 @@ - 0 + 51 - 51 + 0 @@ -14720,11 +14720,11 @@ - 255 + 0 - 238 + 246 @@ -14768,35 +14768,35 @@ - analog + digital - analog + digital - analog + digital - analog + digital - analog + digital - analog + digital - analog + digital - analog + digital @@ -14812,11 +14812,11 @@ - digital + analog - analog + digital @@ -14864,7 +14864,7 @@ - 11 + 12 @@ -15608,11 +15608,11 @@ - 0 + 51 - 51 + 0 @@ -15824,35 +15824,35 @@ - input + output - input + output - input + output - input + output - input + output - input + output - input + output - input + output @@ -15868,11 +15868,11 @@ - input + output - output + input @@ -17163,7 +17163,27 @@ Window delay time 87.5% - + + + mcc_generated_files\mcc.h + a2db7e36e878f686c2bf0c2ef586ef1c6570fa2f27119b4be7b52af6403091a4 + + + mcc_generated_files\device_config.h + 89c6172ff575ce515b93f2fbc85dcedc2978e58a8e0e1fbdc52e42511ae3bc05 + + + mcc_generated_files\interrupt_manager.h + 9c2f1ae45f2ac887bb3e8b3763e1a394a6a22ffe4e9ae1c20c336fe6f12da1aa + + + mcc_generated_files\memory.c + 17fb4759c4719b77287f6c4be48edfbcf117b5b8398b771c434f23aceac256e0 + + + mcc_generated_files\tmr0.h + 6661ab783aae9f11e952805f9bca14209ec06551939552123056eefd5524fff8 + main.c cae37ae3b36cf22e97e106633433f5c00a66dd5d38ec353eb67fbbb0d88bde4d @@ -17172,57 +17192,37 @@ mcc_generated_files\device_config.c 39a6d1181ef5eab59c7dde2c52a9ea889465d4da43262200f3322abc45e77739 - - mcc_generated_files\device_config.h - 89c6172ff575ce515b93f2fbc85dcedc2978e58a8e0e1fbdc52e42511ae3bc05 - - - mcc_generated_files\ecan.c - ea62f50d319e1e537d7632774728ad6a779f442e896d043dbdea8066d028a6c6 - - - mcc_generated_files\ecan.h - aa9a50aae81bab76b876ea6123777af7d6a6d0a58fe953be27e8b88776395b2e - - - mcc_generated_files\interrupt_manager.c - df04edcd2c7d85ef90a8dbe4e46f1b1c9487b872153f4f2321249a4ce0d9635f - - - mcc_generated_files\interrupt_manager.h - 9c2f1ae45f2ac887bb3e8b3763e1a394a6a22ffe4e9ae1c20c336fe6f12da1aa - - - mcc_generated_files\mcc.c - cc9ed44843b509879e6a3f676b561ecde91e1df88d855cf7eca77e1afc8920ca - - - mcc_generated_files\mcc.h - a2db7e36e878f686c2bf0c2ef586ef1c6570fa2f27119b4be7b52af6403091a4 - - - mcc_generated_files\memory.c - 17fb4759c4719b77287f6c4be48edfbcf117b5b8398b771c434f23aceac256e0 - - - mcc_generated_files\memory.h - fbbca4e9d7ce92ddcc637d82b694a1f5cbefa75710a8a18bb1dc9ab5161f0924 - - - mcc_generated_files\pin_manager.c - 30d27d3c212d3420d65a30996dd68e9c3ba572d0d2bf50924ad025e552b9dcbf - mcc_generated_files\pin_manager.h - 76c9c709283a0d30fc6bf8d663b1394044aa806dbd1282fad68c1ebb0a221d36 + 611a409602fd8fba29be052e06a3ce86ad0a3b723b5e0f4c1a998854de7f9a7b mcc_generated_files\tmr0.c e0b4d075e819024ae77ea60a2c01182fdca45b783980cb50358d0a614736339d - mcc_generated_files\tmr0.h - 6661ab783aae9f11e952805f9bca14209ec06551939552123056eefd5524fff8 + mcc_generated_files\pin_manager.c + 04b16a3d3fcbbb333ee6fb545a405b76aba47ef3935be548bf2b8165c43c5654 + + + mcc_generated_files\ecan.c + ea62f50d319e1e537d7632774728ad6a779f442e896d043dbdea8066d028a6c6 + + + mcc_generated_files\mcc.c + cc9ed44843b509879e6a3f676b561ecde91e1df88d855cf7eca77e1afc8920ca + + + mcc_generated_files\interrupt_manager.c + df04edcd2c7d85ef90a8dbe4e46f1b1c9487b872153f4f2321249a4ce0d9635f + + + mcc_generated_files\ecan.h + aa9a50aae81bab76b876ea6123777af7d6a6d0a58fe953be27e8b88776395b2e + + + mcc_generated_files\memory.h + fbbca4e9d7ce92ddcc637d82b694a1f5cbefa75710a8a18bb1dc9ab5161f0924 \ No newline at end of file From 91edfee0527b68a115eef84df528f731536b3962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 23 Aug 2023 13:55:46 +0200 Subject: [PATCH 07/14] update to prog --- UML/can.pdf | Bin 0 -> 2342 bytes UML/can.uxf | 222 +++++++++++----------------------------------------- 2 files changed, 45 insertions(+), 177 deletions(-) create mode 100644 UML/can.pdf diff --git a/UML/can.pdf b/UML/can.pdf new file mode 100644 index 0000000000000000000000000000000000000000..14c421afbcf36c54da4fe22a814626c7cc2ff1ed GIT binary patch literal 2342 zcmb7GYgiL!7A{&qvp}n^VC!vIAb=3&k_!n-Q{*agl^~#UaUcUkLZ&7IMB}5Nf>1;e z5Nu^Zp#-}?fx1%HB0>qEQbC|mR1g-sWr;{x#d1^F8KlLsKD+Jwne&}Z>O+~F;qnt_Z0hX_bJ)+uXrDWmmilf=Q zlCFeL48Phn=2fW4HB2=0Gc(bmH_XPgTQp8>(XevqD@3NThxPutsUKq)YB@{vds|$a zQ{GGMa!udzW%8fX!i}ulj-CI`RnA@}c>3|3b(faq8?~UO!@YZL97-RiA4n>#{m0)d z_r4sNl_`(k6khNg5eL~GZ5cAt$r!!du%~mAG|?u`bam?Tnv?!pjZ^69yK}snqb_c& zJhUcEc<;vdCife*yQ;4xmL+Mr^P6w;HJ(KQCptaN6gfj<_f2BX4&?gN{k>a`BHHH} z1>Ju-w!CVqqsmlimnK{$`Je;YGp@NDWB*<^@*LZwsU5cS^n_k-&c1ok$e`cvOHq%9@~0;M{>*YtX!QZ)~jk* zXGheUXL^|8{fdJ=rRNJ9k#)Q8sXlvWWvS;8>@<|yhi`DXy5j3to93v#^rG@-n#j8A z)0YE~286fvV|s^Os;6~F@}Onr;L9ab9yflp9qzuBS>_kqX7pS+6%oJP@cG(~1Ua#x zn$fhXg15A7+n32n?KBp$-pl79zglKZ-{PPN_2k&=X~sjUcN!e06$Lrknh9E)Z7j;I zD=QE2z)Fh>^+?^p55c^$+E1n5Vlxw{LSg+waj0WT@pw_=g%75cwQWZG{+)Sp@Snuk zb~WteWs=oUqqJ;%IL4{GSR3r8YU&g$m6Z!J>BA!@#-OGL`$N^Zj`oFBwU!Uw+P*SD zE9=y=7m^uYalCre;I`a0C4{K6x_Ha(P;F~jaF2M?-mqB1$@uhhm;2P=Fxd3|y~$WU z6rG=gc4|M_Ka2{jT`HZ6*N3;Y?dkY_Jf@>!w}N}8{A`9M3W6}^80%gdnp z@tUMVSu;BK>dm*R64$x`ij3DE_*EXZ%iAi%WE}@Z`ZMUc+1d0}9=8 z%}C^9D+izIMism8nwH+?@&Otq5zbE_(xOHdZ((%#@B0V?ebFck^umN9)Df5Og2*VB z2?0zV6axBTGCWQifyu}*=ZZ@R>IDNVGQ|&cMF0+E@cE#NoNyBmkg~UF1F|vLq%UWB@fy{YW5Eas_Z-#VOzvTNjnFZ!T}26!U+mH z<$*y*REEvDw_xIUj1Wbjpo@eYz9LB!7$}l#mdHduulf9+>r&uG9k2!t>pF2aPFY&OKUf)H~EGPeZ1 zaN++ - + 15 - - UMLSpecialState - - 450 - 150 - 30 - 30 - - type=initial - - - - UMLState - - 390 - 240 - 150 - 60 - - STCA_WAIT - - - - Relation - - 450 - 165 - 120 - 105 - - lt=-> -evCAinit - - 10.0;10.0;10.0;50.0 - - - Relation - - 450 - 285 - 165 - 105 - - lt=-> -evCAnewMsg - 10.0;10.0;10.0;50.0 - - - UMLState - - 315 - 360 - 285 - 105 - - STCA_READ -- --. -/entry: processCan - - - - Relation - - 480 - 255 - 225 - 360 - - lt=-> -m1=[queue empty] - - 10.0;210.0;130.0;210.0;130.0;10.0;40.0;10.0 - - - UMLSpecialState - - 435 - 540 - 60 - 60 - - type=decision - - - - Relation - - 450 - 450 - 135 - 120 - - lt=-> -evCAdone - 10.0;10.0;10.0;60.0 - - - Relation - - 210 - 375 - 255 - 240 - - lt=-> -m1=[else] - - 150.0;130.0;10.0;130.0;10.0;10.0;70.0;10.0 - UMLNote - 90 - 630 - 615 - 270 + 645 + 255 + 675 + 525 - _*How to use*_ + _*How to use CAN interface*_ + +*In Factory_Init: * +CAN_init(); *In Factory_build: * -ECAN_SetRXBnInterruptHandler(CANINTERFACE_newMsg); -CANINTERFACE_onProcessCan(&processCan); +ECAN_SetRXBnInterruptHandler(CAN_newMsg); +CAN_onReceiveCan(&receiveCan); +CAN_setSender(idSender); -*Somewhere:* -void processCan(uint32_t canId, uint32_t canData) { +*In Factory_start:* +CAN_startBehaviour(); + +*Somewhere for process input can message:* +void receiveCan(uint8_t idSender, uint8_t idMsg, uint32_t canData) { ..... -} +} + +*For send can message: * +CAN_sendCanMsg(uint8_t idRecipient, uint8_t idMsg, uint32_t data); Relation - 900 - 225 + 360 + 330 90 - 105 + 135 lt=-> evInit - 10.0;10.0;10.0;50.0 + 10.0;10.0;10.0;70.0 UMLSpecialState - 900 - 210 + 360 + 315 30 30 @@ -158,71 +58,39 @@ evInit UMLState - 840 - 300 - 150 - 60 - - STCS_WAIT - - - - UMLState - - 810 - 420 - 210 + 240 + 435 + 270 90 - STCS_SEND --- --. -/entry sendCan + STCA_PROCESS Relation - 900 - 345 - 135 - 105 + 450 + 465 + 180 + 180 lt=-> -evCSsend - - 10.0;10.0;10.0;50.0 +m1=evCAsend +m1=\n/sendCan() + 10.0;40.0;10.0;100.0;100.0;100.0;100.0;10.0;40.0;10.0 Relation - 900 - 315 - 270 - 270 + 135 + 465 + 300 + 180 lt=-> -evCSdone +m1= evCAnewMsg +m1= \n/receiveCan() - 10.0;130.0;10.0;160.0;100.0;160.0;100.0;10.0;60.0;10.0 - - - UMLNote - - 765 - 630 - 705 - 270 - - _*How to use*_ - -*Like a static class:* -sendCanMsg(uint32_t id, uint32_t data); - -*Or like an Object: * -CANSENDER_seSender(CANSENDER* me, uint8_t s); -CANSENDER_setRecipient(CANSENDER* me, uint8_t r); -CANSENDER_sendCanMsg(CANSENDER* me, uint8_t id, uint32_t data); - + 100.0;40.0;100.0;100.0;10.0;100.0;10.0;10.0;70.0;10.0 From 0143cd5e90dc45ce4a1beaac473139e7a6455152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 23 Aug 2023 17:16:39 +0200 Subject: [PATCH 08/14] add car CST --- 306-controller_interface.X/app/car.h | 42 +++++++++++++++++++ .../nbproject/configurations.xml | 1 + 2 files changed, 43 insertions(+) create mode 100644 306-controller_interface.X/app/car.h diff --git a/306-controller_interface.X/app/car.h b/306-controller_interface.X/app/car.h new file mode 100644 index 0000000..b3666b3 --- /dev/null +++ b/306-controller_interface.X/app/car.h @@ -0,0 +1,42 @@ +/** + * @author Rémi Heredero + * @version. 0.0.0 + * @date August 2023 + * @file car.h + */ + +#ifndef CAR_H +#define CAR_H + +/************* + * MODULE ID * + *************/ +#define ID_CONTROL 1 // Control the three-wheeler +#define ID_JOYSTICK 2 // Inform control avout current joystick state +#define ID_DISPLAY 3 // User interface to display informations +#define ID_DRIVE 4 // Drive power motor of the three-wheeler +#define ID_STEERING 5 // Drive the direction motor og the three-wheeler +#define ID_SUPPLY 6 // Information about batteries, current, ... +#define ID_BROADCAST 0 // Message to and from any module +#define ID_DEBUG 0 // Message to and from any module + +typedef struct { + uint8_t CONTROL_STEERING_MODE; + uint8_t CONTROL_ALIVE_TIME; + uint32_t CONTROL_SPEED_FACTOR; + uint32_t CONTROL_POWER_FACTOR; + uint32_t CONTROL_STEERING_FACTOR; + uint8_t CONTROL_MAX_SPEED_FW; + uint8_t CONTROL_MAX_SPEED_BW; + uint8_t JOYSTICK_ALIVE_TIME; + uint8_t DISPLAY_ALIVE_TIME; + uint8_t DRIVE_SPEED_TIME; + uint8_t DRIVE_STOP_TIME; + uint8_t DRIVE_ALIVE_TIME; + uint8_t STEERING_ALIVE_TIME; + uint8_t BATTERY_ALIVE_TIME; +} CAR_CST; + + +#endif /* CAR_H */ + diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index 9db35d3..22bcb54 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -6,6 +6,7 @@ projectFiles="true"> app/factory/factory.h + app/car.h board/led/led.h From 6b8e797744a8ca38748e02a39de262223d86602d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 24 Aug 2023 10:26:04 +0200 Subject: [PATCH 09/14] add CAN messages DB --- threewheeler.DBF | 153 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 threewheeler.DBF diff --git a/threewheeler.DBF b/threewheeler.DBF new file mode 100644 index 0000000..6f5fd33 --- /dev/null +++ b/threewheeler.DBF @@ -0,0 +1,153 @@ +//******************************BUSMASTER Messages and signals Database ******************************// + +[DATABASE_VERSION] 1.3 + +[PROTOCOL] CAN + +[BUSMASTER_VERSION] [3.2.2] + +[NUMBER_OF_MESSAGES] 25 + +[START_MSG] JOY_MEASURE,529,3,3,1,S +[START_SIGNALS] posX,8,1,0,I,127,-128,1,0.000000,1.000000,%, +[START_SIGNALS] posY,8,2,0,I,127,-128,1,0.000000,1.000000,%, +[START_SIGNALS] button,1,3,0,B,1,0,1,0.000000,1.000000,, +[VALUE_DESCRIPTION] Pressed,1 +[VALUE_DESCRIPTION] Released,0 +[END_MSG] + +[START_MSG] DRIVE_SPEED,1040,4,1,1,S +[START_SIGNALS] Speed,32,4,0,I,2147483647,-2147483648,0,0.000000,1.000000,RPM, +[END_MSG] + +[START_MSG] DRIVE_POWER,321,2,1,1,S +[START_SIGNALS] Power,16,2,0,I,32767,-32768,0,0.000000,1.000000,mA, +[END_MSG] + +[START_MSG] DISPLAY_SPEED,306,2,1,1,S +[START_SIGNALS] Vehiclespeed,16,2,0,U,65535,0,0,0.000000,0.100000,km/h, +[END_MSG] + +[START_MSG] CONTROL_ALIVE,271,0,0,1,S +[END_MSG] + +[START_MSG] JOY_ALIVE,543,1,1,1,S +[START_SIGNALS] POWER_MODE,8,1,0,U,255,0,1,0.000000,1.000000,, +[VALUE_DESCRIPTION] ECO,0 +[VALUE_DESCRIPTION] NORMAL,1 +[VALUE_DESCRIPTION] RACE,2 +[END_MSG] + +[START_MSG] CONTROL_SETUP,16,4,2,1,S +[START_SIGNALS] AliveTime,8,4,0,U,255,0,1,0.000000,10.000000,mS, +[VALUE_DESCRIPTION] No alive message,0 +[START_SIGNALS] STEERING_MODE,1,1,0,B,1,0,1,0.000000,1.000000,, +[END_MSG] + +[START_MSG] CONTROL_SPEED_FACTOR,17,4,1,1,S +[START_SIGNALS] Speedfactor,32,4,0,U,4294967295,0,0,0.000000,1.000000,, +[END_MSG] + +[START_MSG] CONTROL_POWER_FACTOR,18,4,1,1,S +[START_SIGNALS] PowerFactor,32,4,0,U,4294967295,0,0,0.000000,1.000000,, +[END_MSG] + +[START_MSG] CONTROL_STEERING_FACTOR,19,4,1,1,S +[START_SIGNALS] SteeringFactor,32,4,0,U,4294967295,0,0,0.000000,1.000000,, +[END_MSG] + +[START_MSG] CONTROL_SECURITY_PARAM,20,2,2,1,S +[START_SIGNALS] maxSpeedFw,8,1,0,U,255,0,1,0.000000,0.100000,km/h, +[START_SIGNALS] MaxSpeedBw,8,2,0,U,255,0,1,0.000000,0.100000,km/h, +[END_MSG] + +[START_MSG] JOY_SETUP,288,4,4,1,S +[START_SIGNALS] mode,1,1,0,B,1,0,1,0.000000,1.000000,, +[VALUE_DESCRIPTION] Time Measure,0 +[VALUE_DESCRIPTION] Delta Measure,1 +[START_SIGNALS] timeMeasureOrDeltaX,8,2,0,U,255,0,1,0.000000,10.000000,msOrVal, +[START_SIGNALS] DeltaY,8,3,0,U,255,0,1,0.000000,1.000000,val, +[START_SIGNALS] aliveTime,8,4,0,U,255,0,1,0.000000,10.000000,ms, +[VALUE_DESCRIPTION] No alive message,0 +[END_MSG] + +[START_MSG] DISPLAY_SETUP,48,4,1,1,S +[START_SIGNALS] AliveTime,8,4,0,U,255,0,1,0.000000,10.000000,ms, +[END_MSG] + +[START_MSG] DISPLAY_ALIVE,799,0,0,1,S +[END_MSG] + +[START_MSG] DRIVE_SETUP,320,4,4,1,S +[START_SIGNALS] resetInit,1,1,0,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] speedTime,8,2,0,U,255,0,1,0.000000,10.000000,ms, +[START_SIGNALS] stopTime,8,3,0,U,255,0,1,0.000000,10.000000,ms, +[START_SIGNALS] aliveTime,8,4,0,U,255,0,1,0.000000,10.000000,ms, +[END_MSG] + +[START_MSG] STEERING_SET,337,4,1,1,S +[START_SIGNALS] SteeringPosition,32,4,0,U,4294967295,0,0,0.000000,1.000000,qc, +[END_MSG] + +[START_MSG] DRIVE_ALIVE,1055,2,10,1,S +[START_SIGNALS] STAT_RDY_SWITCH_ON,1,2,0,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_SWITCHED_ON,1,2,1,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_OPERATION_ENABLED,1,2,2,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_FAULT,1,2,3,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_VOLTAGE_ENABLED,1,2,4,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_QUICK_STOP,1,2,5,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_SWITCH_ON_DISABLED,1,2,6,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_WARNING,1,2,7,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_REMOTE,1,1,1,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_INTERNAL_LIMIT_ACTIVE,1,1,3,B,1,0,1,0.000000,1.000000,, +[END_MSG] + +[START_MSG] DISPLAY_CURRENT,1586,2,1,1,S +[START_SIGNALS] BatteryCurrent,16,2,0,I,32767,-32768,0,0.000000,10.000000,mA, +[END_MSG] + +[START_MSG] DISPLAY_VOLTAGE,1585,2,1,1,S +[START_SIGNALS] BatteryVoltage,16,2,0,U,65535,0,0,0.000000,0.001000,Volt, +[END_MSG] + +[START_MSG] DISPLAY_ENERGY,1587,1,1,1,S +[START_SIGNALS] RemainingEnergy,8,1,0,U,255,0,1,0.000000,1.000000,%, +[END_MSG] + +[START_MSG] STEERING_ALIVE,1311,2,16,1,S +[START_SIGNALS] STAT_READ_TO_SWITCH_ON,1,2,0,B,1,0,0,0.000000,1.000000,, +[START_SIGNALS] STAT_SWITCHED_ON,1,2,1,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_OPERATION_ENABLE,1,2,2,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_FAULT,1,2,3,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_VOLTAGE_ENABLED,1,2,4,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_QUICKSTOP,1,2,5,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_SWITCH_ON_DISABLE,1,2,6,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_WARNING,1,2,7,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_OFFSET_CURRENT_MEAS,1,1,0,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_REMOTE,1,1,1,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_TARGET_REACHED,1,1,2,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_INTERNAL_LIMIT_ACTIVE,1,1,3,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_HOMING_ATTAINED,1,1,4,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_HOMING_ERROR,1,1,5,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_REFRESH_POWER_STAGE,1,1,6,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] STAT_POS_REF_TO_HOME,1,1,7,B,1,0,1,0.000000,1.000000,, +[END_MSG] + +[START_MSG] STEERING_SETUP,336,4,4,1,S +[START_SIGNALS] RESET,1,1,0,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] HOMING,1,2,0,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] SET_CENTER,1,3,0,B,1,0,1,0.000000,1.000000,, +[START_SIGNALS] ALIVE_TIME,8,4,0,U,255,0,1,0.000000,10.000000,ms, +[END_MSG] + +[START_MSG] STEERING_CENTER,82,4,1,1,S +[START_SIGNALS] CENTER_POS,32,4,0,U,4294967295,0,0,0.000000,1.000000,qc, +[END_MSG] + +[START_MSG] DISPLAY_DIRECTION,307,1,1,1,S +[START_SIGNALS] DIRECTION,8,1,0,I,127,-128,1,0.000000,1.000000,deg, +[END_MSG] + +[START_MSG] STEERING_GET_POS,1298,4,1,1,S +[START_SIGNALS] POSITION,32,4,0,I,2147483647,-2147483648,0,0.000000,1.000000,qc, +[END_MSG] \ No newline at end of file From 6b9d3953bc471f1d188a2b81303aebf58ed4d577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 24 Aug 2023 15:25:23 +0200 Subject: [PATCH 10/14] add alive_checker --- .../middleware/alive_checker.c | 176 +++++++++++++++++ .../middleware/alive_checker.h | 134 +++++++++++++ UML/alive.uxf | 178 ++++++++++++++++++ 3 files changed, 488 insertions(+) create mode 100644 306-controller_interface.X/middleware/alive_checker.c create mode 100644 306-controller_interface.X/middleware/alive_checker.h create mode 100644 UML/alive.uxf diff --git a/306-controller_interface.X/middleware/alive_checker.c b/306-controller_interface.X/middleware/alive_checker.c new file mode 100644 index 0000000..b674c28 --- /dev/null +++ b/306-controller_interface.X/middleware/alive_checker.c @@ -0,0 +1,176 @@ +/** + * @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; + } + } + 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: + me->isAlive = false; + 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->aliveTime = 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 new file mode 100644 index 0000000..aeecb85 --- /dev/null +++ b/306-controller_interface.X/middleware/alive_checker.h @@ -0,0 +1,134 @@ +/** + * @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 = 100, // TODO change this number (< 256) + 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/UML/alive.uxf b/UML/alive.uxf new file mode 100644 index 0000000..0f31457 --- /dev/null +++ b/UML/alive.uxf @@ -0,0 +1,178 @@ + + + 14 + + UMLSpecialState + + 266 + 98 + 28 + 28 + + type=initial + + + + Relation + + 266 + 112 + 112 + 98 + + lt=-> +evACinit + 10.0;10.0;10.0;50.0 + + + UMLState + + 210 + 182 + 140 + 56 + + STAC_SETUP + + + + UMLNote + + 434 + 182 + 140 + 42 + + Send params + + + + Relation + + 266 + 224 + 126 + 98 + + lt=-> +evACborn + 10.0;10.0;10.0;50.0 + + + UMLState + + 210 + 294 + 140 + 56 + + STAC_BORN + + + + UMLState + + 168 + 406 + 224 + 84 + + STAC_WAIT +-- +/entry: isAlive = false + + + + Relation + + 266 + 336 + 140 + 98 + + lt=-> +evACready + 10.0;10.0;10.0;50.0 + + + UMLState + + 210 + 658 + 140 + 56 + + STAC_DEAD + + + + Relation + + 266 + 476 + 112 + 98 + + lt=-> +evACpoll + 10.0;10.0;10.0;50.0 + + + UMLSpecialState + + 252 + 546 + 56 + 56 + + type=decision + + + + Relation + + 266 + 588 + 84 + 98 + + lt=-> +m1=[else] + 10.0;10.0;10.0;50.0 + + + UMLNote + + 434 + 294 + 140 + 42 + + Reset / Init + + + + Relation + + 294 + 420 + 182 + 196 + + lt=-> +m1=[alive] + 10.0;110.0;110.0;110.0;110.0;10.0;70.0;10.0 + + + Relation + + 140 + 308 + 168 + 490 + + lt=-> +evACborn + 100.0;290.0;100.0;330.0;10.0;330.0;10.0;10.0;50.0;10.0 + + From 18078958b4b62ba90d97d7e2f60cf1b6e2f5e429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 24 Aug 2023 15:25:45 +0200 Subject: [PATCH 11/14] change tool for programming --- 306-controller_interface.X/nbproject/configurations.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index 22bcb54..f742c6a 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -24,6 +24,7 @@ middleware/can_interface.h + middleware/alive_checker.h xf/event.h @@ -58,6 +59,7 @@ middleware/can_interface.c + middleware/alive_checker.c xf/event.c @@ -88,7 +90,7 @@ PIC18F26K83 - noID + PICkit3PlatformTool XC8 2.41 3 From 65e4277dd4294c48387371cc94a5695e1bdc3791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 24 Aug 2023 15:26:12 +0200 Subject: [PATCH 12/14] add MEM_addresse --- 306-controller_interface.X/app/car.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/306-controller_interface.X/app/car.h b/306-controller_interface.X/app/car.h index b3666b3..93513bf 100644 --- a/306-controller_interface.X/app/car.h +++ b/306-controller_interface.X/app/car.h @@ -20,6 +20,24 @@ #define ID_BROADCAST 0 // Message to and from any module #define ID_DEBUG 0 // Message to and from any module +/******************* + * MEMORY ADRESSES * + *******************/ +#define MEMADD_CONTROL_STEERING_MODE 0x00 +#define MEMADD_CONTROL_ALIVE_TIME 0x01 +#define MEMADD_CONTROL_SPEED_FACTOR 0x02 +#define MEMADD_CONTROL_POWER_FACTOR 0x06 +#define MEMADD_CONTROL_STEERING_FACTOR 0x0A +#define MEMADD_CONTROL_MAX_SPEED_FW 0x0E +#define MEMADD_CONTROL_MAX_SPEED_BW 0x0F +#define MEMADD_JOYSTICK_ALIVE_TIME 0x10 +#define MEMADD_DISPLAY_ALIVE_TIME 0x11 +#define MEMADD_DRIVE_SPEED_TIME 0x12 +#define MEMADD_DRIVE_STOP_TIME 0x13 +#define MEMADD_DRIVE_ALIVE_TIME 0x14 +#define MEMADD_STEERING_ALIVE_TIME 0x15 +#define MEMADD_BATTERY_ALIVE_TIME 0x16 + typedef struct { uint8_t CONTROL_STEERING_MODE; uint8_t CONTROL_ALIVE_TIME; @@ -35,7 +53,8 @@ typedef struct { uint8_t DRIVE_ALIVE_TIME; uint8_t STEERING_ALIVE_TIME; uint8_t BATTERY_ALIVE_TIME; -} CAR_CST; +} CAR_CST_TYPE; +CAR_CST_TYPE CAR_CST; #endif /* CAR_H */ From f121f5ddf97f32948eb4eca157e289d32a3a15bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 24 Aug 2023 15:26:29 +0200 Subject: [PATCH 13/14] reduce to only useable data on CAN bus --- 306-controller_interface.X/middleware/can_interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/306-controller_interface.X/middleware/can_interface.c b/306-controller_interface.X/middleware/can_interface.c index 2656dc9..cac0487 100644 --- a/306-controller_interface.X/middleware/can_interface.c +++ b/306-controller_interface.X/middleware/can_interface.c @@ -52,7 +52,7 @@ bool CAN_processEvent(Event* ev) { if (ev->id == evCAsend) { uCAN_MSG canMsg; canMsg.frame.idType = 0; // I don't understand what is it - canMsg.frame.dlc = 8; // 8 bytes to send + canMsg.frame.dlc = 4; // 4 bytes to send canMsg.frame.rtr = 0; // no remote frame canMsg.frame.data0 = (uint8_t) data; data = data >> 8; From d5c345cf32f7182a4973b8c9e551447a847b2a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 24 Aug 2023 15:26:39 +0200 Subject: [PATCH 14/14] start class UML --- UML/class.uxf | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 UML/class.uxf diff --git a/UML/class.uxf b/UML/class.uxf new file mode 100644 index 0000000..4e335b5 --- /dev/null +++ b/UML/class.uxf @@ -0,0 +1,106 @@ + + + 7 + + UMLClass + + 105 + 77 + 301 + 126 + + CAN_INTERFACE +-- +-sender: uint8_t +-- +CAN_init(): void +CAN_startBehaviour(): void +CAN_processEvent(ev: Event*): bool +-- +CAN_onReceiveCan(f: CAN_CALLBACK): void +-- +CAN_newMsg(): void +CAN_Send(idRecipient: uint8_t, idMsg: uint8_t, data: uint32_t): void +-- +CAN_setSender(idSender: uint8_t): void + + + + UMLClass + + 315 + 350 + 301 + 126 + + JOYSTICK +-- +-: uint8_t +-- +JOY_init(JOY* me): void +JOY_startBehaviour(JOY* me): void +JOY_processEvent(ev: Event*): bool +-- +JOY_onMove(f: JOY_CALLBACK): void +-- +JOY_emitMove(me: JOY*, t: uint8_t, data: uint32_t): void +-- +CAN_setSender(idSender: uint8_t): void + + + + UMLClass + + 812 + 154 + 322 + 504 + + MEMORY_CST +-- +-CONTROL_STEERING_MODE: uint8_t +-CONTROL_ALIVE_TIME: uint8_t +-CONTROL_SPEED_FACTOR: uint32_t +-CONTROL_POWER_FACTOR: uint32_t +-CONTROL_STEERING_FACTOR: uint32_t +-CONTROL_MAX_SPEED_FW: uint8_t +-CONTROL_MAX_SPEED_BW: uint8_t +-JOYSTICK_ALIVE_TIME: uint8_t +-DISPLAY_ALIVE_TIME: uint8_t +-DRIVE_SPEED_TIME: uint8_t +-DRIVE_STOP_TIME: uint8_t +-DRIVE_ALIVE_TIME: uint8_t +-STEERING_ALIVE_TIME: uint8_t +-BATTERY_ALIVE_TIME: uint8_t +-- ++MEM_write_CONTROL_STEERING_MODE(data: uint8_t): void ++MEM_write_CONTROL_ALIVE_TIME(data: uint8_t): void ++MEM_write_CONTROL_SPEED_FACTOR(data: uint32_t): void ++MEM_write_CONTROL_POWER_FACTOR(data: uint32_t): void ++MEM_write_CONTROL_STEERING_FACTOR(data: uint32_t): void ++MEM_write_CONTROL_MAX_SPEED_FW(data: uint8_t): void ++MEM_write_CONTROL_MAX_SPEED_BW(data: uint8_t): void ++MEM_write_JOYSTICK_ALIVE_TIME(data: uint8_t): void ++MEM_write_DISPLAY_ALIVE_TIME(data: uint8_t): void ++MEM_write_DRIVE_SPEED_TIME(data: uint8_t): void ++MEM_write_DRIVE_STOP_TIME(data: uint8_t): void ++MEM_write_DRIVE_ALIVE_TIME(data: uint8_t): void ++MEM_write_STEERING_ALIVE_TIME(data: uint8_t): void ++MEM_write_BATTERY_ALIVE_TIME(data: uint8_t): void ++MEM_read_CONTROL_STEERING_MODE(): uint8_t ++MEM_read_CONTROL_ALIVE_TIME(): uint8_t ++MEM_read_CONTROL_SPEED_FACTOR(): uint32_t ++MEM_read_CONTROL_POWER_FACTOR(): uint32_t ++MEM_read_CONTROL_STEERING_FACTOR(): uint32_t ++MEM_read_CONTROL_MAX_SPEED_FW(): uint8_t ++MEM_read_CONTROL_MAX_SPEED_BW(): uint8_t ++MEM_read_JOYSTICK_ALIVE_TIME(): uint8_t ++MEM_read_DISPLAY_ALIVE_TIME(): uint8_t ++MEM_read_DRIVE_SPEED_TIME(): uint8_t ++MEM_read_DRIVE_STOP_TIME(): uint8_t ++MEM_read_DRIVE_ALIVE_TIME(): uint8_t ++MEM_read_STEERING_ALIVE_TIME(): uint8_t ++MEM_read_BATTERY_ALIVE_TIME(): uint8_t + + +