Change config methods. Tested with the second board

Things to be added in the future:
1) Remote requests
2) Possibility to init CAN interrupts
3) Erorrs handling
feature/baseCAN
Oleg 2 months ago
parent 4446eb970a
commit dfb90e3ee8

@ -365,29 +365,29 @@ InitECanaGpio(void)
// This will enable the pullups for the specified pins. // This will enable the pullups for the specified pins.
// Comment out other unwanted lines. // Comment out other unwanted lines.
// //
GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0; // Enable pull-up for GPIO30 (CANRXA) // GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0; // Enable pull-up for GPIO30 (CANRXA)
//GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up for GPIO18 (CANRXA) GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up for GPIO18 (CANRXA)
GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0; //Enable pull-up for GPIO31 (CANTXA) // GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0; //Enable pull-up for GPIO31 (CANTXA)
//GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; //Enable pull-up for GPIO19 (CANTXA) GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; //Enable pull-up for GPIO19 (CANTXA)
// //
// Set qualification for selected CAN pins to asynch only // Set qualification for selected CAN pins to asynch only
// Inputs are synchronized to SYSCLKOUT by default. // Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins. // This will select asynch (no qualification) for the selected pins.
// //
GpioCtrlRegs.GPAQSEL2.bit.GPIO30 = 3; // Asynch qual for GPIO30 (CANRXA) // GpioCtrlRegs.GPAQSEL2.bit.GPIO30 = 3; // Asynch qual for GPIO30 (CANRXA)
//GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch qual for GPIO18 (CANRXA) GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch qual for GPIO18 (CANRXA)
// //
// Configure eCAN-A pins using GPIO regs // Configure eCAN-A pins using GPIO regs
// This specifies which of the possible GPIO pins will be eCAN functional // This specifies which of the possible GPIO pins will be eCAN functional
// pins. // pins.
// //
GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // Configure GPIO30 for CANRXA // GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // Configure GPIO30 for CANRXA
//GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; // Configure GPIO18 for CANRXA GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; // Configure GPIO18 for CANRXA
GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // Configure GPIO31 for CANTXA // GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // Configure GPIO31 for CANTXA
//GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 3; // Configure GPIO19 for CANTXA GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 3; // Configure GPIO19 for CANTXA
EDIS; EDIS;
} }

