#pragma once #include "DSP2833x_Device.h" #include "DSP28x_Project.h" namespace canSpace { enum CAN_VARIANT{ NONE = 0, CANA, CANB }; // eCAN Message Control Register (MSGCTRL) bit definitions struct MsgCtrlBits { // bits description Uint16 DLC:4; // 0:3 Uint16 RTR:1; // 4 Uint16 rsvd1:3; // 7:5 reserved Uint16 TPL:5; // 12:8 Uint16 rsvd2:3; // 15:13 reserved }; union MsgCtrlReg { Uint16 all; struct MsgCtrlBits bit; MsgCtrlReg(){ all = 0; } MsgCtrlReg(Uint16 configData){ all = configData; } }; struct MsgID_Bits { // bits description Uint16 EXTMSGID_L:16; // 0:15 Uint16 EXTMSGID_H:2; // 16:17 Uint16 STDMSGID:11; // 18:28 Uint16 AAM:1; // 29 Uint16 AME:1; // 30 Uint16 IDE:1; // 31 }; // Allow access to the bit fields or entire register union ConfigMsgID { Uint32 all; struct MsgID_Bits bit; ConfigMsgID(bool isExtendedID, Uint16 standartID, Uint32 extendedID, bool isAAM, bool isAME) { if(!isExtendedID){ bit.EXTMSGID_H = 0; bit.EXTMSGID_L = 0; bit.STDMSGID = standartID; } else{ all = extendedID; } bit.AAM = isAAM; bit.AME = isAME; bit.IDE = isExtendedID; } }; struct ConfigMBox{ ConfigMsgID msgID; MsgCtrlReg msgCtrlReg; ConfigMBox(bool isExtendedID, Uint16 standartID, Uint32 extendedID, bool isAAM, bool isAME, Uint16 ctrlReg) : msgID(isExtendedID, standartID, extendedID, isAAM, isAME), msgCtrlReg(ctrlReg) {} }; struct CANMessage { union MsgCtrlReg msgctrl; union CANMDL_REG mdl; union CANMDH_REG mdh; CANMessage(){ msgctrl.all = 0; mdl.all = 0; mdh.all = 0; } // CANMessage(const CANMessage& copyStruct){ // msgctrl.all = copyStruct.msgctrl.all; // mdl.all = copyStruct.mdl.all; // mdh.all = copyStruct.mdh.all; // } }; class CAN{ public: CAN(); void initGpio(CAN_VARIANT canVarinat); void config(CAN_VARIANT canVarinat, Uint16 baudrate); // void configRxMBoxes(); void configRxMBoxes(Uint16 boxNumber, const ConfigMBox& configData); // void configTxMBoxes(); //TODO delete void configTxMBox(Uint16 boxNumber, const ConfigMBox& configData); void transmitMsg(Uint16 boxNumber, const CANMessage& message); bool receiveMsg(Uint16 boxNumber, CANMessage& rxMessage); // CANMessage receiveMsg(Uint16 boxNumber); bool isNewMessage(); bool isNewMessage(Uint16 boxNumber); private: volatile ECAN_REGS* p_CanRegs_; ECAN_REGS CanShadow_; volatile ECAN_MBOXES* p_CanMBoxes_; }; } // canSpace