changeset 459:38afaeb194ea

os_tim_fl.c: os_QueryTimer() decompiled w/o real understanding of the logic
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 23 Jun 2014 06:54:40 +0000
parents 705030e1e8b2
children 9cacd09e8ef3
files gsm-fw/gpf/osl/os_tim_fl.c
diffstat 1 files changed, 43 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gsm-fw/gpf/osl/os_tim_fl.c	Mon Jun 23 05:44:03 2014 +0000
+++ b/gsm-fw/gpf/osl/os_tim_fl.c	Mon Jun 23 06:54:40 2014 +0000
@@ -26,10 +26,10 @@
 unsigned os_tick_to_time_multiplier = TICK_TO_TIME_TDMA_FRAME_MULTIPLIER;
 
 unsigned t_start_ticks;
-T_OS_TIMER_TABLE_ENTRY *t_running;
+T_OS_TIMER_TABLE_ENTRY * volatile t_running;
 int used_timers;
 int next_t_handle;
-int t_list_access;
+int volatile t_list_access;
 int max_used_timers;
 NU_SEMAPHORE TimSemCB;
 NU_TIMER os_timer_cb;
@@ -112,3 +112,44 @@
 	}
 	return(OS_OK);
 }
+
+GLOBAL LONG
+os_QueryTimer(OS_HANDLE TaskHandle, OS_HANDLE TimerHandle,
+		OS_TIME *RemainingTime)
+{
+	T_OS_TIMER_TABLE_ENTRY *timer, *t_r0, *t_r3;
+	OS_TICK c_ticks, r_ticks, e_ticks;
+	STATUS sts;
+
+	t_list_access = 1;
+	if (TimerHandle > MaxSimultaneousTimer) {
+error_out:	t_list_access = 0;
+		return(OS_ERROR);
+	}
+	timer = &TimerTable[TimerHandle].entry;
+	if (!timer->status)
+		goto error_out;
+	sts = NU_Obtain_Semaphore(&TimSemCB, NU_SUSPEND);
+	if (sts != NU_SUCCESS)
+		timer_error(15);
+	c_ticks = NU_Retrieve_Clock();
+	e_ticks = c_ticks - t_start_ticks;
+	t_r0 = t_running;
+	*RemainingTime = 0;
+	t_r3 = t_running;
+	if (t_r0 == t_r3)
+		r_ticks = t_r0->r_ticks - e_ticks;
+	else
+		r_ticks = t_r0->r_ticks;
+	while (t_r0 != timer) {
+		t_r0 = t_r0->next;
+		if (t_r0 == t_r3)
+			goto out;
+		r_ticks += t_r0->r_ticks;
+	}
+	*RemainingTime = SYSTEM_TICKS_TO_TIME(r_ticks);
+out:	if (sts == NU_SUCCESS)
+		NU_Release_Semaphore(&TimSemCB);
+	t_list_access = 0;
+	return(OS_OK);
+}