examples/xenomai_posix/main.c
author Florian Pose <fp@igh-essen.com>
Fri, 03 Mar 2017 13:33:17 +0100
changeset 2669 878a657d920a
parent 2589 2b9c78543663
permissions -rw-r--r--
New tool command 'ethercat crc'.
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     2
 *
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     4
 *
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
     5
 *  Copyright (C)      2011  IgH Andreas Stewering-Bone
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
     6
 *                     2012  Florian Pose <fp@igh-essen.com>
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
     7
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
     8
 *  This file is part of the IgH EtherCAT master
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     9
 *
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    10
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    11
 *  modify it under the terms of the GNU General Public License version 2, as
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    12
 *  published by the Free Software Foundation.
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    13
 *
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    14
 *  The IgH EtherCAT master is distributed in the hope that it will be useful,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    17
 *  Public License for more details.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    18
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    19
 *  You should have received a copy of the GNU General Public License along
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    20
 *  with the IgH EtherCAT master. If not, see <http://www.gnu.org/licenses/>.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    21
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    22
 *  ---
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    23
 *
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    27
 *
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    29
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    30
#include <errno.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    31
#include <mqueue.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    32
#include <signal.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    33
#include <pthread.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    34
#include <stdio.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    35
#include <stdlib.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    36
#include <string.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    37
#include <unistd.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    38
#include <limits.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    39
#include <sys/ioctl.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    40
#include <sys/mman.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    41
#include <time.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    42
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    43
#include <rtdm/rtdm.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    44
#include <rtdk.h>
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    45
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    46
#include "ecrt.h"
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    47
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    48
#define NSEC_PER_SEC 1000000000
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    49
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    50
static unsigned int cycle_us = 1000; /* 1 ms */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    51
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    52
static pthread_t cyclic_thread;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    53
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    54
static int run = 1;
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    55
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    56
/****************************************************************************/
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    57
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    58
// EtherCAT
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    59
static ec_master_t *master = NULL;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    60
static ec_master_state_t master_state = {};
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    61
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    62
static ec_domain_t *domain1 = NULL;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    63
static ec_domain_state_t domain1_state = {};
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    64
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    65
static uint8_t *domain1_pd = NULL;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    66
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    67
static ec_slave_config_t *sc_dig_out_01 = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    68
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    69
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    70
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    71
// process data
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    72
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    73
#define BusCoupler01_Pos  0, 0
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    74
#define DigOutSlave01_Pos 0, 1
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    75
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    76
#define Beckhoff_EK1100 0x00000002, 0x044c2c52
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    77
#define Beckhoff_EL2004 0x00000002, 0x07d43052
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    78
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    79
// offsets for PDO entries
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    80
static unsigned int off_dig_out0 = 0;
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    81
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    82
// process data
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    83
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    84
const static ec_pdo_entry_reg_t domain1_regs[] = {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    85
   {DigOutSlave01_Pos, Beckhoff_EL2004, 0x7000, 0x01, &off_dig_out0, NULL},
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    86
   {}
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    87
};
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    88
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
    89
