Merge pull request #1 from SummerSchool2023-RED/feature/car_param

Feature/car param
This commit is contained in:
Rémi Heredero 2023-08-24 15:28:02 +02:00 committed by GitHub
commit aff69ef4d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 1906 additions and 649 deletions

View File

@ -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());
}
}
}

View File

@ -1,19 +0,0 @@
#ifndef BLCONTROL_DEF
#define BLCONTROL_DEF
#include <stdint.h>
#include <stdbool.h>
#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

View File

@ -0,0 +1,61 @@
/**
* @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
/*******************
* 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;
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_TYPE;
CAR_CST_TYPE CAR_CST;
#endif /* CAR_H */

View File

@ -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();
}

View File

@ -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 <stdint.h>
#include <stdbool.h>
#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

View File

@ -1,5 +1,5 @@
#include "mcc_generated_files/mcc.h" #include "../mcc_generated_files/mcc.h"
#include "xf/xf.h" #include "../xf/xf.h"
#include "factory/factory.h" #include "factory/factory.h"
/* /*

View File

@ -1,66 +1,137 @@
/**
* @author Rémi Heredero (remi@heredero.ch)
* @version. 1.0.0
* @date 2023-06-15
*/
#include "button.h" #include "button.h"
#include "../../mcc_generated_files/pin_manager.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->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) void BUTTON_initHW(BUTTON* me) {
{ switch (me->id) {
}
//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)
{
case 1: case 1:
value = IO_RA7_GetValue(); INPUT1_SetDigitalInput();
break; break;
case 2: case 2:
break; INPUT2_SetDigitalInput();
break;
case 3: case 3:
break; INPUT3_SetDigitalInput();
case 4: break;
break; default:
case 5: break;
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
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) * @brief Check if the button is pressed
{ * The function returns true if the button is pressed, false otherwise
me->id = id; *
* @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;
} }

View File

@ -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 <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "../../xf/xf.h"
/* #define PB_POLL_TIME 20 // Poll time for BUTTON
* this is the declaration of the Button class
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_ /**
{ * @brief Initialize the hardware of the button
uint8_t id; *
bool isPullUp; * @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); * @brief Check if the button is pressed
uint8_t Button_read(Button* me); * The function returns true if the button is pressed, false otherwise
void Button_setId(Button* me, uint8_t id); *
uint8_t Button_getId(Button* me); * @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 */

View File

@ -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;
}

View File

@ -1,69 +0,0 @@
#ifndef BUTTONSM_DEF
#define BUTTONSM_DEF
#include <stdint.h>
#include <stdbool.h>
#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

View File

@ -1,8 +1,13 @@
/**
* @author Rémi Heredero (remi@heredero.ch)
* @version. 1.0.0
* @date 2023-06-15
*/
#include "led.h" #include "led.h"
#include "../../mcc_generated_files/pin_manager.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; me->id = id;
} }
@ -10,94 +15,68 @@ void LED_init(LED* me, uint8_t id)
* @brief Initialize the Driver * @brief Initialize the Driver
* *
*/ */
void LED_initHW(LED* me) void LED_initHW(LED* me) {
{
LED_off(me); LED_off(me);
} }
/* void LED_on(void* me) {
* for the on and the off methods: LED* l = (LED*) me;
* if the output is push pull, it depends if the switch (l->id) {
* 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)
{
case 1: case 1:
IO_RB0_SetLow(); OUTPUT1_SetHigh();
break; break;
case 2: case 2:
OUTPUT2_SetHigh();
break; break;
case 3: case 3:
OUTPUT3_SetHigh();
break; break;
case 4: case 4:
OUTPUT4_SetHigh();
break; break;
case 5: case 5:
OUTPUT5_SetHigh();
break; break;
case 6: case 6:
OUTPUT6_SetHigh();
break; break;
case 7: case 7:
OUTPUT7_SetHigh();
break; break;
case 8: case 8:
break; OUTPUT8_SetHigh();
case 9:
break;
case 10:
break; break;
} }
} }
//switch off the led void LED_off(void* me) {
//maybe you have to adjust your LED* l = (LED*) me;
//low level calls switch (l->id) {
void LED_off(LED* me)
{
switch (me->id)
{
case 1: case 1:
IO_RB0_SetHigh(); OUTPUT1_SetLow();
break; break;
case 2: case 2:
OUTPUT2_SetLow();
break; break;
case 3: case 3:
OUTPUT3_SetLow();
break; break;
case 4: case 4:
OUTPUT4_SetLow();
break; break;
case 5: case 5:
OUTPUT5_SetLow();
break; break;
case 6: case 6:
OUTPUT6_SetLow();
break; break;
case 7: case 7:
OUTPUT7_SetLow();
break; break;
case 8: case 8:
break; OUTPUT8_SetLow();
case 9:
break;
case 10:
break; break;
} }
} }
void LED_setState(LED* me, uint8_t state)
{
if (state == HIGH)
{
LED_on(me);
}
if (state == LOW)
{
LED_off(me);
}
}

View File

@ -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 <stdint.h> #include <stdint.h>
/* // LED struct
* this is the declaration of the Led class 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_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 */

