Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |