sitara_depot/components/free_rtos/ethernet_industry/eth_ecat_api.cpp

117 lines
3.1 KiB
C++
Raw Normal View History

/*
* eth_ecat_api.cpp
*
* Created on: May 29, 2023
* Author: algin
*/
#include "ethernet_industry/eth_ecat_api.hpp"
namespace free_rtos {
/*
* Порядок инициализации:
* Инициализировать и открыть драйвер eth_.Init(...), eth_.Open()
* Вызвать EthEcatApi::init(eth_);
* Создать служебный поток ecat_task_.Create(...) с вызовом EthEcatApi::process()
* Вызвать EthEcatApi::config_init(...)
* Создать пользовательский поток ecat_task_pdo_.Create(...)
* Для чтения/записи данных в пользовательском потоке вызвать
* pdo_write(...), pdo_read(...) или pdo_write_async(...), pdo_read_async(...)
*/
Eth *EthEcatApi::eth_{nullptr};
void EthEcatApi::init(Eth& eth) {
eth_ = ð
}
bool EthEcatApi::config_init(TEthMacPorts port_id, uint16_t address_base) {
bool status = false;
get_ecat().Init(port_id);
get_ecat().config_init(address_base);
get_ecat_buffer_sdo().init(ECT_SII_RXMBXADR, ECT_SII_TXMBXADR);
get_ecat_buffer_sdo().init_sync_manager(sync_manager::SYNC_M0, sync_manager::SYNC_M1);
get_ecat_buffer_pdo().init(ECT_PDOOUTPUTADR, ECT_PDOINPUTADR);
get_ecat().enable_PDI();
status = get_ecat().init_to_preop();
if(status != true) {
return status;
}
get_ecat_sdo_mailbox().init();
get_ecat_sdo_mailbox().read_pdo_map(ECT_RXPDOMAPINDEX, ECT_TXPDOMAPINDEX);
// Override buffer properties from eeprom for PDO
#ifdef COMX
get_ecat_buffer_pdo().set_buffer_offset(get_ecat_sdo_mailbox().get_pdo_map());
#endif
get_ecat_buffer_pdo().set_buffer_length(get_ecat_sdo_mailbox().get_pdo_map());
get_ecat_buffer_pdo().init_sync_manager(sync_manager::SYNC_M2, sync_manager::SYNC_M3);
get_ecat_buffer_pdo().init_fmmu(fmmu::FMMU0, fmmu::FMMU1);
get_ecat_pdo_fmmu().init();
status = get_ecat().preop_to_safeop();
if(status != true) {
return status;
}
status = get_ecat().safeop_to_op();
if(status != true) {
return status;
}
return status;
}
void EthEcatApi::process() {
get_ecat_pdo_fmmu().process();
}
std::vector<ecat_buffer::PDOMap>& EthEcatApi::get_ecat_pdo_map() {
return get_ecat_sdo_mailbox().get_pdo_map();
}
EthEcat& EthEcatApi::get_ecat() {
static EthEcat ecat{*eth_};
return ecat;
}
ecat_buffer::EthEcatBuffer& EthEcatApi::get_ecat_buffer_sdo() {
static ecat_buffer::EthEcatBuffer ecat_buffer_sdo{get_ecat()};
return ecat_buffer_sdo;
}
ecat_buffer::EthEcatBuffer& EthEcatApi::get_ecat_buffer_pdo() {
static ecat_buffer::EthEcatBuffer ecat_buffer_pdo{get_ecat()};
return ecat_buffer_pdo;
}
ecat_sdo_mailbox::EthEcatSdoMailbox& EthEcatApi::get_ecat_sdo_mailbox() {
static ecat_sdo_mailbox::EthEcatSdoMailbox ecat_sdo_mailbox{get_ecat_buffer_sdo()};
return ecat_sdo_mailbox;
}
ecat_pdo_fmmu::EthEcatPdoFMMU& EthEcatApi::get_ecat_pdo_fmmu() {
static ecat_pdo_fmmu::EthEcatPdoFMMU ecat_pdo_fmmu{get_ecat_buffer_pdo()};
return ecat_pdo_fmmu;
}
}