hi,
I am new to ethercat. and got a "TI AM3359 Industrial Communications
Engine" board.
I tested in Windows with twincat, refer to http://www.ti.com/am335x_twincat.
and it cat turn on the led by I wrote value to RxPDO.
I want to use the TI board as slave with the Etherlab master in linux
environment.
First step I want to turn on the led of board.
I wrote a C Code as attachment to do so, but it don't work.
And Ethercat master shows message below
Jun 13 09:08:26 debian kernel: [ 3115.056686] EtherCAT: Requesting master
0...
Jun 13 09:08:26 debian kernel: [ 3115.056691] EtherCAT: Successfully
requested master 0.
Jun 13 09:08:26 debian kernel: [ 3115.056745] EtherCAT 0: Domain0: Logical
address 0x00000000, 4 byte, expected working counter 1.
Jun 13 09:08:26 debian kernel: [ 3115.056749] EtherCAT 0: Datagram
domain0-0: Logical offset 0x00000000, 4 byte, type LWR.
Jun 13 09:08:26 debian kernel: [ 3115.056818] EtherCAT 0: Master thread
exited.
Jun 13 09:08:26 debian kernel: [ 3115.056824] EtherCAT 0: Starting
EtherCAT-OP thread.
Jun 13 09:08:26 debian kernel: [ 3115.056941] EtherCAT WARNING 0: 1
datagram UNMATCHED!
Jun 13 09:08:26 debian kernel: [ 3115.061796] EtherCAT WARNING 0: No
app_time received up to now, but master already active.
Jun 13 09:08:27 debian kernel: [ 3115.289453] EtherCAT 0: Slave states: OP.
I don't knwo what the problem is. Is anybody help me?
slaves information as below.
root@debian:/opt/etherlab/bin# sudo ./ethercat slaves -v
=== Master 0, Slave 0 ===
State: PREOP
Flag: +
Identity:
Vendor Id: 0xe000059d
Product code: 0x54490001
Revision number: 0x00000001
Serial number: 0x00000000
DL information:
FMMU bit operation: no
Distributed clocks: no
Port Type Link Loop Signal NextSlave
0 MII up open yes -
1 MII down closed no -
2 N/A down closed no -
3 N/A down closed no -
Mailboxes:
Bootstrap RX: 0x0000/0, TX: 0x0000/0
Standard RX: 0x1000/128, TX: 0x1400/128
Supported protocols: CoE
General:
Group: Ti Slave
Image name:
Order number: TIESC-001
Device name: TIESC-001
CoE details:
Enable SDO: yes
Enable SDO Info: yes
Enable PDO Assign: no
Enable PDO Configuration: no
Enable Upload at startup: no
Enable SDO complete access: yes
Flags:
Enable SafeOp: no
Enable notLRW: yes
Current consumption: 0 mA
root@debian:/opt/etherlab/bin#
root@debian:/opt/etherlab/bin# sudo ./ethercat pdos
SM0: PhysAddr 0x1000, DefaultSize 128, ControlRegister 0x26, Enable 1
SM1: PhysAddr 0x1400, DefaultSize 128, ControlRegister 0x22, Enable 1
SM2: PhysAddr 0x1800, DefaultSize 4, ControlRegister 0x64, Enable 1
RxPDO 0x1601 "RxPDO-Map"
PDO entry 0x7010:00, 32 bit, "SubIndex 000"
SM3: PhysAddr 0x1c00, DefaultSize 4, ControlRegister 0x20, Enable 1
TxPDO 0x1a00 "TxPDO-Map"
PDO entry 0x6000:00, 32 bit, "SubIndex 000"
root@debian:/opt/etherlab/bin#
/*****************************************************************************
*
* $Id: main.c,v 60a116ed3897 2009/07/27 10:44:16 fp $
*
* Copyright (C) 2007-2009 Florian Pose, Ingenieurgemeinschaft IgH
*
* This file is part of the IgH EtherCAT Master.
*
* The IgH EtherCAT Master is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* The IgH EtherCAT Master is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the IgH EtherCAT Master; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* ---
*
* The license mentioned above concerns the source code only. Using the
* EtherCAT technology and brand is only permitted in compliance with the
* industrial property and similar rights of Beckhoff Automation GmbH.
*
****************************************************************************/
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
/****************************************************************************/
#include "ecrt.h"
/****************************************************************************/
// Application parameters
#define FREQUENCY 100
#define PRIORITY 1
// Optional features
#define CONFIGURE_PDOS 1
/****************************************************************************/
// EtherCAT
static ec_master_t *master = NULL;
static ec_master_state_t master_state = {};
static ec_domain_t *domain1 = NULL;
static ec_domain_state_t domain1_state = {};
static ec_slave_config_t *sc_ana_in = NULL;
static ec_slave_config_state_t sc_ana_in_state = {};
// Timer
static unsigned int sig_alarms = 0;
static unsigned int user_alarms = 0;
/****************************************************************************/
// process data
static uint8_t *domain1_pd = NULL;
#define BusCouplerPos 0, 0
#define TI_AM3359ICE 0xe000059d, 0x54490001
// offsets for PDO entries
static unsigned int off_dig_out2;
static unsigned int counter = 0;
static unsigned int blink = 0;
/*****************************************************************************/
#if CONFIGURE_PDOS
/* Master 0, Slave 0, "TIESC-001"
* Vendor ID: 0xe000059d
* Product code: 0x54490001
* Revision number: 0x00000001
*/
ec_pdo_entry_info_t slave_0_pdo_entries[] = {
{0x7010, 0x00, 32}, /* SubIndex 000 */
{0x6000, 0x00, 32}, /* SubIndex 000 */
};
ec_pdo_info_t slave_0_pdos[] = {
{0x1601, 1, slave_0_pdo_entries + 0}, /* RxPDO-Map */
{0x1a00, 1, slave_0_pdo_entries + 1}, /* TxPDO-Map */
};
ec_sync_info_t slave_0_syncs[] = {
{0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
{1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},
{2, EC_DIR_OUTPUT, 1, slave_0_pdos + 0, EC_WD_ENABLE},
{3, EC_DIR_INPUT, 1, slave_0_pdos + 1, EC_WD_DISABLE},
{0xff}
};
#endif
/*****************************************************************************/
void check_domain1_state(void)
{
ec_domain_state_t ds;
ecrt_domain_state(domain1, &ds);
if (ds.working_counter != domain1_state.working_counter)
printf("Domain1: WC %u.\n", ds.working_counter);
if (ds.wc_state != domain1_state.wc_state)
printf("Domain1: State %u.\n", ds.wc_state);
domain1_state = ds;
}
/*****************************************************************************/
void check_master_state(void)
{
ec_master_state_t ms;
ecrt_master_state(master, &ms);
if (ms.slaves_responding != master_state.slaves_responding)
printf("%u slave(s).\n", ms.slaves_responding);
if (ms.al_states != master_state.al_states)
printf("AL states: 0x%02X.\n", ms.al_states);
if (ms.link_up != master_state.link_up)
printf("Link is %s.\n", ms.link_up ? "up" : "down");
master_state = ms;
}
/****************************************************************************/
void cyclic_task()
{
int i;
// receive process data
ecrt_master_receive(master);
ecrt_domain_process(domain1);
// check process data state (optional)
check_domain1_state();
if (counter) {
counter--;
} else { // do this at 1 Hz
counter = FREQUENCY;
// calculate new process data
blink = !blink;
// check for master state (optional)
check_master_state();
}
#if 0
// read process data
printf("AnaIn: value %u\n", EC_READ_U32(domain1_pd + off_dig_out2));
#endif
#if 1
// write process data
EC_WRITE_U32(domain1_pd + off_dig_out2, blink ? 0xffffff:0x000000);
#endif
// send process data
ecrt_domain_queue(domain1);
ecrt_master_send(master);
}
/****************************************************************************/
void signal_handler(int signum) {
switch (signum) {
case SIGALRM:
sig_alarms++;
break;
}
}
/****************************************************************************/
int main(int argc, char **argv)
{
ec_slave_config_t *sc;
struct sigaction sa;
struct itimerval tv;
master = ecrt_request_master(0);
if (!master)
return -1;
domain1 = ecrt_master_create_domain(master);
if (!domain1)
return -1;
sc = ecrt_master_slave_config(master, BusCouplerPos, TI_AM3359ICE);
if (!sc) {
fprintf(stderr, "Failed to get slave configuration.\n");
return -1;
}
#if CONFIGURE_PDOS
printf("Configuring PDOs...\n");
off_dig_out2 = ecrt_slave_config_reg_pdo_entry(sc,
0x7010, 0, domain1, NULL);
if (off_dig_out2 < 0)
return -1;
#endif
printf("Activating master...\n");
if (ecrt_master_activate(master))
return -1;
if (!(domain1_pd = ecrt_domain_data(domain1))) {
return -1;
}
sa.sa_handler = signal_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
if (sigaction(SIGALRM, &sa, 0)) {
fprintf(stderr, "Failed to install signal handler!\n");
return -1;
}
#if 1
printf("Starting timer...\n");
tv.it_interval.tv_sec = 0;
tv.it_interval.tv_usec = 1000000 / FREQUENCY;
tv.it_value.tv_sec = 0;
tv.it_value.tv_usec = 1000;
if (setitimer(ITIMER_REAL, &tv, NULL)) {
fprintf(stderr, "Failed to start timer: %s\n", strerror(errno));
return 1;
}
#endif
printf("Started.\n");
while (1) {
pause();
#if 0
struct timeval t;
gettimeofday(&t, NULL);
printf("%u.%06u\n", t.tv_sec, t.tv_usec);
#endif
while (sig_alarms != user_alarms) {
cyclic_task();
user_alarms++;
}
}
return 0;
}
/****************************************************************************/
_______________________________________________
etherlab-users mailing list
[email protected]
http://lists.etherlab.org/mailman/listinfo/etherlab-users