Change modbus configuration logic

COMM board asks CPU for modbus config now if it was not sent
earlier (for example after flashing COMM board)
feature/Modbus
Oleg 2 weeks ago
parent b0b42819a8
commit 6a6ca4cd3e

@ -34,7 +34,11 @@ void Periphery::config(){
_canb.configRxMBox(canSpace::DIGITAL_OUTPUT_MBOX, canSpace::MsgID(0x31), canSpace::MsgCtrlReg(0x2)); // Send DO _canb.configRxMBox(canSpace::DIGITAL_OUTPUT_MBOX, canSpace::MsgID(0x31), canSpace::MsgCtrlReg(0x2)); // Send DO
// Remote frame MBOX // Remote frame MBOX
_canb.configTxMBox(canSpace::COMM_VERSION_MBOX, canSpace::MsgID(0x1, false, true), canSpace::MsgCtrlReg(0)); // _canb.configRxMBox(canSpace::MODBUS_SETTINGS_MBOX, canSpace::MsgID(0x0), canSpace::MsgCtrlReg(0x10));
_canb.configTxMBox(canSpace::COMM_VERSION_MBOX, canSpace::MsgID(0x1, false, true), canSpace::MsgCtrlReg(0x4));
_canb.enableTimeOutControl(canSpace::MODBUS_SETTINGS_MBOX);
_canb.setTimeOutValue(canSpace::MODBUS_SETTINGS_MBOX, 1000);
// Interrupts // Interrupts
_canb.configSystemIsr(canSpace::I0EN_ENABLE | _canb.configSystemIsr(canSpace::I0EN_ENABLE |
@ -84,23 +88,7 @@ void Periphery::updateVersionFPGA(){
} }
void Periphery::processDigitalInput(){ void Periphery::initModbusTable(){
Uint16 data = 0;
_digitalIO.readDigitalIO(data);
_canb.transmitMsg(canSpace::DIGITAL_INPUT_MBOX, (data));
}
void Periphery::processDigitalOutput(){
if(_canb.isNewMessage(canSpace::DIGITAL_OUTPUT_MBOX)){
_canb.receiveMsg(canSpace::DIGITAL_OUTPUT_MBOX, _message);
Uint16 data = _message.mdl.word.LOW_WORD;
_digitalIO.writeDigitalIO(data);
}
}
void Periphery::init_modbus_table(){
modbusRTU.setInputRegsAddr(400); modbusRTU.setInputRegsAddr(400);
modbusRTU.setOutputRegsAddr(400); modbusRTU.setOutputRegsAddr(400);
@ -118,13 +106,8 @@ void Periphery::init_modbus_table(){
} }
bool Periphery::isModbusInit() const{
return _modbusInitFlag;
}
void Periphery::receiveModbusParameters(){ void Periphery::receiveModbusParameters(){
if (!_modbusInitFlag && (_canb.isNewMessage(canSpace::MODBUS_SETTINGS_MBOX))) { // TODO check for init is incorect here maybe if (_canb.isNewMessage(canSpace::MODBUS_SETTINGS_MBOX)) {
_canb.receiveMsg(canSpace::MODBUS_SETTINGS_MBOX, _message); _canb.receiveMsg(canSpace::MODBUS_SETTINGS_MBOX, _message);
MODBUSRTU::modbusConfiguration.node_id = _message.mdl.byte.BYTE0; MODBUSRTU::modbusConfiguration.node_id = _message.mdl.byte.BYTE0;
@ -134,10 +117,62 @@ void Periphery::receiveModbusParameters(){
MODBUSRTU::modbusConfiguration.config.stopbits = static_cast<DSP28335::SCIStopBits>(_message.mdh.byte.BYTE5); MODBUSRTU::modbusConfiguration.config.stopbits = static_cast<DSP28335::SCIStopBits>(_message.mdh.byte.BYTE5);
modbusRTU.configure(MODBUSRTU::modbusConfiguration); modbusRTU.configure(MODBUSRTU::modbusConfiguration);
_modbusRegCounter = 0;
}
}
void Periphery::getModbusConfiguration(){
_canb.resetTimeStampCounter();
_canb.clearTimeOutFlag(canSpace::MODBUS_SETTINGS_MBOX);
bool requestIsSent = false;
while(!_canb.isNewMessage(canSpace::MODBUS_SETTINGS_MBOX)){
if(_canb.isTimeOut(canSpace::MODBUS_SETTINGS_MBOX)){
if (!requestIsSent) {
_canb.resetTimeStampCounter();
_canb.clearTimeOutFlag(canSpace::MODBUS_SETTINGS_MBOX);
_message.mdl.word.LOW_WORD = _softVersion.DSP;
_message.mdl.word.HI_WORD = _softVersion.CPLD;
_canb.transmitMsg(canSpace::COMM_VERSION_MBOX, _message);
_modbusInitFlag = true; // TODO modbus init function must be here requestIsSent = true;
}
else{
_canb.clearTimeOutFlag(canSpace::MODBUS_SETTINGS_MBOX);
_canb.disableTimeOutControl(canSpace::MODBUS_SETTINGS_MBOX);
_error = true;
return;
}
}
}
_canb.receiveMsg(canSpace::MODBUS_SETTINGS_MBOX, _message);
MODBUSRTU::modbusConfiguration.node_id = _message.mdl.byte.BYTE0;
MODBUSRTU::modbusConfiguration.config.lenght = static_cast<DSP28335::SCICharLenght>(_message.mdl.byte.BYTE1);
MODBUSRTU::modbusConfiguration.config.baudrate = static_cast<DSP28335::SCIBaudRate>(_message.mdl.word.LOW_WORD);
MODBUSRTU::modbusConfiguration.config.parity = static_cast<DSP28335::SCIParity>(_message.mdh.byte.BYTE4);
MODBUSRTU::modbusConfiguration.config.stopbits = static_cast<DSP28335::SCIStopBits>(_message.mdh.byte.BYTE5);
modbusRTU.configure(MODBUSRTU::modbusConfiguration);
_modbusRegCounter = 0; _modbusRegCounter = 0;
} }
void Periphery::processDigitalInput(){
Uint16 data = 0;
_digitalIO.readDigitalIO(data);
_canb.transmitMsg(canSpace::DIGITAL_INPUT_MBOX, (data));
}
void Periphery::processDigitalOutput(){
if(_canb.isNewMessage(canSpace::DIGITAL_OUTPUT_MBOX)){
_canb.receiveMsg(canSpace::DIGITAL_OUTPUT_MBOX, _message);
Uint16 data = _message.mdl.word.LOW_WORD;
_digitalIO.writeDigitalIO(data);
}
} }

@ -1,6 +1,5 @@
#pragma once #pragma once
// #include <cstdint>
#include <stdint.h> #include <stdint.h>
#include "DSP28x_Project.h" #include "DSP28x_Project.h"
@ -28,12 +27,13 @@ public:
Uint16 getVersionFPGA(); Uint16 getVersionFPGA();
void updateVersionFPGA(); void updateVersionFPGA();
void receiveModbusParameters();
void getModbusConfiguration();
void initModbusTable(); // TODO Must be outside periphery!
void processDigitalInput(); void processDigitalInput();
void processDigitalOutput(); void processDigitalOutput();
void init_modbus_table();
bool isModbusInit() const;
void receiveModbusParameters();
void sendModbusDataToCPU(); void sendModbusDataToCPU();
void receiveCpuModbusData(); void receiveCpuModbusData();
@ -47,6 +47,7 @@ private:
SoftwareVersion _softVersion; SoftwareVersion _softVersion;
canSpace::CANMessage _message; canSpace::CANMessage _message;
bool _modbusInitFlag; bool _modbusInitFlag;
bool _error;
uint16_t _modbusRegCounter; uint16_t _modbusRegCounter;
float test_hmi_float_reg_400_test; float test_hmi_float_reg_400_test;

@ -253,7 +253,7 @@ bool CAN::isNewMessage(Uint16 boxNumber){
void CAN::resetTimeStampCounter(){ void CAN::resetTimeStampCounter(){
EALLOW; EALLOW;
ECanbRegs.CANTSC = 0; p_CanRegs_->CANTSC = 0;
EDIS; EDIS;
} }

@ -77,13 +77,14 @@ void main()
PieCtrlRegs.PIEIER9.bit.INTx8 = 1; PieCtrlRegs.PIEIER9.bit.INTx8 = 1;
periphery.config(); periphery.config();
periphery.init_modbus_table(); periphery.updateVersionFPGA();
periphery.getModbusConfiguration();
periphery.initModbusTable();
// Enable global Interrupts and higher priority real-time debug events: // Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM ERTM; // Enable Global realtime interrupt DBGM
periphery.updateVersionFPGA();
CpuTimer0.RegsAddr->TCR.bit.TSS = 0; CpuTimer0.RegsAddr->TCR.bit.TSS = 0;
CpuTimer1.RegsAddr->TCR.bit.TSS = 0; CpuTimer1.RegsAddr->TCR.bit.TSS = 0;
@ -100,17 +101,12 @@ void idle_loop()
{ {
infCounter++; infCounter++;
if (!periphery.isModbusInit()){
periphery.receiveModbusParameters(); periphery.receiveModbusParameters();
// modbus_port.configure(modbus_port_configuration);
}
// //
// MODBUS RTU HMI Service // MODBUS RTU HMI Service
// //
if (periphery.isModbusInit()){
periphery.modbusRTU.execute(); periphery.modbusRTU.execute();
}
periphery.receiveCpuModbusData(); periphery.receiveCpuModbusData();

Loading…
Cancel
Save