This is Unofficial EPICS BASE Doxygen Site
osdInterrupt.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Saskatchewan
3 * EPICS BASE Versions 3.13.7
4 * and higher are distributed subject to a Software License Agreement found
5 * in file LICENSE that is included with this distribution.
6 \*************************************************************************/
7 /*
8  * RTEMS osdInterrupt.c
9  * Author: W. Eric Norum
10  * eric@cls.usask.ca
11  * (306) 966-6055
12  */
13 
14 #include <syslog.h>
15 #include <rtems.h>
16 #include <rtems/error.h>
17 #include "errlog.h"
18 #include "epicsInterrupt.h"
19 #include "epicsThread.h"
20 
21 #define INTERRUPT_CONTEXT_MESSAGE_QUEUE_COUNT 100
22 
23 static rtems_id interruptContextMessageQueue;
24 
25 int
27 {
28  rtems_interrupt_level level;
29 
30  rtems_interrupt_disable (level);
31  return level;
32 }
33 
34 void
36 {
37  rtems_interrupt_level level = key;
38 
39  rtems_interrupt_enable (level);
40 }
41 
42 int
44 {
45  return rtems_interrupt_is_in_progress ();
46 }
47 
48 /*
49  * Pass a message from an interrupt context.
50  * Note that this passes a pointer to the message, not the message itself.
51  * This implies that the message must remain valid after the
52  * interrupt context is no longer active.
53  */
54 void
55 epicsInterruptContextMessage (const char *message)
56 {
57  rtems_message_queue_send (interruptContextMessageQueue, &message, sizeof message);
58 }
59 
60 /*
61  * Daemon to process interrupt context messages
62  */
63 void
65 {
66  const char *message;
67  size_t size;
68  rtems_status_code sc;
69 
70  sc = rtems_message_queue_create (rtems_build_name ('I', 'C', 'M', 'Q'),
72  sizeof message,
73  RTEMS_FIFO | RTEMS_LOCAL,
74  &interruptContextMessageQueue);
75  if (sc != RTEMS_SUCCESSFUL) {
76  errlogPrintf ("Can't create interrupt context message queue: %s\n", rtems_status_text (sc));
78  }
79  for (;;) {
80  sc = rtems_message_queue_receive (interruptContextMessageQueue,
81  &message,
82  &size,
83  RTEMS_WAIT,
84  RTEMS_NO_TIMEOUT);
85  if (sc != RTEMS_SUCCESSFUL) {
86  errlogPrintf ("Can't receive message from interrupt context: %s\n", rtems_status_text (sc));
88  }
89  if (size == sizeof message)
90  syslog (LOG_ERR, "%s", message);
91  else
92  errlogPrintf ("Received %u-byte message from interrupt context", (unsigned int)size);
93  }
94 }
LIBCOM_API int epicsInterruptIsInterruptContext()
Definition: osdInterrupt.c:48
LIBCOM_API void epicsInterruptUnlock(int key)
Definition: osdInterrupt.c:41
void InterruptContextMessageDaemon(void *unused)
Definition: osdInterrupt.c:64
LIBCOM_API void epicsStdCall epicsThreadSuspendSelf(void)
Definition: osdThread.c:664
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API int epicsInterruptLock()
Definition: osdInterrupt.c:34
C++ and C descriptions for a thread.
#define INTERRUPT_CONTEXT_MESSAGE_QUEUE_COUNT
Definition: osdInterrupt.c:21
LIBCOM_API void epicsInterruptContextMessage(const char *message)
Definition: osdInterrupt.c:53