author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sat, 21 Aug 2021 11:02:09 +0200 | |
branch | svghmi |
changeset 3297 | 7e59bd180bc6 |
parent 3295 | 0375d801fff7 |
child 3298 | e6131894be1d |
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> |
|
11 |
#include <sys/mman.h> |
|
342 | 12 |
#include <sys/fcntl.h> |
321 | 13 |
|
1974 | 14 |
#include <alchemy/task.h> |
15 |
#include <alchemy/timer.h> |
|
16 |
#include <alchemy/sem.h> |
|
17 |
#include <alchemy/pipe.h> |
|
321 | 18 |
|
19 |
unsigned int PLC_state = 0; |
|
615 | 20 |
#define PLC_STATE_TASK_CREATED 1 |
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
|
21 |
#define PLC_STATE_DEBUG_PIPE_CREATED 2 |
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
|
22 |
#define PLC_STATE_PYTHON_PIPE_CREATED 8 |
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
|
23 |
#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
|
24 |
#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
|
25 |
|
615 | 26 |
#define PIPE_SIZE 1 |
321 | 27 |
|
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
|
28 |
// 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
|
29 |
|
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
|
30 |
#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
|
31 |
#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
|
32 |
|
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
|
33 |
#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
|
34 |
|
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
|
35 |
#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
|
36 |
#define DEBUG_UNLOCK 1 |
321 | 37 |
|
38 |
long AtomicCompareExchange(long* atomicvar,long compared, long exchange) |
|
39 |
{ |
|
40 |
return __sync_val_compare_and_swap(atomicvar, compared, exchange); |
|
41 |
} |
|
954 | 42 |
long long AtomicCompareExchange64(long long* atomicvar, long long compared, long long exchange) |
43 |
{ |
|
44 |
return __sync_val_compare_and_swap(atomicvar, compared, exchange); |
|
45 |
} |
|
321 | 46 |
|
47 |
void PLC_GetTime(IEC_TIME *CURRENT_TIME) |
|
48 |
{ |
|
49 |
RTIME current_time = rt_timer_read(); |
|
50 |
CURRENT_TIME->tv_sec = current_time / 1000000000; |
|
51 |
CURRENT_TIME->tv_nsec = current_time % 1000000000; |
|
52 |
} |
|
53 |
||
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
|
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
int pipe_fd; |
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
|
65 |
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
|
66 |
}; |
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 |
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
|
68 |
|
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 |
#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
|
70 |
|
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 |
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
|
72 |
|
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 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
|
74 |
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
|
75 |
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
|
76 |
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
|
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 |
|
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 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
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 |
|
615 | 85 |
|
321 | 86 |
int PLC_shutdown = 0; |
87 |
||
615 | 88 |
void PLC_SetTimer(unsigned long long next, unsigned long long period) |
321 | 89 |
{ |
90 |
RTIME current_time = rt_timer_read(); |
|
91 |
rt_task_set_periodic(&PLC_task, current_time + next, rt_timer_ns2ticks(period)); |
|
92 |
} |
|
93 |
||
94 |
void PLC_task_proc(void *arg) |
|
95 |
{ |
|
1428
e14003eb4d42
Simplified use of runtime's global variable __common_ticktime accross extensions.
Edouard Tisserant
parents:
985
diff
changeset
|
96 |
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
|
97 |
|
695 | 98 |
while (!PLC_shutdown) { |
321 | 99 |
PLC_GetTime(&__CURRENT_TIME); |
100 |
__run(); |
|
101 |
if (PLC_shutdown) break; |
|
102 |
rt_task_wait_period(NULL); |
|
103 |
} |
|
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
|
104 |
/* since xenomai 3 it is not enough to close() |
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
|
105 |
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
|
106 |
{ |
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
|
107 |
/* 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
|
108 |
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
|
109 |
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
|
110 |
} |
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
|
111 |
{ |
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
|
112 |
/* 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
|
113 |
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
|
114 |
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
|
115 |
} |
321 | 116 |
} |
117 |
||
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
|
118 |
static unsigned long __debug_tick; |
321 | 119 |
|
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
|
120 |
#define _LogAndReturnNull(text) \ |
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
|
121 |
{\ |
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
|
122 |
char mstr[256] = text " for ";\ |
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
|
123 |
strncat(mstr, name, 255);\ |
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
|
124 |
LogMessage(LOG_CRITICAL, mstr, strlen(mstr));\ |
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
|
125 |
return NULL;\ |
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
|
126 |
} |
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
|
127 |
|
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
|
128 |
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
|
129 |
int new_index = -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
|
130 |
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
|
131 |
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
|
132 |
|
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
|
133 |
/* 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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
} |
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 |
} |
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 |
|
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
|
142 |
/* 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
|
143 |
if(new_index == -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
|
144 |
_LogAndReturnNull("Maximum count of RT-PIPE reached while creating 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
|
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 |
|
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 |
/* create rt 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
|
148 |
if(rt_pipe_create(&sig->pipe, name, new_index, PIPE_SIZE) < 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
|
149 |
_LogAndReturnNull("Failed opening real-time end of RT-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
|
150 |
} |
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 |
|
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 |
/* open pipe's userland */ |
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 |
snprintf(pipe_dev, 64, "/dev/rtp%d", new_index); |
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 |
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
|
155 |
rt_pipe_delete(&sig->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
|
156 |
_LogAndReturnNull("Failed opening non-real-time end of RT-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
|
157 |
} |
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
|
158 |
|
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 |
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
|
160 |
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
|
161 |
|
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
|
162 |
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
|
163 |
} |
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
|
164 |
|
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 |
void delete_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
|
166 |
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
|
167 |
|
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
|
168 |
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
|
169 |
|
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); |
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
|
171 |
|
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
|
172 |
close(sig->pipe_fd); |
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 |
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
|
175 |
} |
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 |
|
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 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
} |
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
|
182 |
|
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 |
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
|
184 |
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
|
185 |
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
|
186 |
} |
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 |
|
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
|
188 |
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
|
189 |
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
|
190 |
} |
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
|
191 |
|
321 | 192 |
void PLC_cleanup_all(void) |
193 |
{ |
|
194 |
if (PLC_state & PLC_STATE_TASK_CREATED) { |
|
195 |
rt_task_delete(&PLC_task); |
|
196 |
PLC_state &= ~PLC_STATE_TASK_CREATED; |
|
197 |
} |
|
198 |
||
615 | 199 |
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
|
200 |
delete_RT_to_nRT_signal(WaitDebug_handle); |
615 | 201 |
PLC_state &= ~PLC_STATE_WAITDEBUG_PIPE_CREATED; |
202 |
} |
|
203 |
||
204 |
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
|
205 |
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
|
206 |
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
|
207 |
} |
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
208 |
|
342 | 209 |
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
|
210 |
delete_RT_to_nRT_signal(Debug_handle); |
342 | 211 |
PLC_state &= ~PLC_STATE_DEBUG_PIPE_CREATED; |
212 |
} |
|
213 |
||
615 | 214 |
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
|
215 |
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
|
216 |
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
|
217 |
} |
321 | 218 |
} |
219 |
||
220 |
int stopPLC() |
|
221 |
{ |
|
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
222 |
/* Stop the PLC */ |
321 | 223 |
PLC_shutdown = 1; |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
224 |
|
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
225 |
/* Wait until PLC task stops */ |
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
226 |
rt_task_join(&PLC_task); |
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
227 |
|
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
228 |
PLC_cleanup_all(); |
342 | 229 |
__cleanup(); |
321 | 230 |
__debug_tick = -1; |
615 | 231 |
return 0; |
321 | 232 |
} |
233 |
||
234 |
// |
|
235 |
void catch_signal(int sig) |
|
236 |
{ |
|
237 |
stopPLC(); |
|
238 |
// signal(SIGTERM, catch_signal); |
|
239 |
signal(SIGINT, catch_signal); |
|
240 |
printf("Got Signal %d\n",sig); |
|
241 |
exit(0); |
|
242 |
} |
|
243 |
||
1981 | 244 |
#define _startPLCLog(text) \ |
245 |
{\ |
|
246 |
char mstr[] = text;\ |
|
247 |
LogMessage(LOG_CRITICAL, mstr, sizeof(mstr));\ |
|
248 |
goto error;\ |
|
249 |
} |
|
250 |
||
251 |
#define FO "Failed opening " |
|
252 |
||
321 | 253 |
#define max_val(a,b) ((a>b)?a:b) |
254 |
int startPLC(int argc,char **argv) |
|
255 |
{ |
|
256 |
signal(SIGINT, catch_signal); |
|
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
257 |
|
615 | 258 |
/* no memory swapping for that process */ |
321 | 259 |
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
|
260 |
|
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
|
261 |
|
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
|
262 |
/* memory initialization */ |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
263 |
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
|
264 |
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
|
265 |
|
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
|
266 |
/*** RT Pipes ***/ |
615 | 267 |
/* create Debug_pipe */ |
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
|
268 |
if(Debug_handle = create_RT_to_nRT_signal("Debug_pipe")) goto error; |
615 | 269 |
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
|
270 |
|
615 | 271 |
/* create Python_pipe */ |
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
|
272 |
if(Python_handle = create_RT_to_nRT_signal("Python_pipe")) goto error; |
615 | 273 |
PLC_state |= PLC_STATE_PYTHON_PIPE_CREATED; |
274 |
||
342 | 275 |
/* create WaitDebug_pipe */ |
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
|
276 |
if(WaitDebug_handle = create_RT_to_nRT_signal("WaitDebug_pipe")) goto error; |
615 | 277 |
PLC_state |= PLC_STATE_WAITDEBUG_PIPE_CREATED; |
342 | 278 |
|
615 | 279 |
/* create WaitPython_pipe */ |
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
|
280 |
if(WaitPython_handle = create_RT_to_nRT_signal("WaitPython_pipe")) goto error; |
615 | 281 |
PLC_state |= PLC_STATE_WAITPYTHON_PIPE_CREATED; |
282 |
||
283 |
/*** create PLC task ***/ |
|
1981 | 284 |
if(rt_task_create(&PLC_task, "PLC_task", 0, 50, T_JOINABLE)) |
285 |
_startPLCLog("Failed creating PLC task"); |
|
321 | 286 |
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
|
287 |
|
615 | 288 |
if(__init(argc,argv)) goto error; |
289 |
||
290 |
/* start PLC task */ |
|
1981 | 291 |
if(rt_task_start(&PLC_task, &PLC_task_proc, NULL)) |
292 |
_startPLCLog("Failed starting PLC task"); |
|
321 | 293 |
|
294 |
return 0; |
|
295 |
||
296 |
error: |
|
616
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
297 |
|
321 | 298 |
PLC_cleanup_all(); |
299 |
return 1; |
|
300 |
} |
|
301 |
||
615 | 302 |
#define DEBUG_FREE 0 |
303 |
#define DEBUG_BUSY 1 |
|
304 |
static long debug_state = DEBUG_FREE; |
|
305 |
||
321 | 306 |
int TryEnterDebugSection(void) |
307 |
{ |
|
616
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
308 |
if(AtomicCompareExchange( |
615 | 309 |
&debug_state, |
310 |
DEBUG_FREE, |
|
616
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
311 |
DEBUG_BUSY) == DEBUG_FREE){ |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
312 |
if(__DEBUG){ |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
313 |
return 1; |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
314 |
} |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
315 |
AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
316 |
} |
b9271faec96e
Xenomai Fix : runs, but still fail in debug
Edouard Tisserant
parents:
615
diff
changeset
|
317 |
return 0; |
615 | 318 |
} |
319 |
||
321 | 320 |
void LeaveDebugSection(void) |
321 |
{ |
|
615 | 322 |
if(AtomicCompareExchange( &debug_state, |
323 |
DEBUG_BUSY, DEBUG_FREE) == DEBUG_BUSY){ |
|
324 |
char msg = DEBUG_UNLOCK; |
|
325 |
/* 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
|
326 |
send_RT_to_nRT_signal(Debug_handle, msg); |
615 | 327 |
} |
321 | 328 |
} |
329 |
||
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
|
330 |
extern unsigned long __tick; |
615 | 331 |
|
446
1edde533db19
Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents:
397
diff
changeset
|
332 |
int WaitDebugData(unsigned long *tick) |
321 | 333 |
{ |
615 | 334 |
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
|
335 |
int res; |
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
336 |
if (PLC_shutdown) return -1; |
321 | 337 |
/* 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
|
338 |
recv_RT_to_nRT_signal(WaitDebug_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
|
339 |
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
|
340 |
*tick = __debug_tick; |
615 | 341 |
return 0; |
617
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
616
diff
changeset
|
342 |
} |
345
a3520d75a722
get the WaitPythonCommands return (semaphore error code) to quit python_iterator loop when semaphore is destroyed
greg
parents:
342
diff
changeset
|
343 |
return -1; |
321 | 344 |
} |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
345 |
|
321 | 346 |
/* Called by PLC thread when debug_publish finished |
347 |
* This is supposed to unlock debugger thread in WaitDebugData*/ |
|
348 |
void InitiateDebugTransfer() |
|
349 |
{ |
|
615 | 350 |
char msg = DEBUG_PENDING_DATA; |
321 | 351 |
/* remember tick */ |
352 |
__debug_tick = __tick; |
|
353 |
/* 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
|
354 |
send_RT_to_nRT_signal(WaitDebug_handle, msg); |
615 | 355 |
} |
356 |
||
357 |
int suspendDebug(int disable) |
|
358 |
{ |
|
359 |
char cmd = DEBUG_UNLOCK; |
|
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
360 |
if (PLC_shutdown) return -1; |
615 | 361 |
while(AtomicCompareExchange( |
362 |
&debug_state, |
|
363 |
DEBUG_FREE, |
|
364 |
DEBUG_BUSY) != DEBUG_FREE && |
|
365 |
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
|
366 |
if(recv_RT_to_nRT_signal(Debug_handle, &cmd) != 1){ |
615 | 367 |
return -1; |
368 |
} |
|
369 |
} |
|
370 |
__DEBUG = !disable; |
|
617
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
616
diff
changeset
|
371 |
if (disable) |
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
616
diff
changeset
|
372 |
AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
615 | 373 |
return 0; |
321 | 374 |
} |
375 |
||
376 |
void resumeDebug(void) |
|
377 |
{ |
|
615 | 378 |
AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
379 |
} |
|
380 |
||
381 |
#define PYTHON_FREE 0 |
|
382 |
#define PYTHON_BUSY 1 |
|
383 |
static long python_state = PYTHON_FREE; |
|
384 |
||
321 | 385 |
int WaitPythonCommands(void) |
615 | 386 |
{ |
387 |
char cmd; |
|
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
388 |
if (PLC_shutdown) return -1; |
321 | 389 |
/* 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
|
390 |
if(recv_RT_to_nRT_signal(WaitPython_handle, &cmd) == 1 && cmd==PYTHON_PENDING_COMMAND){ |
615 | 391 |
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
|
392 |
} |
a3520d75a722
get the WaitPythonCommands return (semaphore error code) to quit python_iterator loop when semaphore is destroyed
greg
parents:
342
diff
changeset
|
393 |
return -1; |
321 | 394 |
} |
336
ae3488c79283
Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents:
321
diff
changeset
|
395 |
|
321 | 396 |
/* Called by PLC thread on each new python command*/ |
397 |
void UnBlockPythonCommands(void) |
|
398 |
{ |
|
615 | 399 |
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
|
400 |
send_RT_to_nRT_signal(WaitPython_handle, msg); |
321 | 401 |
} |
402 |
||
403 |
int TryLockPython(void) |
|
404 |
{ |
|
615 | 405 |
return AtomicCompareExchange( |
406 |
&python_state, |
|
407 |
PYTHON_FREE, |
|
408 |
PYTHON_BUSY) == PYTHON_FREE; |
|
409 |
} |
|
410 |
||
411 |
#define UNLOCK_PYTHON 1 |
|
412 |
void LockPython(void) |
|
413 |
{ |
|
414 |
char cmd = UNLOCK_PYTHON; |
|
745
96dd6650854d
Fixing Xenomai runtime specific parts to remove segmentation fault when stopping PLC
laurent
parents:
695
diff
changeset
|
415 |
if (PLC_shutdown) return; |
615 | 416 |
while(AtomicCompareExchange( |
417 |
&python_state, |
|
418 |
PYTHON_FREE, |
|
419 |
PYTHON_BUSY) != PYTHON_FREE && |
|
420 |
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
|
421 |
recv_RT_to_nRT_signal(Python_handle, &cmd); |
615 | 422 |
} |
321 | 423 |
} |
424 |
||
425 |
void UnLockPython(void) |
|
426 |
{ |
|
615 | 427 |
if(AtomicCompareExchange( |
428 |
&python_state, |
|
429 |
PYTHON_BUSY, |
|
430 |
PYTHON_FREE) == PYTHON_BUSY){ |
|
431 |
if(rt_task_self()){/*is that the real time task ?*/ |
|
432 |
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
|
433 |
send_RT_to_nRT_signal(Python_handle, cmd); |
615 | 434 |
}/* otherwise, no signaling from non real time */ |
435 |
} /* as plc does not wait for lock. */ |
|
436 |
} |
|
437 |
||
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
|
438 |
#ifndef HAVE_RETAIN |
1717
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
439 |
int CheckRetainBuffer(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
440 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
441 |
return 1; |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
442 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
443 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
444 |
void ValidateRetainBuffer(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
445 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
446 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
447 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
448 |
void InValidateRetainBuffer(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
449 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
450 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
451 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
452 |
void Retain(unsigned int offset, unsigned int count, void *p) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
453 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
454 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
455 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
456 |
void Remind(unsigned int offset, unsigned int count, void *p) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
457 |
{ |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
458 |
} |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
459 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
460 |
void CleanupRetain(void) |
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
461 |
{ |
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 |
|
a86deec92e08
fix target Xenomai missing functions
wuyangtang <wuyangtang@live.com>
parents:
1456
diff
changeset
|
464 |
void InitRetain(void) |
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 |
} |
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
|
467 |
#endif // !HAVE_RETAIN |