sitara_depot/components/free_rtos/ethernet_industry/eth_ecat_api.cpp
algin 5ae051a9ff feat(UML-1462): Добавил API. Перелопатил кучу подмодулей
Доработал класс custom_tuple, упаковку данных, передачу в одном фрейме
2023-06-01 16:13:05 +03:00

104 lines
2.4 KiB
C++

/*
* eth_ecat_api.cpp
*
* Created on: May 29, 2023
* Author: algin
*/
#include "ethernet_industry/eth_ecat_api.hpp"
namespace free_rtos {
Eth *EthEcatApi::eth_{nullptr};
bool EthEcatApi::init(Eth& eth, TEthMacPorts port_id, uint16_t address_base) {
eth_ = ð
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;
}
}