diff --git a/components/free_rtos/ethernet_industry/eth_ecat.cpp b/components/free_rtos/ethernet_industry/eth_ecat.cpp index 603c56f..19af952 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat.cpp +++ b/components/free_rtos/ethernet_industry/eth_ecat.cpp @@ -50,18 +50,18 @@ bool EthEcat::set_slaves_to_default() { /* reset CRC counters */ std::array c_data_out; - c_data_out.fill(0x00); datagram::EcatDatagram> c{ {{broadcast, ECT_REG_RXERR}}, expected_wkc, c_data_out }; + c_data_out.fill(0x00); /* reset FMMU's */ std::array d_data_out; - d_data_out.fill(0x00); datagram::EcatDatagram> d{ {{broadcast, ECT_REG_FMMU0}}, expected_wkc, d_data_out }; + d_data_out.fill(0x00); /* reset SyncM */ std::array e_data_out; - e_data_out.fill(0x00); datagram::EcatDatagram> e{ {{broadcast, ECT_REG_SM0}}, expected_wkc, e_data_out }; + e_data_out.fill(0x00); /* reset activation register */ uint8_t f_data_out{0x00}; @@ -69,8 +69,8 @@ bool EthEcat::set_slaves_to_default() { /* reset system time+ofs */ std::array g_data_out; - g_data_out.fill(0x00); datagram::EcatDatagram> g{ {{broadcast, ECT_REG_DCSYSTIME}}, expected_wkc, g_data_out }; + g_data_out.fill(0x00); /* DC speedstart */ uint16_t h_data_out{0x1000}; @@ -214,6 +214,25 @@ bool EthEcat::get_addresses_of_slaves() { return status; } +bool EthEcat::connection_test() { + const datagram::TEcatWkc expected_wkc = 0; + bool status; + + std::array test_data_out; + datagram::EcatDatagram> datagram{ {{0x0000, 0x0000}}, expected_wkc, test_data_out }; + test_data_out.fill(0x00); + + while(1) { + status = telegram_.transfer(datagram); + + if(status != true) { + break; + } + } + + return status; +} + bool EthEcat::config_init(uint16_t address_base) { uint16_t number_of_slaves; bool status; @@ -247,7 +266,15 @@ bool EthEcat::config_init(uint16_t address_base) { if(status != true) { return status; } +/* + DebugP_log((char*)"Starting connection test...\r\n"); + status = connection_test(); + + if(status != true) { + return status; + } +*/ return status; } @@ -295,8 +322,6 @@ bool EthEcat::safeop_to_op() { uint16_t zero{0x00000000}; bool status; - ecat_timer_.Start(); - process_sem_.post(); if(init_sem_.pend(process_timeout_ticks_) != SystemP_SUCCESS) { DebugP_log((char*)"Process task timeout !\r\n"); diff --git a/components/free_rtos/ethernet_industry/eth_ecat.hpp b/components/free_rtos/ethernet_industry/eth_ecat.hpp index 154bbde..cd92ccd 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat.hpp +++ b/components/free_rtos/ethernet_industry/eth_ecat.hpp @@ -188,6 +188,7 @@ public: uint16_t slaves_detecting(); bool set_addresses_of_slaves(uint16_t number_of_slaves, uint16_t address_base); bool get_addresses_of_slaves(); + bool connection_test(); bool config_init(uint16_t address_base); diff --git a/components/free_rtos/ethernet_industry/eth_ecat_command.hpp b/components/free_rtos/ethernet_industry/eth_ecat_command.hpp index 9afd11f..cd4c89b 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat_command.hpp +++ b/components/free_rtos/ethernet_industry/eth_ecat_command.hpp @@ -104,14 +104,15 @@ class EcatCommand : public EcatCommandBase { static_assert(std::is_base_of::value == true, "DirT should be derived from command::DirBase"); public: - EcatCommand(typename TypeT::TAddress&& address) + using TType = TypeT; + using TDir = DirT; + using TAddress = typename TypeT::TAddress; + + EcatCommand(TAddress&& address) : address_{address} { } EcatCommand() { } - using TType = TypeT; - using TDir = DirT; - static constexpr uint8_t get_cmd() { std::array, 4> commands = {{ {{EC_CMD_APRD, EC_CMD_APWR, EC_CMD_APRW, EC_CMD_ARMW}}, @@ -137,7 +138,7 @@ public: static constexpr bool get_skip_unpack() { std::array, 4> commands = {{ {{false, true, false, false}}, - {{false, false, false, true}}, + {{false, false, false, true}}, {{false, true, false, false}}, {{false, true, false, true}} }}; @@ -155,7 +156,7 @@ public: } private: - typename TypeT::TAddress address_; + TAddress address_; }; /* diff --git a/components/free_rtos/ethernet_industry/eth_ecat_datagram.hpp b/components/free_rtos/ethernet_industry/eth_ecat_datagram.hpp index 9565d5d..8c12789 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat_datagram.hpp +++ b/components/free_rtos/ethernet_industry/eth_ecat_datagram.hpp @@ -128,7 +128,7 @@ public: ~EcatDatagram() { } virtual uint8_t* pack(uint8_t *raw, uint8_t idx) override { - if(as_expected() == true) { + if((as_expected() == true) && (command_.get_cmd() != EC_CMD_NOP)) { return raw; } @@ -136,7 +136,7 @@ public: } virtual uint8_t* unpack(uint8_t *raw, uint8_t idx) override { - if(as_expected() == true) { + if((as_expected() == true) && (command_.get_cmd() != EC_CMD_NOP)) { return raw; } diff --git a/components/free_rtos/ethernet_industry/eth_ecat_telegram.hpp b/components/free_rtos/ethernet_industry/eth_ecat_telegram.hpp index 03a4b6b..1d43a9b 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat_telegram.hpp +++ b/components/free_rtos/ethernet_industry/eth_ecat_telegram.hpp @@ -77,7 +77,7 @@ public: private: static constexpr uint32_t connection_timeout_ticks_ = 70; - static constexpr uint32_t max_transfer_attempts_ = 8; + static constexpr uint32_t max_transfer_attempts_ = 6; Eth& eth_; Timer& ecat_timer_;