TEMU  2
The Terma Emulator
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Events.h
Go to the documentation of this file.
1 //===-- temu-c/Events.h - Event Queue API -----------------------*- C++ -*-===//
2 //
3 // T-EMU: The Terma Emulator
4 // (c) Terma 2015, 2016
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEMU_EVENTS_H
10 #define TEMU_EVENTS_H
11 
12 #include <stdint.h>
13 #include "temu-c/Support/Objsys.h"
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 // Queue allocation and disposal
30 
39 TEMU_API void temu_disposeEventQueue(void *Queue);
40 
41 // New style events
43 
44 typedef struct temu_Event {
45  int64_t Time; // Managed internally, do not touch
46  int64_t EventId; // Managed internally, do not touch
47  uint32_t Flags; // Internal use, do not touch
48  int QueueIdx; // Managed internally, do not touch
49  temu_EventQueue *Queue; // Managed internally, do not touch
50  void *Obj; // Managed internally, only for reading
51  void (*Func)(struct temu_Event*);
52 
53  void *Data; // Managed: For old style event support
54  int64_t Period; // Managed: Period (cycles) for cyclic events
55  int64_t RTTime; // Managed: Time (monotonic ns) for RT exec
56  int64_t RTPeriod; // Managed: Period (ns) for RT events
57 } temu_Event;
58 
59 // Posting callback from other threads
60 typedef void (*temu_ThreadSafeCb)(void*);
72 TEMU_API void temu_postCallbackInQueue(void *Queue, temu_ThreadSafeCb Cb, void *Arg);
73 
85 
86 typedef struct {
87  // Async callbacks
88  void (*postCallback)(void *Obj, temu_ThreadSafeCb Cb, void *Arg);
89  void (*removeCallback)(void *Obj, temu_ThreadSafeCb Cb, void *Arg);
90 
91  // New event API
92  void (*postAbsolute)(void *Obj, int64_t EvId, int64_t T);
93  void (*postRelative)(void *Obj, int64_t EvId, int64_t T);
94  void (*postOnStack)(void *Obj, int64_t EvId);
96 #define TEMU_EVENT_IFACE_TYPE "EventIface"
98 
99 // Publication of old style events
100 // Note that OLD STYLE EVENTS are DEPRECATED, these functions will be
101 // removed in T-EMU 2.3.
109 TEMU_API int64_t temu_eventPublishOldStyle(const char *Name, void *Obj,
110  void (*Ev)(void*,void*));
111 
118 TEMU_API int64_t temu_eventGetOldStyleID(void (*Ev)(void*,void*), void *Sender);
119 
120 
132 TEMU_API int64_t temu_eventPublishStruct(const char *EvName, temu_Event *Ev, void *Obj,
133  void (*Func)(temu_Event*));
134 
141 TEMU_API void temu_eventDepublish(int64_t EvID);
142 
163 TEMU_API int64_t temu_eventPublish(const char *EvName, void *Obj,
164  void (*Func)(temu_Event*));
165 
166 // Synchronisation events
167 typedef enum {
168  teSE_Cpu, // Trigger event when CPU reaches timer
169  teSE_Machine, // Synchronise event on machine
171 
186 TEMU_API void temu_eventPostCycles(void *Q, int64_t EvID, int64_t Delta,
187  temu_SyncEvent Sync);
198 TEMU_API void temu_eventPostNanos(void *Q, int64_t EvID, int64_t Delta,
199  temu_SyncEvent Sync);
209 TEMU_API void temu_eventPostSecs(void *Q, int64_t EvID, double Delta,
210  temu_SyncEvent Sync);
211 
224 TEMU_API void temu_eventPostStack(void *Q, int64_t EvID, temu_SyncEvent Sync);
225 
234 TEMU_API int temu_eventIsScheduled(int64_t EvID);
235 
241 TEMU_API void temu_eventDeschedule(int64_t EvID);
242 
250 TEMU_API int64_t temu_eventGetCycles(void *Q, int64_t EvID);
251 
259 TEMU_API int64_t temu_eventGetNanos(void *Q, int64_t EvID);
260 
268 TEMU_API double temu_eventGetSecs(void *Q, int64_t EvID);
269 
270 
271 //======================== EXPERIMENTAL API ==================================//
273 #define TEMU_ASYNC_CYCLIC 1
274 #define TEMU_ASYNC_READ (1 << 1)
275 #define TEMU_ASYNC_WRITE (1 << 2)
276 
306 TEMU_API int temu_asyncTimerAdd(void *Q, double T,
307  unsigned Flags, void (*CB)(void*),
308  void *Data);
309 
315 TEMU_API void temu_asyncTimerRemove(int Fd);
316 
333 TEMU_API int temu_asyncSocketAdd(void *Q, int Sock, unsigned Flags,
334  void (*CB)(void*),
335  void *Data);
336 
343 TEMU_API void temu_asyncSocketRemove(int Fd, unsigned Flags);
344 
353 TEMU_API void temu_eventPostAsync(void *Q, temu_ThreadSafeCb CB, void *Data,
354  temu_SyncEvent Sync);
355 
356 
387 TEMU_API int temu_eventSetRealTime(int64_t EvID);
388 
389 
403 TEMU_API void temu_eventSetPeriodCycles(int64_t EvID, int64_t Period);
404 
412 TEMU_API void temu_eventSetRTPeriodNanos(int64_t EvID, int64_t Period);
413 
424 TEMU_API void temu_eventSetRTTime(int64_t EvID, int64_t Time);
425 
429 TEMU_API uint64_t temu_eventQueueGetFreq(void *Q);
430 
431 //================= END OF EXPERIMENTAL API ==================================//
432 
433 #ifdef __cplusplus
434 }
435 #endif
436 
437 #endif /* ! TEMU_EVENTS_H */
struct temu_EventQueue temu_EventQueue
Definition: Events.h:42
int64_t Period
Definition: Events.h:54
TEMU_API int temu_asyncTimerAdd(void *Q, double T, unsigned Flags, void(*CB)(void *), void *Data)
void(* temu_ThreadSafeCb)(void *)
Definition: Events.h:60
int QueueIdx
Definition: Events.h:48
uint32_t Flags
Definition: Events.h:47
TEMU_API uint64_t temu_eventQueueGetFreq(void *Q)
TEMU_API int64_t temu_eventPublishStruct(const char *EvName, temu_Event *Ev, void *Obj, void(*Func)(temu_Event *))
TEMU_API int64_t temu_eventGetCycles(void *Q, int64_t EvID)
TEMU_API int temu_eventSetRealTime(int64_t EvID)
TEMU_API int temu_eventIsScheduled(int64_t EvID)
TEMU_API void temu_eventDepublish(int64_t EvID)
void * Obj
Definition: Events.h:50
void(* Func)(struct temu_Event *)
Definition: Events.h:51
temu_EventQueue * Queue
Definition: Events.h:49
TEMU_API void temu_eventPostStack(void *Q, int64_t EvID, temu_SyncEvent Sync)
TEMU_API void temu_eventPostAsync(void *Q, temu_ThreadSafeCb CB, void *Data, temu_SyncEvent Sync)
TEMU_API int temu_asyncSocketAdd(void *Q, int Sock, unsigned Flags, void(*CB)(void *), void *Data)
TEMU_API void * temu_allocateEventQueue(void)
Allocate event queue.
int64_t RTPeriod
Definition: Events.h:56
TEMU_API int64_t temu_eventGetNanos(void *Q, int64_t EvID)
temu_SyncEvent
Definition: Events.h:167
TEMU_API int64_t temu_eventGetOldStyleID(void(*Ev)(void *, void *), void *Sender)
TEMU_API void temu_eventPostNanos(void *Q, int64_t EvID, int64_t Delta, temu_SyncEvent Sync)
int64_t Time
Definition: Events.h:45
#define TEMU_IFACE_REFERENCE_TYPE(N)
Definition: Objsys.h:129
TEMU_API int64_t temu_eventPublishOldStyle(const char *Name, void *Obj, void(*Ev)(void *, void *))
TEMU_API void temu_postCallbackInQueue(void *Queue, temu_ThreadSafeCb Cb, void *Arg)
Post an event directly into a queue object.
TEMU_API double temu_eventGetSecs(void *Q, int64_t EvID)
TEMU_API void temu_eventSetPeriodCycles(int64_t EvID, int64_t Period)
TEMU_API int64_t temu_eventPublish(const char *EvName, void *Obj, void(*Func)(temu_Event *))
void * Data
Definition: Events.h:53
struct temu_Event temu_Event
TEMU_API void temu_asyncSocketRemove(int Fd, unsigned Flags)
TEMU_API void temu_eventDeschedule(int64_t EvID)
TEMU_API void temu_disposeEventQueue(void *Queue)
Dispose event queue.
int64_t EventId
Definition: Events.h:46
TEMU_API void temu_eventPostCycles(void *Q, int64_t EvID, int64_t Delta, temu_SyncEvent Sync)
TEMU_API void temu_eventSetRTPeriodNanos(int64_t EvID, int64_t Period)
TEMU_API void temu_removeCallbackInQueue(void *Queue, temu_ThreadSafeCb Cb, void *Arg)
Remove an event from a queue object.
TEMU_API void temu_eventPostSecs(void *Q, int64_t EvID, double Delta, temu_SyncEvent Sync)
int64_t RTTime
Definition: Events.h:55
TEMU_API void temu_asyncTimerRemove(int Fd)
#define TEMU_API
Definition: Attributes.h:53
TEMU_API void temu_eventSetRTTime(int64_t EvID, int64_t Time)