View File

@ -1,53 +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());
;
}
//connect objects if required
void Factory_build()
{
ButtonSM_setObserver(bsm(), blc(), &BLControl_onButton);
}
//start all state machines
void Factory_start()
{
ButtonSM_startBehaviour(bsm());
}

View File

@ -1,41 +0,0 @@
/* this is the Factory class */
#ifndef FACTORY_ONCE
#define FACTORY_ONCE
#include <stdint.h>
#include <stdbool.h>
#include "../board/led/led.h"
#include "../board/button/button.h"
#include "../board/button/buttonsm.h"
#include "../app/blcontrol.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

View File

@ -70,10 +70,10 @@ typedef union {
uint8_t data1; uint8_t data1;
uint8_t data2; uint8_t data2;
uint8_t data3; uint8_t data3;
uint8_t data4; uint8_t data4; // uselesss
uint8_t data5; uint8_t data5; // uselesss
uint8_t data6; uint8_t data6; // uselesss
uint8_t data7; uint8_t data7; // uselesss
uint8_t rtr; uint8_t rtr;
} frame; } frame;
uint8_t array[15]; uint8_t array[15];

View File

@ -64,16 +64,16 @@ void PIN_MANAGER_Initialize(void)
/** /**
TRISx registers TRISx registers
*/ */
TRISA = 0xFF; TRISA = 0x00;
TRISB = 0xFE; TRISB = 0xF6;
TRISC = 0xFF; TRISC = 0xFF;
/** /**
ANSELx registers ANSELx registers
*/ */
ANSELC = 0xFF; ANSELC = 0xFF;
ANSELB = 0xF6; ANSELB = 0xEE;
ANSELA = 0x7F; ANSELA = 0x00;
/** /**
WPUx registers 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) void PIN_MANAGER_IOC(void)

View File

@ -65,45 +65,165 @@
#define PULL_UP_ENABLED 1 #define PULL_UP_ENABLED 1
#define PULL_UP_DISABLED 0 #define PULL_UP_DISABLED 0
// get/set IO_RA7 aliases // get/set OUTPUT1 aliases
#define IO_RA7_TRIS TRISAbits.TRISA7 #define OUTPUT1_TRIS TRISAbits.TRISA0
#define IO_RA7_LAT LATAbits.LATA7 #define OUTPUT1_LAT LATAbits.LATA0
#define IO_RA7_PORT PORTAbits.RA7 #define OUTPUT1_PORT PORTAbits.RA0
#define IO_RA7_WPU WPUAbits.WPUA7 #define OUTPUT1_WPU WPUAbits.WPUA0
#define IO_RA7_OD ODCONAbits.ODCA7 #define OUTPUT1_OD ODCONAbits.ODCA0
#define IO_RA7_ANS ANSELAbits.ANSELA7 #define OUTPUT1_ANS ANSELAbits.ANSELA0
#define IO_RA7_SetHigh() do { LATAbits.LATA7 = 1; } while(0) #define OUTPUT1_SetHigh() do { LATAbits.LATA0 = 1; } while(0)
#define IO_RA7_SetLow() do { LATAbits.LATA7 = 0; } while(0) #define OUTPUT1_SetLow() do { LATAbits.LATA0 = 0; } while(0)
#define IO_RA7_Toggle() do { LATAbits.LATA7 = ~LATAbits.LATA7; } while(0) #define OUTPUT1_Toggle() do { LATAbits.LATA0 = ~LATAbits.LATA0; } while(0)
#define IO_RA7_GetValue() PORTAbits.RA7 #define OUTPUT1_GetValue() PORTAbits.RA0
#define IO_RA7_SetDigitalInput() do { TRISAbits.TRISA7 = 1; } while(0) #define OUTPUT1_SetDigitalInput() do { TRISAbits.TRISA0 = 1; } while(0)
#define IO_RA7_SetDigitalOutput() do { TRISAbits.TRISA7 = 0; } while(0) #define OUTPUT1_SetDigitalOutput() do { TRISAbits.TRISA0 = 0; } while(0)
#define IO_RA7_SetPullup() do { WPUAbits.WPUA7 = 1; } while(0) #define OUTPUT1_SetPullup() do { WPUAbits.WPUA0 = 1; } while(0)
#define IO_RA7_ResetPullup() do { WPUAbits.WPUA7 = 0; } while(0) #define OUTPUT1_ResetPullup() do { WPUAbits.WPUA0 = 0; } while(0)
#define IO_RA7_SetPushPull() do { ODCONAbits.ODCA7 = 0; } while(0) #define OUTPUT1_SetPushPull() do { ODCONAbits.ODCA0 = 0; } while(0)
#define IO_RA7_SetOpenDrain() do { ODCONAbits.ODCA7 = 1; } while(0) #define OUTPUT1_SetOpenDrain() do { ODCONAbits.ODCA0 = 1; } while(0)
#define IO_RA7_SetAnalogMode() do { ANSELAbits.ANSELA7 = 1; } while(0) #define OUTPUT1_SetAnalogMode() do { ANSELAbits.ANSELA0 = 1; } while(0)
#define IO_RA7_SetDigitalMode() do { ANSELAbits.ANSELA7 = 0; } while(0) #define OUTPUT1_SetDigitalMode() do { ANSELAbits.ANSELA0 = 0; } while(0)
// get/set IO_RB0 aliases // get/set OUTPUT2 aliases
#define IO_RB0_TRIS TRISBbits.TRISB0 #define OUTPUT2_TRIS TRISAbits.TRISA1
#define IO_RB0_LAT LATBbits.LATB0 #define OUTPUT2_LAT LATAbits.LATA1
#define IO_RB0_PORT PORTBbits.RB0 #define OUTPUT2_PORT PORTAbits.RA1
#define IO_RB0_WPU WPUBbits.WPUB0 #define OUTPUT2_WPU WPUAbits.WPUA1
#define IO_RB0_OD ODCONBbits.ODCB0 #define OUTPUT2_OD ODCONAbits.ODCA1
#define IO_RB0_ANS ANSELBbits.ANSELB0 #define OUTPUT2_ANS ANSELAbits.ANSELA1
#define IO_RB0_SetHigh() do { LATBbits.LATB0 = 1; } while(0) #define OUTPUT2_SetHigh() do { LATAbits.LATA1 = 1; } while(0)
#define IO_RB0_SetLow() do { LATBbits.LATB0 = 0; } while(0) #define OUTPUT2_SetLow() do { LATAbits.LATA1 = 0; } while(0)
#define IO_RB0_Toggle() do { LATBbits.LATB0 = ~LATBbits.LATB0; } while(0) #define OUTPUT2_Toggle() do { LATAbits.LATA1 = ~LATAbits.LATA1; } while(0)
#define IO_RB0_GetValue() PORTBbits.RB0 #define OUTPUT2_GetValue() PORTAbits.RA1
#define IO_RB0_SetDigitalInput() do { TRISBbits.TRISB0 = 1; } while(0) #define OUTPUT2_SetDigitalInput() do { TRISAbits.TRISA1 = 1; } while(0)
#define IO_RB0_SetDigitalOutput() do { TRISBbits.TRISB0 = 0; } while(0) #define OUTPUT2_SetDigitalOutput() do { TRISAbits.TRISA1 = 0; } while(0)
#define IO_RB0_SetPullup() do { WPUBbits.WPUB0 = 1; } while(0) #define OUTPUT2_SetPullup() do { WPUAbits.WPUA1 = 1; } while(0)
#define IO_RB0_ResetPullup() do { WPUBbits.WPUB0 = 0; } while(0) #define OUTPUT2_ResetPullup() do { WPUAbits.WPUA1 = 0; } while(0)
#define IO_RB0_SetPushPull() do { ODCONBbits.ODCB0 = 0; } while(0) #define OUTPUT2_SetPushPull() do { ODCONAbits.ODCA1 = 0; } while(0)
#define IO_RB0_SetOpenDrain() do { ODCONBbits.ODCB0 = 1; } while(0) #define OUTPUT2_SetOpenDrain() do { ODCONAbits.ODCA1 = 1; } while(0)
#define IO_RB0_SetAnalogMode() do { ANSELBbits.ANSELB0 = 1; } while(0) #define OUTPUT2_SetAnalogMode() do { ANSELAbits.ANSELA1 = 1; } while(0)
#define IO_RB0_SetDigitalMode() do { ANSELBbits.ANSELB0 = 0; } 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 // get/set RB3 procedures
#define RB3_SetHigh() do { LATBbits.LATB3 = 1; } while(0) #define RB3_SetHigh() do { LATBbits.LATB3 = 1; } while(0)
@ -117,6 +237,18 @@
#define RB3_SetAnalogMode() do { ANSELBbits.ANSELB3 = 1; } while(0) #define RB3_SetAnalogMode() do { ANSELBbits.ANSELB3 = 1; } while(0)
#define RB3_SetDigitalMode() do { ANSELBbits.ANSELB3 = 0; } 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 @Param
none none

View File

@ -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);
}

View File

@ -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

View File

@ -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 = 4; // 4 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);
}

View File

@ -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

View File

@ -5,19 +5,11 @@
displayName="Header Files" displayName="Header Files"
projectFiles="true"> projectFiles="true">
<logicalFolder name="app" displayName="app" projectFiles="true"> <logicalFolder name="app" displayName="app" projectFiles="true">
<itemPath>app/blcontrol.h</itemPath> <itemPath>app/factory/factory.h</itemPath>
<itemPath>app/car.h</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="board" displayName="board" projectFiles="true"> <logicalFolder name="board" displayName="board" projectFiles="true">
<logicalFolder name="button" displayName="button" projectFiles="true"> <itemPath>board/led/led.h</itemPath>
<itemPath>board/button/buttonsm.h</itemPath>
<itemPath>board/button/button.h</itemPath>
</logicalFolder>
<logicalFolder name="led" displayName="led" projectFiles="true">
<itemPath>board/led/led.h</itemPath>
</logicalFolder>
</logicalFolder>
<logicalFolder name="factory" displayName="factory" projectFiles="true">
<itemPath>factory/factory.h</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="MCC Generated Files" <logicalFolder name="MCC Generated Files"
displayName="MCC Generated Files" displayName="MCC Generated Files"
@ -31,6 +23,8 @@
<itemPath>mcc_generated_files/memory.h</itemPath> <itemPath>mcc_generated_files/memory.h</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="middleware" displayName="middleware" projectFiles="true"> <logicalFolder name="middleware" displayName="middleware" projectFiles="true">
<itemPath>middleware/can_interface.h</itemPath>
<itemPath>middleware/alive_checker.h</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="xf" displayName="xf" projectFiles="true"> <logicalFolder name="xf" displayName="xf" projectFiles="true">
<itemPath>xf/event.h</itemPath> <itemPath>xf/event.h</itemPath>
@ -46,19 +40,11 @@
displayName="Source Files" displayName="Source Files"
projectFiles="true"> projectFiles="true">
<logicalFolder name="app" displayName="app" projectFiles="true"> <logicalFolder name="app" displayName="app" projectFiles="true">
<itemPath>app/blcontrol.c</itemPath> <itemPath>app/factory/factory.c</itemPath>
<itemPath>app/main.c</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="board" displayName="board" projectFiles="true"> <logicalFolder name="board" displayName="board" projectFiles="true">
<logicalFolder name="button" displayName="button" projectFiles="true"> <itemPath>board/led/led.c</itemPath>
<itemPath>board/button/button.c</itemPath>
<itemPath>board/button/buttonsm.c</itemPath>
</logicalFolder>
<logicalFolder name="led" displayName="led" projectFiles="true">
<itemPath>board/led/led.c</itemPath>
</logicalFolder>
</logicalFolder>
<logicalFolder name="factory" displayName="factory" projectFiles="true">
<itemPath>factory/factory.c</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="MCC Generated Files" <logicalFolder name="MCC Generated Files"
displayName="MCC Generated Files" displayName="MCC Generated Files"
@ -72,12 +58,13 @@
<itemPath>mcc_generated_files/memory.c</itemPath> <itemPath>mcc_generated_files/memory.c</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="middleware" displayName="middleware" projectFiles="true"> <logicalFolder name="middleware" displayName="middleware" projectFiles="true">
<itemPath>middleware/can_interface.c</itemPath>
<itemPath>middleware/alive_checker.c</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="xf" displayName="xf" projectFiles="true"> <logicalFolder name="xf" displayName="xf" projectFiles="true">
<itemPath>xf/event.c</itemPath> <itemPath>xf/event.c</itemPath>
<itemPath>xf/xf.c</itemPath> <itemPath>xf/xf.c</itemPath>
</logicalFolder> </logicalFolder>
<itemPath>main.c</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="ExternalFiles" <logicalFolder name="ExternalFiles"
displayName="Important Files" displayName="Important Files"
@ -169,7 +156,7 @@
<property key="use-cci" value="false"/> <property key="use-cci" value="false"/>
<property key="use-iar" value="false"/> <property key="use-iar" value="false"/>
<property key="verbose" value="false"/> <property key="verbose" value="false"/>
<property key="warning-level" value="-3"/> <property key="warning-level" value="3"/>
<property key="what-to-do" value="ignore"/> <property key="what-to-do" value="ignore"/>
</HI-TECH-COMP> </HI-TECH-COMP>
<HI-TECH-LINK> <HI-TECH-LINK>
@ -219,10 +206,93 @@
<property key="remove-unused-sections" value="true"/> <property key="remove-unused-sections" value="true"/>
</HI-TECH-LINK> </HI-TECH-LINK>
<PICkit3PlatformTool> <PICkit3PlatformTool>
<property key="firmware.download.all" value="false"/> <property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="debugoptions.debug-startup" value="Use system settings"/>
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
<property key="debugoptions.useswbreakpoints" value="false"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="true"/>
<property key="memories.configurationmemory" value="true"/>
<property key="memories.configurationmemory2" value="true"/>
<property key="memories.dataflash" value="true"/>
<property key="memories.eeprom" value="true"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="true"/>
<property key="memories.instruction.ram" value="true"/>
<property key="memories.instruction.ram.ranges"
value="${memories.instruction.ram.ranges}"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.ranges" value="0-ffff"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.donoteraseauxmem" value="false"/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preservedataflash" value="false"/>
<property key="programoptions.preservedataflash.ranges"
value="${programoptions.preservedataflash.ranges}"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveeeprom.ranges" value="310000-3103ff"/>
<property key="programoptions.preserveprogram.ranges" value=""/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.programcalmem" value="false"/>
<property key="programoptions.programuserotp" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="5.0"/>
</PICkit3PlatformTool> </PICkit3PlatformTool>
<Tool> <Tool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="debugoptions.debug-startup" value="Use system settings"/>
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
<property key="debugoptions.useswbreakpoints" value="false"/>
<property key="firmware.download.all" value="false"/> <property key="firmware.download.all" value="false"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="true"/>
<property key="memories.configurationmemory" value="true"/>
<property key="memories.configurationmemory2" value="true"/>
<property key="memories.dataflash" value="true"/>
<property key="memories.eeprom" value="true"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="true"/>
<property key="memories.instruction.ram" value="true"/>
<property key="memories.instruction.ram.ranges"
value="${memories.instruction.ram.ranges}"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.ranges" value="0-ffff"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.donoteraseauxmem" value="false"/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preservedataflash" value="false"/>
<property key="programoptions.preservedataflash.ranges"
value="${programoptions.preservedataflash.ranges}"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveeeprom.ranges" value="310000-3103ff"/>
<property key="programoptions.preserveprogram.ranges" value=""/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.programcalmem" value="false"/>
<property key="programoptions.programuserotp" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="5.0"/>
</Tool> </Tool>
<XC8-CO> <XC8-CO>
<property key="coverage-enable" value=""/> <property key="coverage-enable" value=""/>

File diff suppressed because one or more lines are too long

178
UML/alive.uxf Normal file
View File

@ -0,0 +1,178 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="15.0.0">
<zoom_level>14</zoom_level>
<element>
<id>UMLSpecialState</id>
<coordinates>
<x>266</x>
<y>98</y>
<w>28</w>
<h>28</h>
</coordinates>
<panel_attributes>type=initial</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>266</x>
<y>112</y>
<w>112</w>
<h>98</h>
</coordinates>
<panel_attributes>lt=-&gt;
evACinit</panel_attributes>
<additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
</element>
<element>
<id>UMLState</id>
<coordinates>
<x>210</x>
<y>182</y>
<w>140</w>
<h>56</h>
</coordinates>
<panel_attributes>STAC_SETUP</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLNote</id>
<coordinates>
<x>434</x>
<y>182</y>
<w>140</w>
<h>42</h>
</coordinates>
<panel_attributes>Send params</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>266</x>
<y>224</y>
<w>126</w>
<h>98</h>
</coordinates>
<panel_attributes>lt=-&gt;
evACborn</panel_attributes>
<additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
</element>
<element>
<id>UMLState</id>
<coordinates>
<x>210</x>
<y>294</y>
<w>140</w>
<h>56</h>
</coordinates>
<panel_attributes>STAC_BORN</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLState</id>
<coordinates>
<x>168</x>
<y>406</y>
<w>224</w>
<h>84</h>
</coordinates>
<panel_attributes>STAC_WAIT
--
/entry: isAlive = false</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>266</x>
<y>336</y>
<w>140</w>
<h>98</h>
</coordinates>
<panel_attributes>lt=-&gt;
evACready</panel_attributes>
<additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
</element>
<element>
<id>UMLState</id>
<coordinates>
<x>210</x>
<y>658</y>
<w>140</w>
<h>56</h>
</coordinates>
<panel_attributes>STAC_DEAD</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>266</x>
<y>476</y>
<w>112</w>
<h>98</h>
</coordinates>
<panel_attributes>lt=-&gt;
evACpoll</panel_attributes>
<additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
</element>
<element>
<id>UMLSpecialState</id>
<coordinates>
<x>252</x>
<y>546</y>
<w>56</w>
<h>56</h>
</coordinates>
<panel_attributes>type=decision</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>266</x>
<y>588</y>
<w>84</w>
<h>98</h>
</coordinates>
<panel_attributes>lt=-&gt;
m1=[else]</panel_attributes>
<additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
</element>
<element>
<id>UMLNote</id>
<coordinates>
<x>434</x>
<y>294</y>
<w>140</w>
<h>42</h>
</coordinates>
<panel_attributes>Reset / Init</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>294</x>
<y>420</y>
<w>182</w>
<h>196</h>
</coordinates>
<panel_attributes>lt=-&gt;
m1=[alive]</panel_attributes>
<additional_attributes>10.0;110.0;110.0;110.0;110.0;10.0;70.0;10.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>140</x>
<y>308</y>
<w>168</w>
<h>490</h>
</coordinates>
<panel_attributes>lt=-&gt;
evACborn</panel_attributes>
<additional_attributes>100.0;290.0;100.0;330.0;10.0;330.0;10.0;10.0;50.0;10.0</additional_attributes>
</element>
</diagram>

BIN
UML/can.pdf Normal file

Binary file not shown.

96
UML/can.uxf Normal file
View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="15.0.0">
<zoom_level>15</zoom_level>
<element>
<id>UMLNote</id>
<coordinates>
<x>645</x>
<y>255</y>
<w>675</w>
<h>525</h>
</coordinates>
<panel_attributes>_*How to use CAN interface*_
*In Factory_Init: *
CAN_init();
*In Factory_build: *
ECAN_SetRXBnInterruptHandler(CAN_newMsg);
CAN_onReceiveCan(&amp;receiveCan);
CAN_setSender(idSender);
*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);</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>360</x>
<y>330</y>
<w>90</w>
<h>135</h>
</coordinates>
<panel_attributes>lt=-&gt;
evInit
</panel_attributes>
<additional_attributes>10.0;10.0;10.0;70.0</additional_attributes>
</element>
<element>
<id>UMLSpecialState</id>
<coordinates>
<x>360</x>
<y>315</y>
<w>30</w>
<h>30</h>
</coordinates>
<panel_attributes>type=initial</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLState</id>
<coordinates>
<x>240</x>
<y>435</y>
<w>270</w>
<h>90</h>
</coordinates>
<panel_attributes>STCA_PROCESS</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>450</x>
<y>465</y>
<w>180</w>
<h>180</h>
</coordinates>
<panel_attributes>lt=-&gt;
m1=evCAsend
m1=\n/sendCan()</panel_attributes>
<additional_attributes>10.0;40.0;10.0;100.0;100.0;100.0;100.0;10.0;40.0;10.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>135</x>
<y>465</y>
<w>300</w>
<h>180</h>
</coordinates>
<panel_attributes>lt=-&gt;
m1= evCAnewMsg
m1= \n/receiveCan()
</panel_attributes>
<additional_attributes>100.0;40.0;100.0;100.0;10.0;100.0;10.0;10.0;70.0;10.0</additional_attributes>
</element>
</diagram>

106
UML/class.uxf Normal file
View File

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="15.0.0">
<zoom_level>7</zoom_level>
<element>
<id>UMLClass</id>
<coordinates>
<x>105</x>
<y>77</y>
<w>301</w>
<h>126</h>
</coordinates>
<panel_attributes>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</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>315</x>
<y>350</y>
<w>301</w>
<h>126</h>
</coordinates>
<panel_attributes>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</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>812</x>
<y>154</y>
<w>322</w>
<h>504</h>
</coordinates>
<panel_attributes>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</panel_attributes>
<additional_attributes/>
</element>
</diagram>

153
threewheeler.DBF Normal file
View File

@ -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]