2 * |
2 * |
3 * $Id$ |
3 * $Id$ |
4 * |
4 * |
5 ****************************************************************************/ |
5 ****************************************************************************/ |
6 |
6 |
|
7 #include <errno.h> |
|
8 #include <signal.h> |
|
9 #include <stdio.h> |
|
10 #include <string.h> |
|
11 #include <sys/resource.h> |
|
12 #include <sys/time.h> |
|
13 #include <sys/types.h> |
7 #include <unistd.h> |
14 #include <unistd.h> |
8 #include <sys/time.h> |
|
9 #include <stdio.h> |
|
10 #include <errno.h> |
|
11 #include <string.h> |
|
12 #include <signal.h> |
|
13 |
15 |
14 #include "ecrt.h" |
16 #include "ecrt.h" |
|
17 |
|
18 #define PRIORITY 1 |
15 |
19 |
16 /****************************************************************************/ |
20 /****************************************************************************/ |
17 |
21 |
18 static unsigned int sig_alarms = 0; |
22 static unsigned int sig_alarms = 0; |
19 static unsigned int user_alarms = 0; |
23 static unsigned int user_alarms = 0; |
48 |
52 |
49 sc = ecrt_master_slave_config(master, 0, 0, 0x00000002, 0x044C2C52); |
53 sc = ecrt_master_slave_config(master, 0, 0, 0x00000002, 0x044C2C52); |
50 if (!sc) |
54 if (!sc) |
51 return -1; |
55 return -1; |
52 |
56 |
|
57 printf("Activating master...\n"); |
53 if (ecrt_master_activate(master)) |
58 if (ecrt_master_activate(master)) |
54 return -1; |
59 return -1; |
|
60 |
|
61 #if PRIORITY |
|
62 pid_t pid = getpid(); |
|
63 if (setpriority(PRIO_PROCESS, pid, -19)) |
|
64 fprintf(stderr, "Warning: Failed to set priority: %s\n", |
|
65 strerror(errno)); |
|
66 #endif |
55 |
67 |
56 sa.sa_handler = signal_handler; |
68 sa.sa_handler = signal_handler; |
57 sigemptyset(&sa.sa_mask); |
69 sigemptyset(&sa.sa_mask); |
58 sa.sa_flags = 0; |
70 sa.sa_flags = 0; |
59 if (sigaction(SIGALRM, &sa, 0)) { |
71 if (sigaction(SIGALRM, &sa, 0)) { |
60 fprintf(stderr, "Failed to install signal handler!\n"); |
72 fprintf(stderr, "Failed to install signal handler!\n"); |
61 return -1; |
73 return -1; |
62 } |
74 } |
63 |
75 |
|
76 printf("Starting timer...\n"); |
64 tv.it_interval.tv_sec = 0; |
77 tv.it_interval.tv_sec = 0; |
65 tv.it_interval.tv_usec = 10000; |
78 tv.it_interval.tv_usec = 100000; |
66 tv.it_value.tv_sec = 0; |
79 tv.it_value.tv_sec = 0; |
67 tv.it_value.tv_usec = 1; |
80 tv.it_value.tv_usec = 1000; |
68 if (setitimer(ITIMER_REAL, &tv, NULL)) { |
81 if (setitimer(ITIMER_REAL, &tv, NULL)) { |
69 fprintf(stderr, "Failed to start timer: %s\n", strerror(errno)); |
82 fprintf(stderr, "Failed to start timer: %s\n", strerror(errno)); |
70 return 1; |
83 return 1; |
71 } |
84 } |
72 |
85 |
|
86 printf("Started.\n"); |
73 while (1) { |
87 while (1) { |
74 sleep(1); |
88 sleep(1); |
75 |
89 |
|
90 #if 1 |
|
91 struct timeval t; |
|
92 gettimeofday(&t, NULL); |
|
93 printf("%u.%06u\n", t.tv_sec, t.tv_usec); |
|
94 #endif |
|
95 |
76 while (sig_alarms != user_alarms) { |
96 while (sig_alarms != user_alarms) { |
77 |
|
78 #if 0 |
|
79 struct timeval t; |
|
80 gettimeofday(&t, NULL); |
|
81 printf("%u %u\n", t.tv_sec, t.tv_usec); |
|
82 #endif |
|
83 ecrt_master_receive(master); |
97 ecrt_master_receive(master); |
84 ecrt_master_send(master); |
98 ecrt_master_send(master); |
85 |
99 |
86 user_alarms++; |
100 user_alarms++; |
87 } |
101 } |