diff --git a/Protocol/CAN.cpp b/Protocol/CAN.cpp index 25c4f12..a3c3b18 100644 --- a/Protocol/CAN.cpp +++ b/Protocol/CAN.cpp @@ -1,5 +1,6 @@ #include "CAN.h" #include "DSP2833x_Device.h" +#include "DSP2833x_ECan.h" namespace canSpace { @@ -25,13 +26,13 @@ void CAN::transmitMsg(Uint16 boxNumber, const CANMessage& 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; + // // Clear TA (transmit acknowledge bit) + // CanShadow_.CANTA.all = 0; + // CanShadow_.CANTA.all |= mboxControl; + // p_CanRegs_->CANTA.all = CanShadow_.CANTA.all; } @@ -250,4 +251,35 @@ bool CAN::isNewMessage(Uint16 boxNumber){ } +void CAN::resetTimeStampCounter(){ + EALLOW; + ECanbRegs.CANTSC = 0; + EDIS; +} + + +void CAN::setTimeOutValue(Uint16 boxNumber, Uint32 canBitsNumber){ + if (boxNumber > 31) { return; } + + volatile Uint32* p_MailBox(0); + p_MailBox = &(p_CanMotoRegs_->MOTO0) + boxNumber; + + *p_MailBox = canBitsNumber; +} + + +bool CAN::isTimeOut(Uint16 boxNumber){ + bool mBOXTimeOut = false; + mBOXTimeOut = p_CanRegs_->CANTOS.all & (1ul << boxNumber); + return mBOXTimeOut; +} + + +void CAN::clearTimeOutFlag(Uint16 boxNumber){ + Uint32 clearFlag = 0; + clearFlag = 1ul << boxNumber; + p_CanRegs_->CANTOS.all = clearFlag; +} + + } // canSpace diff --git a/Protocol/CAN.h b/Protocol/CAN.h index 80cc810..9d50408 100644 --- a/Protocol/CAN.h +++ b/Protocol/CAN.h @@ -1,7 +1,7 @@ #pragma once -#include "DSP2833x_Device.h" -#include "DSP28x_Project.h" +#include "F28335/DSP28x_Project.h" +#include "F28335/DSP2833x_Device.h" namespace canSpace { @@ -113,7 +113,7 @@ public: bool isNewMessage(); bool isNewMessage(Uint16 boxNumber); - void transmitMsg(Uint16 boxNumber, const CANMessage& message); // TODO excessive method? + void transmitMsg(Uint16 boxNumber, const CANMessage& message); void transmitMsg(Uint16 boxNumber, const Uint64& message); void transmitMsg(Uint16 boxNumber, const Uint64& message, const Uint16 dlc); void updateTXMessage(Uint16 boxNumber, const CANMessage& message); @@ -122,11 +122,20 @@ public: int16 receiveMsg(Uint16 boxNumber, CANMessage& rxMessage); int16 receiveMsg(Uint16 boxNumber, Uint64& rxMessage); + void enableTimeOutControl(Uint16 boxNumber); + void disableTimeOutControl(Uint16 boxNumber); + void resetTimeStampCounter(); + void setTimeOutValue(Uint16 boxNumber, Uint32 canBitsNumber); + bool isTimeOut(Uint16 boxNumber); + void clearTimeOutFlag(Uint16 boxNumber); + private: CAN_VARIANT canPort; volatile ECAN_REGS* p_CanRegs_; ECAN_REGS CanShadow_; volatile ECAN_MBOXES* p_CanMBoxes_; + volatile MOTO_REGS* p_CanMotoRegs_; + volatile MOTS_REGS* p_CanMotsRegs_; }; diff --git a/Protocol/CANConfig.cpp b/Protocol/CANConfig.cpp index 0e2a659..868f7c1 100644 --- a/Protocol/CANConfig.cpp +++ b/Protocol/CANConfig.cpp @@ -1,9 +1,14 @@ #include "CAN.h" +#include "DSP2833x_ECan.h" namespace canSpace { CAN::CAN(CAN_VARIANT canVariant) : - canPort(canVariant) + canPort(canVariant), + p_CanRegs_(0), + p_CanMBoxes_(0), + p_CanMotoRegs_(0), + p_CanMotsRegs_(0) {} @@ -19,6 +24,8 @@ void CAN::config(Uint16 baudrate, Uint16 flags){ EDIS; p_CanRegs_ = &ECanaRegs; p_CanMBoxes_ = &ECanaMboxes; + p_CanMotoRegs_ = &ECanaMOTORegs; + p_CanMotsRegs_ = &ECanaMOTSRegs; } else if (canPort == CANB){ EALLOW; @@ -26,6 +33,8 @@ void CAN::config(Uint16 baudrate, Uint16 flags){ EDIS; p_CanRegs_ = &ECanbRegs; p_CanMBoxes_ = &ECanbMboxes; + p_CanMotoRegs_ = &ECanbMOTORegs; + p_CanMotsRegs_ = &ECanbMOTSRegs; } else { return; } @@ -283,4 +292,27 @@ void CAN::configMBoxIsr(Uint16 boxNumber){ EDIS; } + +void CAN::enableTimeOutControl(Uint16 boxNumber){ + if (boxNumber > 31) return; + + Uint32 mboxControl(0); + + mboxControl = p_CanRegs_->CANTOC.all; + mboxControl |= 1ul << boxNumber; + p_CanRegs_->CANTOC.all = mboxControl; +} + + +void CAN::disableTimeOutControl(Uint16 boxNumber){ + if (boxNumber > 31) return; + + Uint32 mboxControl(0); + + mboxControl = p_CanRegs_->CANTOC.all; + mboxControl &= ~(1ul << boxNumber); + p_CanRegs_->CANTOC.all = mboxControl; +} + + } //canSpace