diff --git a/components/free_rtos/ethernet/eth.cpp b/components/free_rtos/ethernet/eth.cpp index aaa7720..a0b0830 100644 --- a/components/free_rtos/ethernet/eth.cpp +++ b/components/free_rtos/ethernet/eth.cpp @@ -171,6 +171,8 @@ void free_rtos::Eth::link_task() for (int i = 0; i < macPortNum_; ++i) { if(linkUp_[i] == true) { + ClockP_usleep(100000); + continue; } @@ -254,7 +256,7 @@ void free_rtos::Eth::link_task() } - ClockP_usleep(1000000); // 100ms /// ������ 10�� ���������� ��������� ����� + ClockP_usleep(100000); // 100ms /// ������ 10�� ���������� ��������� ����� } } diff --git a/components/free_rtos/ethernet/eth_rx_flow.cpp b/components/free_rtos/ethernet/eth_rx_flow.cpp index 47a7d21..d7434d1 100644 --- a/components/free_rtos/ethernet/eth_rx_flow.cpp +++ b/components/free_rtos/ethernet/eth_rx_flow.cpp @@ -81,6 +81,7 @@ void free_rtos::EthRxFlow::reloadDmaRxPktQ(uint32_t qCount) { EnetDma_PktQ rxSubmitQ; EnetDma_Pkt* rxPktInfo = (EnetDma_Pkt *)EnetQueue_deq(&rx_free_pktq_); + int32_t status; EnetQueue_initQ(&rxSubmitQ); @@ -96,11 +97,23 @@ void free_rtos::EthRxFlow::reloadDmaRxPktQ(uint32_t qCount) ENET_PKTSTATE_APP_WITH_FREEQ, ENET_PKTSTATE_APP_WITH_DRIVER); - EnetDma_submitRxPktQ(dma_handle_, &rxSubmitQ); + status = EnetDma_submitRxPktQ(dma_handle_, &rxSubmitQ); + + if(status != ENET_SOK) { + EnetAppUtils_print("rx_flow %u: failed to reload rx dma flow\r\n", id_); + EnetAppUtils_assert(status == ENET_SOK); + + return; + } + + qCount = EnetQueue_getQCount(&rxSubmitQ); /* Assert here, as during init, the number of DMA descriptors should be equal to * the number of free Ethernet buffers available with app */ - EnetAppUtils_assert(EnetQueue_getQCount(&rxSubmitQ) == 0U); + if(qCount != 0U) { + EnetAppUtils_print("rx_flow %u: number of DMA descriptors should be equal to the number of free Ethernet buffers\r\n", id_); + EnetAppUtils_assert(qCount == 0U); + } } void free_rtos::EthRxFlow::rxProcessPktTask() @@ -112,10 +125,13 @@ void free_rtos::EthRxFlow::rxProcessPktTask() while(1) { /// ������� ������� - sem_[e_signalRxPkt].pend(); + status = sem_[e_signalRxPkt].pend(e_signalRxPkt_timeout_ticks_); - /// �������������� ������� (�������� ���� ��������) - EnetQueue_initQ(&rxReadyQ); + if(status != SystemP_SUCCESS) { + EnetAppUtils_print("rx_flow %u: Warning ! No rx packets timeout.\r\n", id_); + + continue; + } /// ��������� ������� � � �������� � rxReadyQ status = EnetDma_retrieveRxPktQ(dma_handle_, &rxReadyQ); diff --git a/components/free_rtos/ethernet/eth_rx_flow.hpp b/components/free_rtos/ethernet/eth_rx_flow.hpp index 6663a55..0da97aa 100644 --- a/components/free_rtos/ethernet/eth_rx_flow.hpp +++ b/components/free_rtos/ethernet/eth_rx_flow.hpp @@ -50,6 +50,8 @@ private: e_signalTotal }; + static constexpr e_signalRxPkt_timeout_ticks_ = 1500; + uint32_t id_; /// ������������� ������ bool open_; /// ���� ����, ��� dma ����� ��� ������ diff --git a/components/free_rtos/ethernet_industry/CoE/eth_ecat_pdo_fmmu.cpp b/components/free_rtos/ethernet_industry/CoE/eth_ecat_pdo_fmmu.cpp index ddda647..a3a855f 100644 --- a/components/free_rtos/ethernet_industry/CoE/eth_ecat_pdo_fmmu.cpp +++ b/components/free_rtos/ethernet_industry/CoE/eth_ecat_pdo_fmmu.cpp @@ -28,7 +28,6 @@ void EthEcatPdoFMMU::init(ProcessCallback callback) { bool EthEcatPdoFMMU::wait_op() { free_rtos::Semaphore& init_sem = ecat_buffer_.get_ecat().get_init_sem(); free_rtos::Semaphore& process_sem = ecat_buffer_.get_ecat().get_process_sem(); - free_rtos::Timer& ecat_timer = ecat_buffer_.get_ecat().get_ecat_timer(); process_sem.pend(); @@ -56,8 +55,6 @@ bool EthEcatPdoFMMU::wait_op() { process_sem.pend(); for(uint32_t i = 0; i < 250; i++) { - ecat_timer.Wait(); - status = read_write(0, data_tuple_read, 0, data_tuple_write); if(status != true) { @@ -145,9 +142,6 @@ void EthEcatPdoFMMU::process() { std::vector pdo_write(logical_full_length_write, 0x00); custom_tuple&> data_tuple_read{pdo_read}; custom_tuple&> data_tuple_write{pdo_write}; - free_rtos::Timer& ecat_timer = ecat_buffer_.get_ecat().get_ecat_timer(); - - ecat_timer.Wait(); status = read(0, pdo_write); // read to pdo_write ! @@ -162,9 +156,6 @@ void EthEcatPdoFMMU::process() { } while(1) { - ecat_timer.Wait(); - //DebugP_log("Tick !\r\n"); - status = read_write(0, data_tuple_read, 0, data_tuple_write); if(status != true) { @@ -233,9 +224,6 @@ void EthEcatPdoFMMU::process_fake(uint32_t period_microsec, ecat_pdo_fmmu::Proce ecat_timer.Start(); while(1) { - ecat_timer.Wait(); - //DebugP_log("Tick !\r\n"); - #if PROFILE_LEVEL > 0 { #warning ( "Profiling for RPDO subscribers is enabled !" ) diff --git a/components/free_rtos/ethernet_industry/eth_ecat.cpp b/components/free_rtos/ethernet_industry/eth_ecat.cpp index 8d5eccc..603c56f 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat.cpp +++ b/components/free_rtos/ethernet_industry/eth_ecat.cpp @@ -15,7 +15,7 @@ namespace free_rtos { EthEcat::EthEcat(Eth& eth) : eth_{eth} , tx_flow_{*eth.getTxFlowPtr()} - , telegram_{eth} + , telegram_{eth, ecat_timer_} , eeprom_{telegram_} { } void EthEcat::Init(TEthMacPorts port_id, uint32_t period_microsec = 250) { @@ -32,7 +32,7 @@ void EthEcat::Init(TEthMacPorts port_id, uint32_t period_microsec = 250) { }; ecat_timer_.Init(ecat_tmr_sett); - ecat_timer_.Stop(); + ecat_timer_.Start(); } bool EthEcat::set_slaves_to_default() { diff --git a/components/free_rtos/ethernet_industry/eth_ecat_telegram.cpp b/components/free_rtos/ethernet_industry/eth_ecat_telegram.cpp index f18c9a0..8841671 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat_telegram.cpp +++ b/components/free_rtos/ethernet_industry/eth_ecat_telegram.cpp @@ -97,13 +97,12 @@ uint8_t* EcatTelegram::unpack(uint8_t *raw) { bool EcatTelegram::transfer() { auto first = datagram_queue_.get_first(); uint32_t transfer_attempts = 0; - bool stat; - bool as_expected; + bool status = (first == nullptr); - if(first == nullptr) { + if(status == true) { status_.result = EcatTelegramResult::SUCCESS; - return true; + return status; } status_.result = EcatTelegramResult::BUSY; @@ -111,23 +110,26 @@ bool EcatTelegram::transfer() { first->reset_all_wkc(); while(1) { - transfer_attempts++; + ecat_timer_.Wait(); - if(transfer_attempts > max_transfer_attempts_) { + transfer_attempts++; + status = (transfer_attempts <= max_transfer_attempts_); + + if(status == false) { DebugP_log((char*)"%s\r\n", status_.get_description().string); status_.attempts_exceeded_errors++; status_.result = EcatTelegramResult::FATAL_ERROR; - DebugP_log((char*)"%s: %d\r\n", status_.get_description().string, status_.attempts_exceeded_errors); + DebugP_log((char*)"%s: %d\r\n", status_.get_description().string, max_transfer_attempts_); break; } - // stat = eth_stack_.send_pkt(port_id_, ETH_PROT_ECAT_LE, 1); - stat = tx_flow_.send(port_id_, this, 1); + // status = eth_stack_.send_pkt(port_id_, ETH_PROT_ECAT_LE, 1); + status = tx_flow_.send(port_id_, this, 1); - if(stat == false) { + if(status == false) { status_.transfer_errors++; status_.result = EcatTelegramResult::WARNING_TRANSFER_ERROR; @@ -136,7 +138,9 @@ bool EcatTelegram::transfer() { continue; } - if(rx_sem_.pend(connection_timeout_ticks_) != SystemP_SUCCESS) { + status = (rx_sem_.pend(connection_timeout_ticks_) == SystemP_SUCCESS); + + if(status == false) { status_.transfer_errors++; status_.result = EcatTelegramResult::WARNING_TIMEOUT_ERROR; @@ -145,9 +149,9 @@ bool EcatTelegram::transfer() { continue; } - as_expected = first->all_as_expected(); + status = first->all_as_expected(); - if(as_expected == false) { + if(status == false) { status_.expected_wkc_errors++; status_.result = EcatTelegramResult::WARNING_WKC_ERROR; @@ -156,16 +160,14 @@ bool EcatTelegram::transfer() { continue; } - if(status_.result == EcatTelegramResult::BUSY) { - status_.result = EcatTelegramResult::SUCCESS; - } + status_.result = EcatTelegramResult::SUCCESS; break; } datagram_queue_.clear(); - return (status_.result != EcatTelegramResult::FATAL_ERROR); + return status; } bool EcatTelegram::transfer(datagram::IEcatDatagram& next) { diff --git a/components/free_rtos/ethernet_industry/eth_ecat_telegram.hpp b/components/free_rtos/ethernet_industry/eth_ecat_telegram.hpp index 5d7644b..74f5aa8 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat_telegram.hpp +++ b/components/free_rtos/ethernet_industry/eth_ecat_telegram.hpp @@ -9,6 +9,7 @@ #define FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_TELEGRAM_HPP_ #include "free_rtos/ethernet/eth.hpp" +#include "free_rtos/timer/timer.hpp" #include "free_rtos/ethernet_industry/eth_ecat_datagram.hpp" @@ -53,8 +54,9 @@ private: class EcatTelegram : public Handler { public: - EcatTelegram(Eth& eth) + EcatTelegram(Eth& eth, Timer& ecat_timer) : eth_{eth} + , ecat_timer_(ecat_timer) , tx_flow_{*eth.getTxFlowPtr()} , eth_stack_{*eth.getEthStackPtr()} { } @@ -74,10 +76,11 @@ public: bool transfer(queue::Queue& next); private: - static constexpr uint32_t connection_timeout_ticks_ = 200; - static constexpr uint32_t max_transfer_attempts_ = 2; + static constexpr uint32_t connection_timeout_ticks_ = 60; + static constexpr uint32_t max_transfer_attempts_ = 10; Eth& eth_; + Timer& ecat_timer_; EthTxFlowIface& tx_flow_; EthStackIface& eth_stack_; TEthMacPorts port_id_;