Skip to content

Commit

Permalink
Merge 6063de9 into 465920f
Browse files Browse the repository at this point in the history
  • Loading branch information
anjohnson committed Oct 12, 2021
2 parents 465920f + 6063de9 commit 14a1835
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
111 changes: 111 additions & 0 deletions 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 <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)
{
}
8 changes: 8 additions & 0 deletions 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 */

0 comments on commit 14a1835

Please sign in to comment.