annotate src/gpf/osl/os_tim_fl.c @ 174:097e25b925a2

doc/Compiling: gtm900 target added
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 19 Jun 2019 06:15:56 +0000
parents 8b2a9a374324
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This C module is a reconstruction based on the disassembly of
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * os_tim.obj in frame_na7_db_fl.lib from the Leonardo package,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * subsequently reworked by Space Falcon.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 /* set of included headers from COFF symtab: */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "nucleus.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "typedefs.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "os.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "gdi.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "os_types.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "os_glob.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern UNSIGNED TMD_Timer;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern INT TMD_Timer_State;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern T_OS_TIMER_ENTRY TimerTable[];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern T_OS_TIMER_TABLE_ENTRY *p_list[];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern void os_Timeout(UNSIGNED t_handle);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern void timer_error(int err);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 unsigned os_time_to_tick_multiplier = TIME_TO_TICK_TDMA_FRAME_MULTIPLIER;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned os_tick_to_time_multiplier = TICK_TO_TIME_TDMA_FRAME_MULTIPLIER;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 unsigned volatile t_start_ticks;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 T_OS_TIMER_TABLE_ENTRY *t_running;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 int used_timers;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 int next_t_handle;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int volatile t_list_access;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 int max_used_timers;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 NU_SEMAPHORE TimSemCB;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 NU_TIMER os_timer_cb;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #ifdef __GNUC__
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #define BARRIER asm volatile ("": : :"memory")
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 #else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 #define BARRIER /* prayer */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 GLOBAL LONG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 os_set_tick(int os_system_tick)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 switch (os_system_tick) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 case SYSTEM_TICK_TDMA_FRAME:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 os_time_to_tick_multiplier = TIME_TO_TICK_TDMA_FRAME_MULTIPLIER;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 os_tick_to_time_multiplier = TICK_TO_TIME_TDMA_FRAME_MULTIPLIER;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case SYSTEM_TICK_10_MS:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 os_time_to_tick_multiplier = TIME_TO_TICK_10MS_MULTIPLIER;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 os_tick_to_time_multiplier = TICK_TO_TIME_10MS_MULTIPLIER;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 return(OS_ERROR);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 GLOBAL LONG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 os_TimerInformation(USHORT Index, char *Buffer)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 static int t_info_read;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (t_info_read) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 t_info_read = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 return(OS_ERROR);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 sprintf(Buffer, "Maximum %d of %d available timers running",
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 max_used_timers, MaxSimultaneousTimer);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 t_info_read = 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 GLOBAL LONG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 os_TimInit(void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 int i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (NU_Create_Semaphore(&TimSemCB, "TIMSEM", 1, NU_PRIORITY)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 != NU_SUCCESS)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 return(OS_ERROR);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (NU_Create_Timer(&os_timer_cb, "OS_TIMER", os_Timeout, 0, 1, 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 NU_DISABLE_TIMER) != NU_SUCCESS)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return(OS_ERROR);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 used_timers = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 max_used_timers = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 next_t_handle = 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 t_list_access = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 t_start_ticks = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 p_list[0] = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 for (i = 1; i < MaxSimultaneousTimer; i++) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 TimerTable[i].entry.status = TMR_FREE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 TimerTable[i].entry.next = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 TimerTable[i].entry.prev = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 TimerTable[i].next_t_handle = i + 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 p_list[i] = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 TimerTable[MaxSimultaneousTimer].entry.status = TMR_FREE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 TimerTable[MaxSimultaneousTimer].next_t_handle = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 t_running = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 GLOBAL LONG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 os_RecoverTick(OS_TICK ticks)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 UNSIGNED current_system_clock;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 current_system_clock = NU_Retrieve_Clock();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 NU_Set_Clock(current_system_clock + ticks);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (TMD_Timer_State == TM_ACTIVE) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 if (TMD_Timer <= ticks) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 TMD_Timer_State = TM_EXPIRED;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 TMD_Timer = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 } else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 TMD_Timer -= ticks;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 GLOBAL LONG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 os_QueryTimer(OS_HANDLE TaskHandle, OS_HANDLE TimerHandle,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 OS_TIME *RemainingTime)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 T_OS_TIMER_TABLE_ENTRY *timer, *t_iter;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 OS_TICK c_ticks, r_ticks, e_ticks;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 STATUS sts;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 if (TimerHandle > MaxSimultaneousTimer)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 return(OS_ERROR);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 sts = NU_Obtain_Semaphore(&TimSemCB, NU_SUSPEND);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 timer = &TimerTable[TimerHandle].entry;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 if (timer->status == TMR_FREE) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 if (sts == NU_SUCCESS)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 NU_Release_Semaphore(&TimSemCB);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 return(OS_ERROR);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 t_list_access = 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 BARRIER;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (!t_running) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 r_ticks = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 goto out;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 c_ticks = NU_Retrieve_Clock();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 e_ticks = c_ticks - t_start_ticks;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 t_iter = t_running;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 if (t_iter->r_ticks >= e_ticks)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 r_ticks = t_iter->r_ticks - e_ticks;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 r_ticks = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 while (t_iter != timer) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 t_iter = t_iter->next;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 if (t_iter == t_running) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 r_ticks = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 goto out;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 r_ticks += t_iter->r_ticks;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 out: BARRIER;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 t_list_access = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (sts == NU_SUCCESS)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 NU_Release_Semaphore(&TimSemCB);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 *RemainingTime = SYSTEM_TICKS_TO_TIME(r_ticks);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 GLOBAL LONG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 os_InactivityTicks(int *next_event, OS_TICK *next_event_ticks)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 *next_event = 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 switch (TMD_Timer_State) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 case TM_ACTIVE:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 *next_event_ticks = TMD_Timer;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 case TM_NOT_ACTIVE:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 *next_event_ticks = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 *next_event = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 *next_event_ticks = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 return(OS_OK);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }