sitara_depot/components/free_rtos/ethernet_industry/eth_ecat_api.cpp

84 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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()
* Создать служебный поток ecat_task_.Create(...) с вызовом EthEcatApi::process()
* Вызвать EthEcatApi::config_init(...)
* Создать пользовательский поток ecat_task_pdo_.Create(...)
* Для чтения/записи данных в пользовательском потоке вызвать
* pdo_write(...), pdo_read(...) или pdo_write_async(...), pdo_read_async(...)
*/
bool EthEcatApi::config_init(TEthMacPorts port_id, uint16_t address_base, uint32_t period_microsec = 250) {
bool status = false;
ecat_.Init(port_id, period_microsec);
ecat_.config_init(address_base);
ecat_buffer_sdo_.init(ECT_SII_RXMBXADR, ECT_SII_TXMBXADR);
ecat_buffer_sdo_.init_sync_manager(sync_manager::SYNC_M0, sync_manager::SYNC_M1);
ecat_buffer_pdo_.init(ECT_PDOOUTPUTADR, ECT_PDOINPUTADR);
ecat_.enable_PDI();
status = ecat_.init_to_preop();
if(status != true) {
return status;
}
ecat_sdo_mailbox_.init();
ecat_sdo_mailbox_.read_pdo_map(ECT_RXPDOMAPINDEX, ECT_TXPDOMAPINDEX);
// Override buffer properties from eeprom for PDO
#ifdef COMX
ecat_buffer_pdo_.set_buffer_offset(ecat_sdo_mailbox_.get_pdo_map());
#endif
ecat_buffer_pdo_.set_buffer_length(ecat_sdo_mailbox_.get_pdo_map());
ecat_buffer_pdo_.init_sync_manager(sync_manager::SYNC_M2, sync_manager::SYNC_M3);
ecat_buffer_pdo_.init_fmmu(fmmu::FMMU0, fmmu::FMMU1);
ecat_pdo_fmmu_.init();
status = ecat_.preop_to_safeop();
if(status != true) {
return status;
}
status = ecat_.safeop_to_op();
if(status != true) {
return status;
}
return status;
}
void EthEcatApi::process() {
ecat_pdo_fmmu_.process();
}
void EthEcatApi::process_fake(uint32_t period_microsec = 250) {
ecat_pdo_fmmu_.process_fake(period_microsec);
}
std::vector<ecat_buffer::PDOMap>& EthEcatApi::get_ecat_pdo_map() {
return ecat_sdo_mailbox_.get_pdo_map();
}
}