can receive part done
This commit is contained in:
parent
f6c775b637
commit
102d4e1992
@ -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
|
||||
|
@ -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
|
||||
|
@ -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];
|
||||
|
123
306-controller_interface.X/middleware/can_interface.c
Normal file
123
306-controller_interface.X/middleware/can_interface.c
Normal file
@ -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);
|
||||
}
|
101
306-controller_interface.X/middleware/can_interface.h
Normal file
101
306-controller_interface.X/middleware/can_interface.h
Normal file
@ -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
|
@ -31,6 +31,7 @@
|
||||
<itemPath>mcc_generated_files/memory.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||
<itemPath>middleware/can_interface.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||
<itemPath>xf/event.h</itemPath>
|
||||
@ -72,6 +73,7 @@
|
||||
<itemPath>mcc_generated_files/memory.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||
<itemPath>middleware/can_interface.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||
<itemPath>xf/event.c</itemPath>
|
||||
@ -103,7 +105,7 @@
|
||||
<targetDevice>PIC18F26K83</targetDevice>
|
||||
<targetHeader></targetHeader>
|
||||
<targetPluginBoard></targetPluginBoard>
|
||||
<platformTool>PICkit3PlatformTool</platformTool>
|
||||
<platformTool>noID</platformTool>
|
||||
<languageToolchain>XC8</languageToolchain>
|
||||
<languageToolchainVersion>2.41</languageToolchainVersion>
|
||||
<platform>3</platform>
|
||||
@ -169,7 +171,7 @@
|
||||
<property key="use-cci" value="false"/>
|
||||
<property key="use-iar" 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"/>
|
||||
</HI-TECH-COMP>
|
||||
<HI-TECH-LINK>
|
||||
@ -219,10 +221,93 @@
|
||||
<property key="remove-unused-sections" value="true"/>
|
||||
</HI-TECH-LINK>
|
||||
<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>
|
||||
<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="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>
|
||||
<XC8-CO>
|
||||
<property key="coverage-enable" value=""/>
|
||||
|
File diff suppressed because one or more lines are too long
134
UML/can.uxf
Normal file
134
UML/can.uxf
Normal file
@ -0,0 +1,134 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<diagram program="umlet" version="15.0.0">
|
||||
<zoom_level>15</zoom_level>
|
||||
<element>
|
||||
<id>UMLSpecialState</id>
|
||||
<coordinates>
|
||||
<x>465</x>
|
||||
<y>165</y>
|
||||
<w>30</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>type=initial</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLState</id>
|
||||
<coordinates>
|
||||
<x>405</x>
|
||||
<y>255</y>
|
||||
<w>150</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>STCA_WAIT</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>465</x>
|
||||
<y>180</y>
|
||||
<w>90</w>
|
||||
<h>105</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=->
|
||||
evInit
|
||||
</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>465</x>
|
||||
<y>300</y>
|
||||
<w>180</w>
|
||||
<h>105</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=->
|
||||
evCaNewMsg</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLState</id>
|
||||
<coordinates>
|
||||
<x>330</x>
|
||||
<y>375</y>
|
||||
<w>285</w>
|
||||
<h>105</h>
|
||||
</coordinates>
|
||||
<panel_attributes>STCA_READ
|
||||
-
|
||||
-.
|
||||
/entry: processCan</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>495</x>
|
||||
<y>270</y>
|
||||
<w>225</w>
|
||||
<h>360</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=->
|
||||
m1=[queue empty]
|
||||
</panel_attributes>
|
||||
<additional_attributes>10.0;210.0;130.0;210.0;130.0;10.0;40.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLSpecialState</id>
|
||||
<coordinates>
|
||||
<x>450</x>
|
||||
<y>555</y>
|
||||
<w>60</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>type=decision</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>465</x>
|
||||
<y>465</y>
|
||||
<w>45</w>
|
||||
<h>120</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=->
|
||||
</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;60.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>225</x>
|
||||
<y>390</y>
|
||||
<w>255</w>
|
||||
<h>240</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=->
|
||||
m1=[else]
|
||||
</panel_attributes>
|
||||
<additional_attributes>150.0;130.0;10.0;130.0;10.0;10.0;70.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLNote</id>
|
||||
<coordinates>
|
||||
<x>750</x>
|
||||
<y>300</y>
|
||||
<w>615</w>
|
||||
<h>270</h>
|
||||
</coordinates>
|
||||
<panel_attributes>_*How to use*_
|
||||
|
||||
*In Factory_build: *
|
||||
ECAN_SetRXBnInterruptHandler(CANINTERFACE_newMsg);
|
||||
CANINTERFACE_onProcessCan(&processCan);
|
||||
|
||||
*Somewhere:*
|
||||
void processCan(uint32_t canId, uint32_t canData) {
|
||||
.....
|
||||
}</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
</diagram>
|
Reference in New Issue
Block a user