annotate src/gpf2/osl/os_tim_ir.c @ 496:2d1e5ad1d54f

OSL: os_mis_ir.c compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 Jun 2018 20:50:05 +0000
parents 91e8dac34ada
children b4dd8c7e84ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
487
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This C module is a reconstruction based on the disassembly of
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * os_tim.obj in frame_na7_db_ir.lib from the Leonardo package,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * subsequently reworked by Space Falcon.
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 *
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * The original decompilation has been contributed by Das Signal.
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 /* set of included headers from COFF symtab: */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "gpfconf.h" /* FreeCalypso addition */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../../nucleus/nucleus.h"
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "typedefs.h"
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "os.h"
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "gdi.h"
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "os_types.h"
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "os_glob.h"
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern T_OS_TIMER_ENTRY TimerTable[];
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern T_OS_TIMER_TABLE_ENTRY *p_list[];
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern unsigned os_time_to_tick_multiplier;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern unsigned os_tick_to_time_multiplier;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern unsigned volatile t_start_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern T_OS_TIMER_TABLE_ENTRY *t_running;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern int used_timers;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 extern int next_t_handle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 extern int volatile t_list_access;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 extern int max_used_timers;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 extern NU_SEMAPHORE TimSemCB;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 extern NU_TIMER os_timer_cb;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #define BARRIER asm volatile ("": : :"memory")
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 void
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 timer_error(int err)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 /* forward declaration */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 void os_Timeout(UNSIGNED t_handle);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 static int
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 os_remove_timer_from_list(T_OS_TIMER_TABLE_ENTRY *timer)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 OS_TICK c_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (timer != t_running) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (timer->next != t_running)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 timer->next->r_ticks += timer->r_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 } else {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 c_ticks = NU_Retrieve_Clock();
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (timer->next == timer) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 t_running = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 } else {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 timer->next->r_ticks =
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 t_start_ticks + timer->r_ticks +
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 timer->next->r_ticks - c_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 t_running = timer->next;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 NU_Control_Timer(&os_timer_cb, NU_DISABLE_TIMER);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (t_running != NULL) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 t_start_ticks = c_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (t_running->r_ticks != 0)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 NU_Reset_Timer(&os_timer_cb, os_Timeout,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 t_running->r_ticks, 0,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 NU_ENABLE_TIMER);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (timer->next != timer) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 timer->prev->next = timer->next;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 timer->next->prev = timer->prev;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 timer->next = NULL;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 timer->prev = NULL;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 timer->status = TMR_USED;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 return TMR_USED;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 static unsigned
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 os_add_timer_to_list(T_OS_TIMER_TABLE_ENTRY *timer, OS_TICK ticks)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 T_OS_TIMER_TABLE_ENTRY *t_list;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 OS_TICK c_ticks, e_ticks, r1_ticks, return_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (ticks == 0)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 ticks = 1;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 c_ticks = NU_Retrieve_Clock();
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 t_list = t_running;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (t_list != NULL) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 e_ticks = c_ticks - t_start_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (t_list->r_ticks >= e_ticks) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 r1_ticks = t_list->r_ticks - e_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 t_list->r_ticks = r1_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 } else {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 r1_ticks = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 t_list->r_ticks = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 t_start_ticks = c_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 return_ticks = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 while (ticks >= r1_ticks) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 ticks -= r1_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 t_list = t_list->next;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (t_list == t_running)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 goto out;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 r1_ticks = t_list->r_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 t_list->r_ticks -= ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 if (t_list == t_running) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 t_running = timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 t_start_ticks = c_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 NU_Control_Timer(&os_timer_cb, NU_DISABLE_TIMER);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 return_ticks = ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 out:
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 timer->next = t_list;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 timer->prev = t_list->prev;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 t_list->prev->next = timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 t_list->prev = timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 timer->r_ticks = ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 } else {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 timer->next = timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 timer->prev = timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 timer->r_ticks = ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 t_start_ticks = c_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 t_running = timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 return_ticks = ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 timer->status = TMR_ACTIVE;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 return return_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 void
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 os_Timeout(UNSIGNED t_handle) /* argument is unused */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 ULONG s_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 OS_HANDLE task_handle, e_handle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 USHORT t_index;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 int i, done;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 T_OS_TIMER_TABLE_ENTRY **t_r4;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 T_OS_TIMER_TABLE_ENTRY *timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 void (*timeout_func) (OS_HANDLE, OS_HANDLE, USHORT);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 if (t_list_access) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 t_start_ticks++;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 NU_Reset_Timer(&os_timer_cb, os_Timeout, 1, 0,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 NU_ENABLE_TIMER);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 return;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 timer = t_running;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 if (timer) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 s_ticks = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 done = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 i = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 do {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 timeout_func = timer->TimeoutProc;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 if (timer->p_ticks)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 p_list[i++] = timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 task_handle = timer->task_handle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 e_handle = timer->entity_handle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 t_index = timer->t_index;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 timer->status = TMR_USED;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (timer->next == timer) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 t_running = NULL;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 done = 1;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 } else {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 timer->prev->next = timer->next;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 timer->next->prev = timer->prev;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 if (timer->next->r_ticks) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 t_running = timer->next;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 s_ticks = timer->next->r_ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 done = 1;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 } else
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 timer = timer->next;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 timeout_func(task_handle, e_handle, t_index);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 while (!done);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 if (s_ticks) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 t_start_ticks = NU_Retrieve_Clock();
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 NU_Reset_Timer(&os_timer_cb, os_Timeout, s_ticks, 0,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 NU_ENABLE_TIMER);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 for (t_r4 = p_list; *t_r4; t_r4++) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 timer = *t_r4;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 s_ticks = os_add_timer_to_list(timer, timer->p_ticks);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 if (s_ticks)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 NU_Reset_Timer(&os_timer_cb, os_Timeout, s_ticks, 0,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 NU_ENABLE_TIMER);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 *t_r4 = NULL;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 GLOBAL LONG os_StartTimer(OS_HANDLE TaskHandle, OS_HANDLE TimerHandle,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 USHORT Index, OS_TIME InitialTime,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 OS_TIME RescheduleTime)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 T_OS_TIMER_TABLE_ENTRY *timer;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 OS_TICK ticks;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 STATUS sts;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 if (TimerHandle > MaxSimultaneousTimer)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 timer = &TimerTable[TimerHandle].entry;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 sts = NU_Obtain_Semaphore(&TimSemCB, NU_SUSPEND);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 if (timer->status == TMR_FREE) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 NU_Release_Semaphore(&TimSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 t_list_access = 1;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 BARRIER;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 if (timer->status == TMR_ACTIVE)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 os_remove_timer_from_list(timer);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 timer->t_handle = TimerHandle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 timer->task_handle = os_MyHandle();
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 timer->entity_handle = TaskHandle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 timer->t_index = Index;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 timer->p_ticks = TIME_TO_SYSTEM_TICKS(RescheduleTime);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 ticks = os_add_timer_to_list(timer, TIME_TO_SYSTEM_TICKS(InitialTime));
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 if (ticks)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 NU_Reset_Timer(&os_timer_cb, os_Timeout, ticks, 0,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 NU_ENABLE_TIMER);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 BARRIER;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 t_list_access = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 NU_Release_Semaphore(&TimSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 return OS_OK;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 GLOBAL LONG os_StopTimer(OS_HANDLE TaskHandle, OS_HANDLE TimerHandle)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 /* TaskHandle argument is unused */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 T_OS_TIMER_ENTRY *timer_e;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 STATUS sts;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 if (TimerHandle > MaxSimultaneousTimer)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 timer_e = &TimerTable[TimerHandle];
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 sts = NU_Obtain_Semaphore(&TimSemCB, NU_SUSPEND);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 if (timer_e->entry.status == TMR_FREE) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 NU_Release_Semaphore(&TimSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 return OS_ERROR;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 t_list_access = 1;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 BARRIER;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 if (timer_e->entry.status == TMR_ACTIVE)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 os_remove_timer_from_list(&timer_e->entry);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 BARRIER;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 t_list_access = 0;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 NU_Release_Semaphore(&TimSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 return OS_OK;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 GLOBAL LONG os_IncrementTick(OS_TICK ticks)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 return OS_OK;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 GLOBAL LONG os_DestroyTimer(OS_HANDLE TaskHandle, OS_HANDLE TimerHandle)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 /* TaskHandle argument is unused */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 STATUS sts;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 T_OS_TIMER_ENTRY *timer_e;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 if (TimerHandle > MaxSimultaneousTimer)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 return(OS_ERROR);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 sts = NU_Obtain_Semaphore(&TimSemCB, NU_SUSPEND);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 timer_e = &TimerTable[TimerHandle];
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 if (timer_e->entry.status != TMR_USED) {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 NU_Release_Semaphore(&TimSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 return OS_ERROR;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 timer_e->next_t_handle = next_t_handle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 next_t_handle = TimerHandle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 timer_e->entry.status = TMR_FREE;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 used_timers--;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 NU_Release_Semaphore(&TimSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 return OS_OK;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 GLOBAL LONG os_CreateTimer(OS_HANDLE TaskHandle,
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 void (*TimeoutProc) (OS_HANDLE, OS_HANDLE, USHORT),
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 OS_HANDLE *TimerHandle, OS_HANDLE MemPoolHandle)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 /* TaskHandle and MemPoolHandle arguments are unused */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 {
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 STATUS sts;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 T_OS_TIMER_ENTRY *timer_e;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 sts = NU_Obtain_Semaphore(&TimSemCB, NU_SUSPEND);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 if (next_t_handle == 0) { /* no free timers left */
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 NU_Release_Semaphore(&TimSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 return OS_ERROR;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 }
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 timer_e = &TimerTable[next_t_handle];
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 timer_e->entry.status = TMR_USED;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 timer_e->entry.TimeoutProc = TimeoutProc;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 *TimerHandle = next_t_handle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 next_t_handle = timer_e->next_t_handle;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 used_timers++;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 if (max_used_timers < used_timers)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 max_used_timers = used_timers;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 if (sts == NU_SUCCESS)
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 NU_Release_Semaphore(&TimSemCB);
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 return OS_OK;
91e8dac34ada src/gpf2/osl: initial import from old freecalypso-sw tree
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 }