2023-05-03 14:01:32 +03:00
|
|
|
|
/*
|
|
|
|
|
|
* eth_ecat.cpp
|
|
|
|
|
|
*
|
|
|
|
|
|
* Created on: 16 <EFBFBD><EFBFBD><EFBFBD>. 2023 <EFBFBD>.
|
|
|
|
|
|
* Author: sychev
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2023-06-26 18:22:30 +03:00
|
|
|
|
#include "free_rtos/ethernet_industry/eth_ecat.hpp"
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
#include <kernel/dpl/ClockP.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace free_rtos {
|
|
|
|
|
|
|
|
|
|
|
|
EthEcat::EthEcat(Eth& eth)
|
2023-05-26 16:21:27 +03:00
|
|
|
|
: eth_{eth}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
, tx_flow_{*eth.getTxFlowPtr()}
|
|
|
|
|
|
, telegram_{eth}
|
|
|
|
|
|
, eeprom_{telegram_} { }
|
|
|
|
|
|
|
2023-06-19 11:33:11 +03:00
|
|
|
|
void EthEcat::Init(TEthMacPorts port_id, uint32_t period_microsec = 250) {
|
2023-05-03 14:01:32 +03:00
|
|
|
|
port_id_ = port_id;
|
|
|
|
|
|
telegram_.init(port_id);
|
2023-06-06 10:27:01 +03:00
|
|
|
|
|
|
|
|
|
|
Timer::Settings ecat_tmr_sett = {
|
|
|
|
|
|
.input_clk_Hz = 25000000, // 25MHz
|
|
|
|
|
|
.base_address = 0x2400000u, // memory mapping,
|
|
|
|
|
|
.clock_src_mux_addr = 0x430081B0u, // sysconfig
|
|
|
|
|
|
.int_num = 152u, // sysconfig
|
|
|
|
|
|
.int_priority = 4, // sysconfig
|
2023-06-19 11:33:11 +03:00
|
|
|
|
.period_us = period_microsec /// microsec
|
2023-06-06 10:27:01 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ecat_timer_.Init(ecat_tmr_sett);
|
|
|
|
|
|
ecat_timer_.Stop();
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
bool EthEcat::set_slaves_to_default() {
|
2023-09-08 17:37:15 +03:00
|
|
|
|
const datagram::TEcatWkc expected_wkc = 1;
|
2023-05-04 18:00:43 +03:00
|
|
|
|
address::Broadcast broadcast{0x0000};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
bool status;
|
2023-05-04 18:00:43 +03:00
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
/* deact loop manual */
|
|
|
|
|
|
uint8_t a_data_out{0x00};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint8_t> a{ {{broadcast, ECT_REG_DLPORT}}, expected_wkc, a_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* set IRQ mask */
|
|
|
|
|
|
uint16_t b_data_out{0x0C04};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint16_t> b{ {{broadcast, ECT_REG_IRQMASK}}, expected_wkc, b_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* reset CRC counters */
|
|
|
|
|
|
std::array<uint8_t, 8> c_data_out;
|
2023-05-10 15:10:01 +03:00
|
|
|
|
c_data_out.fill(0x00);
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, std::array<uint8_t, 8>> c{ {{broadcast, ECT_REG_RXERR}}, expected_wkc, c_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* reset FMMU's */
|
|
|
|
|
|
std::array<uint8_t, 16*3> d_data_out;
|
2023-05-10 15:10:01 +03:00
|
|
|
|
d_data_out.fill(0x00);
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, std::array<uint8_t, 16*3>> d{ {{broadcast, ECT_REG_FMMU0}}, expected_wkc, d_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* reset SyncM */
|
|
|
|
|
|
std::array<uint8_t, 8*4> e_data_out;
|
2023-05-10 15:10:01 +03:00
|
|
|
|
e_data_out.fill(0x00);
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, std::array<uint8_t, 8*4>> e{ {{broadcast, ECT_REG_SM0}}, expected_wkc, e_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* reset activation register */
|
|
|
|
|
|
uint8_t f_data_out{0x00};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint8_t> f{ {{broadcast, ECT_REG_DCSYNCACT}}, expected_wkc, f_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* reset system time+ofs */
|
|
|
|
|
|
std::array<uint8_t, 4> g_data_out;
|
2023-05-10 15:10:01 +03:00
|
|
|
|
g_data_out.fill(0x00);
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, std::array<uint8_t, 4>> g{ {{broadcast, ECT_REG_DCSYSTIME}}, expected_wkc, g_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* DC speedstart */
|
|
|
|
|
|
uint16_t h_data_out{0x1000};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint16_t> h{ {{broadcast, ECT_REG_DCSPEEDCNT}}, expected_wkc, h_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* DC filt expr */
|
|
|
|
|
|
uint16_t i_data_out{0x0C00};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint16_t> i{ {{broadcast, ECT_REG_DCTIMEFILT}}, expected_wkc, i_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* Ignore Alias register */
|
|
|
|
|
|
uint8_t j_data_out{0x00};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint8_t> j{ {{broadcast, ECT_REG_DLALIAS}}, expected_wkc, j_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* Reset all slaves to Init */
|
2023-05-10 15:10:01 +03:00
|
|
|
|
uint16_t k_data_out{EC_STATE_INIT|EC_STATE_ACK};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint16_t> k{ {{broadcast, ECT_REG_ALCTL}}, expected_wkc, k_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* force Eeprom from PDI */
|
|
|
|
|
|
uint8_t l_data_out{0x02};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint8_t> l{ {{broadcast, ECT_REG_EEPCFG}}, expected_wkc, l_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
/* set Eeprom to master */
|
|
|
|
|
|
uint8_t m_data_out{0x00};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint8_t> m{ {{broadcast, ECT_REG_EEPCFG}}, expected_wkc, m_data_out };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-06-16 10:18:13 +03:00
|
|
|
|
auto queue = a + b + c + d + e + f + g + h + i + j + k + l + m;
|
2023-06-09 13:57:20 +03:00
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
status = telegram_.transfer(queue);
|
2023-06-09 13:57:20 +03:00
|
|
|
|
|
2023-05-25 10:20:33 +03:00
|
|
|
|
//telegram_.transfer(b);
|
|
|
|
|
|
//telegram_.transfer(c);
|
|
|
|
|
|
//telegram_.transfer(d);
|
|
|
|
|
|
//telegram_.transfer(e);
|
|
|
|
|
|
//telegram_.transfer(f);
|
|
|
|
|
|
//telegram_.transfer(g);
|
|
|
|
|
|
//telegram_.transfer(h);
|
|
|
|
|
|
//telegram_.transfer(i);
|
|
|
|
|
|
//telegram_.transfer(j);
|
|
|
|
|
|
//telegram_.transfer(k);
|
|
|
|
|
|
//telegram_.transfer(l);
|
|
|
|
|
|
//telegram_.transfer(m);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
DebugP_log((char*)"Deact loop manual wkc = %d\r\n", a.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Set IRQ mask wkc = %d\r\n", b.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Reset CRC counters wkc = %d\r\n", c.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Reset FMMU's wkc = %d\r\n", d.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Reset SyncM wkc = %d\r\n", e.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Reset activation register wkc = %d\r\n", f.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Reset system time+ofs wkc = %d\r\n", g.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"DC speedstart wkc = %d\r\n", h.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"DC filt expr wkc = %d\r\n", i.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Ignore Alias register wkc = %d\r\n", j.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Reset all slaves to Init wkc = %d\r\n", k.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Force Eeprom from PDI wkc = %d\r\n", l.get_wkc());
|
|
|
|
|
|
DebugP_log((char*)"Set Eeprom to master wkc = %d\r\n", m.get_wkc());
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t EthEcat::slaves_detecting() {
|
2023-05-04 18:00:43 +03:00
|
|
|
|
address::Broadcast broadcast{0x0000};
|
2023-05-25 10:20:33 +03:00
|
|
|
|
uint16_t data{0x0000};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagram::EcatDatagram<command::BRD, uint16_t> datagram{ {{broadcast, ECT_REG_TYPE}}, 1, data };
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
|
|
|
|
|
telegram_.transfer(datagram);
|
|
|
|
|
|
|
|
|
|
|
|
return datagram.get_wkc();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-01 16:13:05 +03:00
|
|
|
|
// Setting Station address (FP) of slave via Position addressing (AP)
|
|
|
|
|
|
// Station address is datagram data
|
2023-09-06 18:09:23 +03:00
|
|
|
|
bool EthEcat::set_addresses_of_slaves(uint16_t number_of_slaves, uint16_t address_base) {
|
2023-06-01 16:13:05 +03:00
|
|
|
|
using TDatagram = datagram::EcatDatagram<command::APWR, address::Station>;
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
const datagram::TEcatWkc expected_wkc = 1;
|
2023-06-01 16:13:05 +03:00
|
|
|
|
std::vector<TDatagram> datagrams;
|
2023-09-06 18:09:23 +03:00
|
|
|
|
bool status;
|
2023-05-04 18:00:43 +03:00
|
|
|
|
|
|
|
|
|
|
slaves_.reserve(number_of_slaves);
|
|
|
|
|
|
datagrams.reserve(number_of_slaves);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-05-04 18:00:43 +03:00
|
|
|
|
for(uint16_t i = 0; i < number_of_slaves; i++) {
|
|
|
|
|
|
address::Position position{static_cast<int16_t>(-i)};
|
2023-05-26 16:21:27 +03:00
|
|
|
|
address::Station station{static_cast<uint16_t>(address_base + i)};
|
|
|
|
|
|
address::SlaveAddresses slave_addresses{position, 0x0000, station, 0x00000000};
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-06-01 16:13:05 +03:00
|
|
|
|
slaves_.emplace_back(EcatSlave{std::move(slave_addresses)});
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagrams.emplace_back(TDatagram{ {{position, ECT_REG_STADR}}, expected_wkc, slaves_.back().get_slave_address<command::FP>() });
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 10:18:13 +03:00
|
|
|
|
queue::Queue<datagram::IEcatDatagram> queue;
|
|
|
|
|
|
|
|
|
|
|
|
for(uint16_t i = 0; i < number_of_slaves; i++) {
|
|
|
|
|
|
queue + datagrams[i];
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
status = telegram_.transfer(queue);
|
|
|
|
|
|
|
|
|
|
|
|
if(status != true) {
|
|
|
|
|
|
DebugP_log((char*)"Slave addresses not set\r\n");
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
2023-06-16 10:18:13 +03:00
|
|
|
|
|
|
|
|
|
|
DebugP_log((char*)"Slave addresses set\r\n");
|
2023-09-06 18:09:23 +03:00
|
|
|
|
|
|
|
|
|
|
return status;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
bool EthEcat::get_addresses_of_slaves() {
|
2023-06-01 16:13:05 +03:00
|
|
|
|
using TDatagram = datagram::EcatDatagram<command::APRD, address::Station>;
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
const datagram::TEcatWkc expected_wkc = 1;
|
2023-06-01 16:13:05 +03:00
|
|
|
|
std::vector<TDatagram> datagrams;
|
2023-05-26 16:21:27 +03:00
|
|
|
|
uint16_t number_of_slaves = slaves_.size();
|
2023-09-06 18:09:23 +03:00
|
|
|
|
queue::Queue<datagram::IEcatDatagram> queue;
|
|
|
|
|
|
bool status;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-05-26 16:21:27 +03:00
|
|
|
|
datagrams.reserve(number_of_slaves);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-05-04 18:00:43 +03:00
|
|
|
|
for(EcatSlave& slave : slaves_) {
|
2023-09-06 18:09:23 +03:00
|
|
|
|
datagrams.emplace_back(TDatagram{ {{slave.get_slave_address<command::AP>(), ECT_REG_STADR}}, expected_wkc, slave.get_slave_address<command::FP>() });
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 10:18:13 +03:00
|
|
|
|
for(uint16_t i = 0; i < number_of_slaves; i++) {
|
|
|
|
|
|
queue + datagrams[i];
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
status = telegram_.transfer(queue);
|
|
|
|
|
|
|
|
|
|
|
|
if(status != true) {
|
|
|
|
|
|
DebugP_log((char*)"Slave addresses not read\r\n");
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-05-04 18:00:43 +03:00
|
|
|
|
for(EcatSlave& slave : slaves_) {
|
2023-06-08 14:46:25 +03:00
|
|
|
|
DebugP_log((char*)"Slave %d address = %d\r\n", -slave.get_slave_address<command::AP>(), slave.get_slave_address<command::FP>());
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
2023-09-06 18:09:23 +03:00
|
|
|
|
|
|
|
|
|
|
return status;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
bool EthEcat::config_init(uint16_t address_base) {
|
|
|
|
|
|
uint16_t number_of_slaves;
|
|
|
|
|
|
bool status;
|
|
|
|
|
|
|
2023-09-15 15:37:33 +03:00
|
|
|
|
DebugP_log((char*)"EthercatMaster starting. Initializing slaves...\r\n");
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
status = set_slaves_to_default();
|
|
|
|
|
|
|
|
|
|
|
|
if(status != true) {
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
number_of_slaves = slaves_detecting();
|
|
|
|
|
|
|
2023-06-08 14:46:25 +03:00
|
|
|
|
DebugP_log((char*)"number_of_slaves = %d\r\n", number_of_slaves);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
status = (number_of_slaves > 0);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
if(status != true) {
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status = set_addresses_of_slaves(number_of_slaves, address_base);
|
|
|
|
|
|
|
|
|
|
|
|
if(status != true) {
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status = get_addresses_of_slaves();
|
|
|
|
|
|
|
|
|
|
|
|
if(status != true) {
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
2023-05-04 18:00:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
bool EthEcat::enable_PDI() {
|
|
|
|
|
|
const datagram::TEcatWkc expected_wkc = 1;
|
|
|
|
|
|
bool status = true;
|
|
|
|
|
|
|
2023-05-04 18:00:43 +03:00
|
|
|
|
for(EcatSlave& slave : slaves_) {
|
2023-09-06 18:09:23 +03:00
|
|
|
|
status = (status && slave.enable_PDI<command::FP>(telegram_, expected_wkc));
|
2023-05-04 18:00:43 +03:00
|
|
|
|
}
|
2023-09-06 18:09:23 +03:00
|
|
|
|
|
|
|
|
|
|
return status;
|
2023-05-04 18:00:43 +03:00
|
|
|
|
}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-05-04 18:00:43 +03:00
|
|
|
|
bool EthEcat::init_to_preop() {
|
2023-09-06 18:09:23 +03:00
|
|
|
|
const datagram::TEcatWkc expected_wkc = 1;
|
2023-05-04 18:00:43 +03:00
|
|
|
|
bool success = true;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-05-04 18:00:43 +03:00
|
|
|
|
for(EcatSlave& slave : slaves_) {
|
2023-09-06 18:09:23 +03:00
|
|
|
|
success = (success && slave.init_to_preop<command::FP>(telegram_, expected_wkc));
|
2023-05-04 18:00:43 +03:00
|
|
|
|
}
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-06-08 14:46:25 +03:00
|
|
|
|
DebugP_log((char*)"success = %d\r\n", success);
|
2023-05-03 14:01:32 +03:00
|
|
|
|
|
2023-05-04 18:00:43 +03:00
|
|
|
|
return success;
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-23 10:17:24 +03:00
|
|
|
|
bool EthEcat::preop_to_safeop() {
|
2023-09-06 18:09:23 +03:00
|
|
|
|
const datagram::TEcatWkc expected_wkc = 1;
|
2023-05-23 10:17:24 +03:00
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
|
|
|
|
for(EcatSlave& slave : slaves_) {
|
2023-09-06 18:09:23 +03:00
|
|
|
|
success = (success && slave.preop_to_safeop<command::FP>(telegram_, expected_wkc));
|
2023-05-23 10:17:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 14:46:25 +03:00
|
|
|
|
DebugP_log((char*)"success = %d\r\n", success);
|
2023-05-23 10:17:24 +03:00
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EthEcat::safeop_to_op() {
|
2023-09-15 15:37:33 +03:00
|
|
|
|
const datagram::TEcatWkc expected_wkc = slaves_.size();
|
2023-05-23 10:17:24 +03:00
|
|
|
|
address::Broadcast broadcast{0x0000};
|
|
|
|
|
|
ALSTAT stat{0x0000, 0x0000};
|
|
|
|
|
|
uint16_t zero{0x00000000};
|
2023-09-15 15:37:33 +03:00
|
|
|
|
bool status;
|
2023-05-23 10:17:24 +03:00
|
|
|
|
|
2023-09-20 15:52:57 +03:00
|
|
|
|
ecat_timer_.Start();
|
|
|
|
|
|
|
2023-05-23 18:41:31 +03:00
|
|
|
|
process_sem_.post();
|
2023-09-15 15:37:33 +03:00
|
|
|
|
if(init_sem_.pend(process_timeout_ticks_) != SystemP_SUCCESS) {
|
2023-09-20 15:52:57 +03:00
|
|
|
|
DebugP_log((char*)"Process task timeout !\r\n");
|
|
|
|
|
|
|
2023-09-15 15:37:33 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-05-23 18:41:31 +03:00
|
|
|
|
|
2023-05-23 10:17:24 +03:00
|
|
|
|
{
|
|
|
|
|
|
uint16_t data{EC_STATE_OPERATIONAL};
|
2023-09-15 15:37:33 +03:00
|
|
|
|
datagram::EcatDatagram<command::BWR, uint16_t> datagram{ {{broadcast, ECT_REG_ALCTL}}, expected_wkc, data };
|
2023-05-23 10:17:24 +03:00
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
status = telegram_.transfer(datagram);
|
|
|
|
|
|
|
|
|
|
|
|
if(status != true) {
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
2023-05-23 10:17:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-23 18:41:31 +03:00
|
|
|
|
process_sem_.post();
|
2023-09-15 15:37:33 +03:00
|
|
|
|
if(init_sem_.pend(process_timeout_ticks_) != SystemP_SUCCESS) {
|
2023-09-20 15:52:57 +03:00
|
|
|
|
DebugP_log((char*)"Process task timeout !\r\n");
|
|
|
|
|
|
|
2023-09-15 15:37:33 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-05-23 10:17:24 +03:00
|
|
|
|
|
|
|
|
|
|
{
|
2023-09-15 15:37:33 +03:00
|
|
|
|
datagram::EcatDatagram<command::BRD, ALSTAT, uint16_t> datagram{ {{broadcast, ECT_REG_ALSTAT}}, expected_wkc, stat, zero };
|
2023-09-06 18:09:23 +03:00
|
|
|
|
|
|
|
|
|
|
status = telegram_.transfer(datagram);
|
2023-05-23 10:17:24 +03:00
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
if(status != true) {
|
|
|
|
|
|
return status;
|
|
|
|
|
|
}
|
2023-05-23 10:17:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
status = (stat.state == EC_STATE_OPERATIONAL) && (stat.fault == 0);
|
2023-05-23 18:41:31 +03:00
|
|
|
|
|
2023-09-20 15:52:57 +03:00
|
|
|
|
if(status != true) {
|
|
|
|
|
|
DebugP_log((char*)"stat.state = %d, stat.fault = %d\r\n", stat.state, stat.fault);
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
2023-05-23 18:41:31 +03:00
|
|
|
|
}
|
2023-05-23 10:17:24 +03:00
|
|
|
|
|
2023-08-07 13:52:11 +03:00
|
|
|
|
//DebugP_log((char*)"success = %d\r\n", success);
|
2023-05-23 10:17:24 +03:00
|
|
|
|
|
2023-09-20 15:52:57 +03:00
|
|
|
|
process_sem_.post();
|
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
|
return status;
|
2023-05-23 10:17:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-03 14:01:32 +03:00
|
|
|
|
}
|