2023-09-04 12:21:37 +02:00
|
|
|
/* Node type: ethercat.
|
2018-10-23 14:22:35 +02:00
|
|
|
*
|
|
|
|
* Author: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2020-01-25 17:38:22 +01:00
|
|
|
* Author: Divya Laxetti <divya.laxetti@rwth-aachen.de>
|
|
|
|
* SPDX-FileCopyrightText: 2018-2020 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-10-23 14:22:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-01-25 17:38:22 +01:00
|
|
|
#include <thread>
|
|
|
|
|
2020-03-04 12:41:55 +01:00
|
|
|
#include <villas/common.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/config.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/format.hpp>
|
|
|
|
#include <villas/pool.hpp>
|
|
|
|
#include <villas/queue_signalled.h>
|
|
|
|
#include <villas/task.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2021-02-19 06:38:38 +01:00
|
|
|
// Include hard-coded Ethercat Bus configuration
|
2020-01-25 17:38:22 +01:00
|
|
|
#include <villas/nodes/ethercat_config.hpp>
|
2020-01-20 14:03:49 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
#define DEFAULT_ETHERCAT_QUEUE_LENGTH (DEFAULT_QUEUE_LENGTH * 64)
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2024-10-16 21:23:14 +02:00
|
|
|
namespace villas::node {
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class NodeCompat;
|
|
|
|
class SuperNode;
|
|
|
|
|
2018-10-23 14:22:35 +02:00
|
|
|
// Internal data per ethercat node
|
|
|
|
struct ethercat {
|
2023-09-07 11:46:39 +02:00
|
|
|
// Settings
|
|
|
|
double rate;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
unsigned num_channels;
|
|
|
|
double range;
|
|
|
|
unsigned position;
|
|
|
|
unsigned product_code; // Product ID of EtherCAT slave
|
|
|
|
unsigned vendor_id; // Vendor ID of EtherCAT slave
|
|
|
|
|
|
|
|
ec_slave_config_t *sc;
|
|
|
|
unsigned *offsets; // Offsets for PDO entries
|
|
|
|
} in, out;
|
|
|
|
|
|
|
|
ec_domain_t *domain;
|
|
|
|
ec_pdo_entry_reg_t *domain_regs;
|
|
|
|
uint8_t *domain_pd; // Process data
|
|
|
|
|
|
|
|
std::thread thread; // Cyclic task thread
|
|
|
|
struct Task task; // Periodic timer
|
|
|
|
struct Pool pool;
|
|
|
|
struct CQueueSignalled
|
|
|
|
queue; // For samples which are received from WebSockets
|
|
|
|
|
|
|
|
std::atomic<struct Sample *> send; // Last sample to be sent via EtherCAT
|
2018-10-23 14:22:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Internal datastructures
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_type_start(SuperNode *sn);
|
2018-10-23 14:22:35 +02:00
|
|
|
|
|
|
|
int ethercat_type_stop();
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_init(NodeCompat *n);
|
|
|
|
|
|
|
|
int ethercat_destroy(NodeCompat *n);
|
|
|
|
|
|
|
|
int ethercat_parse(NodeCompat *n, json_t *json);
|
2020-01-25 17:38:22 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_check(NodeCompat *n);
|
2020-01-25 17:38:22 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_prepare(NodeCompat *n);
|
2020-01-25 17:38:22 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_start(NodeCompat *n);
|
2020-01-25 17:38:22 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_stop(NodeCompat *n);
|
2020-01-25 17:38:22 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_poll_fds(NodeCompat *n, int fds[]);
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
char *ethercat_print(NodeCompat *n);
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int ethercat_read(NodeCompat *n, struct Sample *const smps[], unsigned cnt);
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int ethercat_write(NodeCompat *n, struct Sample *const smps[], unsigned cnt);
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2024-10-16 21:23:14 +02:00
|
|
|
} // namespace villas::node
|