examples/user/main.c
author Florian Pose <fp@igh-essen.com>
Tue, 24 Feb 2009 09:05:46 +0000
changeset 1359 a3d54cccba48
parent 1352 275d2fdeab48
child 1363 11c0b2caa253
permissions -rw-r--r--
Added 8139too for 2.6.26, thanks to M. Luescher.
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
     3
 *  $Id$
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
     4
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
     5
 *  Copyright (C) 2007-2009  Florian Pose, Ingenieurgemeinschaft IgH
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
     6
 *
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    11
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    12
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    16
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    17
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    21
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    22
 *  Using the EtherCAT technology and brand is permitted in compliance with
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1261
diff changeset
    23
 *  the industrial property and similar rights of Beckhoff Automation GmbH.
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 ****************************************************************************/
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
1249
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    27
#include <errno.h>
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    28
#include <signal.h>
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    29
#include <stdio.h>
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    30
#include <string.h>
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    31
#include <sys/resource.h>
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    32
#include <sys/time.h>
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    33
#include <sys/types.h>
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
    34
#include <unistd.h>
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
    35
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    36
/****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    37
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "ecrt.h"
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    40
/****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    41
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    42
// Application parameters
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    43
#define FREQUENCY 100
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    44
#define PRIORITY 1
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    45
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    46
// Optional features
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    47
#define CONFIGURE_PDOS  1
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    48
#define SDO_ACCESS      0
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    49
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    50
/****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    51
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    52
// EtherCAT
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    53
static ec_master_t *master = NULL;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    54
static ec_master_state_t master_state = {};
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    55
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    56
static ec_domain_t *domain1 = NULL;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    57
static ec_domain_state_t domain1_state = {};
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    58
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    59
static ec_slave_config_t *sc_ana_in = NULL;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    60
static ec_slave_config_state_t sc_ana_in_state = {};
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    61
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    62
// Timer
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    63
static unsigned int sig_alarms = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    64
static unsigned int user_alarms = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    65
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    66
/****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    67
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    68
// process data
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    69
static uint8_t *domain1_pd = NULL;
1249
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    70
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    71
#define BusCouplerPos  0, 0
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    72
#define DigOutSlavePos 0, 2
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    73
#define AnaInSlavePos  0, 3
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    74
#define AnaOutSlavePos 0, 4
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    75
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    76
#define Beckhoff_EK1100 0x00000002, 0x044c2c52
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    77
#define Beckhoff_EL2004 0x00000002, 0x07d43052
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    78
#define Beckhoff_EL2032 0x00000002, 0x07f03052
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    79
#define Beckhoff_EL3152 0x00000002, 0x0c503052
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    80
#define Beckhoff_EL3102 0x00000002, 0x0c1e3052
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    81
#define Beckhoff_EL4102 0x00000002, 0x10063052
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    82
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    83
// offsets for PDO entries
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    84
static unsigned int off_ana_in_status;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    85
static unsigned int off_ana_in_value;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    86
static unsigned int off_ana_out;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    87
static unsigned int off_dig_out;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    88
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    89
const static ec_pdo_entry_reg_t domain1_regs[] = {
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    90
    {AnaInSlavePos,  Beckhoff_EL3102, 0x3101, 1, &off_ana_in_status},
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    91
    {AnaInSlavePos,  Beckhoff_EL3102, 0x3101, 2, &off_ana_in_value},
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    92
	{AnaOutSlavePos, Beckhoff_EL4102, 0x3001, 1, &off_ana_out},
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    93
	{DigOutSlavePos, Beckhoff_EL2032, 0x3001, 1, &off_dig_out},
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    94
	{}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    95
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
    96
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    97
static unsigned int counter = 0;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    98
static unsigned int blink = 0;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
    99
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   100
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   101
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   102
#if CONFIGURE_PDOS
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   103
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   104
// Analog in --------------------------
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   105
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   106
static ec_pdo_entry_info_t el3102_pdo_entries[] = {
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   107
    {0x3101, 1,  8}, // channel 1 status
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   108
    {0x3101, 2, 16}, // channel 1 value
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   109
    {0x3102, 1,  8}, // channel 2 status
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   110
    {0x3102, 2, 16}, // channel 2 value
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   111
    {0x6401, 1, 16}, // channel 1 value (alt.)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   112
    {0x6401, 2, 16}  // channel 2 value (alt.)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   113
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   114
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   115
static ec_pdo_info_t el3102_pdos[] = {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   116
    {0x1A00, 2, el3102_pdo_entries},
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   117
    {0x1A01, 2, el3102_pdo_entries + 2}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   118
};
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   119
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   120
static ec_sync_info_t el3102_syncs[] = {
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   121
    {2, EC_DIR_OUTPUT},
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   122
    {3, EC_DIR_INPUT, 2, el3102_pdos},
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   123
    {0xff}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   124
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   125
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   126
// Analog out -------------------------
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   127
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   128
static ec_pdo_entry_info_t el4102_pdo_entries[] = {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   129
    {0x3001, 1, 16}, // channel 1 value
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   130
    {0x3002, 1, 16}, // channel 2 value
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   131
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   132
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   133
static ec_pdo_info_t el4102_pdos[] = {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   134
    {0x1600, 1, el4102_pdo_entries},
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   135
    {0x1601, 1, el4102_pdo_entries + 1}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   136
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   137
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   138
static ec_sync_info_t el4102_syncs[] = {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   139
    {2, EC_DIR_OUTPUT, 2, el4102_pdos},
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   140
    {3, EC_DIR_INPUT},
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   141
    {0xff}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   142
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   143
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   144
// Digital out ------------------------
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   145
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   146
static ec_pdo_entry_info_t el2004_channels[] = {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   147
    {0x3001, 1, 1}, // Value 1
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   148
    {0x3001, 2, 1}, // Value 2
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   149
    {0x3001, 3, 1}, // Value 3
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   150
    {0x3001, 4, 1}  // Value 4
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   151
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   152
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   153
static ec_pdo_info_t el2004_pdos[] = {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   154
    {0x1600, 1, &el2004_channels[0]},
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   155
    {0x1601, 1, &el2004_channels[1]},
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   156
    {0x1602, 1, &el2004_channels[2]},
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   157
    {0x1603, 1, &el2004_channels[3]}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   158
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   159
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   160
static ec_sync_info_t el2004_syncs[] = {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   161
    {0, EC_DIR_OUTPUT, 4, el2004_pdos},
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   162
    {1, EC_DIR_INPUT},
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   163
    {0xff}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   164
};
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   165
#endif
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   166
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   167
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   168
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   169
#if SDO_ACCESS
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   170
static ec_sdo_request_t *sdo;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   171
#endif
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   172
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   173
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   174
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   175
void check_domain1_state(void)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   176
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   177
    ec_domain_state_t ds;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   178
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   179
    ecrt_domain_state(domain1, &ds);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   180
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   181
    if (ds.working_counter != domain1_state.working_counter)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   182
        printf("Domain1: WC %u.\n", ds.working_counter);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   183
    if (ds.wc_state != domain1_state.wc_state)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   184
        printf("Domain1: State %u.\n", ds.wc_state);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   185
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   186
    domain1_state = ds;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   187
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   188
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   189
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   190
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   191
void check_master_state(void)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   192
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   193
    ec_master_state_t ms;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   194
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   195
    ecrt_master_state(master, &ms);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   196
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   197
    if (ms.slaves_responding != master_state.slaves_responding)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   198
        printf("%u slave(s).\n", ms.slaves_responding);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   199
    if (ms.al_states != master_state.al_states)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   200
        printf("AL states: 0x%02X.\n", ms.al_states);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   201
    if (ms.link_up != master_state.link_up)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   202
        printf("Link is %s.\n", ms.link_up ? "up" : "down");
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   203
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   204
    master_state = ms;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   205
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   206
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   207
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   208
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   209
void check_slave_config_states(void)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   210
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   211
    ec_slave_config_state_t s;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   212
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   213
    ecrt_slave_config_state(sc_ana_in, &s);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   214
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   215
    if (s.al_state != sc_ana_in_state.al_state)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   216
        printf("AnaIn: State 0x%02X.\n", s.al_state);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   217
    if (s.online != sc_ana_in_state.online)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   218
        printf("AnaIn: %s.\n", s.online ? "online" : "offline");
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   219
    if (s.operational != sc_ana_in_state.operational)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   220
        printf("AnaIn: %soperational.\n",
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   221
                s.operational ? "" : "Not ");
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   222
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   223
    sc_ana_in_state = s;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   224
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   225
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   226
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   227
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   228
#if SDO_ACCESS
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   229
void read_sdo(void)
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   230
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   231
    switch (ecrt_sdo_request_state(sdo)) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   232
        case EC_REQUEST_UNUSED: // request was not used yet
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   233
            ecrt_sdo_request_read(sdo); // trigger first read
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   234
            break;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   235
        case EC_REQUEST_BUSY:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   236
            fprintf(stderr, "Still busy...\n");
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   237
            break;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   238
        case EC_REQUEST_SUCCESS:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   239
            fprintf(stderr, "SDO value: 0x%04X\n",
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   240
                    EC_READ_U16(ecrt_sdo_request_data(sdo)));
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   241
            ecrt_sdo_request_read(sdo); // trigger next read
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   242
            break;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   243
        case EC_REQUEST_ERROR:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   244
            fprintf(stderr, "Failed to read SDO!\n");
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   245
            ecrt_sdo_request_read(sdo); // retry reading
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   246
            break;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   247
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   248
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   249
#endif
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   250
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   251
/****************************************************************************/
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   252
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   253
void cyclic_task()
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   254
{
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   255
    int i;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   256
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   257
    // receive process data
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   258
    ecrt_master_receive(master);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   259
    ecrt_domain_process(domain1);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   260
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   261
    // check process data state (optional)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   262
    check_domain1_state();
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   263
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   264
    if (counter) {
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   265
        counter--;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   266
    } else { // do this at 1 Hz
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   267
        counter = FREQUENCY;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   268
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   269
        // calculate new process data
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   270
        blink = !blink;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   271
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   272
        // check for master state (optional)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   273
        check_master_state();
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   274
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   275
        // check for islave configuration state(s) (optional)
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   276
        check_slave_config_states();
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   277
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   278
#if SDO_ACCESS
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   279
        // read process data SDO
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   280
        read_sdo();
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   281
#endif
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   282
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   283
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   284
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   285
#if 0
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   286
    // read process data
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   287
    printf("AnaIn: state %u value %u\n",
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   288
            EC_READ_U8(domain1_pd + off_ana_in_status),
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   289
            EC_READ_U16(domain1_pd + off_ana_in_value));
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   290
#endif
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   291
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   292
#if 1
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   293
    // write process data
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   294
    EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   295
#endif
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   296
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   297
    // send process data
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   298
    ecrt_domain_queue(domain1);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   299
    ecrt_master_send(master);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   300
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   301
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   302
/****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   303
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   304
void signal_handler(int signum) {
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   305
    switch (signum) {
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   306
        case SIGALRM:
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   307
            sig_alarms++;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   308
            break;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   309
    }
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   310
}
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   311
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   312
/****************************************************************************/
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   313
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
int main(int argc, char **argv)
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
{
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   316
	ec_slave_config_t *sc;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   317
    struct sigaction sa;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   318
    struct itimerval tv;
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
   319
    
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
   320
    master = ecrt_request_master(0);
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
	if (!master)
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
		return -1;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   324
    domain1 = ecrt_master_create_domain(master);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   325
    if (!domain1)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   326
        return -1;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   327
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   328
    if (!(sc_ana_in = ecrt_master_slave_config(
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   329
                    master, AnaInSlavePos, Beckhoff_EL3102))) {
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   330
        fprintf(stderr, "Failed to get slave configuration.\n");
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   331
        return -1;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   332
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   333
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   334
#if SDO_ACCESS
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   335
    fprintf(stderr, "Creating SDO requests...\n");
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   336
    if (!(sdo = ecrt_slave_config_create_sdo_request(sc_ana_in, 0x3102, 2, 2))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   337
        fprintf(stderr, "Failed to create SDO request.\n");
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   338
        return -1;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   339
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   340
    ecrt_sdo_request_timeout(sdo, 500); // ms
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   341
#endif
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   342
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   343
#if CONFIGURE_PDOS
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   344
    printf("Configuring PDOs...\n");
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   345
    if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3102_syncs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   346
        fprintf(stderr, "Failed to configure PDOs.\n");
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   347
        return -1;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   348
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   349
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   350
    if (!(sc = ecrt_master_slave_config(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   351
                    master, AnaOutSlavePos, Beckhoff_EL4102))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   352
        fprintf(stderr, "Failed to get slave configuration.\n");
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   353
        return -1;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   354
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   355
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   356
    if (ecrt_slave_config_pdos(sc, EC_END, el4102_syncs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   357
        fprintf(stderr, "Failed to configure PDOs.\n");
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   358
        return -1;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   359
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   360
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   361
    if (!(sc = ecrt_master_slave_config(
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   362
                    master, DigOutSlavePos, Beckhoff_EL2032))) {
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   363
        fprintf(stderr, "Failed to get slave configuration.\n");
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   364
        return -1;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   365
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   366
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   367
    if (ecrt_slave_config_pdos(sc, EC_END, el2004_syncs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   368
        fprintf(stderr, "Failed to configure PDOs.\n");
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   369
        return -1;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   370
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   371
#endif
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   372
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   373
    // Create configuration for bus coupler
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   374
    sc = ecrt_master_slave_config(master, BusCouplerPos, Beckhoff_EK1100);
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   375
    if (!sc)
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   376
        return -1;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   377
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   378
    if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   379
        fprintf(stderr, "PDO entry registration failed!\n");
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   380
		return -1;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   381
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   382
1249
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   383
    printf("Activating master...\n");
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   384
    if (ecrt_master_activate(master))
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   385
        return -1;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   386
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   387
    if (!(domain1_pd = ecrt_domain_data(domain1))) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   388
        return -1;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   389
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   390
1249
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   391
#if PRIORITY
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   392
    pid_t pid = getpid();
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   393
    if (setpriority(PRIO_PROCESS, pid, -19))
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   394
        fprintf(stderr, "Warning: Failed to set priority: %s\n",
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   395
                strerror(errno));
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   396
#endif
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   397
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   398
    sa.sa_handler = signal_handler;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   399
    sigemptyset(&sa.sa_mask);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   400
    sa.sa_flags = 0;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   401
    if (sigaction(SIGALRM, &sa, 0)) {
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   402
        fprintf(stderr, "Failed to install signal handler!\n");
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   403
        return -1;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   404
    }
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   405
1249
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   406
    printf("Starting timer...\n");
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   407
    tv.it_interval.tv_sec = 0;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   408
    tv.it_interval.tv_usec = 1000000 / FREQUENCY;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   409
    tv.it_value.tv_sec = 0;
1249
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   410
    tv.it_value.tv_usec = 1000;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   411
    if (setitimer(ITIMER_REAL, &tv, NULL)) {
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   412
        fprintf(stderr, "Failed to start timer: %s\n", strerror(errno));
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   413
        return 1;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   414
    }
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   415
1249
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   416
    printf("Started.\n");
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
	while (1) {
1261
72e04173691f Replaced sleep() with pause().
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   418
        pause();
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   419
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1249
diff changeset
   420
#if 0
1249
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   421
        struct timeval t;
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   422
        gettimeofday(&t, NULL);
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   423
        printf("%u.%06u\n", t.tv_sec, t.tv_usec);
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   424
#endif
d64ed42e0d11 Userspace example with priority.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   425
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   426
        while (sig_alarms != user_alarms) {
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   427
            cyclic_task();
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   428
            user_alarms++;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   429
        }
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
	}
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
	return 0;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
}
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   435
/****************************************************************************/