author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Wed, 04 Dec 2024 12:00:37 +0100 | |
changeset 4059 | 03f007a175b5 |
parent 3954 | 5744391252ec |
permissions | -rw-r--r-- |
321 | 1 |
/** |
954 | 2 |
* Xenomai Linux specific code |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
3 |
**/ |
321 | 4 |
|
5 |
#include <stdio.h> |
|
615 | 6 |
#include <unistd.h> |
321 | 7 |
#include <string.h> |
8 |
#include <time.h> |
|
9 |
#include <signal.h> |
|
10 |
#include <stdlib.h> |
|
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
11 |
#include <errno.h> |
321 | 12 |
#include <sys/mman.h> |
342 | 13 |
#include <sys/fcntl.h> |
321 | 14 |
|
1974 | 15 |
#include <alchemy/task.h> |
16 |
#include <alchemy/timer.h> |
|
17 |
#include <alchemy/sem.h> |
|
18 |
#include <alchemy/pipe.h> |
|
321 | 19 |
|
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
20 |
#define _Log(level,text,...) \ |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
21 |
{\ |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
22 |
char mstr[256];\ |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
23 |
snprintf(mstr, 255, text, ##__VA_ARGS__);\ |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
24 |
LogMessage(level, mstr, strlen(mstr));\ |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
25 |
} |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
26 |
|
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
27 |
#define _LogError(text,...) _Log(LOG_CRITICAL, text, ##__VA_ARGS__) |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
28 |
#define _LogWarning(text,...) _Log(LOG_WARNING, text, ##__VA_ARGS__) |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
29 |
|
321 | 30 |
unsigned int PLC_state = 0; |
615 | 31 |
#define PLC_STATE_TASK_CREATED 1 |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
32 |
#define PLC_STATE_DEBUG_PIPE_CREATED 2 |
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
33 |
#define PLC_STATE_PYTHON_PIPE_CREATED 8 |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
34 |
#define PLC_STATE_WAITDEBUG_PIPE_CREATED 16 |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
35 |
#define PLC_STATE_WAITPYTHON_PIPE_CREATED 32 |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
36 |
|
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
37 |
#define PIPE_SIZE 1 |
321 | 38 |
|
1990
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
39 |
// rt-pipes commands |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
40 |
|
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
41 |
#define PYTHON_PENDING_COMMAND 1 |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
42 |
#define PYTHON_FINISH 2 |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
43 |
|
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
44 |
#define DEBUG_FINISH 2 |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
45 |
|
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
46 |
#define DEBUG_PENDING_DATA 1 |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
47 |
#define DEBUG_UNLOCK 1 |
321 | 48 |
|
49 |
long AtomicCompareExchange(long* atomicvar,long compared, long exchange) |
|
50 |
{ |
|
51 |
return __sync_val_compare_and_swap(atomicvar, compared, exchange); |
|
52 |
} |
|
954 | 53 |
long long AtomicCompareExchange64(long long* atomicvar, long long compared, long long exchange) |
54 |
{ |
|
55 |
return __sync_val_compare_and_swap(atomicvar, compared, exchange); |
|
56 |
} |
|
321 | 57 |
|
58 |
void PLC_GetTime(IEC_TIME *CURRENT_TIME) |
|
59 |
{ |
|
60 |
RTIME current_time = rt_timer_read(); |
|
61 |
CURRENT_TIME->tv_sec = current_time / 1000000000; |
|
62 |
CURRENT_TIME->tv_nsec = current_time % 1000000000; |
|
63 |
} |
|
64 |
||
65 |
RT_TASK PLC_task; |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
66 |
void *WaitDebug_handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
67 |
void *WaitPython_handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
68 |
void *Debug_handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
69 |
void *Python_handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
70 |
void *svghmi_handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
71 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
72 |
struct RT_to_nRT_signal_s { |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
73 |
int used; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
74 |
RT_PIPE pipe; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
75 |
int pipe_fd; |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
76 |
char *name; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
77 |
}; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
78 |
typedef struct RT_to_nRT_signal_s RT_to_nRT_signal_t; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
79 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
80 |
#define max_RT_to_nRT_signals 16 |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
81 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
82 |
static RT_to_nRT_signal_t RT_to_nRT_signal_pool[max_RT_to_nRT_signals]; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
83 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
84 |
int recv_RT_to_nRT_signal(void* handle, char* payload){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
85 |
RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
86 |
if(!sig->used) return -EINVAL; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
87 |
return read(sig->pipe_fd, payload, 1); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
88 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
89 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
90 |
int send_RT_to_nRT_signal(void* handle, char payload){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
91 |
RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
92 |
if(!sig->used) return -EINVAL; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
93 |
return rt_pipe_write(&sig->pipe, &payload, 1, P_NORMAL); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
94 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
95 |
|
615 | 96 |
|
321 | 97 |
int PLC_shutdown = 0; |
98 |
||
615 | 99 |
void PLC_SetTimer(unsigned long long next, unsigned long long period) |
321 | 100 |
{ |
101 |
RTIME current_time = rt_timer_read(); |
|
102 |
rt_task_set_periodic(&PLC_task, current_time + next, rt_timer_ns2ticks(period)); |
|
103 |
} |
|
104 |
||
105 |
void PLC_task_proc(void *arg) |
|
106 |
{ |
|
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
107 |
unsigned long overruns = 0; |
1428
e14003eb4d42
Simplified use of runtime's global variable __common_ticktime accross extensions.
Edouard Tisserant
parents:
985
diff
changeset
|
108 |
PLC_SetTimer(common_ticktime__, common_ticktime__); |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
109 |
|
695 | 110 |
while (!PLC_shutdown) { |
321 | 111 |
PLC_GetTime(&__CURRENT_TIME); |
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
112 |
if(overruns == 0){ |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
113 |
__run(); |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
114 |
} else { |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
115 |
// in case of overrun, don't run PLC on next cycle, to prevent CPU hogging. |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
116 |
_LogWarning("PLC execution time is longer than requested PLC cyclic task interval. %d cycles skipped\n", overruns); |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
117 |
// rt_printf("PLC execution time is longer than requested PLC cyclic task interval. %d cycles skipped\n", overruns); |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
118 |
// increment tick count anyhow, so that task scheduling keeps consistent |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
119 |
__tick += overruns; |
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
120 |
} |
321 | 121 |
if (PLC_shutdown) break; |
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
122 |
rt_task_wait_period(&overruns); |
321 | 123 |
} |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
124 |
/* since xenomai 3 it is not enough to close() |
1990
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
125 |
file descriptor to unblock read()... */ |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
126 |
{ |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
127 |
/* explicitely finish python thread */ |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
128 |
char msg = PYTHON_FINISH; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
129 |
send_RT_to_nRT_signal(WaitPython_handle, msg); |
1990
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
130 |
} |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
131 |
{ |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
132 |
/* explicitely finish debug thread */ |
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
133 |
char msg = DEBUG_FINISH; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
134 |
send_RT_to_nRT_signal(WaitDebug_handle, msg); |
1990
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1981
diff
changeset
|
135 |
} |
321 | 136 |
} |
137 |
||
397
6a7ff66a811d
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
345
diff
changeset
|
138 |
static unsigned long __debug_tick; |
321 | 139 |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
140 |
void *create_RT_to_nRT_signal(char* name){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
141 |
int new_index = -1; |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
142 |
int ret; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
143 |
RT_to_nRT_signal_t *sig; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
144 |
char pipe_dev[64]; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
145 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
146 |
/* find a free slot */ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
147 |
for(int i=0; i < max_RT_to_nRT_signals; i++){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
148 |
sig = &RT_to_nRT_signal_pool[i]; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
149 |
if(!sig->used){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
150 |
new_index = i; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
151 |
break; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
152 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
153 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
154 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
155 |
/* fail if none found */ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
156 |
if(new_index == -1) { |
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
157 |
_LogError("Maximum count of RT-PIPE reached while creating pipe for %s (%d)", name, max_RT_to_nRT_signals); |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
158 |
return NULL; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
159 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
160 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
161 |
/* create rt pipe */ |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
162 |
if(ret = rt_pipe_create(&sig->pipe, name, new_index, PIPE_SIZE) < 0){ |
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
163 |
_LogError("Failed opening real-time end of RT-PIPE for %s (%d)", name, ret); |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
164 |
return NULL; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
165 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
166 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
167 |
/* open pipe's userland */ |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
168 |
snprintf(pipe_dev, 63, "/dev/rtp%d", new_index); |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
169 |
if((sig->pipe_fd = open(pipe_dev, O_RDWR)) == -1){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
170 |
rt_pipe_delete(&sig->pipe); |
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
171 |
_LogError("Failed opening non-real-time end of RT-PIPE for %s (%d)", name, errno); |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
172 |
return NULL; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
173 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
174 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
175 |
sig->used = 1; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
176 |
sig->name = name; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
177 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
178 |
return sig; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
179 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
180 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
181 |
void delete_RT_to_nRT_signal(void* handle){ |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
182 |
int ret; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
183 |
RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
184 |
char *name = sig->name; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
185 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
186 |
if(!sig->used) return; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
187 |
|
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
188 |
if(ret = rt_pipe_delete(&sig->pipe) != 0){ |
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
189 |
_LogError("Failed closing real-time end of RT-PIPE for %s (%d)", name, ret); |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
190 |
} |
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
191 |
|
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
192 |
if(close(sig->pipe_fd) != 0){ |
3953
91c39139420f
Xenomai runtime: report and mitigate when PLC cycle overruns.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3398
diff
changeset
|
193 |
_LogError("Failed closing non-real-time end of RT-PIPE for %s (%d)", name, errno); |
3315
5f9db9c6c69c
Xenomai runtime: more verbose error message when problem with RT-Pipes.
Edouard Tisserant
parents:
3298
diff
changeset
|
194 |
} |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
195 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
196 |
sig->used = 0; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
197 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
198 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
199 |
int wait_RT_to_nRT_signal(void* handle){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
200 |
char cmd; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
201 |
int ret = recv_RT_to_nRT_signal(handle, &cmd); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
202 |
return (ret == 1) ? 0 : ((ret == 0) ? ENODATA : -ret); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
203 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
204 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
205 |
int unblock_RT_to_nRT_signal(void* handle){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
206 |
int ret = send_RT_to_nRT_signal(handle, 0); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
207 |
return (ret == 1) ? 0 : ((ret == 0) ? EINVAL : -ret); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
208 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
209 |
|
3295
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
210 |
void nRT_reschedule(void){ |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
211 |
sched_yield(); |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
212 |
} |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
213 |
|
321 | 214 |
void PLC_cleanup_all(void) |
215 |
{ |
|
216 |
if (PLC_state & PLC_STATE_TASK_CREATED) { |
|
217 |
rt_task_delete(&PLC_task); |
|
218 |
PLC_state &= ~PLC_STATE_TASK_CREATED; |
|
219 |
} |
|
220 |
||
615 | 221 |
if (PLC_state & PLC_STATE_WAITDEBUG_PIPE_CREATED) { |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
222 |
delete_RT_to_nRT_signal(WaitDebug_handle); |
615 | 223 |
PLC_state &= ~PLC_STATE_WAITDEBUG_PIPE_CREATED; |
224 |
} |
|
225 |
||
226 |
if (PLC_state & PLC_STATE_WAITPYTHON_PIPE_CREATED) { |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
227 |
delete_RT_to_nRT_signal(WaitPython_handle); |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
228 |
PLC_state &= ~PLC_STATE_WAITPYTHON_PIPE_CREATED; |
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
229 |
} |
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
230 |
|
342 | 231 |
if (PLC_state & PLC_STATE_DEBUG_PIPE_CREATED) { |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
232 |
delete_RT_to_nRT_signal(Debug_handle); |
342 | 233 |
PLC_state &= ~PLC_STATE_DEBUG_PIPE_CREATED; |
234 |
} |
|
235 |
||
615 | 236 |
if (PLC_state & PLC_STATE_PYTHON_PIPE_CREATED) { |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
237 |
delete_RT_to_nRT_signal(Python_handle); |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
238 |
PLC_state &= ~PLC_STATE_PYTHON_PIPE_CREATED; |
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
239 |
} |
321 | 240 |
} |
241 |
||
242 |
int stopPLC() |
|
243 |
{ |
|
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
244 |
/* Stop the PLC */ |
321 | 245 |
PLC_shutdown = 1; |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
246 |
|
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
247 |
/* Wait until PLC task stops */ |
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
248 |
rt_task_join(&PLC_task); |
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
249 |
|
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
250 |
PLC_cleanup_all(); |
342 | 251 |
__cleanup(); |
321 | 252 |
__debug_tick = -1; |
615 | 253 |
return 0; |
321 | 254 |
} |
255 |
||
256 |
// |
|
257 |
void catch_signal(int sig) |
|
258 |
{ |
|
259 |
stopPLC(); |
|
260 |
// signal(SIGTERM, catch_signal); |
|
261 |
signal(SIGINT, catch_signal); |
|
262 |
printf("Got Signal %d\n",sig); |
|
263 |
exit(0); |
|
264 |
} |
|
265 |
||
1981 | 266 |
#define _startPLCLog(text) \ |
267 |
{\ |
|
268 |
char mstr[] = text;\ |
|
269 |
LogMessage(LOG_CRITICAL, mstr, sizeof(mstr));\ |
|
270 |
goto error;\ |
|
271 |
} |
|
272 |
||
273 |
#define FO "Failed opening " |
|
274 |
||
321 | 275 |
#define max_val(a,b) ((a>b)?a:b) |
276 |
int startPLC(int argc,char **argv) |
|
277 |
{ |
|
278 |
signal(SIGINT, catch_signal); |
|
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
279 |
|
615 | 280 |
/* no memory swapping for that process */ |
321 | 281 |
mlockall(MCL_CURRENT | MCL_FUTURE); |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
282 |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
283 |
/* memory initialization */ |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
284 |
PLC_shutdown = 0; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
285 |
bzero(RT_to_nRT_signal_pool, sizeof(RT_to_nRT_signal_pool)); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
286 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
287 |
/*** RT Pipes ***/ |
615 | 288 |
/* create Debug_pipe */ |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
289 |
if(!(Debug_handle = create_RT_to_nRT_signal("Debug_pipe"))) goto error; |
615 | 290 |
PLC_state |= PLC_STATE_DEBUG_PIPE_CREATED; |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
291 |
|
615 | 292 |
/* create Python_pipe */ |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
293 |
if(!(Python_handle = create_RT_to_nRT_signal("Python_pipe"))) goto error; |
615 | 294 |
PLC_state |= PLC_STATE_PYTHON_PIPE_CREATED; |
295 |
||
342 | 296 |
/* create WaitDebug_pipe */ |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
297 |
if(!(WaitDebug_handle = create_RT_to_nRT_signal("WaitDebug_pipe"))) goto error; |
615 | 298 |
PLC_state |= PLC_STATE_WAITDEBUG_PIPE_CREATED; |
342 | 299 |
|
615 | 300 |
/* create WaitPython_pipe */ |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
301 |
if(!(WaitPython_handle = create_RT_to_nRT_signal("WaitPython_pipe"))) goto error; |
615 | 302 |
PLC_state |= PLC_STATE_WAITPYTHON_PIPE_CREATED; |
303 |
||
304 |
/*** create PLC task ***/ |
|
1981 | 305 |
if(rt_task_create(&PLC_task, "PLC_task", 0, 50, T_JOINABLE)) |
306 |
_startPLCLog("Failed creating PLC task"); |
|
321 | 307 |
PLC_state |= PLC_STATE_TASK_CREATED; |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
308 |
|
615 | 309 |
if(__init(argc,argv)) goto error; |
310 |
||
311 |
/* start PLC task */ |
|
1981 | 312 |
if(rt_task_start(&PLC_task, &PLC_task_proc, NULL)) |
313 |
_startPLCLog("Failed starting PLC task"); |
|
321 | 314 |
|
315 |
return 0; |
|
316 |
||
317 |
error: |
|
616
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
318 |
|
321 | 319 |
PLC_cleanup_all(); |
320 |
return 1; |
|
321 |
} |
|
322 |
||
615 | 323 |
#define DEBUG_FREE 0 |
324 |
#define DEBUG_BUSY 1 |
|
325 |
static long debug_state = DEBUG_FREE; |
|
326 |
||
321 | 327 |
int TryEnterDebugSection(void) |
328 |
{ |
|
616
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
329 |
if(AtomicCompareExchange( |
615 | 330 |
&debug_state, |
331 |
DEBUG_FREE, |
|
616
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
332 |
DEBUG_BUSY) == DEBUG_FREE){ |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
333 |
if(__DEBUG){ |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
334 |
return 1; |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
335 |
} |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
336 |
AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
337 |
} |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
338 |
return 0; |
615 | 339 |
} |
340 |
||
321 | 341 |
void LeaveDebugSection(void) |
342 |
{ |
|
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
343 |
if(AtomicCompareExchange( &debug_state, |
615 | 344 |
DEBUG_BUSY, DEBUG_FREE) == DEBUG_BUSY){ |
345 |
char msg = DEBUG_UNLOCK; |
|
346 |
/* signal to NRT for wakeup */ |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
347 |
send_RT_to_nRT_signal(Debug_handle, msg); |
615 | 348 |
} |
321 | 349 |
} |
350 |
||
3947
9b5cb90297e4
All Runtimes: Now sizeof(tick)=4 on all platforms (unsigned int).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3398
diff
changeset
|
351 |
extern unsigned int __tick; |
9b5cb90297e4
All Runtimes: Now sizeof(tick)=4 on all platforms (unsigned int).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3398
diff
changeset
|
352 |
|
9b5cb90297e4
All Runtimes: Now sizeof(tick)=4 on all platforms (unsigned int).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3398
diff
changeset
|
353 |
int WaitDebugData(unsigned int *tick) |
321 | 354 |
{ |
615 | 355 |
char cmd; |
345
a3520d75a722
get the WaitPythonCommands return (semaphore error code) to quit python_iterator loop when semaphore is destroyed
greg
parents:
342
diff
changeset
|
356 |
int res; |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
357 |
if (PLC_shutdown) return -1; |
321 | 358 |
/* Wait signal from PLC thread */ |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
359 |
res = recv_RT_to_nRT_signal(WaitDebug_handle, &cmd); |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
360 |
if (res == 1 && cmd == DEBUG_PENDING_DATA){ |
617
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
616
diff
changeset
|
361 |
*tick = __debug_tick; |
615 | 362 |
return 0; |
617
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
616
diff
changeset
|
363 |
} |
345
a3520d75a722
get the WaitPythonCommands return (semaphore error code) to quit python_iterator loop when semaphore is destroyed
greg
parents:
342
diff
changeset
|
364 |
return -1; |
321 | 365 |
} |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
366 |
|
321 | 367 |
/* Called by PLC thread when debug_publish finished |
368 |
* This is supposed to unlock debugger thread in WaitDebugData*/ |
|
369 |
void InitiateDebugTransfer() |
|
370 |
{ |
|
615 | 371 |
char msg = DEBUG_PENDING_DATA; |
321 | 372 |
/* remember tick */ |
373 |
__debug_tick = __tick; |
|
374 |
/* signal debugger thread it can read data */ |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
375 |
send_RT_to_nRT_signal(WaitDebug_handle, msg); |
615 | 376 |
} |
377 |
||
378 |
int suspendDebug(int disable) |
|
379 |
{ |
|
380 |
char cmd = DEBUG_UNLOCK; |
|
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
381 |
if (PLC_shutdown) return -1; |
615 | 382 |
while(AtomicCompareExchange( |
383 |
&debug_state, |
|
384 |
DEBUG_FREE, |
|
385 |
DEBUG_BUSY) != DEBUG_FREE && |
|
386 |
cmd == DEBUG_UNLOCK){ |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
387 |
if(recv_RT_to_nRT_signal(Debug_handle, &cmd) != 1){ |
615 | 388 |
return -1; |
389 |
} |
|
390 |
} |
|
391 |
__DEBUG = !disable; |
|
617
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
616
diff
changeset
|
392 |
if (disable) |
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
616
diff
changeset
|
393 |
AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
615 | 394 |
return 0; |
321 | 395 |
} |
396 |
||
397 |
void resumeDebug(void) |
|
398 |
{ |
|
3398
7ca3924be865
Xenomai runtime: ensure that __DEBUG global variable is set when resuming debug.
Edouard Tisserant
parents:
3315
diff
changeset
|
399 |
__DEBUG = 1; |
615 | 400 |
AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
401 |
} |
|
402 |
||
403 |
#define PYTHON_FREE 0 |
|
404 |
#define PYTHON_BUSY 1 |
|
405 |
static long python_state = PYTHON_FREE; |
|
406 |
||
321 | 407 |
int WaitPythonCommands(void) |
3298
e6131894be1d
Xenomai runtime: fixed bugs introduced in e3db472b0dfb (RT->nRT wakeup) + other small typos
Edouard Tisserant
parents:
3295
diff
changeset
|
408 |
{ |
615 | 409 |
char cmd; |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
410 |
if (PLC_shutdown) return -1; |
321 | 411 |
/* Wait signal from PLC thread */ |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
412 |
if(recv_RT_to_nRT_signal(WaitPython_handle, &cmd) == 1 && cmd==PYTHON_PENDING_COMMAND){ |
615 | 413 |
return 0; |
345
a3520d75a722
get the WaitPythonCommands return (semaphore error code) to quit python_iterator loop when semaphore is destroyed
greg
parents:
342
diff
changeset
|
414 |
} |
a3520d75a722
get the WaitPythonCommands return (semaphore error code) to quit python_iterator loop when semaphore is destroyed
greg
parents:
342
diff
changeset
|
415 |
return -1; |
321 | 416 |
} |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
417 |
|
321 | 418 |
/* Called by PLC thread on each new python command*/ |
419 |
void UnBlockPythonCommands(void) |
|
420 |
{ |
|
615 | 421 |
char msg = PYTHON_PENDING_COMMAND; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
422 |
send_RT_to_nRT_signal(WaitPython_handle, msg); |
321 | 423 |
} |
424 |
||
425 |
int TryLockPython(void) |
|
426 |
{ |
|
615 | 427 |
return AtomicCompareExchange( |
428 |
&python_state, |
|
429 |
PYTHON_FREE, |
|
430 |
PYTHON_BUSY) == PYTHON_FREE; |
|
431 |
} |
|
432 |
||
433 |
#define UNLOCK_PYTHON 1 |
|
434 |
void LockPython(void) |
|
435 |
{ |
|
436 |
char cmd = UNLOCK_PYTHON; |
|
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
437 |
if (PLC_shutdown) return; |
615 | 438 |
while(AtomicCompareExchange( |
439 |
&python_state, |
|
440 |
PYTHON_FREE, |
|
441 |
PYTHON_BUSY) != PYTHON_FREE && |
|
442 |
cmd == UNLOCK_PYTHON){ |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
443 |
recv_RT_to_nRT_signal(Python_handle, &cmd); |
615 | 444 |
} |
321 | 445 |
} |
446 |
||
447 |
void UnLockPython(void) |
|
448 |
{ |
|
615 | 449 |
if(AtomicCompareExchange( |
450 |
&python_state, |
|
451 |
PYTHON_BUSY, |
|
452 |
PYTHON_FREE) == PYTHON_BUSY){ |
|
453 |
if(rt_task_self()){/*is that the real time task ?*/ |
|
454 |
char cmd = UNLOCK_PYTHON; |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
455 |
send_RT_to_nRT_signal(Python_handle, cmd); |
615 | 456 |
}/* otherwise, no signaling from non real time */ |
457 |
} /* as plc does not wait for lock. */ |
|
458 |
} |
|
459 |
||
1903
084256be3658
Main runtime template C code : Added HAVE_RETAIN preprocessor definition for customized build to signal it provides IEC-61131 Retain memory handling function. Removed targets/Xenomai/plc_Xenomai_noretain.c, now useless.
Edouard Tisserant
parents:
1717
diff
changeset
|
460 |
#ifndef HAVE_RETAIN |
1717
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
461 |
int CheckRetainBuffer(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
462 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
463 |
return 1; |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
464 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
465 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
466 |
void ValidateRetainBuffer(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
467 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
468 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
469 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
470 |
void InValidateRetainBuffer(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
471 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
472 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
473 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
474 |
void Retain(unsigned int offset, unsigned int count, void *p) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
475 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
476 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
477 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
478 |
void Remind(unsigned int offset, unsigned int count, void *p) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
479 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
480 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
481 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
482 |
void CleanupRetain(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
483 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
484 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
485 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
486 |
void InitRetain(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
487 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
488 |
} |
1903
084256be3658
Main runtime template C code : Added HAVE_RETAIN preprocessor definition for customized build to signal it provides IEC-61131 Retain memory handling function. Removed targets/Xenomai/plc_Xenomai_noretain.c, now useless.
Edouard Tisserant
parents:
1717
diff
changeset
|
489 |
#endif // !HAVE_RETAIN |