Adds sitara_depot/free_rtos Original one is on server_gorbunov/SmartForce4.0/sitara_depot
142 lines
3.4 KiB
C++
142 lines
3.4 KiB
C++
/*
|
||
* eth_ecat.hpp
|
||
*
|
||
* Created on: 16 <20><><EFBFBD>. 2023 <20>.
|
||
* Author: sychev
|
||
*/
|
||
|
||
#ifndef FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_HPP_
|
||
#define FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_HPP_
|
||
|
||
#include <ethernet_industry/eth_ecat_datagram.hpp>
|
||
#include <cstdint>
|
||
|
||
#include "handler_store/handler.hpp"
|
||
#include "ethernet/eth_frame.h"
|
||
#include "mutex/mutex.hpp"
|
||
#include "semaphore/semaphore.hpp"
|
||
#include "ethernet/eth.hpp"
|
||
#include "ethernet_industry/ethercattype.hpp"
|
||
#include "ethernet_industry/eth_ecat_types.h"
|
||
#include "ethernet_industry/eth_ecat_command.hpp"
|
||
#include "ethernet_industry/eth_ecat_eeprom.hpp"
|
||
|
||
namespace free_rtos {
|
||
|
||
struct BufferProperties {
|
||
uint16_t address;
|
||
uint16_t length;
|
||
};
|
||
|
||
class EcatSlave {
|
||
public:
|
||
EcatSlave() {
|
||
|
||
}
|
||
|
||
template<typename TypeT>
|
||
void set_slave_address(typename TypeT::TSlaveAddress&& slave_address) {
|
||
std::get<static_cast<size_t>(TypeT::type)>(slave_addresses_) = slave_address;
|
||
}
|
||
|
||
template<typename TypeT>
|
||
typename TypeT::TSlaveAddress& get_slave_address() {
|
||
return std::get<static_cast<size_t>(TypeT::type)>(slave_addresses_);
|
||
}
|
||
|
||
private:
|
||
address::SlaveTypes slave_addresses_;
|
||
|
||
BufferProperties mbx_write_;
|
||
BufferProperties mbx_read_;
|
||
|
||
BufferProperties pdo_output_;
|
||
BufferProperties mbx_input_;
|
||
};
|
||
|
||
class EthEcat : public Handler {
|
||
public:
|
||
struct Statistic {
|
||
uint32_t rx_pkt;
|
||
uint32_t tx_pkt;
|
||
};
|
||
|
||
EthEcat(Eth& eth);
|
||
|
||
void Init(TEthMacPorts port_id);
|
||
|
||
std::vector<uint8_t> receive_datagram();
|
||
void send_datagram(const std::vector<std::uint8_t>& datagram);
|
||
|
||
void set_slaves_to_default();
|
||
uint16_t slaves_detecting();
|
||
void set_addresses_of_slaves(uint16_t address_base);
|
||
void get_addresses_of_slaves();
|
||
|
||
/*
|
||
* Тип адресации slave_address зависит от типа команды CommandT
|
||
* Может иметь тип Position, Broadcast, Node
|
||
* Logical не поддерживается
|
||
*/
|
||
template<typename TypeT, typename DirT, typename EcatDgDataT>
|
||
void simple_send_datagram(typename TypeT::TSlaveAddress& slave_address, uint16_t offset, EcatDgDataT& data) {
|
||
using TCommand = command::EcatCommand<TypeT, DirT>;
|
||
datagram::EcatDatagram<TCommand, EcatDgDataT> datagram{ {{slave_address, offset}}, data };
|
||
|
||
telegram_.transfer(datagram);
|
||
}
|
||
|
||
datagram::EcatTelegram& get_telegram() {
|
||
return telegram_;
|
||
}
|
||
|
||
eeprom::EEPROM& get_eeprom() {
|
||
return eeprom_;
|
||
}
|
||
|
||
uint16_t config_init();
|
||
|
||
bool is_ready() { return ready_; }
|
||
|
||
Statistic getStat() { return stat_;}
|
||
|
||
virtual int32_t Process(uint8_t * p_data, uint32_t len) override; /// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ecat
|
||
private:
|
||
enum {
|
||
e_pktFirst,
|
||
e_pktSecond,
|
||
e_pktTotal
|
||
};
|
||
|
||
static constexpr uint16_t max_number_of_slaves = 32;
|
||
|
||
TEthPkt * p_pkt_;
|
||
TEthPkt * p_pkt_next_;
|
||
|
||
TEthPkt pkt_[e_pktTotal];
|
||
|
||
Mutex mut_;
|
||
|
||
free_rtos::Semaphore rx_sem_;
|
||
|
||
Eth& eth_;
|
||
EthTxFlowIface& tx_flow_;
|
||
|
||
datagram::EcatTelegram telegram_;
|
||
eeprom::EEPROM eeprom_;
|
||
|
||
TEthMacPorts port_id_; /// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
bool ready_;
|
||
|
||
Statistic stat_;
|
||
|
||
std::array<EcatSlave, max_number_of_slaves> slaves_;
|
||
|
||
uint16_t number_of_slaves_ = 0;
|
||
};
|
||
|
||
}
|
||
|
||
#endif /* FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_HPP_ */
|