Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / realtime / realtime_timer.c
blob32bd758fef1052b7c909d89cbfd42bc1e8d97987
1 /*
2 Copyright © 2015-2016, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: timer implementation.
6 Lang: English.
7 */
9 #ifndef DEBUG
10 #define DEBUG 0
11 #endif
12 #include <aros/debug.h>
14 #include <proto/dos.h>
15 #include <proto/exec.h>
17 #include <exec/interrupts.h>
18 #include <hardware/intbits.h>
20 #include "realtime_intern.h"
22 extern void Pulse();
24 /* RealTime timer interrupt -- currently only a VBlank interrupt */
25 static AROS_INTH1(rtVBlank, struct internal_RealTimeBase *, RealTimeBase)
27 AROS_INTFUNC_INIT
29 // kprintf("Signalling task %p\n", RealTimeBase->rtb_PulseTask);
30 Signal(RealTimeBase->rtb_PulseTask, SIGF_SINGLE);
32 return 0;
34 AROS_INTFUNC_EXIT
38 BOOL AllocTimer(struct internal_RealTimeBase *RealTimeBase)
40 RealTimeBase->rtb_TickErr = 0; /* How may such a thing be measured? */
41 RealTimeBase->rtb_Reserved1 = 60; /* NB: rtb_Reserved1 contains the TICK_FREQ,
42 * which in our case is vblank (60) */
44 /* I use a process here just to be able to use CreateNewProc() so
45 I don't have to fiddle with stack order and such... */
47 struct TagItem tags[] = { { NP_Entry , (IPTR)Pulse },
48 { NP_Name , (IPTR)"RealTime Pulse" },
49 { NP_Priority, (IPTR)127 },
50 { NP_UserData, (IPTR)RealTimeBase },
51 { TAG_DONE , (IPTR)NULL } };
53 RealTimeBase->rtb_PulseTask = (struct Task *)CreateNewProc(tags);
56 if (RealTimeBase->rtb_PulseTask == NULL)
58 return FALSE;
61 D(bug("[realtime.library] pulse task created @ 0x%p\n", GPB(RealTimeBase)->rtb_PulseTask));
63 /* TODO */
64 /* This should be replaced by some timer.device thing when an accurate
65 timer is available -- UNIT_MICROHZ? */
67 RealTimeBase->rtb_VBlank.is_Code = (APTR)&rtVBlank;
68 RealTimeBase->rtb_VBlank.is_Data = (APTR)RealTimeBase;
69 RealTimeBase->rtb_VBlank.is_Node.ln_Name = "RealTime VBlank server";
70 RealTimeBase->rtb_VBlank.is_Node.ln_Pri = 127;
71 RealTimeBase->rtb_VBlank.is_Node.ln_Type = NT_INTERRUPT;
73 /* Add a VBLANK server to take care of the heartbeats. */
74 AddIntServer(INTB_VERTB, &RealTimeBase->rtb_VBlank);
76 return TRUE;
80 void FreeTimer(struct internal_RealTimeBase *RealTimeBase)
82 RemIntServer(INTB_VERTB, &RealTimeBase->rtb_VBlank);
84 if (RealTimeBase->rtb_PulseTask)
85 Signal(RealTimeBase->rtb_PulseTask, SIGBREAKF_CTRL_C);