diff --git a/Protocol/CAN.cpp b/Protocol/CAN.cpp index ff91ef4..464b733 100644 --- a/Protocol/CAN.cpp +++ b/Protocol/CAN.cpp @@ -1,13 +1,14 @@ -#include "DSP2833x_Device.h" -#include +#include "CAN.h" namespace canSpace { -void CAN::transmitMsg(Uint16 boxNumber, const CANMessage& message){ +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; diff --git a/Protocol/CAN.h b/Protocol/CAN.h index d07e7be..149a90b 100644 --- a/Protocol/CAN.h +++ b/Protocol/CAN.h @@ -1,6 +1,5 @@ #pragma once -#include "DSP2833x_Device.h" #include "DSP28x_Project.h" namespace canSpace { diff --git a/Protocol/CANConfig.cpp b/Protocol/CANConfig.cpp index 2e500a9..7817555 100644 --- a/Protocol/CANConfig.cpp +++ b/Protocol/CANConfig.cpp @@ -1,6 +1,4 @@ -#include "DSP2833x_Device.h" -#include "DSP2833x_ECan.h" -#include +#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); @@ -256,17 +253,13 @@ void CAN::configRxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg // Overwrite protection // If "ON" make sure that an additional mailbox is configured to store ’overflow’ messages. // CanShadow_.CANOPC.all = p_CanRegs_->CANOPC.all; - // CanShadow_.CANOPC.all |= mboxControl; // Should be one more mailbox to store 'overflow' messages + // CanShadow_.CANOPC.all |= mboxControl; // Should be one more mailbox to store 'overflow' messages // p_CanRegs_->CANOPC.all = CanShadow_.CANOPC.all; // Enable Mailbox 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; } diff --git a/main.cpp b/main.cpp index 89f81c2..b1eb785 100644 --- a/main.cpp +++ b/main.cpp @@ -47,7 +47,7 @@ void main() PieVectTable.ECAN0INTB = &canb_isr; EDIS; -// memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize); + // memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize); InitCpuTimers(); ConfigCpuTimer(&CpuTimer0, 150, 100000);