From 6063de9a8bc0bc5209a4e3024c44bde08a7f35ec Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 12 Oct 2021 12:37:57 -0500 Subject: [PATCH] Added Heinz new osdEvent.c to RTEMS-posix --- .../libcom/src/osi/os/RTEMS-posix/osdEvent.c | 111 ++++++++++++++++++ .../libcom/src/osi/os/RTEMS-posix/osdEvent.h | 8 ++ 2 files changed, 119 insertions(+) create mode 100644 modules/libcom/src/osi/os/RTEMS-posix/osdEvent.c create mode 100644 modules/libcom/src/osi/os/RTEMS-posix/osdEvent.h diff --git a/modules/libcom/src/osi/os/RTEMS-posix/osdEvent.c b/modules/libcom/src/osi/os/RTEMS-posix/osdEvent.c new file mode 100644 index 000000000..54dfccfff --- /dev/null +++ b/modules/libcom/src/osi/os/RTEMS-posix/osdEvent.c @@ -0,0 +1,111 @@ +/*************************************************************************\ +* Copyright (c) 2021 Fritz Haber Institute, Berlin +* SPDX-License-Identifier: EPICS +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* + * RTEMS osdEvent.c + * Author: H. Junkes + * junkes@fhi.mpg.de + */ + +#include +#include +#include +#include +#include + +#include + +#include "libComAPI.h" +#include "epicsEvent.h" + +typedef struct epicsEventOSD { + rtems_binary_semaphore rbs; +} epicsEventOSD; + +/* + * Create a simple binary semaphore + */ +LIBCOM_API epicsEventId +epicsEventCreate(epicsEventInitialState initialState) +{ + epicsEventOSD *pSem = malloc (sizeof(*pSem)); + + if (pSem) { + rtems_binary_semaphore_init(&pSem->rbs, NULL); + if (initialState) + rtems_binary_semaphore_post(&pSem->rbs); + } + return pSem; +} + +LIBCOM_API void +epicsEventDestroy(epicsEventId pSem) +{ + rtems_binary_semaphore_destroy(&pSem->rbs); +} + +LIBCOM_API epicsEventStatus +epicsEventTrigger(epicsEventId pSem) +{ + rtems_binary_semaphore_post(&pSem->rbs); + return epicsEventOK; +} + +LIBCOM_API epicsEventStatus +epicsEventWait(epicsEventId pSem) +{ + rtems_binary_semaphore_wait(&pSem->rbs); + return epicsEventOK; +} + +LIBCOM_API epicsEventStatus +epicsEventWaitWithTimeout(epicsEventId pSem, double timeOut) +{ + int sc; + rtems_interval delay; + int rate = rtems_clock_get_ticks_per_second(); + + if (!rate) + return epicsEventError; + + if (timeOut <= 0.0) { + sc = rtems_binary_semaphore_try_wait(&pSem->rbs); + if (!sc) + return epicsEventOK; + else + return epicsEventWaitTimeout; + } + else if (timeOut >= (double) INT_MAX / rate) { + delay = 0; + } + else { + delay = timeOut * rate; + } + + sc = rtems_binary_semaphore_wait_timed_ticks(&pSem->rbs, delay); + if (!sc) + return epicsEventOK; + else if (sc == ETIMEDOUT) + return epicsEventWaitTimeout; + else + return epicsEventError; +} + +LIBCOM_API epicsEventStatus +epicsEventTryWait(epicsEventId pSem) +{ + int sc = rtems_binary_semaphore_try_wait(&pSem->rbs); + + if (!sc) + return epicsEventOK; + else + return epicsEventWaitTimeout; +} + +LIBCOM_API void +epicsEventShow(epicsEventId pSem, unsigned int level) +{ +} diff --git a/modules/libcom/src/osi/os/RTEMS-posix/osdEvent.h b/modules/libcom/src/osi/os/RTEMS-posix/osdEvent.h new file mode 100644 index 000000000..6778c4662 --- /dev/null +++ b/modules/libcom/src/osi/os/RTEMS-posix/osdEvent.h @@ -0,0 +1,8 @@ +/*************************************************************************\ +* Copyright (c) 2021 Fritz Haber Institute, Berlin +* SPDX-License-Identifier: EPICS +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* No definitions are needed for this implementation */