Merge branch 'feature/baseCAN' into dev

CAN module is added here. This is not the can protocol for communication
between CPU and COMM boards, but common CAN protocol that must be
extended in the future
feature/CAN_timeOut
Oleg 2 months ago
commit 714f0265cc

@ -1,13 +1,14 @@
#include "DSP2833x_Device.h"
#include <cstddef>
#include "CAN.h"
namespace canSpace {
void CAN::transmitMsg(Uint16 boxNumber, const CANMessage& message){
if (boxNumber > 31) return;
Uint32 mboxControl(0);
mboxControl = 1ul << boxNumber;
volatile MBOX* p_MailBox(NULL);
volatile MBOX* p_MailBox(0);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
p_MailBox->MDH.all = 0x0;
@ -22,8 +23,9 @@ void CAN::transmitMsg(Uint16 boxNumber, const CANMessage& message){
CanShadow_.CANTRS.all |= mboxControl;
p_CanRegs_->CANTRS.all = CanShadow_.CANTRS.all;
do { CanShadow_.CANTA.all = p_CanRegs_->CANTA.all; } // TODO add tx error somewhere here
while((CanShadow_.CANTA.all & mboxControl) == 0 );// Wait for TA bit to be set
// Wait for TA bit to be set
do { CanShadow_.CANTA.all = p_CanRegs_->CANTA.all; }
while((CanShadow_.CANTA.all & mboxControl) == 0 );
// Clear TA (transmit acknowledge bit)
CanShadow_.CANTA.all = 0;
@ -38,7 +40,7 @@ void CAN::updateTXMessage(Uint16 boxNumber, const CANMessage& message){ // TODO
// then transmitted.
if (boxNumber > 31) return;
volatile MBOX* p_MailBox(NULL);
volatile MBOX* p_MailBox(0);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
// Set change data request (CDR bit + MBOX number)
@ -56,7 +58,7 @@ void CAN::updateTXMessage(Uint16 boxNumber, const CANMessage& message){ // TODO
void CAN::sendRemoteRequest(Uint16 boxNumber){
if (boxNumber > 31) return;
volatile MBOX* p_MailBox(NULL);
volatile MBOX* p_MailBox(0);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
Uint32 mboxControl(0);
@ -87,7 +89,7 @@ bool CAN::receiveMsg(Uint16 boxNumber, CANMessage& rxMessage){ // TODO faults ju
Uint32 mboxControl(0);
mboxControl = 1ul << boxNumber;
volatile MBOX* p_MailBox(NULL);
volatile MBOX* p_MailBox(0);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
bool isNewMessageInBox = p_CanRegs_->CANRMP.all & mboxControl;
@ -107,7 +109,6 @@ bool CAN::receiveMsg(Uint16 boxNumber, CANMessage& rxMessage){ // TODO faults ju
if(newMessage || lostMessage) {
return -1;
// set_fault();
}
return 0;

@ -1,6 +1,5 @@
#pragma once
#include "DSP2833x_Device.h"
#include "DSP28x_Project.h"
namespace canSpace {

@ -1,6 +1,4 @@
#include "DSP2833x_Device.h"
#include "DSP2833x_ECan.h"
#include <cstddef>
#include "CAN.h"
namespace canSpace {
@ -185,7 +183,7 @@ void CAN::config(Uint16 baudrate, Uint16 flags){
void CAN::configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg){
if (boxNumber > 31) return;
volatile MBOX* p_MailBox(NULL);
volatile MBOX* p_MailBox(0);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
Uint32 mboxControl(0);
@ -201,7 +199,6 @@ void CAN::configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg
while((CanShadow_.CANTRS.all & mboxControl) != 0); // Wait for TRS bit to be cleared
}
// Mailbox disable
CanShadow_.CANME.all = p_CanRegs_->CANME.all;
CanShadow_.CANME.all &= ~(mboxControl);
@ -217,7 +214,7 @@ void CAN::configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg
// Write to RTR and TPL field in control reg
p_MailBox->MSGCTRL.bit.RTR = configCtrlReg.bit.RTR;
// p_MailBox->MSGCTRL.bit.TPL = configData.msgCtrlReg.bit.TPL; // enable if you need to set msg priority lvl
p_MailBox->MSGCTRL.bit.TPL = configCtrlReg.bit.TPL;
// Mailbox enable
CanShadow_.CANME.all = p_CanRegs_->CANME.all;
@ -229,7 +226,7 @@ void CAN::configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg
void CAN::configRxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg){
if (boxNumber > 31) return;
volatile MBOX* p_MailBox(NULL);
volatile MBOX* p_MailBox(0);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
Uint32 mboxControl(0);
@ -263,10 +260,6 @@ void CAN::configRxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg
CanShadow_.CANME.all = p_CanRegs_->CANME.all;
CanShadow_.CANME.all |= mboxControl;
p_CanRegs_->CANME.all = CanShadow_.CANME.all;
// Write to the mailbox RAM field // TODO doesn't work when rx. Check for RTR
// p_MailBox->MDL.all = 0x55555555;
// p_MailBox->MDH.all = 0x55555555;
}

Loading…
Cancel
Save