Commit 6b59f087 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Remove globals from ethercat code.

Allow multiple ethercat busses to exist.
NOT TESTED YET!
parent 870e7d47
......@@ -41,6 +41,11 @@ struct controller_mem_chunk {
bool used;
};
static struct controller_mem_chunk *new_chunk(void)
{
return calloc(1, sizeof(struct controller_mem_chunk));
}
static struct controller_mem_block *blocks;
static struct controller_mem_block *add_block(void)
......@@ -55,7 +60,7 @@ static struct controller_mem_block *add_block(void)
if (!block->base)
goto err_base;
block->chunks = calloc(1, sizeof(struct controller_mem_chunk));
block->chunks = new_chunk();
if (!block->chunks)
goto err_chunk;
block->chunks->len = BLOCK_SIZE;
......@@ -72,11 +77,6 @@ err_block:
return NULL;
}
static struct controller_mem_chunk *new_chunk(void)
{
return calloc(1, sizeof(struct controller_mem_chunk));
}
void *controller_mem_calloc(int flags, size_t nmemb, size_t size)
{
char *ptr = NULL;
......
......@@ -23,6 +23,8 @@
#include <controller/controller_block.h>
#include <controller/controller_bus.h>
#include <controller/controller_sample.h>
#include <controller/controller_time.h>
#include <ec/block_ec.h>
#include <ec/ec.h>
......@@ -32,17 +34,21 @@
struct controller_block_private {
bool pdo_data;
bool operational;
struct ec *ec;
struct controller_bus *bus;
};
static void calculate(struct controller_block *ec)
{
if (ec_rx_pdo()) {
struct controller_bus *bus = ec->private->bus;
if (ec_rx_pdo(ec->private->ec)) {
ec->private->pdo_data = false;
} else {
ec->private->pdo_data = true;
}
if (ec_bus->state != CONTROLLER_BUS_STATE_OK)
if (bus->state != CONTROLLER_BUS_STATE_OK)
ec->private->operational = false;
else
ec->private->operational = true;
......@@ -50,24 +56,9 @@ static void calculate(struct controller_block *ec)
static void calculate_tx(struct controller_block *ec)
{
ec_tx_pdo();
}
static int param_set(struct controller_block *ec, char *param, int argc,
va_list val)
{
int enabled = va_arg(val, int);
ec_rx_pdo_enable(enabled);
ec_tx_pdo_enable(enabled);
return 0;
ec_tx_pdo(ec->private->ec);
}
static struct controller_block_param_list params[] = {
{ "pdo_enabled", true, param_set, .args = { "int", NULL } },
{ NULL },
};
static struct controller_block_outterm_list outterms[] = {
{ "pdo_data", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, pdo_data) },
{ "operational", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, operational) },
......@@ -82,32 +73,62 @@ static enum controller_bus_state ec_poll(struct controller_bus *bus)
return CONTROLLER_BUS_STATE_ERROR;
}
static void ec_sample_init(void *arg)
{
struct ec_dgram_addr addr;
size_t len;
unsigned char *pdo_tx, *pdo_rx;
int i;
struct controller_bus *bus = arg;
double timeout_sec;
len = bus->private->logical_rx - EC_LOGICAL_RX_START;
if (len) {
addr.type = EC_DGRAM_ADDR_LOGICAL;
addr.addr.logical.addr = EC_LOGICAL_RX_START;
ec_rx_pdo_add(bus->private->ec, &addr, &pdo_rx, len);
for (i = 0; i < bus->input_clients; i++) {
unsigned char *pdo_ic;
pdo_ic = pdo_rx + bus->input_client[i].offset;
bus->input_client[i].callback(
bus->input_client[i].block, pdo_ic);
}
}
len = bus->private->logical_tx - EC_LOGICAL_TX_START;
if (len) {
addr.type = EC_DGRAM_ADDR_LOGICAL;
addr.addr.logical.addr = EC_LOGICAL_TX_START;
ec_tx_pdo_add(bus->private->ec, &addr, &pdo_tx, len);
for (i = 0; i < bus->output_clients; i++) {
unsigned char *pdo_oc;
pdo_oc = pdo_tx + bus->output_client[i].offset;
bus->output_client[i].callback(
bus->output_client[i].block, pdo_oc);
}
}
timeout_sec = controller_time_period_get(bus->owner->time) * 200;
ec_timeout_set(bus->private->ec, timeout_sec);
}
static struct controller_block * block_ec_create(char *name, int argc, va_list ap)
{
struct controller_block *ec, *ec_tx;
struct controller_bus *bus;
int ret;
char *ifname;
int nr_slaves;
int single_cycle;
char name_tx[strlen(name)+strlen("_pdo_tx0")];
/* For now we only support a single ethercat interface,
but we allow multiple inits
*/
if (ec_block) {
return ec_block;
}
ifname = va_arg(ap, char *);
nr_slaves = va_arg(ap, int);
single_cycle = va_arg(ap, int);
ret = ec_init(ifname, nr_slaves, single_cycle);
if (ret != 0)
return NULL;
sprintf(name_tx, "%s_pdo_tx", name);
ec = controller_block_alloc("ec", name,
......@@ -125,6 +146,12 @@ static struct controller_block * block_ec_create(char *name, int argc, va_list a
sizeof(struct controller_bus_private));
if (!bus)
goto err_bus;
ec->private->bus = bus;
bus->private->ec = ec_init(ifname, nr_slaves, single_cycle);
if (!bus->private->ec)
goto err_init;
ec->private->ec = bus->private->ec;
controller_bus_output_set(bus, ec_tx);
......@@ -137,23 +164,19 @@ static struct controller_block * block_ec_create(char *name, int argc, va_list a
ec->calculate = calculate;
ec_tx->calculate = calculate_tx;
if (controller_block_param_list_add(ec, params))
goto err_params;
if (controller_block_add(ec))
goto err_add;
if (controller_block_add(ec_tx))
goto err_add;
ec_block = ec;
ec_bus = bus;
controller_sample_start_hook(ec_sample_init, bus);
controller_bus_poll_set(bus, ec_poll, NULL);
return ec;
err_add:
err_params:
err_init:
free(bus);
err_bus:
free(ec_tx);
......
......@@ -29,9 +29,8 @@
struct controller_bus_private {
size_t logical_rx;
size_t logical_tx;
struct ec *ec;
};
struct controller_block *ec_block;
struct controller_bus *ec_bus;
#endif /* _INCLUDE_BLOCK_EC_ */
This diff is collapsed.
......@@ -36,11 +36,10 @@
#include <ec/canopen.h>
int ec_init(char *ifname, int nr_slaves, bool single_cycle);
bool ec_initialized(void);
struct ec *ec_init(char *ifname, int nr_slaves, bool single_cycle);
int ec_slave_count(void);
int ec_slave_dc_count(void);
int ec_slave_count(struct ec *ec);
int ec_slave_dc_count(struct ec *ec);
struct ec_dgram_addr {
enum {
......@@ -71,20 +70,14 @@ do { \
} while (0)
ssize_t ec_datagram_read(struct ec_dgram_addr *addr, void *buffer, size_t len);
ssize_t ec_datagram_write(struct ec_dgram_addr *addr, void *buffer, size_t len);
ssize_t ec_datagram_read(struct ec*, struct ec_dgram_addr *addr, void *buffer, size_t len);
ssize_t ec_datagram_write(struct ec*, struct ec_dgram_addr *addr, void *buffer, size_t len);
int ec_rx_pdo_add(struct ec_dgram_addr *addr, unsigned char **data, size_t len);
int ec_tx_pdo_add(struct ec_dgram_addr *addr, unsigned char **data, size_t len);
int ec_tx_pdo(void);
int ec_rx_pdo(void);
int ec_rx_pdo_add(struct ec *ec, struct ec_dgram_addr *addr, unsigned char **data, size_t len);
int ec_tx_pdo_add(struct ec *ec, struct ec_dgram_addr *addr, unsigned char **data, size_t len);
int ec_tx_pdo(struct ec *ec);
int ec_rx_pdo(struct ec *ec);
int ec_rx_pdo_enable(int enable);
int ec_tx_pdo_enable(int enable);
int ec_rx_pdo_enable_hook_attach(int (*hook)(void *arg), void *arg);
int ec_tx_pdo_enable_hook_attach(int (*hook)(void *arg), void *arg);
int ec_rx_pdo_disable_hook_attach(int (*hook)(void *arg), void *arg);
int ec_tx_pdo_disable_hook_attach(int (*hook)(void *arg), void *arg);
void ec_timeout_set(struct ec *ec, double timeout_sec);
#endif /* _INCLUDE_EC_H_ */
......@@ -32,7 +32,7 @@
#include <ec/esc_id.h>
#include <log/log.h>
void describe_esc(struct ec_dgram_addr *ec_addr)
void describe_esc(struct ec *ec, struct ec_dgram_addr *ec_addr)
{
int r, r2;
uint8_t val8;
......@@ -46,10 +46,10 @@ void describe_esc(struct ec_dgram_addr *ec_addr)
struct esc_device *dev;
struct esc_esi_category *cat;
dev = esc_device_create2(ec_addr, "ec_enum");
dev = esc_device_create2(ec, ec_addr, "ec_enum");
ec_addr->addr.position.off = ESC_ADDR_MAP_TYPE;
r = ec_datagram_read(ec_addr, &val8, 1);
r = ec_datagram_read(ec, ec_addr, &val8, 1);
if (r == 1) {
char *type;
switch (val8) {
......@@ -72,38 +72,38 @@ void describe_esc(struct ec_dgram_addr *ec_addr)
}
ec_addr->addr.position.off = ESC_ADDR_MAP_REVISION;
r = ec_datagram_read(ec_addr, &val8, 1);
r = ec_datagram_read(ec, ec_addr, &val8, 1);
ec_addr->addr.position.off = ESC_ADDR_MAP_BUILD;
r2 = ec_datagram_read(ec_addr, &val16, 2);
r2 = ec_datagram_read(ec, ec_addr, &val16, 2);
if (r == 1 && r2 == 2) {
printf("\tRevision & Build: 0x%02x 0x%04x\n", val8, le16toh(val16));
}
ec_addr->addr.position.off = ESC_ADDR_MAP_FMMUS_SUPPORTED;
r = ec_datagram_read(ec_addr, &val8, 1);
r = ec_datagram_read(ec, ec_addr, &val8, 1);
if (r == 1) {
printf("\tFMMUs supported: %d\n", val8);
}
ec_addr->addr.position.off = ESC_ADDR_MAP_SYNCMANAGERS_SUPPORTED;
r = ec_datagram_read(ec_addr, &val8, 1);
r = ec_datagram_read(ec, ec_addr, &val8, 1);
if (r == 1) {
printf("\tSyncmanagers supported: %d\n", val8);
}
ec_addr->addr.position.off = ESC_ADDR_MAP_RAM_SIZE;
r = ec_datagram_read(ec_addr, &val8, 1);
r = ec_datagram_read(ec, ec_addr, &val8, 1);
if (r == 1) {
printf("\tRAM size: %d Kb\n", val8);
}
ec_addr->addr.position.off = ESC_ADDR_MAP_FEATURES;
r = ec_datagram_read(ec_addr, &val16, 2);
r = ec_datagram_read(ec, ec_addr, &val16, 2);
if (r == 2) {
val16 = le16toh(val16);
......@@ -127,7 +127,7 @@ void describe_esc(struct ec_dgram_addr *ec_addr)
}
ec_addr->addr.position.off = ESC_ADDR_MAP_SYNC_LATCH_PDI_CONFIG;
r = ec_datagram_read(ec_addr, &val8, 1);
r = ec_datagram_read(ec, ec_addr, &val8, 1);
if (r == 1) {
printf("\tSync/Latch PDI config: 0x%02x\n", val8);
......@@ -153,33 +153,33 @@ void describe_esc(struct ec_dgram_addr *ec_addr)
printf("\tESI RevisionNo: 0x%04x\n", esc_esi_revisionno_get(dev));
printf("\tESI SerialNo: 0x%04x\n", esc_esi_serialno_get(dev));
eeprom_size = esc_esi_read16(ec_addr, ESC_ESI_ADDR_SIZE);
eeprom_size = esc_esi_read16(ec, ec_addr, ESC_ESI_ADDR_SIZE);
printf("\tESI Size: 0x%08zx\n", eeprom_size);
eeprom_version = esc_esi_read16(ec_addr, ESC_ESI_ADDR_VERSION);
eeprom_version = esc_esi_read16(ec, ec_addr, ESC_ESI_ADDR_VERSION);
printf("\tESI Version: 0x%08x\n", eeprom_version);
val16 = esc_esi_read16(ec_addr, ESC_ESI_BOOTSTRAP_RX_MAILBOX_OFFSET);
val16 = esc_esi_read16(ec, ec_addr, ESC_ESI_BOOTSTRAP_RX_MAILBOX_OFFSET);
printf("\tESI Bootstrap RX mailbox offset: 0x%04x\n", val16);
val16 = esc_esi_read16(ec_addr, ESC_ESI_BOOTSTRAP_RX_MAILBOX_SIZE);
val16 = esc_esi_read16(ec, ec_addr, ESC_ESI_BOOTSTRAP_RX_MAILBOX_SIZE);
printf("\tESI Bootstrap RX mailbox size: 0x%04x\n", val16);
val16 = esc_esi_read16(ec_addr, ESC_ESI_BOOTSTRAP_TX_MAILBOX_OFFSET);
val16 = esc_esi_read16(ec, ec_addr, ESC_ESI_BOOTSTRAP_TX_MAILBOX_OFFSET);
printf("\tESI Bootstrap TX mailbox offset: 0x%04x\n", val16);
val16 = esc_esi_read16(ec_addr, ESC_ESI_BOOTSTRAP_TX_MAILBOX_SIZE);
val16 = esc_esi_read16(ec, ec_addr, ESC_ESI_BOOTSTRAP_TX_MAILBOX_SIZE);
printf("\tESI Bootstrap TX mailbox size: 0x%04x\n", val16);
printf("\tESI Standard RX mailbox offset: 0x%04zx\n",
esc_esi_standard_rx_mailbox_offset_get(ec_addr));
esc_esi_standard_rx_mailbox_offset_get(ec, ec_addr));
printf("\tESI Standard RX mailbox size: 0x%04zx\n",
esc_esi_standard_rx_mailbox_size_get(ec_addr));
esc_esi_standard_rx_mailbox_size_get(ec, ec_addr));
printf("\tESI Standard TX mailbox offset: 0x%04zx\n",
esc_esi_standard_tx_mailbox_offset_get(ec_addr));
esc_esi_standard_tx_mailbox_offset_get(ec, ec_addr));
printf("\tESI Standard TX mailbox size: 0x%04zx\n",
esc_esi_standard_rx_mailbox_size_get(ec_addr));
esc_esi_standard_rx_mailbox_size_get(ec, ec_addr));
val16 = esc_esi_read16(ec_addr, ESC_ESI_MAILBOX_PROTOCOL);
val16 = esc_esi_read16(ec, ec_addr, ESC_ESI_MAILBOX_PROTOCOL);
printf("\tESI Mailbox Protocol: 0x%04x\n", val16);
r = esc_esi_eeprom_read(ec_addr, &eeprom, 0, sizeof(eeprom));
r = esc_esi_eeprom_read(ec, ec_addr, &eeprom, 0, sizeof(eeprom));
if (r == sizeof(eeprom)) {
printf("\tESI EEPROM:\n");
for (i = 0; i < sizeof(eeprom)/sizeof(*eeprom); i += 16) {
......@@ -281,18 +281,19 @@ int main(int argc, char **argv)
{
int slaves;
int i;
struct ec *ec;
if (argc < 2) {
printf("Usage: %s [ethernet device]\n", argv[0]);
return -1;
}
if (ec_init(argv[1], 0, 0)) {
if (!(ec = ec_init(argv[1], 0, 0))) {
printf("EtherCat init failed\n");
return -1;
}
slaves = ec_slave_count();
slaves = ec_slave_count(ec);
printf("Number of slaves found: %d\n", slaves);
......@@ -304,7 +305,7 @@ int main(int argc, char **argv)
ec_addr_set_auto_inc_nr(&ec_addr, i);
describe_esc(&ec_addr);
describe_esc(ec, &ec_addr);
}
return 0;
......
......@@ -65,12 +65,12 @@ enum esc_al_state esc_al_state_get(struct esc_device *esc)
memcpy(&state_add, &esc->addr, sizeof(state_add));
state_add.addr.position.off = ESC_ADDR_MAP_AL_STATUS;
ret = ec_datagram_read(&state_add, &state, 2);
ret = ec_datagram_read(esc->ec, &state_add, &state, 2);
if (ret == 2)
return le16toh(state) & 0x000f;
ret = ec_datagram_read(&state_add, &state, 2);
ret = ec_datagram_read(esc->ec, &state_add, &state, 2);
if (ret == 2) {
return le16toh(state) & 0x000f;
......@@ -92,7 +92,7 @@ int esc_al_state_set(struct esc_device *esc, enum esc_al_state newstate,
state = htole16(newstate);
clock_gettime(CLOCK_MONOTONIC, &t_start);
do {
ret = ec_datagram_write(&state_add, &state, sizeof(uint16_t));
ret = ec_datagram_write(esc->ec, &state_add, &state, sizeof(uint16_t));
} while (ret == 0 && !esc_timeout_expired(&t_start, timeout));
if (ret == 2) {
......@@ -143,13 +143,13 @@ enum esc_al_status esc_al_status_code_get(struct esc_device *esc)
memcpy(&state_add, &esc->addr, sizeof(state_add));
state_add.addr.position.off = ESC_ADDR_MAP_AL_STATUS;
ret = ec_datagram_read(&state_add, &state, 2);
ret = ec_datagram_read(esc->ec, &state_add, &state, 2);
if (ret != 2)
goto err_get_state;
if (le16toh(state) & ESC_ADDR_MAP_AL_STATUS_ERR_IND) {
state_add.addr.position.off = ESC_ADDR_MAP_AL_STATUS_CODE;
ret = ec_datagram_read(&state_add, &state, 2);
ret = ec_datagram_read(esc->ec, &state_add, &state, 2);
state = le16toh(state);
} else {
state = ESC_AL_STATUS_NO_ERROR;
......@@ -180,7 +180,7 @@ int esc_al_error_ack(struct esc_device *esc)
state_add.addr.position.off = ESC_ADDR_MAP_AL_CONTROL;
ctrl |= htole16(ESC_ADDR_MAP_AL_CONTROL_ERROR_ACK);
ret = ec_datagram_write(&state_add, &ctrl, 2);
ret = ec_datagram_write(esc->ec, &state_add, &ctrl, 2);
if (ret == 2)
return 0;
......@@ -201,7 +201,7 @@ int esc_init(struct esc_device *esc)
log_send(LOG_T_ERROR, "Could not go to state init");
addr.addr.position.off = ESC_ADDR_MAP_SYNCMANAGERS_SUPPORTED;
ret = ec_datagram_read(&addr, &nr_syncmgr, 1);
ret = ec_datagram_read(esc->ec, &addr, &nr_syncmgr, 1);
if (ret != 1) {
log_send(LOG_T_ERROR, "Could not read ESC information");
return -1;
......@@ -217,7 +217,7 @@ int esc_init(struct esc_device *esc)
addr.addr.position.off = off | ESC_ADDR_MAP_SYNCMANAGER_ACTIVATE;
val8 = 0;
ret = ec_datagram_write(&addr, &val8, 1);
ret = ec_datagram_write(esc->ec, &addr, &val8, 1);
if (ret != 1) {
log_send(LOG_T_ERROR,
"Could not deactivate sync manager %d", i);
......@@ -226,7 +226,7 @@ int esc_init(struct esc_device *esc)
val16 = 0;
addr.addr.position.off = off | ESC_ADDR_MAP_SYNCMANAGER_LENGTH;
ec_datagram_write(&addr, &val16, 2);
ec_datagram_write(esc->ec, &addr, &val16, 2);
}
log_send(LOG_T_DEBUG, "ACK any errors");
......
......@@ -30,7 +30,7 @@
#define ESC_DC_INIT_LOOPCOUNT 100
int esc_dc_init_system_time(struct ec_dgram_addr *addr)
int esc_dc_init_system_time(struct ec *ec, struct ec_dgram_addr *addr)
{
struct timespec t;
uint64_t leval64, local_time;
......@@ -41,18 +41,18 @@ int esc_dc_init_system_time(struct ec_dgram_addr *addr)
int i;
addr->addr.position.off = ESC_ADDR_MAP_DC_SYSTEM_TIME_OFFSET;
ec_datagram_read(addr, &leval64, 8);
ec_datagram_read(ec, addr, &leval64, 8);
log_send(LOG_T_DEBUG, "\told DC system time offset: %"PRId64,
le64toh(leval64));
/* reset offset */
leval64 = 0;
addr->addr.position.off = ESC_ADDR_MAP_DC_SYSTEM_TIME_OFFSET;
ec_datagram_write(addr, &leval64, 8);
ec_datagram_write(ec, addr, &leval64, 8);
/* Read system time without offset (= local_time @ slave) */
addr->addr.position.off = ESC_ADDR_MAP_DC_SYSTEM_TIME;
ec_datagram_read(addr, &leval64, 8);
ec_datagram_read(ec, addr, &leval64, 8);
local_time = le64toh(leval64);
/* Write new time offset to device */
......@@ -63,7 +63,7 @@ int esc_dc_init_system_time(struct ec_dgram_addr *addr)
local_time;
leval64 = htole64(offset);
addr->addr.position.off = ESC_ADDR_MAP_DC_SYSTEM_TIME_OFFSET;
ec_datagram_write(addr, &leval64, 8);
ec_datagram_write(ec, addr, &leval64, 8);
log_send(LOG_T_DEBUG, "\tDC local time: %"PRIu64,
local_time);
......@@ -77,12 +77,12 @@ int esc_dc_init_system_time(struct ec_dgram_addr *addr)
(ESC_DC_EPOCH + (int64_t)t.tv_sec) * 1000*1000*1000 +
(int64_t)t.tv_nsec);
addr->addr.position.off = ESC_ADDR_MAP_DC_SYSTEM_TIME;
ec_datagram_write(addr, &leval64, 8);
ec_datagram_write(ec, addr, &leval64, 8);
}
/* Check system time difference */
addr->addr.position.off = ESC_ADDR_MAP_DC_SYSTEM_TIME_DIFFERENCE;
ec_datagram_read(addr, &leval32, 4);
ec_datagram_read(ec, addr, &leval32, 4);
mean = le32toh(leval32) & ESC_DC_SYSTEM_TIME_DIFFERENCE_MEAN_MASK;
smaller = le32toh(leval32) & ESC_DC_SYSTEM_TIME_DIFFERENCE_SMALLER;
log_send(LOG_T_DEBUG,
......@@ -92,7 +92,7 @@ int esc_dc_init_system_time(struct ec_dgram_addr *addr)
return 0;
}
int esc_dc_init(struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
int esc_dc_init(struct ec *ec, struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
{
uint8_t val8;
uint64_t leval64;
......@@ -105,7 +105,7 @@ int esc_dc_init(struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
log_send(LOG_T_DEBUG, "Configure & initialise DC");
addr->addr.position.off = ESC_ADDR_MAP_FEATURES;
r = ec_datagram_read(addr, &leval16, 2);
r = ec_datagram_read(ec, addr, &leval16, 2);
if (r != 2)
return -1;
......@@ -118,14 +118,14 @@ int esc_dc_init(struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
/* Deactivate any old sync settings */
addr->addr.position.off = ESC_ADDR_MAP_DC_ACTIVATION_REGISTER;
val8 = 0;
ec_datagram_write(addr, &val8, 1);
ec_datagram_write(ec, addr, &val8, 1);
/* initialize the distributed clock */
esc_dc_init_system_time(addr);
esc_dc_init_system_time(ec, addr);
addr->addr.position.off = ESC_ADDR_MAP_DC_PULSE_LENGTH;
r = ec_datagram_read(addr, &leval16, 2);
r = ec_datagram_read(ec, addr, &leval16, 2);
if (r != 2)
return -1;
pulse_length = le16toh(leval16);
......@@ -138,7 +138,7 @@ int esc_dc_init(struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
sync->sync0_cycle, sync->sync0_shift);
addr->addr.position.off = ESC_ADDR_MAP_DC_SYNC0_CYCLE_TIME;
leval32 = htole32(sync->sync0_cycle);
r = ec_datagram_write(addr, &leval32, 4);
r = ec_datagram_write(ec, addr, &leval32, 4);
// TODO: is this always allowed? does positive/negative factor
// mean anything here???
......@@ -146,7 +146,7 @@ int esc_dc_init(struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
pulse_length = 100;
addr->addr.position.off = ESC_ADDR_MAP_DC_PULSE_LENGTH;
leval16 = htole16(pulse_length);
r = ec_datagram_write(addr, &leval16, 2);
r = ec_datagram_write(ec, addr, &leval16, 2);
log_send(LOG_T_DEBUG, "\tSync pulse length: %d ns", pulse_length * 10);
/* start at begin of next second ( + sync0 shift )*/
......@@ -156,7 +156,7 @@ int esc_dc_init(struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
(int64_t)sync->sync0_shift
);
addr->addr.position.off = ESC_ADDR_MAP_DC_START_TIME_CYCLIC_OPERATION;
ec_datagram_write(addr, &leval64, 8);
ec_datagram_write(ec, addr, &leval64, 8);
log_send(LOG_T_DEBUG, "\tSYNC0 start time: %"PRIu64,
le64toh(leval64));
......@@ -166,7 +166,7 @@ int esc_dc_init(struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
sync->sync1_shift);
addr->addr.position.off = ESC_ADDR_MAP_DC_SYNC1_CYCLE_TIME;
leval32 = htole32(sync->sync1_shift);
r = ec_datagram_write(addr, &leval32, 4);
r = ec_datagram_write(ec, addr, &leval32, 4);
}
/* Configure distributed clock */
......@@ -174,7 +174,7 @@ int esc_dc_init(struct ec_dgram_addr *addr, struct esc_dc_sync *sync)
val8 = (