can interface tested

IT WORKING !!!!
This commit is contained in:
Rémi Heredero 2023-08-24 20:31:40 +02:00
parent 357a7af1e8
commit 519cbfff68
5 changed files with 102 additions and 66 deletions

View File

@ -57,8 +57,12 @@ void Factory_init() {
} }
void foo(uint8_t a, uint8_t b, uint32_t c){ void foo(uint8_t a, uint8_t b, uint32_t c){
LED_on(l1()); if(b){
CAN_Send(b, a, c); LED_on(l1());
} else {
LED_off(l1());
}
CAN_Send(a, b, c);
} }
//connect objects if required //connect objects if required

View File

@ -30,8 +30,6 @@ void main(void)
//the xf.h file to the same value as the TMR0 value. //the xf.h file to the same value as the TMR0 value.
TMR0_SetInterruptHandler(XF_decrementAndQueueTimers); TMR0_SetInterruptHandler(XF_decrementAndQueueTimers);
CAN_Send(1,1,42);
while (1) while (1)
{ {
//handle the next event if there is any in the queue //handle the next event if there is any in the queue

View File

@ -36,20 +36,20 @@ bool ALIVE_CHECKER_processEvent(Event* ev) {
break; break;
case STAC_SETUP: case STAC_SETUP:
if (ev->id = evACborn) { if (ev->id == evACborn) {
me->state = STAC_BORN; me->state = STAC_BORN;
} }
break; break;
case STAC_BORN: case STAC_BORN:
if (ev->id = evACready) { if (ev->id == evACready) {
me->state = STAC_WAIT; me->state = STAC_WAIT;
ALIVE_CHECKER_emitPoll(me, me->aliveTime*10, 0); ALIVE_CHECKER_emitPoll(me, me->aliveTime*10, 0);
} }
break; break;
case STAC_WAIT: case STAC_WAIT:
if (ev->id = evACpoll) { if (ev->id == evACpoll) {
if (me->isAlive) { if (me->isAlive) {
me->state = STAC_WAIT; me->state = STAC_WAIT;
ALIVE_CHECKER_emitPoll(me, me->aliveTime*10, 0); ALIVE_CHECKER_emitPoll(me, me->aliveTime*10, 0);
@ -60,7 +60,7 @@ bool ALIVE_CHECKER_processEvent(Event* ev) {
break; break;
case STAC_DEAD: case STAC_DEAD:
if(ev->id = evACborn) { if(ev->id == evACborn) {
me->state = STAC_BORN; me->state = STAC_BORN;
} }
break; break;

View File

@ -6,6 +6,38 @@
*/ */
#include "can_interface.h" #include "can_interface.h"
#include "../mcc_generated_files/ecan.h"
typedef union {
struct {
uint8_t sender;
uint8_t recipient;
uint8_t message;
uint32_t data;
} full;
struct {
uint8_t sender;
uint8_t recipient;
uint8_t message;
uint8_t data0;
uint8_t data1;
uint8_t data2;
uint8_t data3;
} separate;
} CAN_MESSAGE;
typedef union {
struct {
uint8_t byte0;
uint8_t byte1;
uint8_t byte2;
uint8_t byte3;
} separate;
struct {
uint32_t bytes;
} full;
} CAN_4_BYTES;
void CAN_init(){ void CAN_init(){
CAN_myself.receiveCan = NULL; CAN_myself.receiveCan = NULL;
@ -39,11 +71,13 @@ bool CAN_processEvent(Event* ev) {
if (me->receiveCan != NULL) { if (me->receiveCan != NULL) {
uint32_t canData = (uint32_t) data; uint32_t canData = (uint32_t) data;
data = data>>32; data = data>>32;
uint8_t idMsg = (uint8_t) data;
data = data>>4; CAN_4_BYTES tmpData;
uint8_t idRecipient = (uint8_t) data; tmpData.full.bytes = data;
data = data>>4; uint8_t idMsg = 0x0F && (tmpData.separate.byte0>>4);
uint8_t idSender = (uint8_t) data; uint8_t idRecipient = 0x0F && tmpData.separate.byte1;
uint8_t idSender = (tmpData.separate.byte1>>4);
me->receiveCan(idSender, idMsg, canData); me->receiveCan(idSender, idMsg, canData);
} }
} }
@ -54,13 +88,13 @@ bool CAN_processEvent(Event* ev) {
canMsg.frame.idType = 0; // I don't understand what is it canMsg.frame.idType = 0; // I don't understand what is it
canMsg.frame.dlc = 4; // 4 bytes to send canMsg.frame.dlc = 4; // 4 bytes to send
canMsg.frame.rtr = 0; // no remote frame canMsg.frame.rtr = 0; // no remote frame
canMsg.frame.data0 = (uint8_t) data; canMsg.frame.data3 = (uint8_t) data;
data = data >> 8;
canMsg.frame.data1 = (uint8_t) data;
data = data >> 8; data = data >> 8;
canMsg.frame.data2 = (uint8_t) data; canMsg.frame.data2 = (uint8_t) data;
data = data >> 8; data = data >> 8;
canMsg.frame.data3 = (uint8_t) data; canMsg.frame.data1 = (uint8_t) data;
data = data >> 8;
canMsg.frame.data0 = (uint8_t) data;
data = data >> 8; data = data >> 8;
canMsg.frame.id = (uint32_t) data; canMsg.frame.id = (uint32_t) data;
CAN_transmit(&canMsg); CAN_transmit(&canMsg);
@ -107,14 +141,14 @@ void CAN_newMsg() {
uCAN_MSG canMsg; uCAN_MSG canMsg;
CAN_receive(&canMsg); CAN_receive(&canMsg);
data = canMsg.frame.id; data = canMsg.frame.id;
data = data<<32; data = data<<12;
data = canMsg.frame.data0; data = data | canMsg.frame.data0;
data = data<<8; data = data<<8;
data = canMsg.frame.data1; data = data | canMsg.frame.data1;
data = data<<8; data = data<<8;
data = canMsg.frame.data2; data = data | canMsg.frame.data2;
data = data<<8; data = data<<8;
data = canMsg.frame.data3; data = data | canMsg.frame.data3;
POST(&CAN_myself, &CAN_processEvent, evCAnewMsg, 0, data); POST(&CAN_myself, &CAN_processEvent, evCAnewMsg, 0, data);
} }

File diff suppressed because one or more lines are too long