2018-10-23 14:22:35 +02:00
|
|
|
/** Node type: ethercat
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @author Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
2022-12-14 17:41:58 +01:00
|
|
|
* @author Steffen Vogel <post@steffenvogel.de>
|
2020-01-25 17:38:22 +01:00
|
|
|
* @author Divya Laxetti <divya.laxetti@rwth-aachen.de>
|
|
|
|
* @copyright 2018-2020, Institute for Automation of Complex Power Systems, EONERC
|
2022-07-04 18:20:03 +02:00
|
|
|
* @license Apache 2.0
|
2018-10-23 14:22:35 +02:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-01-25 17:38:22 +01:00
|
|
|
#include <thread>
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/pool.hpp>
|
2020-03-04 13:06:28 +01:00
|
|
|
#include <villas/task.hpp>
|
2018-10-23 14:22:35 +02:00
|
|
|
#include <villas/queue_signalled.h>
|
2020-03-04 12:41:55 +01:00
|
|
|
#include <villas/common.hpp>
|
2021-05-10 00:12:30 +02:00
|
|
|
#include <villas/format.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/config.hpp>
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2021-06-21 16:11:42 -04:00
|
|
|
/* Forward declarations */
|
2021-08-10 10:12:48 -04:00
|
|
|
class NodeCompat;
|
|
|
|
class SuperNode;
|
2021-06-21 16:11:42 -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
|
|
|
|
2018-10-23 14:22:35 +02:00
|
|
|
extern "C" {
|
2021-02-19 06:38:38 +01:00
|
|
|
#include <ecrt.h>
|
|
|
|
}
|
2020-01-20 14:03:49 +01:00
|
|
|
|
2018-10-23 14:22:35 +02:00
|
|
|
#define DEFAULT_ETHERCAT_QUEUE_LENGTH (DEFAULT_QUEUE_LENGTH * 64)
|
|
|
|
|
|
|
|
/** Internal data per ethercat node */
|
|
|
|
struct ethercat {
|
2020-01-20 14:03:49 +01:00
|
|
|
/* Settings */
|
2020-01-25 17:38:22 +01:00
|
|
|
double rate;
|
|
|
|
|
2020-01-20 14:03:49 +01:00
|
|
|
struct {
|
2020-01-25 17:38:22 +01:00
|
|
|
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 */
|
2020-01-20 14:03:49 +01:00
|
|
|
} in, out;
|
|
|
|
|
2020-01-25 17:38:22 +01:00
|
|
|
ec_domain_t *domain;
|
|
|
|
ec_pdo_entry_reg_t *domain_regs;
|
|
|
|
uint8_t *domain_pd; /**< Process data */
|
2020-01-20 14:03:49 +01:00
|
|
|
|
2020-01-25 17:38:22 +01:00
|
|
|
std::thread thread; /**< Cyclic task thread */
|
2020-03-04 13:06:28 +01:00
|
|
|
struct Task task; /**< Periodic timer */
|
2021-08-10 10:12:48 -04:00
|
|
|
struct Pool pool;
|
|
|
|
struct CQueueSignalled queue; /**< For samples which are received from WebSockets */
|
2020-01-20 14:03:49 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
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
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
char * ethercat_print(NodeCompat *n);
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_read(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int ethercat_write(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
|
2018-10-23 14:22:35 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
} /* namespace node */
|
|
|
|
} /* namespace villas */
|