@ -1,9 +1,3 @@
# include "DSP2833x_Device.h"
# include "DSP28x_Project.h"
# include "Protocol/CAN.h"
# include "Protocol/CAN_data.h"
# include "Protocol/DigitalIO.h"
# include "Protocol/MemoryMap.h"
# include "Periphery.h"
Periphery : : Periphery ( ) :
@ -11,16 +5,20 @@ Periphery::Periphery() :
_digitalIO ( ) ,
_zone6_ptr ( reinterpret_cast < Uint16 * > ( 0x100000 ) ) ,
_scib ( ScibRegs ) ,
_modbusSetup ( ) ,
_modbusConfiguration ( ) ,
_crc ( ) ,
_intervalMeasure ( CpuTimer2 ) ,
_modbusPort ( _scib , _intervalMeasure , _crc ) ,
_ASUTP ( _crc ) ,
// _modbusSetup(),
// _modbusConfiguration(),
// _crc(),
// _intervalMeasure(CpuTimer2),
// _modbusPort(_scib, _intervalMeasure, _crc),
// _ASUTP(_crc),
_modbusRTU ( CpuTimer2 , _scib ) ,
_modbusInitFlag ( false )
{
_softVersion . DSP = 202 ;
_softVersion . CPLD = 0 ;
elementCounter = 0 ;
test = 0 ;
}
@ -32,8 +30,8 @@ void Periphery::config(){
// Data Frame MBOX
_canb . configRxMBox ( canSpace : : MODBUS_SETTINGS_MBOX , canSpace : : MsgID ( 0x0 ) , canSpace : : MsgCtrlReg ( 0x6 ) ) ; // Modbus settings
// _canb.configTxMBox(canSpace::MODBUS_DATA_COMM_TO_CPU_MBOX, canSpace::MsgID(0x29), canSpace::MsgCtrlReg(0x26)); // Send Modbus data to CPU
// _canb.configRxMBox(canSpace::MODBUS_DATA_CPU_TO_COMM_MBOX, canSpace::MsgID(0x28), canSpace::MsgCtrlReg(0x 6 )); // Receive Modbus data from CPU
_canb . configTxMBox ( canSpace : : MODBUS_DATA_COMM_TO_CPU_MBOX , canSpace : : MsgID ( 0x29 ) , canSpace : : MsgCtrlReg ( 0x28 ) ) ; // Send Modbus data to CPU
// _canb.configRxMBox(canSpace::MODBUS_DATA_CPU_TO_COMM_MBOX, canSpace::MsgID(0x28), canSpace::MsgCtrlReg(0x 8 )); // Receive Modbus data from CPU
_canb . configTxMBox ( canSpace : : DIGITAL_INPUT_MBOX , canSpace : : MsgID ( 0x30 ) , canSpace : : MsgCtrlReg ( 0x2 ) ) ; // Receive DI
_canb . configRxMBox ( canSpace : : DIGITAL_OUTPUT_MBOX , canSpace : : MsgID ( 0x31 ) , canSpace : : MsgCtrlReg ( 0x2 ) ) ; // Send DO
@ -66,14 +64,14 @@ void Periphery::config(){
//------------------------------------------Init Modbus----------------------------------------------------------
_modbusSetup . gpio_re_de_setup = & DSP28335 : : GPIO : : gpio_scib_re_de_setup ;
_modbusSetup . gpio_driver_enable = & DSP28335 : : GPIO : : gpio_scib_re_de_set ;
_modbusSetup . gpio_receiver_enable = & DSP28335 : : GPIO : : gpio_scib_re_de_clear ;
// _modbusSetup.gpio_re_de_setup = &DSP28335::GPIO::gpio_scib_re_de_setup;
// _modbusSetup.gpio_driver_enable = &DSP28335::GPIO::gpio_scib_re_de_set;
// _modbusSetup.gpio_receiver_enable = &DSP28335::GPIO::gpio_scib_re_de_clear;
_intervalMeasure . reset ( ) ;
_intervalMeasure . set_magic ( 19 ) ;
// _intervalMeasure.reset();
// _intervalMeasure.set_magic(19);
_modbusPort . setup ( _modbusSetup ) ;
// _modbusPort.setup(_modbusSetup);
// modbus_port_configuration.node_id = 0x5;
// modbus_port_configuration.config.baudrate = DSP28335::BR9600;
@ -86,9 +84,13 @@ void Periphery::config(){
// clear_array((uint16_t *)hmi.rxStack, sizeof(hmi.rxStack)/sizeof(uint16_t));
// clear_array((uint16_t *)hmi.txStack, sizeof(hmi.txStack)/sizeof(uint16_t));
_modbusPort . setRXBuffer ( ( uint16_t * ) _ASUTP . rxStack , & _ASUTP . rxLength ) ;
_modbusPort . setTXBuffer ( ( uint16_t * ) _ASUTP . txStack , & _ASUTP . txLength ) ;
// _modbusPort.setRXBuffer((uint16_t*)_ASUTP.rxStack, &_ASUTP.rxLength);
// _modbusPort.setTXBuffer((uint16_t*)_ASUTP.txStack, &_ASUTP.txLength);
MODBUSRTU : : modbusSetup . gpio_re_de_setup = & DSP28335 : : GPIO : : gpio_scib_re_de_setup ;
MODBUSRTU : : modbusSetup . gpio_driver_enable = & DSP28335 : : GPIO : : gpio_scib_re_de_set ;
MODBUSRTU : : modbusSetup . gpio_receiver_enable = & DSP28335 : : GPIO : : gpio_scib_re_de_clear ;
_modbusRTU . setup ( MODBUSRTU : : modbusSetup ) ;
}
@ -132,39 +134,72 @@ void Periphery::receiveModbusParameters(){
if ( ! _modbusInitFlag & & ( _canb . isNewMessage ( canSpace : : MODBUS_SETTINGS_MBOX ) ) ) { // TODO check for init is incorect here maybe
_canb . receiveMsg ( canSpace : : MODBUS_SETTINGS_MBOX , _message ) ;
_modbusConfiguration . node_id = _message . mdl . byte . BYTE0 ;
_modbusConfiguration . config . lenght = static_cast < DSP28335 : : SCICharLenght > ( _message . mdl . byte . BYTE1 ) ;
_modbusConfiguration . config . baudrate = static_cast < DSP28335 : : SCIBaudRate > ( _message . mdl . word . LOW_WORD ) ;
_modbusConfiguration . config . parity = static_cast < DSP28335 : : SCIParity > ( _message . mdh . byte . BYTE4 ) ;
_modbusConfiguration . config . stopbits = static_cast < DSP28335 : : SCIStopBits > ( _message . mdh . byte . BYTE5 ) ;
// _modbusConfiguration.node_id = _message.mdl.byte.BYTE0;
// _modbusConfiguration.config.lenght = static_cast<DSP28335::SCICharLenght>(_message.mdl.byte.BYTE1);
// _modbusConfiguration.config.baudrate = static_cast<DSP28335::SCIBaudRate>(_message.mdl.word.LOW_WORD);
// _modbusConfiguration.config.parity = static_cast<DSP28335::SCIParity>(_message.mdh.byte.BYTE4);
// _modbusConfiguration.config.stopbits = static_cast<DSP28335::SCIStopBits>(_message.mdh.byte.BYTE5);
// _modbusPort.configure(_modbusConfiguration);
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 ) ;
_modbusPort . configure ( _modbusConfiguration ) ;
_modbus RTU. configure ( MODBUSRTU : : modbusConfiguration) ;
_modbusInitFlag = true ; // TODO modbus init function must be here
}
}
void Periphery : : test_init_hmi_buffers ( )
{
//
// hmi writeable registers
_ASUTP . inputRegisters . set ( WEINBUS : : INPUTREGISTERS , 400 ) ;
_ASUTP . inputRegisters . add ( 0 , & test_hmi_float_reg_400 . f ) ;
_ASUTP . inputRegisters . add ( 1 , & ( float & ) test_hmi_float_reg_401 . f ) ;
_ASUTP . inputRegisters . add ( 2 , & ( float & ) test_hmi_float_reg_402 . f ) ;
_ASUTP . inputRegisters . add ( 3 , & ( float & ) test_hmi_float_reg_403 . f ) ;
_ASUTP . inputRegisters . add ( 4 , & ( float & ) test_hmi_float_reg_404 . f ) ;
//
// hmi readable registers
_ASUTP . outputRegisters . set ( WEINBUS : : OUTPUTREGISTERS , 400 ) ;
_ASUTP . outputRegisters . add ( 0 , & ( float & ) test_hmi_float_reg_400 . f ) ;
_ASUTP . outputRegisters . add ( 1 , & ( float & ) test_hmi_float_reg_401 . f ) ;
_ASUTP . outputRegisters . add ( 2 , & ( float & ) test_hmi_float_reg_402 . f ) ;
_ASUTP . outputRegisters . add ( 3 , & ( float & ) test_hmi_float_reg_403 . f ) ;
_ASUTP . outputRegisters . add ( 4 , & ( float & ) test_hmi_float_reg_404 . f ) ;
//
} //
void Periphery : : processExternalModbus ( ) {
if ( _modbusRTU . _dataHandler . inputRegisters . address_range ( elementCounter + _modbusRTU . inputRegStartAddr ) ) {
_modbusRTU . _dataHandler . inputRegisters . get_register_cursor ( elementCounter ) . read ( _message . mdl . all ) ;
elementCounter + + ;
}
else {
elementCounter = 0 ;
_modbusRTU . _dataHandler . inputRegisters . get_register_cursor ( elementCounter ) . read ( _message . mdl . all ) ;
elementCounter + + ;
}
if ( _modbusRTU . _dataHandler . inputRegisters . address_range ( elementCounter + _modbusRTU . inputRegStartAddr ) ) {
_modbusRTU . _dataHandler . inputRegisters . get_register_cursor ( elementCounter ) . read ( _message . mdh . all ) ;
elementCounter + + ;
}
else {
elementCounter = 0 ;
_modbusRTU . _dataHandler . inputRegisters . get_register_cursor ( elementCounter ) . read ( _message . mdh . all ) ;
elementCounter + + ;
}
_canb . transmitMsg ( canSpace : : MODBUS_DATA_COMM_TO_CPU_MBOX , _message ) ;
}
// void Periphery::test_init_hmi_buffers()
// {
// //
// // hmi writeable registers
// _ASUTP.inputRegisters.set(WEINBUS::INPUTREGISTERS, 400);
// _ASUTP.inputRegisters.add( 0, &test_hmi_float_reg_400.f);
// _ASUTP.inputRegisters.add( 1, &(float&)test_hmi_float_reg_401.f);
// _ASUTP.inputRegisters.add( 2, &(float&)test_hmi_float_reg_402.f);
// _ASUTP.inputRegisters.add( 3, &(float&)test_hmi_float_reg_403.f);
// _ASUTP.inputRegisters.add( 4, &(float&)test_hmi_float_reg_404.f);
// //
// // hmi readable registers
// _ASUTP.outputRegisters.set(WEINBUS::OUTPUTREGISTERS, 400);
// _ASUTP.outputRegisters.add( 0 , &(float&)test_hmi_float_reg_400.f);
// _ASUTP.outputRegisters.add( 1, &(float&)test_hmi_float_reg_401.f);
// _ASUTP.outputRegisters.add( 2, &(float&)test_hmi_float_reg_402.f);
// _ASUTP.outputRegisters.add( 3, &(float&)test_hmi_float_reg_403.f);
// _ASUTP.outputRegisters.add( 4, &(float&)test_hmi_float_reg_404.f);
// //
// }//
// void Periphery::addInputRegFloat(uint16_t addr, float& param){
// // if(_ASUTP.inputRegisters.address_range(addr)){