Commit 82c17db2 authored by Claes Sjofors's avatar Claes Sjofors

Merge branch 'master' of newton:/data1/x0-0-0/pwr

parents 3efd3a05 698e9069
......@@ -1137,7 +1137,8 @@ static void mb_shift_write(
for (i = 0; i < (quant + sh) / 8; i++) {
if (i == 0) {
unsigned char mask = ~0 << sh;
unsigned char mask = ~0;
mask = mask << sh;
out[0] &= ~mask;
out[0] |= mask & (in[0] << sh);
......@@ -1147,7 +1148,8 @@ static void mb_shift_write(
}
}
if ((quant + sh) % 8 != 0) {
unsigned char mask = ~0 << ((quant + sh) % 8);
unsigned char mask = ~0;
mask = mask << ((quant + sh) % 8);
mask = ~mask;
out[i] &= ~mask;
......
......@@ -986,7 +986,8 @@ static void mb_shift_write(
for (i = 0; i < (quant + sh) / 8; i++) {
if (i == 0) {
unsigned char mask = ~0 << sh;
unsigned char mask = ~0;
mask = mask << sh;
out[0] &= ~mask;
out[0] |= mask & (in[0] << sh);
......@@ -996,7 +997,8 @@ static void mb_shift_write(
}
}
if ((quant + sh) % 8 != 0) {
unsigned char mask = ~0 << ((quant + sh) % 8);
unsigned char mask = ~0;
mask = mask << ((quant + sh) % 8);
mask = ~mask;
out[i] &= ~mask;
......
......@@ -273,9 +273,13 @@ static pwr_tStatus IoCardRead(
/* Buttons */
idx = js.number;
/*
// TODO:
// js.number is an unsigned 8-bit, which has a maximum value of 256.
// KEY_MAX - BTN_MISC = 511, so this is always false.
if (js.number < KEY_MAX - BTN_MISC)
idx = local->button_map[js.number];
else
else */
break;
*(pwr_tBoolean*)cp->chanlist[idx].vbp = (js.value != 0);
......
......@@ -4595,23 +4595,27 @@ int sev_dbhdf5::check_deadband(pwr_eType type, unsigned int size,
}
break;
case pwr_eType_UInt64:
if (ABS(*(pwr_tUInt64*)value - *(pwr_tUInt64*)oldvalue) < deadband) {
if (ABS(((pwr_tInt64)(*(pwr_tUInt64*)value - *(pwr_tUInt64*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt32:
case pwr_eType_Boolean:
if (ABS(*(pwr_tUInt32*)value - *(pwr_tUInt32*)oldvalue) < deadband) {
if (ABS(((pwr_tInt32)(*(pwr_tUInt32*)value - *(pwr_tUInt32*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt16:
if (ABS(*(pwr_tUInt16*)value - *(pwr_tUInt16*)oldvalue) < deadband) {
if (ABS(((pwr_tInt16)(*(pwr_tUInt16*)value - *(pwr_tUInt16*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt8:
if (ABS(*(pwr_tUInt8*)value - *(pwr_tUInt8*)oldvalue) < deadband) {
if (ABS(((pwr_tInt8)(*(pwr_tUInt8*)value - *(pwr_tUInt8*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
......
......@@ -1323,8 +1323,8 @@ int sev_dbms::write_value(pwr_tStatus* sts, int item_idx, int attr_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt64)))
|| (ABS(*(pwr_tUInt64*)buf
- *(pwr_tUInt64*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt64)(*(pwr_tUInt64*)buf
- *(pwr_tUInt64*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
update_time_only = 1;
} else {
......@@ -1337,8 +1337,8 @@ int sev_dbms::write_value(pwr_tStatus* sts, int item_idx, int attr_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt32)))
|| (ABS(*(pwr_tUInt32*)buf
- *(pwr_tUInt32*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt32)(*(pwr_tUInt32*)buf
- *(pwr_tUInt32*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
update_time_only = 1;
} else {
......@@ -1350,8 +1350,8 @@ int sev_dbms::write_value(pwr_tStatus* sts, int item_idx, int attr_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt16)))
|| (ABS(*(pwr_tUInt16*)buf
- *(pwr_tUInt16*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt16)(*(pwr_tUInt16*)buf
- *(pwr_tUInt16*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
update_time_only = 1;
} else {
......@@ -1363,8 +1363,8 @@ int sev_dbms::write_value(pwr_tStatus* sts, int item_idx, int attr_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt8)))
|| (ABS(*(pwr_tUInt8*)buf
- *(pwr_tUInt8*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt8)(*(pwr_tUInt8*)buf
- *(pwr_tUInt8*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
update_time_only = 1;
} else {
......@@ -1464,8 +1464,8 @@ int sev_dbms::write_value(pwr_tStatus* sts, int item_idx, int attr_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt64)))
|| (ABS(*(pwr_tUInt64*)buf
- *(pwr_tUInt64*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt64)(*(pwr_tUInt64*)buf
- *(pwr_tUInt64*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
m_items[item_idx].deadband_active = 1;
set_jump = 1;
......@@ -1477,8 +1477,8 @@ int sev_dbms::write_value(pwr_tStatus* sts, int item_idx, int attr_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt32)))
|| (ABS(*(pwr_tUInt32*)buf
- *(pwr_tUInt32*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt32)(*(pwr_tUInt32*)buf
- *(pwr_tUInt32*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
m_items[item_idx].deadband_active = 1;
set_jump = 1;
......@@ -1489,8 +1489,8 @@ int sev_dbms::write_value(pwr_tStatus* sts, int item_idx, int attr_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt16)))
|| (ABS(*(pwr_tUInt16*)buf
- *(pwr_tUInt16*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt16)(*(pwr_tUInt16*)buf
- *(pwr_tUInt16*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
m_items[item_idx].deadband_active = 1;
set_jump = 1;
......@@ -1501,8 +1501,8 @@ int sev_dbms::write_value(pwr_tStatus* sts, int item_idx, int attr_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt8)))
|| (ABS(*(pwr_tUInt8*)buf
- *(pwr_tUInt8*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt8)(*(pwr_tUInt8*)buf
- *(pwr_tUInt8*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
m_items[item_idx].deadband_active = 1;
set_jump = 1;
......@@ -3893,23 +3893,27 @@ int sev_dbms::check_deadband(pwr_eType type, unsigned int size,
}
break;
case pwr_eType_UInt64:
if (ABS(*(pwr_tUInt64*)value - *(pwr_tUInt64*)oldvalue) < deadband) {
if (ABS(((pwr_tInt64)(*(pwr_tUInt64*)value - *(pwr_tUInt64*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt32:
case pwr_eType_Boolean:
if (ABS(*(pwr_tUInt32*)value - *(pwr_tUInt32*)oldvalue) < deadband) {
if (ABS(((pwr_tInt32)(*(pwr_tUInt32*)value - *(pwr_tUInt32*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt16:
if (ABS(*(pwr_tUInt16*)value - *(pwr_tUInt16*)oldvalue) < deadband) {
if (ABS(((pwr_tInt16)(*(pwr_tUInt16*)value - *(pwr_tUInt16*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt8:
if (ABS(*(pwr_tUInt8*)value - *(pwr_tUInt8*)oldvalue) < deadband) {
if (ABS(((pwr_tInt8)(*(pwr_tUInt8*)value - *(pwr_tUInt8*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
......
......@@ -703,8 +703,8 @@ int sev_dbsqlite::store_value(pwr_tStatus* sts, void* thread, int item_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt64)))
|| (ABS(*(pwr_tUInt64*)buf
- *(pwr_tUInt64*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt64)(*(pwr_tUInt64*)buf
- *(pwr_tUInt64*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
update_time_only = 1;
} else {
......@@ -717,8 +717,8 @@ int sev_dbsqlite::store_value(pwr_tStatus* sts, void* thread, int item_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt32)))
|| (ABS(*(pwr_tUInt32*)buf
- *(pwr_tUInt32*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt32)(*(pwr_tUInt32*)buf
- *(pwr_tUInt32*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
update_time_only = 1;
} else {
......@@ -730,8 +730,8 @@ int sev_dbsqlite::store_value(pwr_tStatus* sts, void* thread, int item_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt16)))
|| (ABS(*(pwr_tUInt16*)buf
- *(pwr_tUInt16*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt16)(*(pwr_tUInt16*)buf
- *(pwr_tUInt16*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
update_time_only = 1;
} else {
......@@ -743,8 +743,8 @@ int sev_dbsqlite::store_value(pwr_tStatus* sts, void* thread, int item_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt8)))
|| (ABS(*(pwr_tUInt8*)buf
- *(pwr_tUInt8*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt8)(*(pwr_tUInt8*)buf
- *(pwr_tUInt8*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
update_time_only = 1;
} else {
......@@ -844,8 +844,8 @@ int sev_dbsqlite::store_value(pwr_tStatus* sts, void* thread, int item_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt64)))
|| (ABS(*(pwr_tUInt64*)buf
- *(pwr_tUInt64*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt64)(*(pwr_tUInt64*)buf
- *(pwr_tUInt64*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
m_items[item_idx].deadband_active = 1;
set_jump = 1;
......@@ -857,8 +857,8 @@ int sev_dbsqlite::store_value(pwr_tStatus* sts, void* thread, int item_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt32)))
|| (ABS(*(pwr_tUInt32*)buf
- *(pwr_tUInt32*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt32)(*(pwr_tUInt32*)buf
- *(pwr_tUInt32*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
m_items[item_idx].deadband_active = 1;
set_jump = 1;
......@@ -869,8 +869,8 @@ int sev_dbsqlite::store_value(pwr_tStatus* sts, void* thread, int item_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt16)))
|| (ABS(*(pwr_tUInt16*)buf
- *(pwr_tUInt16*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt16)(*(pwr_tUInt16*)buf
- *(pwr_tUInt16*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
m_items[item_idx].deadband_active = 1;
set_jump = 1;
......@@ -881,8 +881,8 @@ int sev_dbsqlite::store_value(pwr_tStatus* sts, void* thread, int item_idx,
if ((feqf(m_items[item_idx].deadband, 0.0f)
&& !memcmp(
buf, m_items[item_idx].old_value, sizeof(pwr_tUInt8)))
|| (ABS(*(pwr_tUInt8*)buf
- *(pwr_tUInt8*)m_items[item_idx].old_value)
|| (ABS(((pwr_tInt8)(*(pwr_tUInt8*)buf
- *(pwr_tUInt8*)m_items[item_idx].old_value)))
< m_items[item_idx].deadband)) {
m_items[item_idx].deadband_active = 1;
set_jump = 1;
......@@ -2812,23 +2812,27 @@ int sev_dbsqlite::check_deadband(pwr_eType type, unsigned int size,
}
break;
case pwr_eType_UInt64:
if (ABS(*(pwr_tUInt64*)value - *(pwr_tUInt64*)oldvalue) < deadband) {
if (ABS(((pwr_tInt64)(*(pwr_tUInt64*)value - *(pwr_tUInt64*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt32:
case pwr_eType_Boolean:
if (ABS(*(pwr_tUInt32*)value - *(pwr_tUInt32*)oldvalue) < deadband) {
if (ABS(((pwr_tInt32)(*(pwr_tUInt32*)value - *(pwr_tUInt32*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt16:
if (ABS(*(pwr_tUInt16*)value - *(pwr_tUInt16*)oldvalue) < deadband) {
if (ABS(((pwr_tInt16)(*(pwr_tUInt16*)value - *(pwr_tUInt16*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
case pwr_eType_UInt8:
if (ABS(*(pwr_tUInt8*)value - *(pwr_tUInt8*)oldvalue) < deadband) {
if (ABS(((pwr_tInt8)(*(pwr_tUInt8*)value - *(pwr_tUInt8*)oldvalue)))
< deadband) {
deadband_active = 1;
}
break;
......
......@@ -869,12 +869,12 @@ int CnvReadWbl::graphplcnode_attr(char* name, char* value)
strcat(doc_text[doc_cnt - 1], " (document)");
else if (streq(value, "7"))
strcat(doc_text[doc_cnt - 1], " (Get,Set)");
} else if (streq(low(name), "compmethod"))
} /* else if (streq(low(name), "compmethod"))
;
else if (streq(low(name), "tracemethod"))
;
else if (streq(low(name), "executeordermethod"))
;
; */
return 1;
}
......@@ -896,6 +896,7 @@ int CnvReadWbl::graphplccon_attr(char* name, char* value)
strcpy(doc_text[doc_cnt++], value);
// Description
/*
if (streq(low(name), "curvature"))
;
else if (streq(low(name), "corners"))
......@@ -904,6 +905,7 @@ int CnvReadWbl::graphplccon_attr(char* name, char* value)
;
else if (streq(low(name), "attributes"))
;
*/
return 1;
}
......
include $(pwre_dir_symbols)
-include $(pwre_sroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_sroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_sroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
/*
* chrt.c - chrt
* Command-line utility for manipulating a task's real-time attributes
*
* Robert Love <rml@tech9.net>
* 27-Apr-2002: initial version
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, v2, as
* published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Copyright (C) 2004 Robert Love
*/
#include <errno.h>
#include <getopt.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void show_usage(const char* cmd)
{
// fprintf(stderr, "chrt version " VERSION "\n");
fprintf(stderr, "usage: %s [options] [prio] [pid | cmd [args...]]\n", cmd);
fprintf(stderr, "manipulate real-time attributes of a process\n");
fprintf(stderr, " -f, --fifo "
"set policy to SCHED_FF\n");
fprintf(stderr, " -p, --pid "
"operate on existing given pid\n");
fprintf(stderr, " -m, --max "
"show min and max valid priorities\n");
fprintf(stderr, " -o, --other "
"set policy to SCHED_OTHER\n");
fprintf(stderr, " -r, --rr "
"set policy to SCHED_RR (default)\n");
fprintf(stderr, " -h, --help "
"display this help\n");
fprintf(stderr, " -v, --verbose "
"display status information\n");
// fprintf(stderr, " -V, --version "
// "output version information\n\n");
fprintf(stderr, "You must give a priority if changing policy.\n\n");
fprintf(stderr, "Report bugs and send patches to <rml@tech9.net>\n");
}
static void show_rt_info(const char* what, pid_t pid)
{
struct sched_param sp;
int policy;
/* don't display "pid 0" as that is confusing */
if (!pid)
pid = getpid();
policy = sched_getscheduler(pid);
if (policy == -1) {
perror("sched_getscheduler");
fprintf(stderr, "failed to get pid %d's policy\n", pid);
exit(1);
}
printf("pid %d's %s scheduling policy: ", pid, what);
switch (policy) {
case SCHED_OTHER:
printf("SCHED_OTHER\n");
break;
case SCHED_FIFO:
printf("SCHED_FIFO\n");
break;
case SCHED_RR:
printf("SCHED_RR\n");
break;
default:
printf("unknown\n");
}
if (sched_getparam(pid, &sp)) {
perror("sched_getparam");
fprintf(stderr, "failed to get pid %d's attributes\n", pid);
exit(1);
}
printf("pid %d's %s scheduling priority: %d\n", pid, what, sp.sched_priority);
}
static void show_min_max(void)
{
int max, min;
max = sched_get_priority_max(SCHED_FIFO);
min = sched_get_priority_min(SCHED_FIFO);
if (max >= 0 && min >= 0)
printf("SCHED_FIFO min/max priority\t: %d/%d\n", min, max);
else
printf("SCHED_FIFO not supported?\n");
max = sched_get_priority_max(SCHED_RR);
min = sched_get_priority_min(SCHED_RR);
if (max >= 0 && min >= 0)
printf("SCHED_RR min/max priority\t: %d/%d\n", min, max);
else
printf("SCHED_RR not supported?\n");
max = sched_get_priority_max(SCHED_OTHER);
min = sched_get_priority_min(SCHED_OTHER);
if (max >= 0 && min >= 0)
printf("SCHED_OTHER min/max priority\t: %d/%d\n", min, max);
else
printf("SCHED_OTHER not supported?\n");
}
int main(int argc, char* argv[])
{
int i, policy = SCHED_RR, priority = 0, verbose = 0;
struct sched_param sp;
pid_t pid = 0;
struct option longopts[] = { { "fifo", 0, NULL, 'f' },
{ "pid", 0, NULL, 'p' }, { "help", 0, NULL, 'h' }, { "max", 0, NULL, 'm' },
{ "other", 0, NULL, 'o' }, { "rr", 0, NULL, 'r' },
{ "verbose", 0, NULL, 'v' }, { "reboot", 0, NULL, 'B' },
// { "version", 0, NULL, 'V' },
{ NULL, 0, NULL, 0 } };
while ((i = getopt_long(argc, argv, "+fphmorv", longopts, NULL)) != -1) {
int ret = 1;
switch (i) {
case 'f':
policy = SCHED_FIFO;
break;
case 'm':
show_min_max();
return 0;
case 'o':
policy = SCHED_OTHER;
break;
case 'p':
errno = 0;
pid = strtol(argv[argc - 1], NULL, 10);
if (errno) {
perror("strtol");
fprintf(stderr, "failed to parse pid!\n");
return 1;
}
break;
case 'r':
policy = SCHED_RR;
break;
case 'v':
verbose = 1;
break;
// case 'V':
// printf("chrt version " VERSION "\n");
// return 0;
case 'B': {
int sts;
sts = system("/sbin/reboot");
if (sts != 0)
printf("Reboot return sts: %d\n", sts);
return 0;
}
case 'h':
ret = 0;
default:
show_usage(argv[0]);
return ret;
}
}
if ((pid && argc - optind < 1) || (!pid && argc - optind < 2)) {
show_usage(argv[0]);
return 1;
}
if (pid && (verbose || argc - optind == 1)) {
show_rt_info("current", pid);
if (argc - optind == 1)
return 0;
}
errno = 0;
priority = strtol(argv[optind], NULL, 10);
if (errno) {
perror("strtol");
fprintf(stderr, "failed to parse priority!\n");
return 1;
}
sp.sched_priority = priority;
if (sched_setscheduler(pid, policy, &sp) == -1) {
perror("sched_setscheduler");
fprintf(stderr, "failed to set pid %d's policy\n", pid);
return 1;
}
if (verbose)
show_rt_info("new", pid);
if (!pid) {
argv += optind + 1;
execvp(argv[0], argv);
perror("execvp");
fprintf(stderr, "failed to execute %s\n", argv[0]);
return 1;
}
return 0;
}
......@@ -174,7 +174,6 @@ int main(int argc, char* argv[])
qcom_WaitAnd(
&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcStart, qcom_cTmoEternal);
// proc_SetPriority(pp->PlcProcess->Prio);
set_values(pp);
start_threads(pp);
run_threads(pp);
......
......@@ -1629,8 +1629,8 @@ struct register_info {
if (stack_last_malloced != NULL) \
free(stack_last_malloced); \
stack_last_malloced = stackx; \
if (stackx == NULL) \
; /* left to do */ \
/* if (stackx == NULL) \
; // left to do */ \
/* end of change */ \
/* Only copy what is in use. */ \
bcopy(stackb, stackx, len * sizeof(char*)); \
......
......@@ -115,7 +115,11 @@ pwr_tStatus syi_UserName(char* user, int len)
{
char* p;
#if defined(OS_CYGWIN) || defined(OS_LINUX)
p = cuserid(0);
#else
p = getlogin();
#endif
if (!p)
return 0;
strncpy(user, p, len);
......@@ -137,15 +141,18 @@ const char* syi_Hardware()
const char* syi_OpSys()
{
#if defined OS_LINUX
static const char opsys[] = "Linux";
return "Linux";
#elif defined OS_MACOS
static const char opsys[] = "MacOS";
return "MacOS";
#elif defined OS_FREEBSD
static const char opsys[] = "FreeBSD";
return "FreeBSD";
#elif defined OS_OPENBSD
return "OpenBSD";
#elif defined OS_CYGWIN
return "Cygwin";
#else
static const char opsys[] = "Unknown";
return "Unknown";
#endif
return opsys;
}
char* syi_ProcessId()
......
......@@ -37,10 +37,6 @@
/* co_time_os.c -- OS specific time routines.
*/
#ifndef OS_LINUX
#error This file is only for Linux
#endif
#include <string.h>
#include <unistd.h>
#include <sys/times.h>
......
......@@ -48,7 +48,7 @@
*/
#define PWR_XDR_BYTES(xdrs, addr, len) \
{ \
if (((xdrs)->x_handy -= len) < 0) \
if (((int) ((xdrs)->x_handy -= len)) < 0) \
return (FALSE); \
\
if ((xdrs)->x_op == XDR_DECODE) \
......@@ -65,7 +65,7 @@
*/
#define PWR_XDR_STRING(xdrs, addr, len) \
{ \
if (((xdrs)->x_handy -= len) < 0) \
if (((int) ((xdrs)->x_handy -= len)) < 0) \
return (FALSE); \
\
if ((xdrs)->x_op == XDR_DECODE) \
......@@ -82,7 +82,7 @@
*/
#define PWR_XDR_INT(xdrs, objp, objtype) \
{ \
if (((xdrs)->x_handy -= sizeof(int)) < 0) \
if (((int) ((xdrs)->x_handy -= sizeof(int))) < 0) \
return (FALSE); \
\
if ((xdrs)->x_op == XDR_DECODE) \
......
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_syi.c -- System information
This module gives information about the system. */
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "co_errno.h"
#include "co_syi.h"
#include "co_syi_msg.h"
char* syi_HostName(pwr_tStatus* status, char* ibuffer, int isize)
{
return syi_NodeName(status, ibuffer, isize);
}
char* syi_NodeName(pwr_tStatus* status, char* ibuffer, int isize)
{
char* cp;
pwr_dStatus(sts, status, SYI__SUCCESS);
if (gethostname(ibuffer, isize) != 0) {
if (errno == EINVAL) {
*sts = SYI__TRUNCATED;
} else {
*sts = errno_Status(errno);
ibuffer = NULL;
}
}
/* Remove domain */
if ((cp = strchr(ibuffer, '.')))
*cp = 0;
return ibuffer;
}
char* syi_Ethernet(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_NodeSpec(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_HostSpec(pwr_tStatus* status, char* ibuffer, int size)
{
return syi_NodeSpec(status, ibuffer, size);
}
/* Return true if node is booted locally or
false if booted from remote node via network. */
pwr_tBoolean syi_LocalBoot(pwr_tStatus* status)
{
return YES;
}
/* . */
char* syi_BootDisk(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
pwr_tStatus syi_UserName(char* user, int len)
{
char* p;
p = cuserid(0);
if (!p)
return 0;
strncpy(user, p, len);
return 1;
}
const char* syi_Hardware()
{
#if defined HW_X86_64
static const char hw[] = "x86_64";
#elif defined HW_ARM
static const char hw[] = "ARM";
#else
static const char hw[] = "x86";
#endif
return hw;
}
const char* syi_OpSys()
{
#if defined OS_LINUX
static const char opsys[] = "Linux";
#elif defined OS_MACOS
static const char opsys[] = "MacOS";
#elif defined OS_FREEBSD
static const char opsys[] = "FreeBSD";
#elif defined OS_OPENBSD
static const char opsys[] = "OpenBSD";
#elif defined OS_CYGWIN
static const char opsys[] = "Cygwin";
#else
static const char opsys[] = "Unknown";
#endif
return opsys;
}
char* syi_ProcessId()
{
static char pidstr[40];
sprintf(pidstr, "%u", getpid());
return pidstr;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_time_os.c -- OS specific time routines.
*/
#ifndef OS_CYGWIN
#error This file is only for Cygwin
#endif
#include <string.h>
#include <unistd.h>
#include <sys/times.h>
#include "co_time.h"
#include "co_time_msg.h"
/* Modified to keep uptime tics as a 64-bit unsigned.
* This way uptime tics won't wrap around for another 8000 years or so
* when HZ is at a 1000.
* RK 031112
*/
pwr_tDeltaTime* time_Uptime(
pwr_tStatus* status, pwr_tDeltaTime* tp, pwr_tDeltaTime* ap)
{
pwr_tDeltaTime time;
unsigned long tics;
static pwr_tUInt64 tics_64;
struct tms buff;
static int tics_per_sec = 0;
static pwr_tTime boot_time = { 0, 0 };
static pwr_tDeltaTime max_diff = { 0, 20000000 };
pwr_tDeltaTime uptime_tics;
pwr_tTime current_time;
pwr_tDeltaTime diff;
static pwr_tUInt16 msb_flips = 0;
static pwr_tBoolean old_high_bit = 0;
pwr_tBoolean high_bit;
lldiv_t uptime_s;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
if (tp == NULL)
tp = &time;
tics = times(&buff);
high_bit = tics >> (32 - 1);
if (!high_bit && old_high_bit)
msb_flips++;
old_high_bit = high_bit;
tics_64 = ((pwr_tUInt64)msb_flips << 32) | tics;
uptime_s = lldiv(tics_64, (pwr_tInt64)tics_per_sec);
uptime_tics.tv_sec = (pwr_tInt64)uptime_s.quot;
uptime_tics.tv_nsec
= ((pwr_tUInt64)uptime_s.rem) * (1000000000 / tics_per_sec);
// pwr_Assert(tp->tv_sec >= 0 && tp->tv_nsec >= 0);
time_GetTime(&current_time);
if (!boot_time.tv_sec) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
} else {
time_Adiff(tp, &current_time, &boot_time);
time_Dsub(&diff, tp, &uptime_tics);
time_Dabs(NULL, &diff);
if (time_Dcomp(&diff, &max_diff) > 0) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
if (status != NULL) {
*status = TIME__CLKCHANGE;
}
}
}
if (ap != NULL)
return time_Dadd(tp, tp, ap);
else
return tp;
}
/* Return number of clock ticks since system start.
Add number of tics corresponding to delta time 'add'. */
time_tClock time_Clock(pwr_tStatus* status, pwr_tDeltaTime* ap)
{
long tics;
struct tms buff;
static int tics_per_sec = 0;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
tics = times(&buff);
if (ap != NULL) {
tics += (ap->tv_sec * tics_per_sec)
+ (ap->tv_nsec / (1000000000 / tics_per_sec));
}
return tics;
}
time_tOs* time_Os(pwr_tStatus* status, time_tOs* tp)
{
static time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
time_GetTime(tp);
return tp;
}
/* Set system time */
pwr_tStatus time_SetTime(pwr_tTime* pt)
{
pwr_tStatus sts = TIME__SUCCESS;
return sts;
}
time_tOs* time_AtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tTime* ap)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
*tp = *ap;
return tp;
}
/* Convert from Proview delta time format
to native time format. */
time_tOs* time_DtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tDeltaTime* dp)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
memcpy(tp, dp, sizeof(*tp));
return tp;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_syi.c -- System information
This module gives information about the system. */
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "co_errno.h"
#include "co_syi.h"
#include "co_syi_msg.h"
char* syi_HostName(pwr_tStatus* status, char* ibuffer, int isize)
{
return syi_NodeName(status, ibuffer, isize);
}
char* syi_NodeName(pwr_tStatus* status, char* ibuffer, int isize)
{
char* cp;
pwr_dStatus(sts, status, SYI__SUCCESS);
if (gethostname(ibuffer, isize) != 0) {
if (errno == EINVAL) {
*sts = SYI__TRUNCATED;
} else {
*sts = errno_Status(errno);
ibuffer = NULL;
}
}
/* Remove domain */
if ((cp = strchr(ibuffer, '.')))
*cp = 0;
return ibuffer;
}
char* syi_Ethernet(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_NodeSpec(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_HostSpec(pwr_tStatus* status, char* ibuffer, int size)
{
return syi_NodeSpec(status, ibuffer, size);
}
/* Return true if node is booted locally or
false if booted from remote node via network. */
pwr_tBoolean syi_LocalBoot(pwr_tStatus* status)
{
return YES;
}
/* . */
char* syi_BootDisk(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
pwr_tStatus syi_UserName(char* user, int len)
{
char* p;
p = getlogin();
if (!p)
return 0;
strncpy(user, p, len);
return 1;
}
const char* syi_Hardware()
{
#if defined HW_X86_64
static const char hw[] = "x86_64";
#else
static const char hw[] = "x86";
#endif
return hw;
}
const char* syi_OpSys()
{
#if defined OS_LINUX
static const char opsys[] = "Linux";
#elif defined OS_MACOS
static const char opsys[] = "MacOS";
#elif defined OS_FREEBSD
static const char opsys[] = "FreeBSD";
#else
static const char opsys[] = "Unknown";
#endif
return opsys;
}
char* syi_ProcessId()
{
static char pidstr[40];
sprintf(pidstr, "%u", getpid());
return pidstr;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_time_os.c -- OS specific time routines.
*/
#ifndef OS_FREEBSD
#error This file is only for FreeBSD
#endif
#include <string.h>
#include <unistd.h>
#include <sys/times.h>
#include "co_time.h"
#include "co_time_msg.h"
/* Modified to keep uptime tics as a 64-bit unsigned.
* This way uptime tics won't wrap around for another 8000 years or so
* when HZ is at a 1000.
* RK 031112
*/
pwr_tDeltaTime* time_Uptime(
pwr_tStatus* status, pwr_tDeltaTime* tp, pwr_tDeltaTime* ap)
{
pwr_tDeltaTime time;
unsigned long tics;
static pwr_tUInt64 tics_64;
struct tms buff;
static int tics_per_sec = 0;
static pwr_tTime boot_time = { 0, 0 };
static pwr_tDeltaTime max_diff = { 0, 20000000 };
pwr_tDeltaTime uptime_tics;
pwr_tTime current_time;
pwr_tDeltaTime diff;
static pwr_tUInt16 msb_flips = 0;
static pwr_tBoolean old_high_bit = 0;
pwr_tBoolean high_bit;
lldiv_t uptime_s;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
if (tp == NULL)
tp = &time;
tics = times(&buff);
high_bit = tics >> (32 - 1);
if (!high_bit && old_high_bit)
msb_flips++;
old_high_bit = high_bit;
tics_64 = ((pwr_tUInt64)msb_flips << 32) | tics;
uptime_s = lldiv(tics_64, (pwr_tInt64)tics_per_sec);
uptime_tics.tv_sec = (pwr_tInt64)uptime_s.quot;
uptime_tics.tv_nsec
= ((pwr_tUInt64)uptime_s.rem) * (1000000000 / tics_per_sec);
// pwr_Assert(tp->tv_sec >= 0 && tp->tv_nsec >= 0);
time_GetTime(&current_time);
if (!boot_time.tv_sec) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
} else {
time_Adiff(tp, &current_time, &boot_time);
time_Dsub(&diff, tp, &uptime_tics);
time_Dabs(NULL, &diff);
if (time_Dcomp(&diff, &max_diff) > 0) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
if (status != NULL) {
*status = TIME__CLKCHANGE;
}
}
}
if (ap != NULL)
return time_Dadd(tp, tp, ap);
else
return tp;
}
/* Return number of clock ticks since system start.
Add number of tics corresponding to delta time 'add'. */
time_tClock time_Clock(pwr_tStatus* status, pwr_tDeltaTime* ap)
{
long tics;
struct tms buff;
static int tics_per_sec = 0;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
tics = times(&buff);
if (ap != NULL) {
tics += (ap->tv_sec * tics_per_sec)
+ (ap->tv_nsec / (1000000000 / tics_per_sec));
}
return tics;
}
time_tOs* time_Os(pwr_tStatus* status, time_tOs* tp)
{
static time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
time_GetTime(tp);
return tp;
}
/* Set system time */
pwr_tStatus time_SetTime(pwr_tTime* pt)
{
pwr_tStatus sts = TIME__SUCCESS;
return sts;
}
time_tOs* time_AtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tTime* ap)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
*tp = *ap;
return tp;
}
/* Convert from Proview delta time format
to native time format. */
time_tOs* time_DtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tDeltaTime* dp)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
memcpy(tp, dp, sizeof(*tp));
return tp;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_syi.c -- System information
This module gives information about the system. */
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "co_errno.h"
#include "co_syi.h"
#include "co_syi_msg.h"
char* syi_HostName(pwr_tStatus* status, char* ibuffer, int isize)
{
return syi_NodeName(status, ibuffer, isize);
}
char* syi_NodeName(pwr_tStatus* status, char* ibuffer, int isize)
{
char* cp;
pwr_dStatus(sts, status, SYI__SUCCESS);
if (gethostname(ibuffer, isize) != 0) {
if (errno == EINVAL) {
*sts = SYI__TRUNCATED;
} else {
*sts = errno_Status(errno);
ibuffer = NULL;
}
}
/* Remove domain */
if ((cp = strchr(ibuffer, '.')))
*cp = 0;
return ibuffer;
}
char* syi_Ethernet(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_NodeSpec(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_HostSpec(pwr_tStatus* status, char* ibuffer, int size)
{
return syi_NodeSpec(status, ibuffer, size);
}
/* Return true if node is booted locally or
false if booted from remote node via network. */
pwr_tBoolean syi_LocalBoot(pwr_tStatus* status)
{
return YES;
}
/* . */
char* syi_BootDisk(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
pwr_tStatus syi_UserName(char* user, int len)
{
char* p;
p = getlogin();
if (!p)
return 0;
strncpy(user, p, len);
return 1;
}
const char* syi_Hardware()
{
#if defined HW_X86_64
static const char hw[] = "x86_64";
#else
static const char hw[] = "x86";
#endif
return hw;
}
const char* syi_OpSys()
{
#if defined OS_LINUX
static const char opsys[] = "Linux";
#elif defined OS_MACOS
static const char opsys[] = "MacOS";
#else
static const char opsys[] = "Unknown";
#endif
return opsys;
}
char* syi_ProcessId()
{
static char pidstr[40];
sprintf(pidstr, "%u", getpid());
return pidstr;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_time_os.c -- OS specific time routines.
*/
#ifndef OS_MACOS
#error This file is only for Mac OS
#endif
#include <string.h>
#include <unistd.h>
#include <sys/times.h>
#include "co_time.h"
#include "co_time_msg.h"
/* Modified to keep uptime tics as a 64-bit unsigned.
* This way uptime tics won't wrap around for another 8000 years or so
* when HZ is at a 1000.
* RK 031112
*/
pwr_tDeltaTime* time_Uptime(
pwr_tStatus* status, pwr_tDeltaTime* tp, pwr_tDeltaTime* ap)
{
pwr_tDeltaTime time;
unsigned long tics;
static pwr_tUInt64 tics_64;
struct tms buff;
static int tics_per_sec = 0;
static pwr_tTime boot_time = { 0, 0 };
static pwr_tDeltaTime max_diff = { 0, 20000000 };
pwr_tDeltaTime uptime_tics;
pwr_tTime current_time;
pwr_tDeltaTime diff;
static pwr_tUInt16 msb_flips = 0;
static pwr_tBoolean old_high_bit = 0;
pwr_tBoolean high_bit;
lldiv_t uptime_s;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
if (tp == NULL)
tp = &time;
tics = times(&buff);
high_bit = tics >> (32 - 1);
if (!high_bit && old_high_bit)
msb_flips++;
old_high_bit = high_bit;
tics_64 = ((pwr_tUInt64)msb_flips << 32) | tics;
uptime_s = lldiv(tics_64, (pwr_tInt64)tics_per_sec);
uptime_tics.tv_sec = (pwr_tInt64)uptime_s.quot;
uptime_tics.tv_nsec
= ((pwr_tUInt64)uptime_s.rem) * (1000000000 / tics_per_sec);
// pwr_Assert(tp->tv_sec >= 0 && tp->tv_nsec >= 0);
time_GetTime(&current_time);
if (!boot_time.tv_sec) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
} else {
time_Adiff(tp, &current_time, &boot_time);
time_Dsub(&diff, tp, &uptime_tics);
time_Dabs(NULL, &diff);
if (time_Dcomp(&diff, &max_diff) > 0) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
if (status != NULL) {
*status = TIME__CLKCHANGE;
}
}
}
if (ap != NULL)
return time_Dadd(tp, tp, ap);
else
return tp;
}
/* Return number of clock ticks since system start.
Add number of tics corresponding to delta time 'add'. */
time_tClock time_Clock(pwr_tStatus* status, pwr_tDeltaTime* ap)
{
long tics;
struct tms buff;
static int tics_per_sec = 0;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
tics = times(&buff);
if (ap != NULL) {
tics += (ap->tv_sec * tics_per_sec)
+ (ap->tv_nsec / (1000000000 / tics_per_sec));
}
return tics;
}
time_tOs* time_Os(pwr_tStatus* status, time_tOs* tp)
{
static time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
time_GetTime(tp);
return tp;
}
/* Set system time */
pwr_tStatus time_SetTime(pwr_tTime* pt)
{
pwr_tStatus sts = TIME__SUCCESS;
return sts;
}
time_tOs* time_AtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tTime* ap)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
*tp = *ap;
return tp;
}
/* Convert from Proview delta time format
to native time format. */
time_tOs* time_DtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tDeltaTime* dp)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
memcpy(tp, dp, sizeof(*tp));
return tp;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_syi.c -- System information
This module gives information about the system. */
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "co_errno.h"
#include "co_syi.h"
#include "co_syi_msg.h"
char* syi_HostName(pwr_tStatus* status, char* ibuffer, int isize)
{
return syi_NodeName(status, ibuffer, isize);
}
char* syi_NodeName(pwr_tStatus* status, char* ibuffer, int isize)
{
char* cp;
pwr_dStatus(sts, status, SYI__SUCCESS);
if (gethostname(ibuffer, isize) != 0) {
if (errno == EINVAL) {
*sts = SYI__TRUNCATED;
} else {
*sts = errno_Status(errno);
ibuffer = NULL;
}
}
/* Remove domain */
if ((cp = strchr(ibuffer, '.')))
*cp = 0;
return ibuffer;
}
char* syi_Ethernet(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_NodeSpec(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_HostSpec(pwr_tStatus* status, char* ibuffer, int size)
{
return syi_NodeSpec(status, ibuffer, size);
}
/* Return true if node is booted locally or
false if booted from remote node via network. */
pwr_tBoolean syi_LocalBoot(pwr_tStatus* status)
{
return YES;
}
/* . */
char* syi_BootDisk(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
pwr_tStatus syi_UserName(char* user, int len)
{
char* p;
p = getlogin();
if (!p)
return 0;
strncpy(user, p, len);
return 1;
}
const char* syi_Hardware()
{
#if defined HW_X86_64
static const char hw[] = "x86_64";
#else
static const char hw[] = "x86";
#endif
return hw;
}
const char* syi_OpSys()
{
#if defined OS_LINUX
static const char opsys[] = "Linux";
#elif defined OS_MACOS
static const char opsys[] = "MacOS";
#elif defined OS_FREEBSD
static const char opsys[] = "FreeBSD";
#elif defined OS_OPENBSD
static const char opsys[] = "OpenBSD";
#else
static const char opsys[] = "Unknown";
#endif
return opsys;
}
char* syi_ProcessId()
{
static char pidstr[40];
sprintf(pidstr, "%u", getpid());
return pidstr;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_time_os.c -- OS specific time routines.
*/
#ifndef OS_OPENBSD
#error This file is only for OpenBSD
#endif
#include <string.h>
#include <unistd.h>
#include <sys/times.h>
#include "co_time.h"
#include "co_time_msg.h"
/* Modified to keep uptime tics as a 64-bit unsigned.
* This way uptime tics won't wrap around for another 8000 years or so
* when HZ is at a 1000.
* RK 031112
*/
pwr_tDeltaTime* time_Uptime(
pwr_tStatus* status, pwr_tDeltaTime* tp, pwr_tDeltaTime* ap)
{
pwr_tDeltaTime time;
unsigned long tics;
static pwr_tUInt64 tics_64;
struct tms buff;
static int tics_per_sec = 0;
static pwr_tTime boot_time = { 0, 0 };
static pwr_tDeltaTime max_diff = { 0, 20000000 };
pwr_tDeltaTime uptime_tics;
pwr_tTime current_time;
pwr_tDeltaTime diff;
static pwr_tUInt16 msb_flips = 0;
static pwr_tBoolean old_high_bit = 0;
pwr_tBoolean high_bit;
lldiv_t uptime_s;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
if (tp == NULL)
tp = &time;
tics = times(&buff);
high_bit = tics >> (32 - 1);
if (!high_bit && old_high_bit)
msb_flips++;
old_high_bit = high_bit;
tics_64 = ((pwr_tUInt64)msb_flips << 32) | tics;
uptime_s = lldiv(tics_64, (pwr_tInt64)tics_per_sec);
uptime_tics.tv_sec = (pwr_tInt64)uptime_s.quot;
uptime_tics.tv_nsec
= ((pwr_tUInt64)uptime_s.rem) * (1000000000 / tics_per_sec);
// pwr_Assert(tp->tv_sec >= 0 && tp->tv_nsec >= 0);
time_GetTime(&current_time);
if (!boot_time.tv_sec) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
} else {
time_Adiff(tp, &current_time, &boot_time);
time_Dsub(&diff, tp, &uptime_tics);
time_Dabs(NULL, &diff);
if (time_Dcomp(&diff, &max_diff) > 0) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
if (status != NULL) {
*status = TIME__CLKCHANGE;
}
}
}
if (ap != NULL)
return time_Dadd(tp, tp, ap);
else
return tp;
}
/* Return number of clock ticks since system start.
Add number of tics corresponding to delta time 'add'. */
time_tClock time_Clock(pwr_tStatus* status, pwr_tDeltaTime* ap)
{
long tics;
struct tms buff;
static int tics_per_sec = 0;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
tics = times(&buff);
if (ap != NULL) {
tics += (ap->tv_sec * tics_per_sec)
+ (ap->tv_nsec / (1000000000 / tics_per_sec));
}
return tics;
}
time_tOs* time_Os(pwr_tStatus* status, time_tOs* tp)
{
static time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
time_GetTime(tp);
return tp;
}
/* Set system time */
pwr_tStatus time_SetTime(pwr_tTime* pt)
{
pwr_tStatus sts = TIME__SUCCESS;
return sts;
}
time_tOs* time_AtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tTime* ap)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
*tp = *ap;
return tp;
}
/* Convert from Proview delta time format
to native time format. */
time_tOs* time_DtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tDeltaTime* dp)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
memcpy(tp, dp, sizeof(*tp));
return tp;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_syi.c -- System information
This module gives information about the system. */
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "co_errno.h"
#include "co_syi.h"
#include "co_syi_msg.h"
char* syi_HostName(pwr_tStatus* status, char* ibuffer, int isize)
{
return syi_NodeName(status, ibuffer, isize);
}
char* syi_NodeName(pwr_tStatus* status, char* ibuffer, int isize)
{
char* cp;
pwr_dStatus(sts, status, SYI__SUCCESS);
if (gethostname(ibuffer, isize) != 0) {
if (errno == EINVAL) {
*sts = SYI__TRUNCATED;
} else {
*sts = errno_Status(errno);
ibuffer = NULL;
}
}
/* Remove domain */
if ((cp = strchr(ibuffer, '.')))
*cp = 0;
return ibuffer;
}
char* syi_Ethernet(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_NodeSpec(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
char* syi_HostSpec(pwr_tStatus* status, char* ibuffer, int size)
{
return syi_NodeSpec(status, ibuffer, size);
}
/* Return true if node is booted locally or
false if booted from remote node via network. */
pwr_tBoolean syi_LocalBoot(pwr_tStatus* status)
{
return YES;
}
/* . */
char* syi_BootDisk(pwr_tStatus* status, char* ibuffer, int size)
{
pwr_dStatus(sts, status, SYI__NYI);
return NULL;
}
pwr_tStatus syi_UserName(char* user, int len)
{
char* p;
p = getlogin();
if (!p)
return 0;
strncpy(user, p, len);
return 1;
}
const char* syi_Hardware()
{
#if defined HW_X86_64
static const char hw[] = "x86_64";
#elif defined HW_ARM
static const char hw[] = "ARM";
#else
static const char hw[] = "x86";
#endif
return hw;
}
const char* syi_OpSys()
{
#if defined OS_LINUX
static const char opsys[] = "Linux";
#elif defined OS_MACOS
static const char opsys[] = "MacOS";
#else
static const char opsys[] = "Unknown";
#endif
return opsys;
}
char* syi_ProcessId()
{
static char pidstr[40];
sprintf(pidstr, "%u", getpid());
return pidstr;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_time_os.c -- OS specific time routines.
*/
#ifndef OS_LINUX
#error This file is only for Linux
#endif
#include <string.h>
#include <unistd.h>
#include <sys/times.h>
#include "co_time.h"
#include "co_time_msg.h"
/* Modified to keep uptime tics as a 64-bit unsigned.
* This way uptime tics won't wrap around for another 8000 years or so
* when HZ is at a 1000.
* RK 031112
*/
pwr_tDeltaTime* time_Uptime(
pwr_tStatus* status, pwr_tDeltaTime* tp, pwr_tDeltaTime* ap)
{
pwr_tDeltaTime time;
unsigned long tics;
static pwr_tUInt64 tics_64;
struct tms buff;
static int tics_per_sec = 0;
static pwr_tTime boot_time = { 0, 0 };
static pwr_tDeltaTime max_diff = { 0, 20000000 };
pwr_tDeltaTime uptime_tics;
pwr_tTime current_time;
pwr_tDeltaTime diff;
static pwr_tUInt16 msb_flips = 0;
static pwr_tBoolean old_high_bit = 0;
pwr_tBoolean high_bit;
lldiv_t uptime_s;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
if (tp == NULL)
tp = &time;
tics = times(&buff);
high_bit = tics >> (32 - 1);
if (!high_bit && old_high_bit)
msb_flips++;
old_high_bit = high_bit;
tics_64 = ((pwr_tUInt64)msb_flips << 32) | tics;
uptime_s = lldiv(tics_64, (pwr_tInt64)tics_per_sec);
uptime_tics.tv_sec = (pwr_tInt64)uptime_s.quot;
uptime_tics.tv_nsec
= ((pwr_tUInt64)uptime_s.rem) * (1000000000 / tics_per_sec);
// pwr_Assert(tp->tv_sec >= 0 && tp->tv_nsec >= 0);
time_GetTime(&current_time);
if (!boot_time.tv_sec) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
} else {
time_Adiff(tp, &current_time, &boot_time);
time_Dsub(&diff, tp, &uptime_tics);
time_Dabs(NULL, &diff);
if (time_Dcomp(&diff, &max_diff) > 0) {
time_Asub(&boot_time, &current_time, &uptime_tics);
*tp = uptime_tics;
if (status != NULL) {
*status = TIME__CLKCHANGE;
}
}
}
if (ap != NULL)
return time_Dadd(tp, tp, ap);
else
return tp;
}
/* Return number of clock ticks since system start.
Add number of tics corresponding to delta time 'add'. */
time_tClock time_Clock(pwr_tStatus* status, pwr_tDeltaTime* ap)
{
long tics;
struct tms buff;
static int tics_per_sec = 0;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (!tics_per_sec)
tics_per_sec = sysconf(_SC_CLK_TCK);
tics = times(&buff);
if (ap != NULL) {
tics += (ap->tv_sec * tics_per_sec)
+ (ap->tv_nsec / (1000000000 / tics_per_sec));
}
return tics;
}
time_tOs* time_Os(pwr_tStatus* status, time_tOs* tp)
{
static time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
time_GetTime(tp);
return tp;
}
/* Set system time */
pwr_tStatus time_SetTime(pwr_tTime* pt)
{
pwr_tStatus sts = TIME__SUCCESS;
return sts;
}
time_tOs* time_AtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tTime* ap)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
*tp = *ap;
return tp;
}
/* Convert from Proview delta time format
to native time format. */
time_tOs* time_DtoOs(pwr_tStatus* status, time_tOs* tp, pwr_tDeltaTime* dp)
{
time_tOs os_time;
pwr_dStatus(sts, status, TIME__SUCCESS);
if (tp == NULL)
tp = &os_time;
memcpy(tp, dp, sizeof(*tp));
return tp;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef __PBDRVR__
#define __PBDRVR__
#define INIT_MODE 0x00
#define CONFIG_MODE 0x05
#define COMM_MODE 0x08
#define H_READY_MASK 0x874B2D1E
#define C_READY_MASK 0x78B4D2E1
#define IDLE 0x00
#define BUSY 0x01
#define D_DATA_IDLE 0x00
#define D_DATA_APPLY 0xF0
#define D_DATA_BUSY 0x0F
// Macros for defining ioctl commands
#define PB_IOCTL_MAGIC 'c'
#define PB_IOCTL_READCMIDESC _IO(PB_IOCTL_MAGIC, 1)
#define PB_IOCTL_READLOCALREG _IO(PB_IOCTL_MAGIC, 2)
#define PB_IOCTL_WRITECMIDESC _IO(PB_IOCTL_MAGIC, 3)
#define PB_IOCTL_HWRESET _IO(PB_IOCTL_MAGIC, 4)
#define PB_IOCTL_CMI_INIT _IO(PB_IOCTL_MAGIC, 5)
#define PB_IOCTL_READDATADESC _IO(PB_IOCTL_MAGIC, 6)
#define PB_IOCTL_CMI_WRITE _IO(PB_IOCTL_MAGIC, 7)
#define PB_IOCTL_READ_SDB _IO(PB_IOCTL_MAGIC, 8)
#define PB_IOCTL_READ_DB _IO(PB_IOCTL_MAGIC, 9)
#define PB_IOCTL_CMI_READ _IO(PB_IOCTL_MAGIC, 10)
#define PB_IOCTL_READ_IRQ_VALUES _IO(PB_IOCTL_MAGIC, 11)
#define PB_IOCTL_READ_FIRST_SLAVE _IO(PB_IOCTL_MAGIC, 12)
#define PB_IOCTL_WRITE_FIRST_SLAVE _IO(PB_IOCTL_MAGIC, 13)
#define PB_IOCTL_READVERSION _IO(PB_IOCTL_MAGIC, 14)
#define PB_IOCTL_READSERIAL _IO(PB_IOCTL_MAGIC, 15)
#define PB_IOCTL_SET_STALLTIME _IO(PB_IOCTL_MAGIC, 16)
#define ERROR_DESCR_LENGTH 32
typedef struct {
unsigned int h_ready_mask;
unsigned int h_base_address;
unsigned char h_id;
unsigned char h_int_enable;
unsigned char h_address_swap_mode;
unsigned char h_state;
unsigned int h_param_addr;
unsigned int h_data_addr;
unsigned short h_param_size;
unsigned short h_data_size;
unsigned char h_sema;
unsigned char h_ret_val;
unsigned char h_head;
unsigned char h_tail;
unsigned int h_data_descr_addr;
unsigned int c_ready_mask;
unsigned int c_base_address;
unsigned char c_id;
unsigned char c_int_enable;
unsigned char c_address_swap_mode;
unsigned char c_state;
unsigned int c_param_addr;
unsigned int c_data_addr;
unsigned short c_param_size;
unsigned short c_data_size;
unsigned char c_sema;
unsigned char c_ret_val;
unsigned char c_head;
unsigned char c_tail;
unsigned int c_data_descr_addr;
} T_CMI_DESCRIPTOR;
typedef struct {
unsigned int reg[21];
} T_LOCALREG;
typedef struct {
unsigned char d_id;
unsigned char dummy;
unsigned char d_sema_c;
unsigned char d_sema_h;
unsigned short d_data_size;
unsigned int d_data_addr;
} T_DATA_DESCR;
typedef struct {
T_PROFI_SERVICE_DESCR* sdb_ptr;
USIGN8* data_ptr;
USIGN16* data_len_ptr;
USIGN16* retval_ptr;
} cmi_request_access_struct;
typedef struct {
USIGN8 data_id; // Id of data structure
USIGN16 offset; // Offset in data area
USIGN8* data_ptr; // Pointer to data to write/to be read
USIGN16* retval_ptr; // Pointer to return value
} cmi_data_access_struct;
#endif
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef rt_futex_h
#define rt_futex_h
#ifdef __cplusplus
extern "C" {
#endif
int futex_wait(int* futex, int val);
int futex_timed_wait(int* futex, int val, const struct timespec* timespec);
int futex_wake(int* futex, int nr);
#ifdef __cplusplus
}
#endif
#endif
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_sect.h */
/*-< SEMAPHORE.H >--------------------------------------------------*--------*/
/* POSIX.1b Version 1.0 (c) 1998 GARRET * ? */
/* (POSIX.1b implementation for Linux) * /\| */
/* * / \ */
/* Created: 25-Aug-98 K.A. Knizhnik * / [] \ */
/* Last update: 27-Aug-98 K.A. Knizhnik * GARRET */
/*------------------------------------------------------------------*--------*/
/* Semaphore interface * */
/*------------------------------------------------------------------*--------*/
#ifndef rt_semaphore_h
#define rt_semaphore_h
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
long semkey;
int semid;
int initialized;
} sem_t;
// Not POSIX. The caller generates the key
int posix_sem_init_shared(sem_t* sem, int key, unsigned int value);
int posix_sem_init(sem_t* sem, int pshared, unsigned int value);
sem_t* posix_sem_open(const char* name, int oflag, ...);
int posix_sem_post(sem_t* sem);
int posix_sem_getvalue(sem_t* sem, int* sval);
int posix_sem_wait(sem_t* sem);
int posix_sem_trywait(sem_t* sem);
int posix_sem_unlink(const char* name);
int posix_sem_close(sem_t* sem);
int posix_sem_destroy(sem_t* sem);
#ifdef __cplusplus
}
#endif
#endif
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef __PBDRVR__
#define __PBDRVR__
#define INIT_MODE 0x00
#define CONFIG_MODE 0x05
#define COMM_MODE 0x08
#define H_READY_MASK 0x874B2D1E
#define C_READY_MASK 0x78B4D2E1
#define IDLE 0x00
#define BUSY 0x01
#define D_DATA_IDLE 0x00
#define D_DATA_APPLY 0xF0
#define D_DATA_BUSY 0x0F
// Macros for defining ioctl commands
#define PB_IOCTL_MAGIC 'c'
#define PB_IOCTL_READCMIDESC _IO(PB_IOCTL_MAGIC, 1)
#define PB_IOCTL_READLOCALREG _IO(PB_IOCTL_MAGIC, 2)
#define PB_IOCTL_WRITECMIDESC _IO(PB_IOCTL_MAGIC, 3)
#define PB_IOCTL_HWRESET _IO(PB_IOCTL_MAGIC, 4)
#define PB_IOCTL_CMI_INIT _IO(PB_IOCTL_MAGIC, 5)
#define PB_IOCTL_READDATADESC _IO(PB_IOCTL_MAGIC, 6)
#define PB_IOCTL_CMI_WRITE _IO(PB_IOCTL_MAGIC, 7)
#define PB_IOCTL_READ_SDB _IO(PB_IOCTL_MAGIC, 8)
#define PB_IOCTL_READ_DB _IO(PB_IOCTL_MAGIC, 9)
#define PB_IOCTL_CMI_READ _IO(PB_IOCTL_MAGIC, 10)
#define PB_IOCTL_READ_IRQ_VALUES _IO(PB_IOCTL_MAGIC, 11)
#define PB_IOCTL_READ_FIRST_SLAVE _IO(PB_IOCTL_MAGIC, 12)
#define PB_IOCTL_WRITE_FIRST_SLAVE _IO(PB_IOCTL_MAGIC, 13)
#define PB_IOCTL_READVERSION _IO(PB_IOCTL_MAGIC, 14)
#define PB_IOCTL_READSERIAL _IO(PB_IOCTL_MAGIC, 15)
#define PB_IOCTL_SET_STALLTIME _IO(PB_IOCTL_MAGIC, 16)
#define ERROR_DESCR_LENGTH 32
typedef struct {
unsigned int h_ready_mask;
unsigned int h_base_address;
unsigned char h_id;
unsigned char h_int_enable;
unsigned char h_address_swap_mode;
unsigned char h_state;
unsigned int h_param_addr;
unsigned int h_data_addr;
unsigned short h_param_size;
unsigned short h_data_size;
unsigned char h_sema;
unsigned char h_ret_val;
unsigned char h_head;
unsigned char h_tail;
unsigned int h_data_descr_addr;
unsigned int c_ready_mask;
unsigned int c_base_address;
unsigned char c_id;
unsigned char c_int_enable;
unsigned char c_address_swap_mode;
unsigned char c_state;
unsigned int c_param_addr;
unsigned int c_data_addr;
unsigned short c_param_size;
unsigned short c_data_size;
unsigned char c_sema;
unsigned char c_ret_val;
unsigned char c_head;
unsigned char c_tail;
unsigned int c_data_descr_addr;
} T_CMI_DESCRIPTOR;
typedef struct {
unsigned int reg[21];
} T_LOCALREG;
typedef struct {
unsigned char d_id;
unsigned char dummy;
unsigned char d_sema_c;
unsigned char d_sema_h;
unsigned short d_data_size;
unsigned int d_data_addr;
} T_DATA_DESCR;
typedef struct {
T_PROFI_SERVICE_DESCR* sdb_ptr;
USIGN8* data_ptr;
USIGN16* data_len_ptr;
USIGN16* retval_ptr;
} cmi_request_access_struct;
typedef struct {
USIGN8 data_id; // Id of data structure
USIGN16 offset; // Offset in data area
USIGN8* data_ptr; // Pointer to data to write/to be read
USIGN16* retval_ptr; // Pointer to return value
} cmi_data_access_struct;
#endif
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_errl.c -- Logging module
Handles logging for Linux.
*/
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <mqueue.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "rt_errh.h"
#define MAX_NO_MSG 100;
#define DEF_MAX_NO_MSG 10;
static pthread_mutex_t fileMutex;
static pthread_mutex_t termMutex;
static int mqid = -1;
static int logFile = -1;
static int newLogFile = 1;
static int term = -1;
static pthread_t tid = 0;
static int yday = -1;
static pwr_tBoolean logToStdout = FALSE;
static void (*errl_log_cb)(void*, char*, char, pwr_tStatus, int, int) = 0;
static void* errl_log_userdata = 0;
static void CheckTimeStamp(int force);
static void* log_thread(void* arg);
void errl_Init(const char* termName,
void (*log_cb)(void*, char*, char, pwr_tStatus, int, int), void* userdata)
{
pthread_mutexattr_t mutexattr;
pthread_attr_t pthreadattr;
char name[64];
char* busid = getenv(pwr_dEnvBusId);
static int initDone = 0;
int policy;
struct sched_param param;
key_t key;
int fd;
int flags = O_RDWR | O_CREAT;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
errl_log_cb = log_cb;
errl_log_userdata = userdata;
if (initDone)
return;
if ((pthread_getschedparam(pthread_self(), &policy, &param)) == -1) {
perror("rt_errl: pthread_getprio(pthread_self() ");
return;
}
pthread_mutexattr_init(&mutexattr);
if (pthread_mutex_init(&fileMutex, &mutexattr) == -1) {
perror("rt_logmod: pthread_mutex_init(&fileMutex, mutexattr) ");
return;
}
if (pthread_mutex_init(&termMutex, &mutexattr) == -1) {
perror("rt_logmod: pthread_mutex_init(&termMutex, mutexattr) ");
return;
}
pthread_mutexattr_destroy(&mutexattr);
sprintf(name, "%s_%s", LOG_QUEUE_NAME, busid ? busid : "");
fd = open(name, flags, mode);
if (fd == -1) {
printf("Message Queue, open failed on %s, errno: %d\n", name, errno);
}
key = ftok(name, 'm');
close(fd);
mqid = msgget(key, IPC_CREAT | 0660);
if (mqid == -1) {
perror("Open message queue: msgget ");
return;
}
pthread_attr_init(&pthreadattr);
if (pthread_create(&tid, &pthreadattr, log_thread, NULL) == -1) {
perror("rt_logmod: pthread_create ");
pthread_attr_destroy(&pthreadattr);
return;
}
pthread_attr_destroy(&pthreadattr);
param.sched_priority -= 1;
pthread_setschedparam(tid, policy, &param);
if (termName && *termName)
errl_SetTerm(termName);
logToStdout = getenv("PWR_LOG_TO_STDOUT") != NULL ? TRUE : FALSE;
initDone = 1;
return;
}
void errl_Unlink()
{
pthread_cancel(tid);
/* Remove the message queue */
msgctl(mqid, IPC_RMID, 0);
}
void errl_SetFile(const char* logFileName)
{
pwr_tStatus sts = 1;
int oflags = O_CREAT | O_APPEND | O_WRONLY;
int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
pthread_mutex_lock(&fileMutex);
if (logFile != -1) {
close(logFile);
logFile = -1;
}
if ((logFile = open(logFileName, oflags, mode)) == -1) {
errh_Error("Cannot open log file: %s", logFileName);
sts = 2;
} else {
// errh_Info("Logging to %s", logFileName);
newLogFile = 1;
}
pthread_mutex_unlock(&fileMutex);
}
void errl_SetTerm(const char* termName)
{
int oflags = O_APPEND | O_WRONLY;
pthread_mutex_lock(&termMutex);
if (term != -1) {
close(term);
term = -1;
}
if (termName && *termName) {
if ((term = open(termName, oflags)) == -1) {
errh_Error("Cannot open terminal: %s", termName);
}
}
pthread_mutex_unlock(&termMutex);
}
static void CheckTimeStamp(int force)
{
time_t t;
struct tm tmpTm;
t = time(NULL);
localtime_r(&t, &tmpTm);
if (force || (yday != tmpTm.tm_yday)) {
char buf[64];
#define STAMP "DATE STAMP: "
write(logFile, STAMP, strlen(STAMP));
strftime(buf, sizeof(buf), "%e-%b-%Y\n", &tmpTm);
write(logFile, buf, strlen(buf));
pthread_mutex_lock(&termMutex);
if (term != -1)
write(term, buf, strlen(buf));
pthread_mutex_unlock(&termMutex);
if (logToStdout)
printf("%.*s", (int)strlen(buf), buf);
yday = tmpTm.tm_yday;
}
}
static void* log_thread(void* arg)
{
int len;
errh_sMsg buf;
while (1) {
len = msgrcv(mqid, (char*)&buf, LOG_MAX_MSG_SIZE, 0, 0);
if (len == -1) {
if (errno != EINTR) {
perror("rt_logmod.c: mq_receive ");
sleep(1);
}
} else {
switch (buf.message_type) {
case errh_eMsgType_Log:
len -= (sizeof(buf) - sizeof(buf.str) - sizeof(buf.message_type) + 1);
buf.str[len] = 0;
pthread_mutex_lock(&fileMutex);
if (logFile != -1) {
/* Set up a timer if you want better performance, ML */
CheckTimeStamp(newLogFile);
newLogFile = 0;
write(logFile, buf.str, len);
write(logFile, "\n", 1);
}
pthread_mutex_unlock(&fileMutex);
pthread_mutex_lock(&termMutex);
if (term != -1) {
write(term, buf.str, len);
write(term, "\n", 1);
}
pthread_mutex_unlock(&termMutex);
if (logToStdout)
printf("%.*s\n", len, buf.str);
if (errl_log_cb)
(errl_log_cb)(errl_log_userdata, buf.str, buf.severity, buf.sts,
buf.anix, buf.message_type);
break;
case errh_eMsgType_Status:
if (errl_log_cb)
(errl_log_cb)(
errl_log_userdata, 0, 0, buf.sts, buf.anix, buf.message_type);
}
}
}
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_inet.c -- Internet help functions */
#include "rt_inet.h"
pwr_tBoolean inet_SetArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
pwr_tBoolean inet_DeleteArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
pwr_tBoolean inet_GetArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#if !defined(OS_LYNX) && !defined(OS_LINUX) && !defined(OS_MACOS) \
&& !defined OS_FREEBSD
#error \
"This file is valid only for OS_LYNX and OS_LINUX and OS_MACOS and OS_FREEBSD"
#endif
#include <errno.h>
#include <sched.h>
#include <string.h>
#include <unistd.h>
#include "co_cdh.h"
#include "co_strtoargv.h"
#include "rt_proc.h"
#include "rt_proc_msg.h"
#include "rt_errh.h"
pwr_tStatus proc_Load(proc_sProcess* p)
{
pwr_tStatus sts = PROC__SUCCESS;
return sts;
}
pwr_tStatus proc_Start(proc_sProcess* p)
{
pwr_tStatus sts = PROC__SUCCESS;
char** argv;
p->pid = fork();
if (p->pid) {
if (p->pid == -1) {
errh_Error("Could not start %s, %m\nfile: %s", p->name, errno_GetStatus(),
p->file);
} else {
errh_Info("Started %s, prio: %d, pid: %d\nfile: %s", p->name, p->p_prio,
(int)p->pid, p->file);
}
} else {
sts = proc_SetPriority(p->p_prio);
if (EVEN(sts))
errh_Warning("%s: error setprio, %m\nfile: %s", p->name, sts, p->file);
argv = co_StrToArgv(p->file, p->arg);
execvp(p->file, argv);
errh_Error(
"%s: error execvp, %m\nfile: %s", p->name, errno_GetStatus(), p->file);
exit(EXIT_FAILURE);
}
return sts;
}
pwr_tStatus proc_SetPriority(int prio)
{
// struct sched_param param;
// int rc;
int pid;
char set[100];
pwr_tStatus sts = PROC__SUCCESS;
pid = getpid();
// rc = sched_getparam((pid_t)0, &param);
// if (rc != 0)
// return errno_GetStatus();
// param.sched_priority = prio;
// rc = sched_setscheduler((pid_t)0, SCHED_RR, &param);
// if (rc != 0)
// return errno_GetStatus();
// Priorities set from rt_ini after start of all processes
sprintf(set, "rt_prio -rp %d %d", prio, pid);
// system(set);
return sts;
}
pwr_tStatus proc_UnloadProgram(proc_sProcess* p)
{
pwr_tStatus sts = PROC__SUCCESS;
return sts;
}
pwr_tStatus proc_SchedWait()
{
return PROC__SUCCESS;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_qos.c -- Queue Communication
Contains functions that are heavily os-dependant. */
#if !defined(OS_FREEBSD)
#error "This file is valid only for FreeBSD"
#endif
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include "co_errno.h"
#include "rt_hash_msg.h"
#include "rt_errh.h"
#include "rt_qdb.h"
#include "rt_futex.h"
pwr_tBoolean qos_WaitQue(pwr_tStatus* status, qdb_sQue* qp, int tmo)
{
struct timespec ts;
int remaining_time = tmo;
int delta = 100;
ts.tv_sec = 0;
qdb_AssumeLocked;
qp->lock.waiting = TRUE;
qdb_Unlock;
if (tmo == -1) {
ts.tv_nsec = delta * 1000000;
while (1) {
if (!qp->lock.waiting) {
*status = QCOM__SUCCESS;
qdb_Lock;
return 1;
}
nanosleep(&ts, 0);
}
} else {
while (1) {
if (!qp->lock.waiting) {
*status = QCOM__SUCCESS;
qdb_Lock;
return 1;
}
if (!remaining_time) {
/* Timeout */
*status = QCOM__TMO;
qdb_Lock;
return 0;
}
if (remaining_time <= delta) {
ts.tv_nsec = remaining_time * 1000000;
remaining_time = 0;
} else {
ts.tv_nsec = delta * 1000000;
remaining_time -= delta;
}
nanosleep(&ts, 0);
}
}
return 0;
}
pwr_tStatus qos_SignalQue(pwr_tStatus* status, qdb_sQue* qp)
{
pwr_dStatus(sts, status, QCOM__SUCCESS);
qp->lock.waiting = FALSE;
return TRUE;
}
qdb_sQlock* qos_CreateQlock(pwr_tStatus* sts, qdb_sQue* qp)
{
qdb_AssumeLocked;
return &qp->lock;
}
void qos_DeleteQlock(pwr_tStatus* sts, qdb_sQue* qp)
{
qdb_AssumeLocked;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* Distribution terms
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the Software), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
* NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*-< SEMAPHORE.C >--------------------------------------------------*--------*/
/* POSIX.1b Version 1.0 (c) 1998 GARRET * ? */
/* (POSIX.1b implementation for Linux) * /\| */
/* * / \ */
/* Created: 25-Aug-98 K.A. Knizhnik * / [] \ */
/* Last update: 27-Aug-98 K.A. Knizhnik * GARRET */
/*------------------------------------------------------------------*--------*/
/* Semaphore implementation * */
/*------------------------------------------------------------------*--------*/
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include "rt_semaphore.h"
sem_t* posix_sem_open(const char* name, int oflag, ...)
{
key_t key = IPC_PRIVATE;
int semid, mode = 0;
struct sembuf sops[2];
sem_t* s;
if (name != NULL) {
int fd = open(name, O_WRONLY | O_CREAT, 0777);
if (fd < 0) {
return (sem_t*)-1;
}
close(fd);
key = ftok(name, 'P');
if (key < 0) {
return (sem_t*)-1;
}
}
if (oflag & O_CREAT) {
int init_value;
va_list ap;
va_start(ap, oflag);
mode = va_arg(ap, int);
init_value = va_arg(ap, unsigned int);
if (init_value < 0) {
errno = EINVAL;
return (sem_t*)-1;
}
va_end(ap);
sops[0].sem_num = 1;
sops[0].sem_op = 1; /* mark sempahore as initialuzed */
sops[0].sem_flg = 0;
sops[1].sem_num = 0;
sops[1].sem_op = init_value;
sops[1].sem_flg = 0;
mode |= IPC_CREAT;
} else {
sops[0].sem_num = 1;
sops[0].sem_op = -1; /* wait until semaphore is initialized */
sops[0].sem_flg = 0;
sops[1].sem_num = 1;
sops[1].sem_op = 1; /* restore initialized flag */
sops[1].sem_flg = 0;
}
if (oflag & O_EXCL) {
mode |= IPC_EXCL;
}
semid = semget(key, 2, mode);
if (semid < 0) {
return (sem_t*)-1;
}
if (semop(semid, sops, 2) != 0) {
return (sem_t*)-1;
}
s = (sem_t*)malloc(sizeof(sem_t));
s->semid = semid;
s->initialized = 1;
s->semkey = key;
return s;
}
int posix_sem_init_shared(sem_t* sem, int key, unsigned int value)
{
int semid;
sem->semkey = key;
sem->initialized = 0;
sem->semid = -1;
semid = semget(sem->semkey, 1, IPC_CREAT | IPC_EXCL | 0777);
if (semid < 0) {
return -1;
}
sem->initialized = 1;
sem->semid = semid;
if (value != 0) {
struct sembuf sops[1];
sops[0].sem_num = 0;
sops[0].sem_op = value;
sops[0].sem_flg = 0;
if (semop(semid, sops, 1) != 0) {
return -1;
}
}
return 0;
}
int posix_sem_init(sem_t* sem, int pshared, unsigned int value)
{
int semid;
sem->semkey = pshared ? (long)sem : IPC_PRIVATE;
sem->initialized = 0;
sem->semid = -1;
semid = semget(sem->semkey, 1, IPC_CREAT | 0777);
if (semid < 0) {
return -1;
}
sem->initialized = 1; // Initialize, so we don't need the hash table. ML
sem->semid = semid;
if (value != 0) {
struct sembuf sops[1];
sops[0].sem_num = 0;
sops[0].sem_op = value;
sops[0].sem_flg = 0;
if (semop(semid, sops, 1) != 0) {
return -1;
}
}
return 0;
}
int posix_sem_post(sem_t* sem)
{
static struct sembuf sops[] = { { 0, 1, SEM_UNDO } };
return semop(sem->semid, sops, 1);
}
int posix_sem_getvalue(sem_t* sem, int* sval)
{
int result;
if (sval == NULL) {
errno = EINVAL;
return -1;
}
result = semctl(sem->semid, 0, GETVAL, (union semun)0);
if (result == -1) {
return -1;
}
*sval = result;
return 0;
}
int posix_sem_wait(sem_t* sem)
{
static struct sembuf sops[] = { { 0, -1, SEM_UNDO } };
return semop(sem->semid, sops, 1);
}
int posix_sem_trywait(sem_t* sem)
{
static struct sembuf sops[] = { { 0, -1, SEM_UNDO | IPC_NOWAIT } };
return semop(sem->semid, sops, 1);
}
int posix_sem_unlink(const char* name)
{
int key, semid;
key = ftok(name, 'P');
if (key < 0) {
return -1;
}
semid = semget(key, 1, 0);
if (semid < 0) {
return -1;
}
unlink(name);
return semctl(semid, 0, IPC_RMID, (union semun)0);
}
int posix_sem_close(sem_t* sem)
{
free(sem);
return 0;
}
int posix_sem_destroy(sem_t* sem)
{
return semctl(sem->semid, 0, IPC_RMID, (union semun)0);
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef __PBDRVR__
#define __PBDRVR__
#define INIT_MODE 0x00
#define CONFIG_MODE 0x05
#define COMM_MODE 0x08
#define H_READY_MASK 0x874B2D1E
#define C_READY_MASK 0x78B4D2E1
#define IDLE 0x00
#define BUSY 0x01
#define D_DATA_IDLE 0x00
#define D_DATA_APPLY 0xF0
#define D_DATA_BUSY 0x0F
// Macros for defining ioctl commands
#define PB_IOCTL_MAGIC 'c'
#define PB_IOCTL_READCMIDESC _IO(PB_IOCTL_MAGIC, 1)
#define PB_IOCTL_READLOCALREG _IO(PB_IOCTL_MAGIC, 2)
#define PB_IOCTL_WRITECMIDESC _IO(PB_IOCTL_MAGIC, 3)
#define PB_IOCTL_HWRESET _IO(PB_IOCTL_MAGIC, 4)
#define PB_IOCTL_CMI_INIT _IO(PB_IOCTL_MAGIC, 5)
#define PB_IOCTL_READDATADESC _IO(PB_IOCTL_MAGIC, 6)
#define PB_IOCTL_CMI_WRITE _IO(PB_IOCTL_MAGIC, 7)
#define PB_IOCTL_READ_SDB _IO(PB_IOCTL_MAGIC, 8)
#define PB_IOCTL_READ_DB _IO(PB_IOCTL_MAGIC, 9)
#define PB_IOCTL_CMI_READ _IO(PB_IOCTL_MAGIC, 10)
#define PB_IOCTL_READ_IRQ_VALUES _IO(PB_IOCTL_MAGIC, 11)
#define PB_IOCTL_READ_FIRST_SLAVE _IO(PB_IOCTL_MAGIC, 12)
#define PB_IOCTL_WRITE_FIRST_SLAVE _IO(PB_IOCTL_MAGIC, 13)
#define PB_IOCTL_READVERSION _IO(PB_IOCTL_MAGIC, 14)
#define PB_IOCTL_READSERIAL _IO(PB_IOCTL_MAGIC, 15)
#define PB_IOCTL_SET_STALLTIME _IO(PB_IOCTL_MAGIC, 16)
#define ERROR_DESCR_LENGTH 32
typedef struct {
unsigned int h_ready_mask;
unsigned int h_base_address;
unsigned char h_id;
unsigned char h_int_enable;
unsigned char h_address_swap_mode;
unsigned char h_state;
unsigned int h_param_addr;
unsigned int h_data_addr;
unsigned short h_param_size;
unsigned short h_data_size;
unsigned char h_sema;
unsigned char h_ret_val;
unsigned char h_head;
unsigned char h_tail;
unsigned int h_data_descr_addr;
unsigned int c_ready_mask;
unsigned int c_base_address;
unsigned char c_id;
unsigned char c_int_enable;
unsigned char c_address_swap_mode;
unsigned char c_state;
unsigned int c_param_addr;
unsigned int c_data_addr;
unsigned short c_param_size;
unsigned short c_data_size;
unsigned char c_sema;
unsigned char c_ret_val;
unsigned char c_head;
unsigned char c_tail;
unsigned int c_data_descr_addr;
} T_CMI_DESCRIPTOR;
typedef struct {
unsigned int reg[21];
} T_LOCALREG;
typedef struct {
unsigned char d_id;
unsigned char dummy;
unsigned char d_sema_c;
unsigned char d_sema_h;
unsigned short d_data_size;
unsigned int d_data_addr;
} T_DATA_DESCR;
typedef struct {
T_PROFI_SERVICE_DESCR* sdb_ptr;
USIGN8* data_ptr;
USIGN16* data_len_ptr;
USIGN16* retval_ptr;
} cmi_request_access_struct;
typedef struct {
USIGN8 data_id; // Id of data structure
USIGN16 offset; // Offset in data area
USIGN8* data_ptr; // Pointer to data to write/to be read
USIGN16* retval_ptr; // Pointer to return value
} cmi_data_access_struct;
#endif
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_errl.c -- Logging module
Handles logging for Linux.
*/
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <mqueue.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "rt_errh.h"
#define MAX_NO_MSG 100;
#define DEF_MAX_NO_MSG 10;
static pthread_mutex_t fileMutex;
static pthread_mutex_t termMutex;
static mqd_t mqid = (mqd_t)-1;
static int logFile = -1;
static int newLogFile = 1;
static int term = -1;
static pthread_t tid = 0;
static int yday = -1;
static pwr_tBoolean logToStdout = FALSE;
static void (*errl_log_cb)(void*, char*, char, pwr_tStatus, int, int) = 0;
static void* errl_log_userdata = 0;
static void CheckTimeStamp(int force);
static void* log_thread(void* arg);
void errl_Init(const char* termName,
void (*log_cb)(void*, char*, char, pwr_tStatus, int, int), void* userdata)
{
pthread_mutexattr_t mutexattr;
pthread_attr_t pthreadattr;
struct mq_attr mqattr;
mode_t mode;
int oflags;
char name[64];
char* busid = getenv(pwr_dEnvBusId);
static int initDone = 0;
int policy;
struct sched_param param;
errl_log_cb = log_cb;
errl_log_userdata = userdata;
if (initDone)
return;
if ((pthread_getschedparam(pthread_self(), &policy, &param)) == -1) {
perror("rt_errl: pthread_getprio(pthread_self() ");
return;
}
pthread_mutexattr_init(&mutexattr);
if (pthread_mutex_init(&fileMutex, &mutexattr) == -1) {
perror("rt_logmod: pthread_mutex_init(&fileMutex, mutexattr) ");
return;
}
if (pthread_mutex_init(&termMutex, &mutexattr) == -1) {
perror("rt_logmod: pthread_mutex_init(&termMutex, mutexattr) ");
return;
}
pthread_mutexattr_destroy(&mutexattr);
mqattr.mq_msgsize = LOG_MAX_MSG_SIZE; /* max mess size */
mqattr.mq_maxmsg = MAX_NO_MSG; /* max no of msg in this queue */
mqattr.mq_flags = 0; // O_NONBLOCK;
oflags = O_CREAT | O_RDWR;
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
sprintf(name, "%s_%s", LOG_QUEUE_NAME, busid ? busid : "");
mqid = mq_open(name, oflags, mode, &mqattr);
if (mqid == (mqd_t)-1) {
if (errno == EINVAL) {
mqattr.mq_maxmsg = DEF_MAX_NO_MSG; /* Try with smaller queue */
mqid = mq_open(name, oflags, mode, &mqattr);
if (mqid == (mqd_t)-1) {
perror("rt_logmod: mq_open ");
return;
}
} else {
perror("rt_logmod: mq_open ");
return;
}
}
pthread_attr_init(&pthreadattr);
if (pthread_create(&tid, &pthreadattr, log_thread, NULL) == -1) {
perror("rt_logmod: pthread_create ");
pthread_attr_destroy(&pthreadattr);
return;
}
pthread_attr_destroy(&pthreadattr);
param.sched_priority -= 1;
pthread_setschedparam(tid, policy, &param);
if (termName && *termName)
errl_SetTerm(termName);
logToStdout = getenv("PWR_LOG_TO_STDOUT") != NULL ? TRUE : FALSE;
initDone = 1;
return;
}
void errl_Unlink()
{
char name[64];
char* busid = getenv(pwr_dEnvBusId);
pthread_cancel(tid);
sprintf(name, "%s_%s", LOG_QUEUE_NAME, busid ? busid : "");
/* We don't care about return status */
mq_unlink(name);
}
void errl_SetFile(const char* logFileName)
{
pwr_tStatus sts = 1;
int oflags = O_CREAT | O_APPEND | O_WRONLY;
int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
pthread_mutex_lock(&fileMutex);
if (logFile != -1) {
close(logFile);
logFile = -1;
}
if ((logFile = open(logFileName, oflags, mode)) == -1) {
errh_Error("Cannot open log file: %s", logFileName);
sts = 2;
} else {
// errh_Info("Logging to %s", logFileName);
newLogFile = 1;
}
pthread_mutex_unlock(&fileMutex);
}
void errl_SetTerm(const char* termName)
{
int oflags = O_APPEND | O_WRONLY;
pthread_mutex_lock(&termMutex);
if (term != -1) {
close(term);
term = -1;
}
if (termName && *termName) {
if ((term = open(termName, oflags)) == -1) {
errh_Error("Cannot open terminal: %s", termName);
}
}
pthread_mutex_unlock(&termMutex);
}
static void CheckTimeStamp(int force)
{
time_t t;
struct tm tmpTm;
t = time(NULL);
localtime_r(&t, &tmpTm);
if (force || (yday != tmpTm.tm_yday)) {
char buf[64];
#define STAMP "DATE STAMP: "
write(logFile, STAMP, strlen(STAMP));
strftime(buf, sizeof(buf), "%e-%b-%Y\n", &tmpTm);
write(logFile, buf, strlen(buf));
pthread_mutex_lock(&termMutex);
if (term != -1)
write(term, buf, strlen(buf));
pthread_mutex_unlock(&termMutex);
if (logToStdout)
printf("%.*s", (int)strlen(buf), buf);
yday = tmpTm.tm_yday;
}
}
static void* log_thread(void* arg)
{
int len;
errh_sMsg buf;
while (1) {
len = mq_receive(mqid, (char*)&buf, LOG_MAX_MSG_SIZE, NULL);
if (len == -1) {
if (errno != EINTR)
perror("rt_logmod.c: mq_receive ");
} else {
switch (buf.message_type) {
case errh_eMsgType_Log:
len -= (sizeof(buf) - sizeof(buf.str) - sizeof(buf.message_type) + 1);
buf.str[len] = 0;
pthread_mutex_lock(&fileMutex);
if (logFile != -1) {
/* Set up a timer if you want better performance, ML */
CheckTimeStamp(newLogFile);
newLogFile = 0;
write(logFile, buf.str, len);
write(logFile, "\n", 1);
}
pthread_mutex_unlock(&fileMutex);
pthread_mutex_lock(&termMutex);
if (term != -1) {
write(term, buf.str, len);
write(term, "\n", 1);
}
pthread_mutex_unlock(&termMutex);
if (logToStdout)
printf("%.*s\n", len, buf.str);
if (errl_log_cb)
(errl_log_cb)(errl_log_userdata, buf.str, buf.severity, buf.sts,
buf.anix, buf.message_type);
break;
case errh_eMsgType_Status:
if (errl_log_cb)
(errl_log_cb)(
errl_log_userdata, 0, 0, buf.sts, buf.anix, buf.message_type);
}
}
}
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_futex.c -- Futex operations
PROVIEW/R
Contains functions that are heavily os-dependant.
Author: Robert Karlsson 21 Apr 2004
Description:
This module provides an interface to futexes - "fast user level
locking in Linux". This is achieved through the multiplexing
system call sys_futex(). As implemented below this interface provides
a synchronization mechanism that can be used both between threads
in one process as well as between threads in different processes */
#if !defined(OS_LINUX)
#error "This file is valid only for OS_LINUX"
#endif
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>
#define FUTEX_WAIT (0)
#define FUTEX_WAKE (1)
int futex_wait(int* futex, int val)
{
int ok;
ok = syscall(SYS_futex, futex, FUTEX_WAIT, val, NULL);
if (ok == -1) {
return errno;
} else {
return ok;
}
}
int futex_timed_wait(int* futex, int val, const struct timespec* timespec)
{
int ok;
ok = syscall(SYS_futex, futex, FUTEX_WAIT, val, timespec);
if (ok == -1) {
return errno;
} else {
return ok;
}
}
int futex_wake(int* futex, int nr)
{
int ok;
ok = syscall(SYS_futex, futex, FUTEX_WAKE, nr, NULL);
if (ok == -1) {
return errno;
} else {
return ok;
}
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef rt_futex_h
#define rt_futex_h
#ifdef __cplusplus
extern "C" {
#endif
int futex_wait(int* futex, int val);
int futex_timed_wait(int* futex, int val, const struct timespec* timespec);
int futex_wake(int* futex, int nr);
#ifdef __cplusplus
}
#endif
#endif
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_inet.c -- Internet help functions */
#include "rt_inet.h"
pwr_tBoolean inet_SetArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
pwr_tBoolean inet_DeleteArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
pwr_tBoolean inet_GetArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#if !defined(OS_LYNX) && !defined(OS_LINUX)
#error "This file is valid only for OS_LYNX and OS_LINUX"
#endif
#include <errno.h>
#include <sched.h>
#include <string.h>
#include <unistd.h>
#include "co_cdh.h"
#include "co_strtoargv.h"
#include "rt_proc.h"
#include "rt_proc_msg.h"
#include "rt_errh.h"
pwr_tStatus proc_Load(proc_sProcess* p)
{
pwr_tStatus sts = PROC__SUCCESS;
return sts;
}
pwr_tStatus proc_Start(proc_sProcess* p)
{
pwr_tStatus sts = PROC__SUCCESS;
char** argv;
p->pid = fork();
if (p->pid) {
if (p->pid == -1) {
errh_Error("Could not start %s, %m\nfile: %s", p->name, errno_GetStatus(),
p->file);
} else {
errh_Info("Started %s, prio: %d, pid: %d\nfile: %s", p->name, p->p_prio,
(int)p->pid, p->file);
}
} else {
sts = proc_SetPriority(p->p_prio);
if (EVEN(sts))
errh_Warning("%s: error setprio, %m\nfile: %s", p->name, sts, p->file);
argv = co_StrToArgv(p->file, p->arg);
execvp(p->file, argv);
errh_Error(
"%s: error execvp, %m\nfile: %s", p->name, errno_GetStatus(), p->file);
exit(EXIT_FAILURE);
}
return sts;
}
pwr_tStatus proc_SetPriority(int prio)
{
// struct sched_param param;
// int rc;
int pid;
char set[100];
pwr_tStatus sts = PROC__SUCCESS;
pid = getpid();
// rc = sched_getparam((pid_t)0, &param);
// if (rc != 0)
// return errno_GetStatus();
// param.sched_priority = prio;
// rc = sched_setscheduler((pid_t)0, SCHED_RR, &param);
// if (rc != 0)
// return errno_GetStatus();
// Priorities set from rt_ini after start of all processes
sprintf(set, "rt_prio -rp %d %d", prio, pid);
// system(set);
return sts;
}
pwr_tStatus proc_UnloadProgram(proc_sProcess* p)
{
pwr_tStatus sts = PROC__SUCCESS;
return sts;
}
pwr_tStatus proc_SchedWait()
{
pid_t pid;
int count = 0;
int sched;
pid = getpid();
while (((sched = sched_getscheduler(pid)) == SCHED_OTHER) && (count < 5)) {
sleep(1);
count++;
}
if (sched == SCHED_OTHER)
return PROC__NOSCHED;
return PROC__SUCCESS;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_qos.c -- Queue Communication
Contains functions that are heavily os-dependant. */
#if !defined(OS_LINUX)
#error "This file is valid only for OS_LINUX"
#endif
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include "co_errno.h"
#include "rt_hash_msg.h"
#include "rt_errh.h"
#include "rt_qdb.h"
#include "rt_futex.h"
pwr_tBoolean qos_WaitQueOld(pwr_tStatus* status, qdb_sQue* qp, int tmo)
{
pwr_tDeltaTime dtime;
struct timespec dtime_ts;
sigset_t newset;
siginfo_t info;
int ok;
pwr_tBoolean signal = FALSE;
pwr_dStatus(sts, status, QCOM__SUCCESS);
qdb_AssumeLocked;
if (tmo == qcom_cTmoNone)
return FALSE;
qp->lock.waiting = TRUE;
sigemptyset(&newset);
sigaddset(&newset, qdb_cSigMsg);
// qp->lock.pid = BUILDPID(getpid(), pthread_self());
// I think that each thread has it's own pid in Linux. ML
qp->lock.pid = getpid();
qdb_Unlock;
if (tmo != qcom_cTmoEternal) {
time_MsToD(&dtime, tmo);
dtime_ts.tv_sec = dtime.tv_sec;
dtime_ts.tv_nsec = dtime.tv_nsec;
ok = sigtimedwait(&newset, &info, &dtime_ts);
} else {
for (;;) {
ok = sigwaitinfo(&newset, &info);
if (ok == -1 && errno == EINTR)
continue;
break;
}
}
if (ok == -1 && errno != EAGAIN) {
errh_Error("waitQue (%d) %s", errno, strerror(errno));
} else if (!(ok == -1 || ok == qdb_cSigMsg)) {
errh_Error("qos waitQue signr %d", ok);
}
qdb_Lock;
if (qp->lock.waiting) {
*sts = QCOM__TMO;
qp->lock.waiting = FALSE;
} else {
signal = TRUE;
}
return signal;
}
pwr_tBoolean qos_WaitQue(pwr_tStatus* status, qdb_sQue* qp, int tmo)
{
pwr_tDeltaTime dtime;
pwr_tTime atime;
struct timespec atime_ts;
int ok;
pwr_tBoolean signal = FALSE;
pwr_dStatus(sts, status, QCOM__SUCCESS);
qdb_AssumeLocked;
if (tmo == qcom_cTmoNone)
return FALSE;
pthread_mutex_lock(&qp->lock.mutex);
qp->lock.waiting = TRUE;
qp->lock.pid = 0;
qdb_Unlock;
if (tmo != qcom_cTmoEternal) {
time_GetTimeMonotonic(&atime);
time_MsToD(&dtime, tmo);
time_Aadd(&atime, &atime, &dtime);
atime_ts.tv_sec = atime.tv_sec;
atime_ts.tv_nsec = atime.tv_nsec;
ok = pthread_cond_timedwait(&qp->lock.cond, &qp->lock.mutex, &atime_ts);
} else {
ok = pthread_cond_wait(&qp->lock.cond, &qp->lock.mutex);
}
pthread_mutex_unlock(&qp->lock.mutex);
qdb_Lock;
if ((qp->lock.waiting) || (ok == ETIMEDOUT)) {
*sts = QCOM__TMO;
qp->lock.waiting = FALSE;
} else {
signal = TRUE;
}
return signal;
}
pwr_tStatus qos_SignalQueOld(pwr_tStatus* status, qdb_sQue* qp)
{
union sigval value;
int ok;
pwr_dStatus(sts, status, QCOM__SUCCESS);
qdb_AssumeLocked;
if (qp->lock.waiting) {
// value.sival_int = BUILDPID(getpid(), pthread_self());
value.sival_int = getpid();
qp->lock.waiting = FALSE;
ok = sigqueue(qp->lock.pid, qdb_cSigMsg, value);
if (ok == -1) {
*sts = errno_Status(errno);
}
}
return TRUE;
}
pwr_tStatus qos_SignalQue(pwr_tStatus* status, qdb_sQue* qp)
{
pwr_dStatus(sts, status, QCOM__SUCCESS);
qdb_AssumeLocked;
pthread_mutex_lock(&qp->lock.mutex);
qp->lock.waiting = FALSE;
pthread_cond_signal(&qp->lock.cond);
pthread_mutex_unlock(&qp->lock.mutex);
return TRUE;
}
qdb_sQlock* qos_CreateQlock(pwr_tStatus* sts, qdb_sQue* qp)
{
qdb_AssumeLocked;
return &qp->lock;
}
void qos_DeleteQlock(pwr_tStatus* sts, qdb_sQue* qp)
{
qdb_AssumeLocked;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* Distribution terms
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the Software), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
* NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*-< SEMAPHORE.C >--------------------------------------------------*--------*/
/* POSIX.1b Version 1.0 (c) 1998 GARRET * ? */
/* (POSIX.1b implementation for Linux) * /\| */
/* * / \ */
/* Created: 25-Aug-98 K.A. Knizhnik * / [] \ */
/* Last update: 27-Aug-98 K.A. Knizhnik * GARRET */
/*------------------------------------------------------------------*--------*/
/* Semaphore implementation * */
/*------------------------------------------------------------------*--------*/
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include "rt_semaphore.h"
union semun {
int val;
struct semid_ds* buf;
u_short* array;
};
sem_t* posix_sem_open(const char* name, int oflag, ...)
{
key_t key = IPC_PRIVATE;
int semid, mode = 0;
struct sembuf sops[2];
sem_t* s;
if (name != NULL) {
int fd = open(name, O_WRONLY | O_CREAT, 0777);
if (fd < 0) {
return (sem_t*)-1;
}
close(fd);
key = ftok(name, 'P');
if (key < 0) {
return (sem_t*)-1;
}
}
if (oflag & O_CREAT) {
int init_value;
va_list ap;
va_start(ap, oflag);
mode = va_arg(ap, mode_t);
init_value = va_arg(ap, unsigned int);
if (init_value < 0) {
errno = EINVAL;
return (sem_t*)-1;
}
va_end(ap);
sops[0].sem_num = 1;
sops[0].sem_op = 1; /* mark sempahore as initialuzed */
sops[0].sem_flg = 0;
sops[1].sem_num = 0;
sops[1].sem_op = init_value;
sops[1].sem_flg = 0;
mode |= IPC_CREAT;
} else {
sops[0].sem_num = 1;
sops[0].sem_op = -1; /* wait until semaphore is initialized */
sops[0].sem_flg = 0;
sops[1].sem_num = 1;
sops[1].sem_op = 1; /* restore initialized flag */
sops[1].sem_flg = 0;
}
if (oflag & O_EXCL) {
mode |= IPC_EXCL;
}
semid = semget(key, 2, mode);
if (semid < 0) {
return (sem_t*)-1;
}
if (semop(semid, sops, 2) != 0) {
return (sem_t*)-1;
}
s = (sem_t*)malloc(sizeof(sem_t));
s->semid = semid;
s->initialized = 1;
s->semkey = key;
return s;
}
int posix_sem_init_shared(sem_t* sem, int key, unsigned int value)
{
int semid;
sem->semkey = key;
sem->initialized = 0;
sem->semid = -1;
semid = semget(sem->semkey, 1, IPC_CREAT | IPC_EXCL | 0777);
if (semid < 0) {
return -1;
}
sem->initialized = 1;
sem->semid = semid;
if (value != 0) {
struct sembuf sops[1];
sops[0].sem_num = 0;
sops[0].sem_op = value;
sops[0].sem_flg = 0;
if (semop(semid, sops, 1) != 0) {
return -1;
}
}
return 0;
}
int posix_sem_init(sem_t* sem, int pshared, unsigned int value)
{
int semid;
sem->semkey = pshared ? (long)sem : IPC_PRIVATE;
sem->initialized = 0;
sem->semid = -1;
semid = semget(sem->semkey, 1, IPC_CREAT | 0777);
if (semid < 0) {
return -1;
}
sem->initialized = 1; // Initialize, so we don't need the hash table. ML
sem->semid = semid;
if (value != 0) {
struct sembuf sops[1];
sops[0].sem_num = 0;
sops[0].sem_op = value;
sops[0].sem_flg = 0;
if (semop(semid, sops, 1) != 0) {
return -1;
}
}
return 0;
}
int posix_sem_post(sem_t* sem)
{
static struct sembuf sops[] = { { 0, 1, SEM_UNDO } };
return semop(sem->semid, sops, 1);
}
int posix_sem_getvalue(sem_t* sem, int* sval)
{
int result;
if (sval == NULL) {
errno = EINVAL;
return -1;
}
result = semctl(sem->semid, 0, GETVAL, (union semun)0);
if (result == -1) {
return -1;
}
*sval = result;
return 0;
}
int posix_sem_wait(sem_t* sem)
{
static struct sembuf sops[] = { { 0, -1, SEM_UNDO } };
return semop(sem->semid, sops, 1);
}
int posix_sem_trywait(sem_t* sem)
{
static struct sembuf sops[] = { { 0, -1, SEM_UNDO | IPC_NOWAIT } };
return semop(sem->semid, sops, 1);
}
int posix_sem_unlink(const char* name)
{
int key, semid;
key = ftok(name, 'P');
if (key < 0) {
return -1;
}
semid = semget(key, 1, 0);
if (semid < 0) {
return -1;
}
unlink(name);
return semctl(semid, 0, IPC_RMID, (union semun)0);
}
int posix_sem_close(sem_t* sem)
{
free(sem);
return 0;
}
int posix_sem_destroy(sem_t* sem)
{
return semctl(sem->semid, 0, IPC_RMID, (union semun)0);
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_sect.h */
/*-< SEMAPHORE.H >--------------------------------------------------*--------*/
/* POSIX.1b Version 1.0 (c) 1998 GARRET * ? */
/* (POSIX.1b implementation for Linux) * /\| */
/* * / \ */
/* Created: 25-Aug-98 K.A. Knizhnik * / [] \ */
/* Last update: 27-Aug-98 K.A. Knizhnik * GARRET */
/*------------------------------------------------------------------*--------*/
/* Semaphore interface * */
/*------------------------------------------------------------------*--------*/
#ifndef rt_semaphore_h
#define rt_semaphore_h
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
long semkey;
int semid;
int initialized;
} sem_t;
// Not POSIX. The caller generates the key
int posix_sem_init_shared(sem_t* sem, int key, unsigned int value);
int posix_sem_init(sem_t* sem, int pshared, unsigned int value);
sem_t* posix_sem_open(const char* name, int oflag, ...);
int posix_sem_post(sem_t* sem);
int posix_sem_getvalue(sem_t* sem, int* sval);
int posix_sem_wait(sem_t* sem);
int posix_sem_trywait(sem_t* sem);
int posix_sem_unlink(const char* name);
int posix_sem_close(sem_t* sem);
int posix_sem_destroy(sem_t* sem);
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
This diff is collapsed.
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* rt_inet.c -- Internet help functions */
#include "rt_inet.h"
pwr_tBoolean inet_SetArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
pwr_tBoolean inet_DeleteArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
pwr_tBoolean inet_GetArpEntry(pwr_tStatus* sts, int s, struct arpreq* rp)
{
return 1;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -121,7 +121,7 @@ void pwrs_Node_Exec(void (*handler_event_cb)(int, int))
if (!reboot_done) {
errh_Fatal("Emergency break action: reboot");
sts = system("rt_prio --reboot");
sts = system("/sbin/reboot");
if (sts != 0)
errh_Fatal("Unable to reboot, sts %d", sts);
reboot_done = 1;
......
......@@ -1697,11 +1697,14 @@ void ini_ProcPrio(pwr_tStatus* status, ini_sContext* cp, ini_sProc* pp)
if (pp->flags.b.run) {
#if defined(OS_LINUX)
char set[100];
if (!(pp->flags.b.plc)) {
sprintf(set, "rt_prio -rp %d %d", pp->proc.p_prio, pp->proc.pid);
system(set);
struct sched_param sp;
sp.sched_priority = pp->proc.p_prio;
if (sched_setscheduler(pp->proc.pid, SCHED_RR, &sp) == -1) {
perror("sched_setscheduler");
fprintf(stderr, "failed to set pid %d's policy\n", pp->proc.pid);
return;
}
}
#endif
}
......
......@@ -82,7 +82,6 @@ typedef struct {
pwr_tStatus proc_Load(proc_sProcess*);
pwr_tStatus proc_Start(proc_sProcess*);
pwr_tStatus proc_SetPriority(int);
pwr_tStatus proc_UnloadProgram(proc_sProcess*);
pwr_tStatus proc_RegisterObject(pwr_tOid);
......
......@@ -34,8 +34,6 @@
* General Public License plus this exception.
*/
/* rt_sect.h */
/*-< SEMAPHORE.H >--------------------------------------------------*--------*/
/* POSIX.1b Version 1.0 (c) 1998 GARRET * ? */
/* (POSIX.1b implementation for Linux) * /\| */
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment