From 4987fbabd022a5f51f5d82ff6703e1230eea0f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 30 Aug 2023 16:19:42 +0200 Subject: [PATCH 1/4] add send for 4,1 or 0 bytes --- .../middleware/can_interface.c | 101 ++++++++++++++++-- .../middleware/can_interface.h | 10 +- 2 files changed, 104 insertions(+), 7 deletions(-) diff --git a/306-controller_interface.X/middleware/can_interface.c b/306-controller_interface.X/middleware/can_interface.c index 6c893fd..a60b653 100644 --- a/306-controller_interface.X/middleware/can_interface.c +++ b/306-controller_interface.X/middleware/can_interface.c @@ -34,9 +34,7 @@ typedef union { uint8_t byte2; uint8_t byte3; } separate; - struct { - uint32_t bytes; - } full; + uint32_t full; } CAN_4_BYTES; void CAN_init(){ @@ -73,7 +71,7 @@ bool CAN_processEvent(Event* ev) { data = data>>32; CAN_4_BYTES tmpData; - tmpData.full.bytes = data; + tmpData.full = data; uint8_t idMsg = tmpData.separate.byte0; idMsg = idMsg >> 4; idMsg = idMsg & 0xF; @@ -87,7 +85,7 @@ bool CAN_processEvent(Event* ev) { } // Send a message - if (ev->id == evCAsend) { + if (ev->id == evCAsend4) { uCAN_MSG canMsg; canMsg.frame.idType = dSTANDARD_CAN_MSG_ID_2_0B; // standard canMsg.frame.dlc = 4; // 4 bytes to send @@ -103,6 +101,57 @@ bool CAN_processEvent(Event* ev) { canMsg.frame.id = (uint32_t) data; CAN_transmit(&canMsg); } + + if (ev->id == evCAsend2) { + uCAN_MSG canMsg; + canMsg.frame.idType = dSTANDARD_CAN_MSG_ID_2_0B; // standard + canMsg.frame.dlc = 2; // 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); + } + + if (ev->id == evCAsend1) { + uCAN_MSG canMsg; + canMsg.frame.idType = dSTANDARD_CAN_MSG_ID_2_0B; // standard + canMsg.frame.dlc = 1; // 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); + } + + if (ev->id == evCAsend0) { + uCAN_MSG canMsg; + canMsg.frame.idType = dSTANDARD_CAN_MSG_ID_2_0B; // standard + canMsg.frame.dlc = 0; // 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; } @@ -161,7 +210,47 @@ void CAN_Send(uint8_t idRecipient, uint8_t idMsg, uint32_t data) { tmpData = (tmpData<<4) | idRecipient; tmpData = (tmpData<<4) | idMsg; tmpData = (tmpData<<32) | data; - POST(&CAN_myself, &CAN_processEvent, evCAsend, 0, tmpData); + POST(&CAN_myself, &CAN_processEvent, evCAsend4, 0, tmpData); +} + +void CAN_send_4_bytes(uint8_t idRecipient, uint8_t idMsg, uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3) { + CAN_MESSAGE canMsg; + canMsg.separate.sender = CAN_myself.sender; + canMsg.separate.recipient = idRecipient; + canMsg.separate.message = idMsg; + canMsg.separate.data0 = byte0; + canMsg.separate.data1 = byte1; + canMsg.separate.data2 = byte2; + canMsg.separate.data0 = byte3; + POST(&CAN_myself, &CAN_processEvent, evCAsend4, 0, canMsg); +} + +void CAN_send_16_bytes(uint8_t idRecipient, uint8_t idMsg, uint16_t data) { + // BYTES_4 + // TODO finish + CAN_MESSAGE canMsg; + canMsg.separate.sender = CAN_myself.sender; + canMsg.separate.recipient = idRecipient; + canMsg.separate.message = idMsg; + canMsg.separate.data0 = data; + POST(&CAN_myself, &CAN_processEvent, evCAsend1, 0, canMsg); +} + +void CAN_send_1_byte(uint8_t idRecipient, uint8_t idMsg, uint8_t data) { + CAN_MESSAGE canMsg; + canMsg.separate.sender = CAN_myself.sender; + canMsg.separate.recipient = idRecipient; + canMsg.separate.message = idMsg; + canMsg.separate.data0 = data; + POST(&CAN_myself, &CAN_processEvent, evCAsend1, 0, canMsg); +} + +void CAN_send_0_byte(uint8_t idRecipient, uint8_t idMsg) { + CAN_MESSAGE canMsg; + canMsg.separate.sender = CAN_myself.sender; + canMsg.separate.recipient = idRecipient; + canMsg.separate.message = idMsg; + POST(&CAN_myself, &CAN_processEvent, evCAsend0, 0, canMsg); } /*********** diff --git a/306-controller_interface.X/middleware/can_interface.h b/306-controller_interface.X/middleware/can_interface.h index d65266b..79d7655 100644 --- a/306-controller_interface.X/middleware/can_interface.h +++ b/306-controller_interface.X/middleware/can_interface.h @@ -17,7 +17,10 @@ typedef enum { typedef enum { evCAinit = 10, evCAnewMsg, - evCAsend + evCAsend4, + evCAsend2, + evCAsend1, + evCAsend0 } CAN_EVENTS; typedef void (*CAN_CALLBACK)(uint8_t, uint8_t, uint32_t); @@ -78,6 +81,11 @@ void CAN_newMsg(); */ void CAN_Send(uint8_t idRecipient, uint8_t idMsg, uint32_t data); +void CAN_send_4_bytes(uint8_t idRecipient, uint8_t idMsg, uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3); +void CAN_send_2_bytes(uint8_t idRecipient, uint8_t idMsg, uint16_t data); +void CAN_send_1_byte(uint8_t idRecipient, uint8_t idMsg, uint8_t byte0); +void CAN_send_0_byte(uint8_t idRecipient, uint8_t idMsg); + /*********** * SETTERS * ***********/ From 448b5e66adc77c8ad3a975b16558c3cd89ca28e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 30 Aug 2023 16:20:41 +0200 Subject: [PATCH 2/4] fix 1 byte sending --- 306-controller_interface.X/middleware/can_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/306-controller_interface.X/middleware/can_interface.h b/306-controller_interface.X/middleware/can_interface.h index 79d7655..b76967b 100644 --- a/306-controller_interface.X/middleware/can_interface.h +++ b/306-controller_interface.X/middleware/can_interface.h @@ -83,7 +83,7 @@ void CAN_Send(uint8_t idRecipient, uint8_t idMsg, uint32_t data); void CAN_send_4_bytes(uint8_t idRecipient, uint8_t idMsg, uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3); void CAN_send_2_bytes(uint8_t idRecipient, uint8_t idMsg, uint16_t data); -void CAN_send_1_byte(uint8_t idRecipient, uint8_t idMsg, uint8_t byte0); +void CAN_send_1_byte(uint8_t idRecipient, uint8_t idMsg, uint8_t data); void CAN_send_0_byte(uint8_t idRecipient, uint8_t idMsg); /*********** From 11c95d9fd640ffec65047435d983555c06740440 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Fri, 1 Sep 2023 18:41:25 +0200 Subject: [PATCH 3/4] fix eeprom --- 306-controller_interface.X/app/can_message.c | 2 +- 306-controller_interface.X/app/eeprom.c | 18 +++++---- .../nbproject/configurations.xml | 4 +- .../queuelogs/debugtool | 0 busmaster_config.cfx | 40 +++++++++---------- 5 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 306-controller_interface.X/queuelogs/debugtool diff --git a/306-controller_interface.X/app/can_message.c b/306-controller_interface.X/app/can_message.c index 72ff705..89e21df 100644 --- a/306-controller_interface.X/app/can_message.c +++ b/306-controller_interface.X/app/can_message.c @@ -68,7 +68,7 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ // valHH valH valL valLL KART_CST.CONTROL_POWER_FACTOR = data; MEM_write_4_byte(MEMADD_CONTROL_POWER_FACTOR, KART_CST.CONTROL_POWER_FACTOR); - + CAN_Send(0, 5, KART_CST.CONTROL_POWER_FACTOR); } if(idMsg == 0x3) { // CONTROL_STEERING_FACTOR diff --git a/306-controller_interface.X/app/eeprom.c b/306-controller_interface.X/app/eeprom.c index 2e1ba5d..4efdbf8 100644 --- a/306-controller_interface.X/app/eeprom.c +++ b/306-controller_interface.X/app/eeprom.c @@ -7,6 +7,7 @@ #include "eeprom.h" #include "../app/car.h" +#include "../middleware/can_interface.h" typedef union { struct { @@ -21,12 +22,12 @@ typedef union { void MEM_init(){ uint8_t check = MEM_read_1_byte(0x0); - if(check != 0x2A){ + if(check != 0x42){ KART_CST.CONTROL_STEERING_MODE = 0; KART_CST.CONTROL_ALIVE_TIME = 50; - KART_CST.CONTROL_SPEED_FACTOR = 111111; - KART_CST.CONTROL_POWER_FACTOR = 10000; - KART_CST.CONTROL_STEERING_FACTOR = 400000000; + KART_CST.CONTROL_SPEED_FACTOR = 111111; // 111'111 + KART_CST.CONTROL_POWER_FACTOR = 10000; // 10'000 + KART_CST.CONTROL_STEERING_FACTOR = 400000000; // 400'000'000 KART_CST.CONTROL_MAX_SPEED_FW = 50; KART_CST.CONTROL_MAX_SPEED_BW = 25; @@ -74,13 +75,13 @@ void MEM_init(){ MEM_write_1_byte(MEMADD_BATTERY_ENERGY_TIME, KART_CST.BATTERY_ENERGY_TIME); MEM_write_1_byte(MEMADD_BATTERY_ALIVE_TIME, KART_CST.BATTERY_ALIVE_TIME); - MEM_write_1_byte(0x0, 0x2A); + MEM_write_1_byte(0x0, 0x42); } else { KART_CST.CONTROL_STEERING_MODE = MEM_read_1_byte(MEMADD_CONTROL_STEERING_MODE); KART_CST.CONTROL_ALIVE_TIME = MEM_read_1_byte(MEMADD_CONTROL_ALIVE_TIME); - KART_CST.CONTROL_SPEED_FACTOR = MEM_read_1_byte(MEMADD_CONTROL_SPEED_FACTOR); - KART_CST.CONTROL_POWER_FACTOR = MEM_read_1_byte(MEMADD_CONTROL_POWER_FACTOR); - KART_CST.CONTROL_STEERING_FACTOR = MEM_read_1_byte(MEMADD_CONTROL_STEERING_FACTOR); + KART_CST.CONTROL_SPEED_FACTOR = MEM_read_4_byte(MEMADD_CONTROL_SPEED_FACTOR); + KART_CST.CONTROL_POWER_FACTOR = MEM_read_4_byte(MEMADD_CONTROL_POWER_FACTOR); + KART_CST.CONTROL_STEERING_FACTOR = MEM_read_4_byte(MEMADD_CONTROL_STEERING_FACTOR); KART_CST.CONTROL_MAX_SPEED_FW = MEM_read_1_byte(MEMADD_CONTROL_MAX_SPEED_FW); KART_CST.CONTROL_MAX_SPEED_BW = MEM_read_1_byte(MEMADD_CONTROL_MAX_SPEED_BW); @@ -103,6 +104,7 @@ void MEM_init(){ KART_CST.BATTERY_ALIVE_TIME = MEM_read_1_byte(MEMADD_BATTERY_ALIVE_TIME); } + CAN_Send(0, 5, KART_CST.CONTROL_POWER_FACTOR); } void MEM_reset() { diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index 2d248e4..ded209f 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -245,7 +245,7 @@ - + @@ -292,7 +292,7 @@ - + diff --git a/306-controller_interface.X/queuelogs/debugtool b/306-controller_interface.X/queuelogs/debugtool new file mode 100644 index 0000000..e69de29 diff --git a/busmaster_config.cfx b/busmaster_config.cfx index f5a4e23..d41b117 100644 --- a/busmaster_config.cfx +++ b/busmaster_config.cfx @@ -366,9 +366,9 @@ 452 - 147 + 94 94 - 139 + 189 94 @@ -436,7 +436,7 @@ SHOWNORMAL - SHOWNORMAL + HIDE 291 205 957 @@ -567,9 +567,9 @@ SHOWNORMAL RESTORETOMAXIMIZED - 173 + 179 10 - 451 + 457 359 @@ -577,8 +577,8 @@ 1 - 0 - 0 + 1 + 19 Time @@ -650,11 +650,11 @@ Data Byte(s) 13 1 - 720 + 701 1 - 1 - 0 + 0 + 1 SYSTEM SHOWNORMAL @@ -667,9 +667,9 @@ SHOWNORMAL RESTORETOMAXIMIZED - 173 + 179 10 - 451 + 457 359 @@ -680,8 +680,8 @@ 1 - 0 - 0 + 1 + 19 Time @@ -735,11 +735,11 @@ Checksum 10 1 - 734 + 715 1 - 1 - 0 + 0 + 1 SYSTEM SHOWNORMAL @@ -752,9 +752,9 @@ SHOWNORMAL RESTORETOMAXIMIZED - 173 + 179 10 - 451 + 457 359 @@ -798,7 +798,7 @@ FALSE FALSE 4 - 0,0,0,0 + 0,0,39,16 10 FALSE a From 24f63b261bb0932152a2dc65d8ebc4a3b463f6be Mon Sep 17 00:00:00 2001 From: Klagarge Date: Mon, 4 Sep 2023 07:33:33 +0200 Subject: [PATCH 4/4] fix union --- 306-controller_interface.X/middleware/can_interface.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/306-controller_interface.X/middleware/can_interface.c b/306-controller_interface.X/middleware/can_interface.c index 6c893fd..ab667e2 100644 --- a/306-controller_interface.X/middleware/can_interface.c +++ b/306-controller_interface.X/middleware/can_interface.c @@ -34,9 +34,7 @@ typedef union { uint8_t byte2; uint8_t byte3; } separate; - struct { - uint32_t bytes; - } full; + uint32_t full; } CAN_4_BYTES; void CAN_init(){ @@ -55,6 +53,7 @@ bool CAN_processEvent(Event* ev) { evIDT evid = Event_getId(ev); uint64_t data = Event_getData(ev); + CAN_4_BYTES tmpData; switch (me->state) { // onState @@ -72,8 +71,7 @@ bool CAN_processEvent(Event* ev) { uint32_t canData = (uint32_t) data; data = data>>32; - CAN_4_BYTES tmpData; - tmpData.full.bytes = data; + tmpData.full = data; uint8_t idMsg = tmpData.separate.byte0; idMsg = idMsg >> 4; idMsg = idMsg & 0xF;