sitara_depot/components/free_rtos/ethernet_industry/eth_ecat_api.hpp

101 lines
3.3 KiB
C++

/*
* eth_ecat_api.hpp
*
* Created on: May 29, 2023
* Author: algin
*/
#ifndef FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_API_HPP_
#define FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_API_HPP_
#define COMX 1
#include "free_rtos/ethernet/eth.hpp"
#include "free_rtos/ethernet_industry/eth_ecat.hpp"
#include "free_rtos/ethernet_industry/eth_ecat_buffer.hpp"
#include "free_rtos/ethernet_industry/CoE/eth_ecat_sdo_mailbox.hpp"
#include "free_rtos/ethernet_industry/CoE/eth_ecat_pdo_fmmu.hpp"
namespace free_rtos {
class EthEcatApi {
public:
EthEcatApi(Eth *eth)
: eth_{eth}
, ecat_{*eth}
, ecat_buffer_sdo_{ecat_}
, ecat_buffer_pdo_{ecat_}
, ecat_sdo_mailbox_{ecat_buffer_sdo_}
, ecat_pdo_fmmu_{ecat_buffer_pdo_} { }
bool config_init(TEthMacPorts port_id, uint16_t address_base, uint32_t period_microsec = 250, ecat_pdo_fmmu::ProcessCallback callback = nullptr);
template<class DataT, class Allocator>
void process(Allocator& allocator) {
ecat_pdo_fmmu_.process<DataT, Allocator>(allocator);
}
template<class DataT, class Allocator>
void process_fake(Allocator& allocator, uint32_t period_microsec, ecat_pdo_fmmu::ProcessCallback callback) {
ecat_pdo_fmmu_.process_fake<DataT, Allocator>(allocator, period_microsec, callback);
}
std::vector<ecat_buffer::PDOMap>& get_ecat_pdo_map();
uint32_t get_pdo_counter() {
return ecat_pdo_fmmu_.get_pdo_counter();
}
const telegram::EcatTelegramStatus& get_telegram_status() {
return ecat_.get_telegram_status();
}
template<typename... DataTypes>
ecat_sdo_mailbox::CompleteSize sdo_write(size_t slave_index, uint16_t index, uint8_t subindex, DataTypes&... data) {
return ecat_sdo_mailbox_.sdo_write<command::FP, DataTypes...>(slave_index, index, subindex, data...);
}
template<typename... DataTypes>
ecat_sdo_mailbox::CompleteSize sdo_read(size_t slave_index, uint16_t index, uint8_t subindex, DataTypes&... data) {
return ecat_sdo_mailbox_.sdo_read<command::FP, DataTypes...>(slave_index, index, subindex, data...);
}
template<typename... DataTypes>
bool pdo_write(uint32_t timeout_ticks, address::Offset offset, DataTypes&... data) {
return ecat_pdo_fmmu_.pdo_write<DataTypes...>(timeout_ticks, offset, data...);
}
template<typename... DataTypes>
bool pdo_read(uint32_t timeout_ticks, address::Offset offset, DataTypes&... data) {
return ecat_pdo_fmmu_.pdo_read<DataTypes...>(timeout_ticks, offset, data...);
}
void pdo_write_async_static(custom_promise::IPromise& promise) {
ecat_pdo_fmmu_.pdo_write_async_static(promise);
}
void pdo_read_async_static(custom_promise::IPromise& promise) {
ecat_pdo_fmmu_.pdo_read_async_static(promise);
}
void pdo_write_async(custom_promise::IPromise& promise) {
ecat_pdo_fmmu_.pdo_write_async(promise);
}
void pdo_read_async(custom_promise::IPromise& promise) {
ecat_pdo_fmmu_.pdo_read_async(promise);
}
private:
Eth *eth_;
EthEcat ecat_;
ecat_buffer::EthEcatBuffer ecat_buffer_sdo_;
ecat_buffer::EthEcatBuffer ecat_buffer_pdo_;
ecat_sdo_mailbox::EthEcatSdoMailbox ecat_sdo_mailbox_;
ecat_pdo_fmmu::EthEcatPdoFMMU ecat_pdo_fmmu_;
};
}
#endif /* FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_API_HPP_ */