/****************************************************************************/
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    90
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    91
/* Slave 1, "EL2004"
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    92
 * Vendor ID:       0x00000002
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    93
 * Product code:    0x07d43052
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    94
 * Revision number: 0x00100000
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    95
 */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    96
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    97
ec_pdo_entry_info_t slave_1_pdo_entries[] = {
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    98
   {0x7000, 0x01, 1}, /* Output */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    99
   {0x7010, 0x01, 1}, /* Output */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   100
   {0x7020, 0x01, 1}, /* Output */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   101
   {0x7030, 0x01, 1}, /* Output */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   102
};
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   103
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   104
ec_pdo_info_t slave_1_pdos[] = {
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   105
   {0x1600, 1, slave_1_pdo_entries + 0}, /* Channel 1 */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   106
   {0x1601, 1, slave_1_pdo_entries + 1}, /* Channel 2 */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   107
   {0x1602, 1, slave_1_pdo_entries + 2}, /* Channel 3 */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   108
   {0x1603, 1, slave_1_pdo_entries + 3}, /* Channel 4 */
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   109
};
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   110
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   111
ec_sync_info_t slave_1_syncs[] = {
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   112
   {0, EC_DIR_OUTPUT, 4, slave_1_pdos + 0, EC_WD_ENABLE},
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   113
   {0xff}
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   114
};
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   115
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   116
/*****************************************************************************
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   117
 * Realtime task
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   118
 ****************************************************************************/
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   119
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   120
void rt_check_domain_state(void)
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   121
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   122
    ec_domain_state_t ds = {};
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   123
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   124
	ecrt_domain_state(domain1, &ds);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   125
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   126
    if (ds.working_counter != domain1_state.working_counter) {
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   127
        rt_printf("Domain1: WC %u.\n", ds.working_counter);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   128
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   129
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   130
    if (ds.wc_state != domain1_state.wc_state) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   131
        rt_printf("Domain1: State %u.\n", ds.wc_state);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   132
    }
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   133
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   134
    domain1_state = ds;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   135
}
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   136
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   137
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   138
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   139
void rt_check_master_state(void)
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   140
{
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   141
    ec_master_state_t ms;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   142
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   143
	ecrt_master_state(master, &ms);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   144
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   145
    if (ms.slaves_responding != master_state.slaves_responding) {
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   146
        rt_printf("%u slave(s).\n", ms.slaves_responding);
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   147
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   148
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   149
    if (ms.al_states != master_state.al_states) {
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   150
        rt_printf("AL states: 0x%02X.\n", ms.al_states);
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   151
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   152
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   153
    if (ms.link_up != master_state.link_up) {
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   154
        rt_printf("Link is %s.\n", ms.link_up ? "up" : "down");
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   155
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   156
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   157
    master_state = ms;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   158
}
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   159
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   160
/****************************************************************************/
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   161
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   162
void *my_thread(void *arg)
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   163
{
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   164
    struct timespec next_period;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   165
    int cycle_counter = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   166
	unsigned int blink = 0;
2057
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   167
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   168
    clock_gettime(CLOCK_REALTIME, &next_period);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   169
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   170
    while (run) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   171
        next_period.tv_nsec += cycle_us * 1000;
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   172
        while (next_period.tv_nsec >= NSEC_PER_SEC) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   173
			next_period.tv_nsec -= NSEC_PER_SEC;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   174
			next_period.tv_sec++;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   175
		}
2057
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   176
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   177
        clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next_period, NULL);
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   178
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   179
        cycle_counter++;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   180
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   181
        // receive EtherCAT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   182
        ecrt_master_receive(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   183
        ecrt_domain_process(domain1);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   184
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   185
        rt_check_domain_state();
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   186
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   187
        if (!(cycle_counter % 1000)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   188
			rt_check_master_state();
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   189
		}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   190
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   191
        if (!(cycle_counter % 200)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   192
			blink = !blink;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   193
		}
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   194
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   195
        EC_WRITE_U8(domain1_pd + off_dig_out0, blink ? 0x0 : 0x0F);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   196
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   197
        // send process data
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   198
        ecrt_domain_queue(domain1);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   199
        ecrt_master_send(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   200
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   201
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   202
    return NULL;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   203
}
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   204
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   205
/****************************************************************************
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   206
 * Signal handler
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   207
 ***************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   208
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   209
void signal_handler(int sig)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   210
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   211
    run = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   212
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   213
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   214
/****************************************************************************
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   215
 * Main function
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   216
 ***************************************************************************/
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   217
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   218
int main(int argc, char *argv[])
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   219
{
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   220
    ec_slave_config_t *sc;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   221
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   222
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   223
    signal(SIGTERM, signal_handler);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   224
    signal(SIGINT, signal_handler);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   225
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   226
    mlockall(MCL_CURRENT | MCL_FUTURE);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   227
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   228
    printf("Requesting master...\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   229
    master = ecrt_request_master(0);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   230
    if (!master) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   231
        return -1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   232
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   233
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   234
    domain1 = ecrt_master_create_domain(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   235
    if (!domain1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   236
        return -1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   237
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   238
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   239
    printf("Creating slave configurations...\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   240
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   241
    // Create configuration for bus coupler
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   242
    sc = ecrt_master_slave_config(master, BusCoupler01_Pos, Beckhoff_EK1100);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   243
    if (!sc) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   244
        return -1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   245
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   246
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   247
    sc_dig_out_01 =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   248
        ecrt_master_slave_config(master, DigOutSlave01_Pos, Beckhoff_EL2004);
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   249
    if (!sc_dig_out_01) {
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   250
        fprintf(stderr, "Failed to get slave configuration.\n");
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   251
        return -1;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   252
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   253
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   254
    if (ecrt_slave_config_pdos(sc_dig_out_01, EC_END, slave_1_syncs)) {
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   255
        fprintf(stderr, "Failed to configure PDOs.\n");
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   256
        return -1;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   257
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   258
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   259
    if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   260
        fprintf(stderr, "PDO entry registration failed!\n");
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   261
        return -1;
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   262
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   263
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   264
    printf("Activating master...\n");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   265
    if (ecrt_master_activate(master)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   266
        return -1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   267
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   268
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   269
    if (!(domain1_pd = ecrt_domain_data(domain1))) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   270
        fprintf(stderr, "Failed to get domain data pointer.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   271
        return -1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   272
    }
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   273
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   274
    /* Create cyclic RT-thread */
2057
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   275
    struct sched_param param = { .sched_priority = 82 };
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   276
2057
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   277
    pthread_attr_t thattr;
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   278
    pthread_attr_init(&thattr);
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   279
    pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
2057
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   280
    pthread_attr_setinheritsched(&thattr, PTHREAD_EXPLICIT_SCHED);
23fca60b7ca2 Working Xenomai Posix example
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2056
diff changeset
   281
    pthread_attr_setschedpolicy(&thattr, SCHED_FIFO);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   282
    pthread_setschedparam(cyclic_thread, SCHED_FIFO, &param);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   283
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   284
    ret = pthread_create(&cyclic_thread, &thattr, &my_thread, NULL);
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   285
    if (ret) {
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   286
        fprintf(stderr, "%s: pthread_create cyclic task failed\n",
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   287
                strerror(-ret));
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   288
		return 1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   289
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   290
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   291
	while (run) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   292
		sched_yield();
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   293
	}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   294
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   295
    pthread_join(cyclic_thread, NULL);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   296
2056
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   297
    printf("End of Program\n");
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   298
    ecrt_release_master(master);
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   299
a92e8f119723 Work on Xenomai Posix interface, to be tested
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   300
    return 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   301
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   302
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2057
diff changeset
   303
/****************************************************************************/