examples/dc_user/main.c
author Florian Pose <fp@igh-essen.com>
Thu, 31 May 2012 11:03:58 +0200
branchredundancy
changeset 2380 cf9db49bcce8
parent 1971 ba8a75cb1c98
child 2421 bc2d4bf9cbe5
permissions -rw-r--r--
Added ecrt_master_link_state() to retrieve information about a redundant link.
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2007-2009  Florian Pose, Ingenieurgemeinschaft IgH
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <errno.h>
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <signal.h>
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <stdio.h>
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <string.h>
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <sys/resource.h>
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <sys/time.h>
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include <sys/types.h>
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <unistd.h>
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    38
#include <time.h>
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    39
#include <sys/mman.h>
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    40
#include <malloc.h>
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
/****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "ecrt.h"
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
// Application parameters
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    49
#define FREQUENCY 1000
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    50
#define CLOCK_TO_USE CLOCK_REALTIME
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    51
#define MEASURE_TIMING
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    52
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    53
/****************************************************************************/
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    54
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    55
#define NSEC_PER_SEC (1000000000L)
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    56
#define PERIOD_NS (NSEC_PER_SEC / FREQUENCY)
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    57
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    58
#define DIFF_NS(A, B) (((B).tv_sec - (A).tv_sec) * NSEC_PER_SEC + \
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    59
	(B).tv_nsec - (A).tv_nsec)
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    60
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    61
#define TIMESPEC2NS(T) ((uint64_t) (T).tv_sec * NSEC_PER_SEC + (T).tv_nsec)
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    62
  
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
/****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
// EtherCAT
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
static ec_master_t *master = NULL;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
static ec_master_state_t master_state = {};
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
static ec_domain_t *domain1 = NULL;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
static ec_domain_state_t domain1_state = {};
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
/****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
// process data
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
static uint8_t *domain1_pd = NULL;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
#define BusCouplerPos    0, 0
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
#define DigOutSlavePos   0, 1
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
#define CounterSlavePos  0, 2
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
#define Beckhoff_EK1100 0x00000002, 0x044c2c52
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
#define Beckhoff_EL2008 0x00000002, 0x07d83052
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
#define IDS_Counter     0x000012ad, 0x05de3052
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
// offsets for PDO entries
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
static int off_dig_out;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
static int off_counter_in;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
static int off_counter_out;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
static unsigned int counter = 0;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
static unsigned int blink = 0;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
static unsigned int sync_ref_counter = 0;
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    93
const struct timespec cycletime = {0, PERIOD_NS};
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    94
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    95
/*****************************************************************************/
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    96
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    97
struct timespec timespec_add(struct timespec time1, struct timespec time2)
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    98
{
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
    99
	struct timespec result;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   100
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   101
	if ((time1.tv_nsec + time2.tv_nsec) >= NSEC_PER_SEC) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   102
		result.tv_sec = time1.tv_sec + time2.tv_sec + 1;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   103
		result.tv_nsec = time1.tv_nsec + time2.tv_nsec - NSEC_PER_SEC;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   104
	} else {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   105
		result.tv_sec = time1.tv_sec + time2.tv_sec;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   106
		result.tv_nsec = time1.tv_nsec + time2.tv_nsec;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   107
	}
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   108
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   109
	return result;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   110
}
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
/*****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
void check_domain1_state(void)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
{
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    ec_domain_state_t ds;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    ecrt_domain_state(domain1, &ds);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    if (ds.working_counter != domain1_state.working_counter)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
        printf("Domain1: WC %u.\n", ds.working_counter);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
    if (ds.wc_state != domain1_state.wc_state)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        printf("Domain1: State %u.\n", ds.wc_state);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    domain1_state = ds;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
}
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
/*****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
void check_master_state(void)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
{
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    ec_master_state_t ms;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    ecrt_master_state(master, &ms);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   136
	if (ms.slaves_responding != master_state.slaves_responding)
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
        printf("%u slave(s).\n", ms.slaves_responding);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    if (ms.al_states != master_state.al_states)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
        printf("AL states: 0x%02X.\n", ms.al_states);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
    if (ms.link_up != master_state.link_up)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        printf("Link is %s.\n", ms.link_up ? "up" : "down");
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    master_state = ms;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
}
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
/****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
void cyclic_task()
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
{
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   150
    struct timespec wakeupTime, time;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   151
#ifdef MEASURE_TIMING
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   152
    struct timespec startTime, endTime, lastStartTime = {};
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   153
    uint32_t period_ns = 0, exec_ns = 0, latency_ns = 0,
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   154
             latency_min_ns = 0, latency_max_ns = 0,
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   155
             period_min_ns = 0, period_max_ns = 0,
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   156
             exec_min_ns = 0, exec_max_ns = 0;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   157
#endif
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   158
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   159
    // get current time
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   160
    clock_gettime(CLOCK_TO_USE, &wakeupTime);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   161
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   162
	while(1) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   163
		wakeupTime = timespec_add(wakeupTime, cycletime);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   164
        clock_nanosleep(CLOCK_TO_USE, TIMER_ABSTIME, &wakeupTime, NULL);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   165
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   166
#ifdef MEASURE_TIMING
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   167
        clock_gettime(CLOCK_TO_USE, &startTime);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   168
        latency_ns = DIFF_NS(wakeupTime, startTime);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   169
        period_ns = DIFF_NS(lastStartTime, startTime);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   170
        exec_ns = DIFF_NS(lastStartTime, endTime);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   171
        lastStartTime = startTime;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   172
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   173
        if (latency_ns > latency_max_ns) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   174
            latency_max_ns = latency_ns;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   175
        }
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   176
        if (latency_ns < latency_min_ns) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   177
            latency_min_ns = latency_ns;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   178
        }
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   179
        if (period_ns > period_max_ns) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   180
            period_max_ns = period_ns;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   181
        }
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   182
        if (period_ns < period_min_ns) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   183
            period_min_ns = period_ns;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   184
        }
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   185
        if (exec_ns > exec_max_ns) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   186
            exec_max_ns = exec_ns;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   187
        }
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   188
        if (exec_ns < exec_min_ns) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   189
            exec_min_ns = exec_ns;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   190
        }
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   191
#endif
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   192
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   193
		// receive process data
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   194
		ecrt_master_receive(master);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   195
		ecrt_domain_process(domain1);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   196
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   197
		// check process data state (optional)
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   198
		check_domain1_state();
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   199
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   200
		if (counter) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   201
			counter--;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   202
		} else { // do this at 1 Hz
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   203
			counter = FREQUENCY;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   204
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   205
			// check for master state (optional)
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   206
			check_master_state();
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   207
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   208
#ifdef MEASURE_TIMING
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   209
            // output timing stats
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   210
            printf("period     %10u ... %10u\n",
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   211
                    period_min_ns, period_max_ns); 
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   212
            printf("exec       %10u ... %10u\n",
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   213
                    exec_min_ns, exec_max_ns); 
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   214
            printf("latency    %10u ... %10u\n",
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   215
                    latency_min_ns, latency_max_ns); 
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   216
            period_max_ns = 0;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   217
            period_min_ns = 0xffffffff;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   218
            exec_max_ns = 0;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   219
            exec_min_ns = 0xffffffff;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   220
            latency_max_ns = 0;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   221
            latency_min_ns = 0xffffffff;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   222
#endif
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   223
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   224
			// calculate new process data
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   225
			blink = !blink;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   226
		}
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   227
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   228
		// write process data
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   229
		EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x66 : 0x99);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   230
		EC_WRITE_U8(domain1_pd + off_counter_out, blink ? 0x00 : 0x02);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   231
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   232
		// write application time to master
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   233
		clock_gettime(CLOCK_TO_USE, &time);
1971
ba8a75cb1c98 Fixed TIMESPEC2NS() macro use.
Florian Pose <fp@igh-essen.com>
parents: 1970
diff changeset
   234
		ecrt_master_application_time(master, TIMESPEC2NS(time));
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   235
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   236
		if (sync_ref_counter) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   237
			sync_ref_counter--;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   238
		} else {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   239
			sync_ref_counter = 1; // sync every cycle
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   240
			ecrt_master_sync_reference_clock(master);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   241
		}
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   242
		ecrt_master_sync_slave_clocks(master);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   243
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   244
		// send process data
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   245
		ecrt_domain_queue(domain1);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   246
		ecrt_master_send(master);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   247
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   248
#ifdef MEASURE_TIMING
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   249
        clock_gettime(CLOCK_TO_USE, &endTime);
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   250
#endif
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   251
	}
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
}
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
/****************************************************************************/
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
int main(int argc, char **argv)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1466
diff changeset
   258
    ec_slave_config_t *sc;
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   259
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   260
	if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   261
		perror("mlockall failed");
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   262
		return -1;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   263
	}
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
    
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
    master = ecrt_request_master(0);
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1466
diff changeset
   266
    if (!master)
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1466
diff changeset
   267
        return -1;
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
    domain1 = ecrt_master_create_domain(master);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
    if (!domain1)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
    // Create configuration for bus coupler
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
    sc = ecrt_master_slave_config(master, BusCouplerPos, Beckhoff_EK1100);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    if (!sc)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
    if (!(sc = ecrt_master_slave_config(master,
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
                    DigOutSlavePos, Beckhoff_EL2008))) {
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
        fprintf(stderr, "Failed to get slave configuration.\n");
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
    }
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
    off_dig_out = ecrt_slave_config_reg_pdo_entry(sc,
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
            0x7000, 1, domain1, NULL);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
    if (off_dig_out < 0)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
	if (!(sc = ecrt_master_slave_config(master,
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
					CounterSlavePos, IDS_Counter))) {
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
        fprintf(stderr, "Failed to get slave configuration.\n");
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
	}
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
	off_counter_in = ecrt_slave_config_reg_pdo_entry(sc,
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
			0x6020, 0x11, domain1, NULL);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
	if (off_counter_in < 0)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
	off_counter_out = ecrt_slave_config_reg_pdo_entry(sc,
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
			0x7020, 1, domain1, NULL);
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
	if (off_counter_out < 0)
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
    // configure SYNC signals for this slave
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   306
	ecrt_slave_config_dc(sc, 0x0700, PERIOD_NS, 4400000, 0, 0);
1414
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
    printf("Activating master...\n");
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
    if (ecrt_master_activate(master))
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
    if (!(domain1_pd = ecrt_domain_data(domain1))) {
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
        return -1;
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
    }
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
    pid_t pid = getpid();
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
    if (setpriority(PRIO_PROCESS, pid, -19))
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
        fprintf(stderr, "Warning: Failed to set priority: %s\n",
0037a63d3cc5 DC example applications.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
                strerror(errno));
1970
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   320
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   321
	printf("Starting cyclic function.\n");
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   322
    cyclic_task();
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   323
    
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   324
    return 0;
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   325
}
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   326
00e18cef9fc8 Improved dc_user example.
Florian Pose <fp@igh-essen.com>
parents: 1941
diff changeset
   327
/****************************************************************************/