@ -6,7 +6,6 @@
namespace canSpace { namespace canSpace {
enum CAN_VARIANT{ enum CAN_VARIANT{
NONE = 0,
CANA, CANA,
CANB CANB
}; };
@ -24,11 +23,7 @@ union MsgCtrlReg {
Uint16 all; Uint16 all;
struct MsgCtrlBits bit; struct MsgCtrlBits bit;
MsgCtrlReg(){ MsgCtrlReg(Uint16 configData = 0){
all = 0;
}
MsgCtrlReg(Uint16 configData){
all = configData; all = configData;
} }
}; };
@ -43,34 +38,53 @@ struct MsgID_Bits { // bits description
}; };
// Allow access to the bit fields or entire register // Allow access to the bit fields or entire register
union ConfigMsgID { union MsgID {
Uint32 all; Uint32 all;
struct MsgID_Bits bit; struct MsgID_Bits bit;
ConfigMsgID(bool isExtendedID, Uint16 standartID, Uint32 extendedID, bool isAAM, bool isAME) MsgID(Uint32 boxID = 0xAAA, bool isExtendedID = false, bool isAAM = false, bool isAME = false) {
{
if(!isExtendedID){ if(!isExtendedID){
bit.STDMSGID = boxID;
bit.EXTMSGID_H = 0; bit.EXTMSGID_H = 0;
bit.EXTMSGID_L = 0; bit.EXTMSGID_L = 0;
bit.STDMSGID = standartID;
} }
else{ all = extendedID; } else{ all = boxID; }
bit.IDE = isExtendedID;
bit.AAM = isAAM; bit.AAM = isAAM;
bit.AME = isAME; bit.AME = isAME;
bit.IDE = isExtendedID; }
MsgID(const MsgID& init) {
all = init.all;
} }
}; };
struct ConfigMBox{ /* struct ConfigMsgIDReg{
ConfigMsgID msgID; Uint32 boxID;
bool isExtendedID;
bool isAAM;
bool isAME;
ConfigMsgIDReg(Uint32 initBoxID = 0xAAA, bool initIsExtendedID = false, bool initIsAAM = false, bool initIsAME = false) :
boxID(initBoxID),
isExtendedID(initIsExtendedID),
isAAM(initIsAAM),
isAME(initIsAME)
{}
}; */
/* struct ConfigMBox{
MsgID msgID;
MsgCtrlReg msgCtrlReg; MsgCtrlReg msgCtrlReg;
ConfigMBox(bool isExtendedID, Uint16 standartID, Uint32 extendedID, bool isAAM, bool isAME, Uint16 ctrlReg) : ConfigMBox(const MsgID& configMsgID, const Uint16& configMsgCtrlReg) :
msgID(isExtendedID, standartID, extendedID, isAAM, isAME), // msgID(configMsgID.boxID, configMsgID.isExtendedID, configMsgID.isAAM, configMsgID.isAME),
msgCtrlReg(ctrlReg) msgID(configMsgID),
msgCtrlReg(configMsgCtrlReg)
{} {}
}; }; */
struct CANMessage { struct CANMessage {
union MsgCtrlReg msgctrl; union MsgCtrlReg msgctrl;
@ -78,28 +92,20 @@ struct CANMessage {
union CANMDH_REG mdh; union CANMDH_REG mdh;
CANMessage(){ CANMessage(){
msgctrl.all = 0;
mdl.all = 0; mdl.all = 0;
mdh.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{ class CAN{
public: public:
CAN(); CAN(CAN_VARIANT canVariant);
void initGpio(CAN_VARIANT canVarinat); void initGpio();
void config(CAN_VARIANT canVarinat, Uint16 baudrate); void config(Uint16 baudrate);
// void configRxMBoxes(); // void configTxMBox(Uint16 boxNumber, const ConfigMBox& configData);
void configRxMBoxes(Uint16 boxNumber, const ConfigMBox& configData); void configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg);
// void configTxMBoxes(); //TODO delete void configRxMBoxes(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg);
void configTxMBox(Uint16 boxNumber, const ConfigMBox& configData);
void transmitMsg(Uint16 boxNumber, const CANMessage& message); void transmitMsg(Uint16 boxNumber, const CANMessage& message);
bool receiveMsg(Uint16 boxNumber, CANMessage& rxMessage); bool receiveMsg(Uint16 boxNumber, CANMessage& rxMessage);
@ -111,6 +117,7 @@ private:
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;
}; };

@ -4,24 +4,24 @@
namespace canSpace { namespace canSpace {
CAN::CAN(){ CAN::CAN(CAN_VARIANT canVariant) :
// TODO Make it impossible to create 2 CANA/CANB objects. Give CANA/CANB as a constructor parameter canPort(canVariant)
} {}
void CAN::initGpio(CAN_VARIANT canVarinat){ void CAN::initGpio(){
if(canVarinat == CANA) InitECanaGpio(); if(canPort == CANA) InitECanaGpio();
else if (canVarinat == CANB) InitECanbGpio(); else if (canPort == CANB) InitECanbGpio();
} }
void CAN::config(CAN_VARIANT canVarinat, Uint16 baudrate){ void CAN::config(Uint16 baudrate){
if (canVarinat == CANA){ if (canPort == CANA){
EALLOW; EALLOW;
SysCtrlRegs.PCLKCR0.bit.ECANAENCLK = 1; SysCtrlRegs.PCLKCR0.bit.ECANAENCLK = 1;
EDIS; EDIS;
p_CanRegs_ = &ECanaRegs; p_CanRegs_ = &ECanaRegs;
p_CanMBoxes_ = &ECanaMboxes; p_CanMBoxes_ = &ECanaMboxes;
} }
else if (canVarinat == CANB){ else if (canPort == CANB){
EALLOW; EALLOW;
SysCtrlRegs.PCLKCR0.bit.ECANBENCLK = 1; SysCtrlRegs.PCLKCR0.bit.ECANBENCLK = 1;
EDIS; EDIS;
@ -172,33 +172,15 @@ void CAN::config(CAN_VARIANT canVarinat, Uint16 baudrate){
// Debug feature // Debug feature
// Configure the eCAN for self test mode. // Configure the eCAN for self test mode.
// //
CanShadow_.CANMC.all = p_CanRegs_->CANMC.all; // CanShadow_.CANMC.all = p_CanRegs_->CANMC.all;
CanShadow_.CANMC.bit.STM = 1; // Configure CAN for self-test mode // CanShadow_.CANMC.bit.STM = 1; // Configure CAN for self-test mode
p_CanRegs_->CANMC.all = CanShadow_.CANMC.all; // p_CanRegs_->CANMC.all = CanShadow_.CANMC.all;
EDIS; EDIS;
} }
// void CAN::configTxMBoxes(){ void CAN::configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg){
// // Write to the MSGID field
// p_CanMBoxes_->MBOX1.MSGID.all = 0x0; // IDE-0, AME-0, AAM-0
// p_CanMBoxes_->MBOX1.MSGID.bit.STDMSGID = 0xAAA;
// p_CanMBoxes_->MBOX1.MSGCTRL.bit.DLC = 8; // Data length in bytes (0-8)
// p_CanMBoxes_->MBOX1.MSGCTRL.bit.RTR = 0; // Remote Transmission Request
// CanShadow_.CANMD.all = p_CanRegs_->CANMD.all;
// CanShadow_.CANMD.bit.MD1 = 0; // Mailbox direction - transmit
// p_CanRegs_->CANMD.all = CanShadow_.CANMD.all;
// CanShadow_.CANME.all = p_CanRegs_->CANME.all;
// CanShadow_.CANME.bit.ME1 = 1;
// p_CanRegs_->CANME.all = CanShadow_.CANME.all;
// } // TODO delete
void CAN::configTxMBox(Uint16 boxNumber, const ConfigMBox& configData){
volatile MBOX* p_MailBox(NULL); volatile MBOX* p_MailBox(NULL);
p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber; p_MailBox = &(p_CanMBoxes_->MBOX0) + boxNumber;
@ -219,7 +201,7 @@ void CAN::configTxMBox(Uint16 boxNumber, const ConfigMBox& configData){
p_CanRegs_->CANME.all = CanShadow_.CANME.all; p_CanRegs_->CANME.all = CanShadow_.CANME.all;
// Write to the MSGID field // Write to the MSGID field
p_MailBox->MSGID.all = configData.msgID.all; p_MailBox->MSGID.all = configID.all;
// Mailbox direction - transmit // Mailbox direction - transmit
CanShadow_.CANMD.all = p_CanRegs_->CANMD.all; CanShadow_.CANMD.all = p_CanRegs_->CANMD.all;
@ -227,7 +209,7 @@ void CAN::configTxMBox(Uint16 boxNumber, const ConfigMBox& configData){
p_CanRegs_->CANMD.all = CanShadow_.CANMD.all; p_CanRegs_->CANMD.all = CanShadow_.CANMD.all;
// Write to RTR and TPL field in control reg // Write to RTR and TPL field in control reg
p_MailBox->MSGCTRL.bit.RTR = configData.msgCtrlReg.bit.RTR; 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 = configData.msgCtrlReg.bit.TPL; // enable if you need to set msg priority lvl
// Mailbox enable // Mailbox enable
@ -236,40 +218,8 @@ void CAN::configTxMBox(Uint16 boxNumber, const ConfigMBox& configData){
p_CanRegs_->CANME.all = CanShadow_.CANME.all; p_CanRegs_->CANME.all = CanShadow_.CANME.all;
} }
// void CAN::configRxMBoxes(){ // TODO make this method with parameters
// // Write to the MSGID field
// p_CanMBoxes_->MBOX25.MSGID.all = 0x0;
// p_CanMBoxes_->MBOX25.MSGID.bit.STDMSGID = 0xAAA;
// // Write to DLC field in Master Control reg
// p_CanMBoxes_->MBOX25.MSGCTRL.bit.DLC = 8;
// p_CanMBoxes_->MBOX25.MSGCTRL.bit.RTR = 0;
// //
// // Configure Mailbox under test as a Receive mailbox
// //
// CanShadow_.CANMD.all = p_CanRegs_->CANMD.all;
// CanShadow_.CANMD.bit.MD25 = 1;
// p_CanRegs_->CANMD.all = CanShadow_.CANMD.all;
// // Overwrite protection
// // CanShadow_.CANOPC.all = p_CanRegs_->CANOPC.all;
// // CanShadow_.CANOPC.bit.OPC1 = 1; // 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.bit.ME25 = 1;
// p_CanRegs_->CANME.all = CanShadow_.CANME.all;
// // Write to the mailbox RAM field
// p_CanMBoxes_->MBOX25.MDL.all = 0x55555555;
// p_CanMBoxes_->MBOX25.MDH.all = 0x55555555;
// }
void CAN::configRxMBoxes(Uint16 boxNumber, const ConfigMBox& configData){ void CAN::configRxMBoxes(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;
@ -279,11 +229,11 @@ void CAN::configRxMBoxes(Uint16 boxNumber, const ConfigMBox& configData){
// Write to the MSGID field // Write to the MSGID field
p_MailBox->MSGID.all = 0x0; p_MailBox->MSGID.all = 0x0;
p_MailBox->MSGID.all = configData.msgID.all; p_MailBox->MSGID.all = configID.all;
// Write to DLC and RTR field in control reg // Write to DLC and RTR field in control reg
p_MailBox->MSGCTRL.bit.DLC = configData.msgCtrlReg.bit.DLC; p_MailBox->MSGCTRL.bit.DLC = configCtrlReg.bit.DLC;
p_MailBox->MSGCTRL.bit.RTR = configData.msgCtrlReg.bit.RTR; p_MailBox->MSGCTRL.bit.RTR = configCtrlReg.bit.RTR;
// Configure Mailbox under test as a Receive mailbox // Configure Mailbox under test as a Receive mailbox
CanShadow_.CANMD.all = p_CanRegs_->CANMD.all; CanShadow_.CANMD.all = p_CanRegs_->CANMD.all;

@ -14,7 +14,7 @@ void idle_loop(void);
interrupt void cpu_timer0_isr(void); interrupt void cpu_timer0_isr(void);
//interrupt void adc_isr(void); //interrupt void adc_isr(void);
canSpace::CAN canTest; canSpace::CAN canTest(canSpace::CANB);
Uint16 msgsSent = 0; Uint16 msgsSent = 0;
Uint16 infCounter = 0; Uint16 infCounter = 0;
volatile Uint16 testCounter = 0; volatile Uint16 testCounter = 0;
@ -78,11 +78,10 @@ void main()
// core.cpu_timers.start(); // core.cpu_timers.start();
// //
canTest.initGpio(canSpace::CANB); canTest.initGpio();
canTest.config(canSpace::CANB, 100); canTest.config(100);
// canTest.configTxMBoxes(); canTest.configTxMBox(1, canSpace::MsgID(0xAAA), canSpace::MsgCtrlReg(0x8));
canTest.configTxMBox(1, canSpace::ConfigMBox(false, 0xAAA, 0x0, false, false, 0xF)); canTest.configRxMBoxes(25, canSpace::MsgID(0xAAA), canSpace::MsgCtrlReg(0x8));
canTest.configRxMBoxes(25, canSpace::ConfigMBox(false, 0xAAA, 0x0, false, false, 0xF));
// InitECanGpio(); // InitECanGpio();
// InitECan(); // InitECan();

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configurations XML_version="1.2" id="configurations_0">
<configuration XML_version="1.2" id="Texas Instruments XDS100v3 USB Debug Probe_0">
<instance XML_version="1.2" desc="Texas Instruments XDS100v3 USB Debug Probe_0" href="connections/TIXDS100v3_Dot7_Connection.xml" id="Texas Instruments XDS100v3 USB Debug Probe_0" xml="TIXDS100v3_Dot7_Connection.xml" xmlpath="connections"/>
<connection XML_version="1.2" id="Texas Instruments XDS100v3 USB Debug Probe_0">
<instance XML_version="1.2" href="drivers/tixds100v2c28x.xml" id="drivers" xml="tixds100v2c28x.xml" xmlpath="drivers"/>
<property Type="choicelist" Value="1" id="Emulator Selection">
<choice Name="Select by serial number" value="0">
<property Type="stringfield" Value="FT57N1L8" id="-- Enter the serial number"/>
</choice>
</property>
<platform XML_version="1.2" id="platform_0">
<instance XML_version="1.2" desc="TMS320F28335_0" href="devices/f28335.xml" id="TMS320F28335_0" xml="f28335.xml" xmlpath="devices"/>
</platform>
</connection>
</configuration>
</configurations>

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configurations XML_version="1.2" id="configurations_0">
<configuration XML_version="1.2" id="Texas Instruments XDS100v3 USB Debug Probe_0">
<instance XML_version="1.2" desc="Texas Instruments XDS100v3 USB Debug Probe_0" href="connections/TIXDS100v3_Dot7_Connection.xml" id="Texas Instruments XDS100v3 USB Debug Probe_0" xml="TIXDS100v3_Dot7_Connection.xml" xmlpath="connections"/>
<connection XML_version="1.2" id="Texas Instruments XDS100v3 USB Debug Probe_0">
<instance XML_version="1.2" href="drivers/tixds100v2c28x.xml" id="drivers" xml="tixds100v2c28x.xml" xmlpath="drivers"/>
<property Type="choicelist" Value="1" id="Emulator Selection">
<choice Name="Select by serial number" value="0">
<property Type="stringfield" Value="TI7EZCHI" id="-- Enter the serial number"/>
</choice>
</property>
<platform XML_version="1.2" id="platform_0">
<instance XML_version="1.2" desc="TMS320F28335_0" href="devices/f28335.xml" id="TMS320F28335_0" xml="f28335.xml" xmlpath="devices"/>
</platform>
</connection>
</configuration>
</configurations>
Loading…
Cancel
Save