Added Heinz new osdEvent.c to RTEMS-posix

This commit is contained in:
Andrew Johnson
2021-10-12 12:37:57 -05:00
parent fb46786ccb
commit 6063de9a8b
2 changed files with 119 additions and 0 deletions

View File

@@ -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 <stdio.h>
#include <malloc.h>
#include <limits.h>
#include <rtems.h>
#include <rtems/error.h>
#include <rtems/thread.h>
#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)
{
}

View File

@@ -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 */