Add remote frames

feature/baseCAN
Oleg 2 months ago
parent dfb90e3ee8
commit fd72d2833b

@ -1,4 +1,5 @@
#include "CAN.h" #include "CAN.h"
#include "DSP2833x_Device.h"
#include <cstddef> #include <cstddef>
namespace canSpace { namespace canSpace {
@ -17,8 +18,9 @@ void CAN::transmitMsg(Uint16 boxNumber, const CANMessage& message){
p_MailBox->MDH.all = message.mdh.all; p_MailBox->MDH.all = message.mdh.all;
p_MailBox->MDL.all = message.mdl.all; p_MailBox->MDL.all = message.mdl.all;
// Set TRS for mailbox
CanShadow_.CANTRS.all = 0; CanShadow_.CANTRS.all = 0;
CanShadow_.CANTRS.all |= mboxControl; // Set TRS for mailbox under test CanShadow_.CANTRS.all |= mboxControl;
p_CanRegs_->CANTRS.all = CanShadow_.CANTRS.all; p_CanRegs_->CANTRS.all = CanShadow_.CANTRS.all;
do { CanShadow_.CANTA.all = p_CanRegs_->CANTA.all; } // TODO add tx error somewhere here do { CanShadow_.CANTA.all = p_CanRegs_->CANTA.all; } // TODO add tx error somewhere here
@ -29,18 +31,44 @@ void CAN::transmitMsg(Uint16 boxNumber, const CANMessage& message){
p_CanRegs_->CANTA.all = CanShadow_.CANTA.all; p_CanRegs_->CANTA.all = CanShadow_.CANTA.all;
} }
void CAN::updateTXMessage(Uint16 boxNumber, const CANMessage& message){ // TODO check trs bit and set it at the end if it was here
volatile MBOX* p_MailBox(NULL);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
bool CAN::isNewMessage(){ p_CanRegs_->CANMC.all |= (128 + boxNumber);
return static_cast<bool>(p_CanRegs_->CANRMP.all);
p_MailBox->MDL.all = message.mdl.all;
p_MailBox->MDH.all = message.mdh.all;
CanShadow_.CANMC.all = p_CanRegs_->CANMC.all;
CanShadow_.CANMC.bit.CDR = 0;
p_CanRegs_->CANMC.all = CanShadow_.CANMC.all;
} }
bool CAN::isNewMessage(Uint16 boxNumber){ void CAN::sendRemoteRequest(Uint16 boxNumber){
volatile MBOX* p_MailBox(NULL);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
Uint32 mboxControl(0); Uint32 mboxControl(0);
mboxControl = 1ul << boxNumber; mboxControl = 1ul << boxNumber;
bool isNewMessageInBox = p_CanRegs_->CANRMP.all & mboxControl; // Mailbox disable
return isNewMessageInBox; CanShadow_.CANME.all = p_CanRegs_->CANME.all;
CanShadow_.CANME.all &= ~(mboxControl);
p_CanRegs_->CANME.all = CanShadow_.CANME.all;
p_MailBox->MSGCTRL.bit.RTR = 1;
// Mailbox enable
CanShadow_.CANME.all = p_CanRegs_->CANME.all;
CanShadow_.CANME.all |= mboxControl;
p_CanRegs_->CANME.all = CanShadow_.CANME.all;
// Set TRS for mailbox
CanShadow_.CANTRS.all = 0;
CanShadow_.CANTRS.all |= mboxControl;
p_CanRegs_->CANTRS.all = CanShadow_.CANTRS.all;
} }
@ -75,6 +103,20 @@ bool CAN::receiveMsg(Uint16 boxNumber, CANMessage& rxMessage){ // TODO faults ju
} }
bool CAN::isNewMessage(){
return static_cast<bool>(p_CanRegs_->CANRMP.all);
}
bool CAN::isNewMessage(Uint16 boxNumber){
Uint32 mboxControl(0);
mboxControl = 1ul << boxNumber;
bool isNewMessageInBox = p_CanRegs_->CANRMP.all & mboxControl;
return isNewMessageInBox;
}
/* CANMessage CAN::receiveMsg(Uint16 boxNumber){ /* CANMessage CAN::receiveMsg(Uint16 boxNumber){
Uint32 mboxControl(0); Uint32 mboxControl(0);
mboxControl = 1ul << boxNumber; mboxControl = 1ul << boxNumber;

@ -103,21 +103,22 @@ public:
void initGpio(); void initGpio();
void config(Uint16 baudrate); void config(Uint16 baudrate);
// void configTxMBox(Uint16 boxNumber, const ConfigMBox& configData);
void configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg); void configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg);
void configRxMBoxes(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg); void configRxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg);
void transmitMsg(Uint16 boxNumber, const CANMessage& message);
bool receiveMsg(Uint16 boxNumber, CANMessage& rxMessage);
// CANMessage receiveMsg(Uint16 boxNumber);
bool isNewMessage(); bool isNewMessage();
bool isNewMessage(Uint16 boxNumber); bool isNewMessage(Uint16 boxNumber);
void transmitMsg(Uint16 boxNumber, const CANMessage& message);
void updateTXMessage(Uint16 boxNumber, const CANMessage& message);
void sendRemoteRequest(Uint16 boxNumber);
bool receiveMsg(Uint16 boxNumber, CANMessage& rxMessage);
private: private:
CAN_VARIANT canPort;
volatile ECAN_REGS* p_CanRegs_; volatile ECAN_REGS* p_CanRegs_;
ECAN_REGS CanShadow_; ECAN_REGS CanShadow_;
volatile ECAN_MBOXES* p_CanMBoxes_; volatile ECAN_MBOXES* p_CanMBoxes_;
CAN_VARIANT canPort;
}; };

@ -219,7 +219,7 @@ void CAN::configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg
} }
void CAN::configRxMBoxes(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg){ void CAN::configRxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg){
volatile MBOX* p_MailBox(NULL); volatile MBOX* p_MailBox(NULL);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber; p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
@ -227,6 +227,11 @@ void CAN::configRxMBoxes(Uint16 boxNumber, const MsgID& configID, const MsgCtrlR
Uint32 mboxControl(0); Uint32 mboxControl(0);
mboxControl = 1ul << boxNumber; mboxControl = 1ul << boxNumber;
// Mailbox disable
CanShadow_.CANME.all = p_CanRegs_->CANME.all;
CanShadow_.CANME.all &= ~(mboxControl);
p_CanRegs_->CANME.all = CanShadow_.CANME.all;
// Write to the MSGID field // Write to the MSGID field
p_MailBox->MSGID.all = 0x0; p_MailBox->MSGID.all = 0x0;
p_MailBox->MSGID.all = configID.all; p_MailBox->MSGID.all = configID.all;

@ -20,7 +20,10 @@ Uint16 infCounter = 0;
volatile Uint16 testCounter = 0; volatile Uint16 testCounter = 0;
Uint32 testVar = 0; Uint32 testVar = 0;
volatile bool startTX = false; volatile bool startTX = false;
volatile bool update = false;
volatile bool sendRemote = false;
canSpace::CANMessage message; canSpace::CANMessage message;
canSpace::CANMessage rxMessage;
void main() void main()
{ {
@ -57,7 +60,7 @@ void main()
// configuration_parameters.extract_configuration(test_config); // configuration_parameters.extract_configuration(test_config);
InitCpuTimers(); InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 150, 800); ConfigCpuTimer(&CpuTimer0, 150, 10000);
IER |= M_INT1; // Enable CPU Interrupt 1 IER |= M_INT1; // Enable CPU Interrupt 1
// Enable ADCINT in PIE // Enable ADCINT in PIE
@ -81,7 +84,10 @@ void main()
canTest.initGpio(); canTest.initGpio();
canTest.config(100); canTest.config(100);
canTest.configTxMBox(1, canSpace::MsgID(0xAAA), canSpace::MsgCtrlReg(0x8)); canTest.configTxMBox(1, canSpace::MsgID(0xAAA), canSpace::MsgCtrlReg(0x8));
canTest.configRxMBoxes(25, canSpace::MsgID(0xAAA), canSpace::MsgCtrlReg(0x8)); canTest.configRxMBox(25, canSpace::MsgID(0xAAA), canSpace::MsgCtrlReg(0x8));
// Remote frame
canTest.configRxMBox(2, canSpace::MsgID(0x111), canSpace::MsgCtrlReg(0x13));
// canTest.configTxMBox(30, canSpace::MsgID(0x111, false, true), canSpace::MsgCtrlReg(0x3)); // for remote answer
// InitECanGpio(); // InitECanGpio();
// InitECan(); // InitECan();
@ -97,6 +103,7 @@ void main()
message.mdh.byte.BYTE5 = 0xBB; message.mdh.byte.BYTE5 = 0xBB;
message.mdh.byte.BYTE6 = 0xCC; message.mdh.byte.BYTE6 = 0xCC;
message.mdh.byte.BYTE7 = 0xDD; message.mdh.byte.BYTE7 = 0xDD;
// canTest.updateTXMessage(30, message); // for remote answer
idle_loop(); idle_loop();
// //
@ -116,7 +123,21 @@ void idle_loop()
} }
if(canTest.isNewMessage()){ if(canTest.isNewMessage()){
testCounter++; testCounter++;
testVar = canTest.receiveMsg(25, message); testVar = canTest.receiveMsg(25, rxMessage);
// testVar = canTest.receiveMsg(2, rxMessage);
}
// testVar = canTest.receiveMsg(2, rxMessage);
if (update){
update = false;
message.mdh.all = 0xBBEEBBEE;
canTest.updateTXMessage(1, message);
}
if (sendRemote){
sendRemote = false;
canTest.sendRemoteRequest(2);
} }
}//end while }//end while
@ -126,7 +147,13 @@ void idle_loop()
interrupt void cpu_timer0_isr(void) interrupt void cpu_timer0_isr(void)
{ {
canTest.sendRemoteRequest(2);
//
if(canTest.isNewMessage()){
testCounter++;
testVar = canTest.receiveMsg(25, rxMessage);
testVar = canTest.receiveMsg(2, rxMessage);
}
PieCtrlRegs.PIEACK.all |= PIEACK_GROUP1; PieCtrlRegs.PIEACK.all |= PIEACK_GROUP1;
}//end }//end

Loading…
Cancel
Save