From cc5994801188017198e882210073e0bf7e882326 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 14 Mar 2025 11:26:18 +0300 Subject: [PATCH] Fix can transmitMsg() 1. Now method takes Uint62 instead of Uint32 2. Comment TA bit checking for not potentially make processor to stand in endless loop if there is no answer from another node 3. The method do not set data lenght now. It should be set when MBOX configuring --- Protocol/CAN.cpp | 32 ++++++++++++++++---------------- Protocol/CAN.h | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Protocol/CAN.cpp b/Protocol/CAN.cpp index ad521e8..5918203 100644 --- a/Protocol/CAN.cpp +++ b/Protocol/CAN.cpp @@ -15,7 +15,7 @@ void CAN::transmitMsg(Uint16 boxNumber, const CANMessage& message){ p_MailBox->MDH.all = 0x0; p_MailBox->MDL.all = 0x0; - p_MailBox->MSGCTRL.bit.DLC = message.dataLength; + // p_MailBox->MSGCTRL.bit.DLC = message.dataLength; p_MailBox->MDH.all = message.mdh.all; p_MailBox->MDL.all = message.mdl.all; @@ -35,7 +35,7 @@ void CAN::transmitMsg(Uint16 boxNumber, const CANMessage& message){ } -void CAN::transmitMsg(Uint16 boxNumber, const Uint32& message){ +void CAN::transmitMsg(Uint16 boxNumber, const Uint64& message){ if (boxNumber > 31) return; Uint32 mboxControl(0); @@ -46,8 +46,8 @@ void CAN::transmitMsg(Uint16 boxNumber, const Uint32& message){ p_MailBox->MDH.all = 0x0; p_MailBox->MDL.all = 0x0; - - p_MailBox->MDH.all = message >> 16; + + p_MailBox->MDH.all = message >> 32; p_MailBox->MDL.all = message; // Set TRS for mailbox @@ -56,17 +56,17 @@ void CAN::transmitMsg(Uint16 boxNumber, const Uint32& message){ p_CanRegs_->CANTRS.all = CanShadow_.CANTRS.all; // Wait for TA bit to be set - do { CanShadow_.CANTA.all = p_CanRegs_->CANTA.all; } - while((CanShadow_.CANTA.all & mboxControl) == 0 ); + // do { CanShadow_.CANTA.all = p_CanRegs_->CANTA.all; } + // while((CanShadow_.CANTA.all & mboxControl) == 0 ); // Clear TA (transmit acknowledge bit) - CanShadow_.CANTA.all = 0; - CanShadow_.CANTA.all |= mboxControl; - p_CanRegs_->CANTA.all = CanShadow_.CANTA.all; + // CanShadow_.CANTA.all = 0; + // CanShadow_.CANTA.all |= mboxControl; + // p_CanRegs_->CANTA.all = CanShadow_.CANTA.all; } -void CAN::transmitMsg(Uint16 boxNumber, const Uint32& message, const Uint16 dlc){ +void CAN::transmitMsg(Uint16 boxNumber, const Uint64& message, const Uint16 dlc){ if (boxNumber > 31) return; Uint32 mboxControl(0); @@ -79,7 +79,7 @@ void CAN::transmitMsg(Uint16 boxNumber, const Uint32& message, const Uint16 dlc) p_MailBox->MDL.all = 0x0; p_MailBox->MSGCTRL.bit.DLC = dlc; - p_MailBox->MDH.all = message >> 16; + p_MailBox->MDH.all = message >> 32; p_MailBox->MDL.all = message; // Set TRS for mailbox @@ -88,13 +88,13 @@ void CAN::transmitMsg(Uint16 boxNumber, const Uint32& message, const Uint16 dlc) p_CanRegs_->CANTRS.all = CanShadow_.CANTRS.all; // Wait for TA bit to be set - do { CanShadow_.CANTA.all = p_CanRegs_->CANTA.all; } - while((CanShadow_.CANTA.all & mboxControl) == 0 ); + // do { CanShadow_.CANTA.all = p_CanRegs_->CANTA.all; } + // while((CanShadow_.CANTA.all & mboxControl) == 0 ); // Clear TA (transmit acknowledge bit) - CanShadow_.CANTA.all = 0; - CanShadow_.CANTA.all |= mboxControl; - p_CanRegs_->CANTA.all = CanShadow_.CANTA.all; + // CanShadow_.CANTA.all = 0; + // CanShadow_.CANTA.all |= mboxControl; + // p_CanRegs_->CANTA.all = CanShadow_.CANTA.all; } diff --git a/Protocol/CAN.h b/Protocol/CAN.h index f230c14..8625a44 100644 --- a/Protocol/CAN.h +++ b/Protocol/CAN.h @@ -114,8 +114,8 @@ public: bool isNewMessage(Uint16 boxNumber); void transmitMsg(Uint16 boxNumber, const CANMessage& message); // TODO excessive method? - void transmitMsg(Uint16 boxNumber, const Uint32& message); - void transmitMsg(Uint16 boxNumber, const Uint32& message, const Uint16 dlc); + void transmitMsg(Uint16 boxNumber, const Uint64& message); + void transmitMsg(Uint16 boxNumber, const Uint64& message, const Uint16 dlc); void updateTXMessage(Uint16 boxNumber, const CANMessage& message); void updateTXMessage(Uint16 boxNumber, const Uint32& message); void sendRemoteRequest(Uint16 boxNumber);