sitara_depot/components/free_rtos/ethernet_industry/eth_ecat_api.hpp

84 lines
3.1 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.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 "ethernet/eth.hpp"
#include "ethernet_industry/eth_ecat.hpp"
#include "ethernet_industry/eth_ecat_buffer.hpp"
#include "ethernet_industry/CoE/eth_ecat_sdo_mailbox.hpp"
#include "ethernet_industry/CoE/eth_ecat_pdo_fmmu.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(...)
*/
class EthEcatApi {
public:
static void init(Eth& eth);
static bool config_init(TEthMacPorts port_id, uint16_t address_base);
static void process(); // Внутри бесконечный цикл. Запускать в отдельном потоке
static std::vector<ecat_buffer::PDOMap>& get_ecat_pdo_map();
static uint32_t get_pdo_counter() {
return get_ecat_pdo_fmmu().get_pdo_counter();
}
template<typename... DataTypes>
static ecat_sdo_mailbox::CompleteSize sdo_write(size_t slave_index, uint16_t index, uint8_t subindex, DataTypes&... data) {
return get_ecat_sdo_mailbox().sdo_write<command::FP, DataTypes...>(slave_index, index, subindex, data...);
}
template<typename... DataTypes>
static ecat_sdo_mailbox::CompleteSize sdo_read(size_t slave_index, uint16_t index, uint8_t subindex, DataTypes&... data) {
return get_ecat_sdo_mailbox().sdo_read<command::FP, DataTypes...>(slave_index, index, subindex, data...);
}
template<typename... DataTypes>
static bool pdo_write(uint32_t timeout_ticks, address::Offset offset, DataTypes&... data) {
return get_ecat_pdo_fmmu().pdo_write<DataTypes...>(timeout_ticks, offset, data...);
}
template<typename... DataTypes>
static bool pdo_read(uint32_t timeout_ticks, address::Offset offset, DataTypes&... data) {
return get_ecat_pdo_fmmu().pdo_read<DataTypes...>(timeout_ticks, offset, data...);
}
static void pdo_write_async(custom_promise::IPromise& promise) {
get_ecat_pdo_fmmu().pdo_write_async(promise);
}
static void pdo_read_async(custom_promise::IPromise& promise) {
get_ecat_pdo_fmmu().pdo_read_async(promise);
}
private:
static Eth *eth_;
static EthEcat& get_ecat();
static ecat_buffer::EthEcatBuffer& get_ecat_buffer_sdo();
static ecat_buffer::EthEcatBuffer& get_ecat_buffer_pdo();
static ecat_sdo_mailbox::EthEcatSdoMailbox& get_ecat_sdo_mailbox();
static ecat_pdo_fmmu::EthEcatPdoFMMU& get_ecat_pdo_fmmu();
};
}
#endif /* FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_API_HPP_ */