src/timer.c
author Edouard Tisserant
Wed, 06 Mar 2013 13:40:54 +0900
changeset 773 c10def4bfbde
parent 629 b9274b595650
child 801 32d146b64a35
permissions -rwxr-xr-x
win32: reverted DLL loading from LoadLibraryA to LoadLibrary
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
     1
/*
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
     3
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
     5
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
     6
See COPYING file for copyrights details.
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
     7
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
     8
This library is free software; you can redistribute it and/or
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    10
License as published by the Free Software Foundation; either
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    12
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    13
This library is distributed in the hope that it will be useful,
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    16
Lesser General Public License for more details.
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    17
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    19
License along with this library; if not, write to the Free Software
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    21
*/
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    22
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    23
** @file   timer.c
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    24
** @author Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    25
** @date   Tue Jun  5 09:32:32 2007
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    26
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    27
** @brief
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    28
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    29
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 167
diff changeset
    30
*/
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    31
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 48
diff changeset
    32
/* #define DEBUG_WAR_CONSOLE_ON */
95cd3376cc9f compilator compatitibility
frdupin
parents: 48
diff changeset
    33
/* #define DEBUG_ERR_CONSOLE_ON */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    34
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    35
#include <applicfg.h>
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    36
#include "timer.h"
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    37
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 48
diff changeset
    38
/*  ---------  The timer table --------- */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    39
s_timer_entry timers[MAX_NB_TIMER] = {{TIMER_FREE, NULL, NULL, 0, 0, 0},};
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 48
diff changeset
    40
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    41
TIMEVAL total_sleep_time = TIMEVAL_MAX;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    42
TIMER_HANDLE last_timer_raw = -1;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    43
167
b2f8b91d89b5 Removed compilation warnings with some GCC.
etisserant
parents: 149
diff changeset
    44
#define min_val(a,b) ((a<b)?a:b)
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    45
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    46
/*!
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    47
** -------  Use this to declare a new alarm ------
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    48
**
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    49
** @param d
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    50
** @param id
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    51
** @param callback
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    52
** @param value
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    53
** @param period
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    54
**
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    55
** @return
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    56
**/
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    57
TIMER_HANDLE SetAlarm(CO_Data* d, UNS32 id, TimerCallback_t callback, TIMEVAL value, TIMEVAL period)
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    58
{
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    59
	TIMER_HANDLE row_number;
470
86ff6646b721 Applied Edwards timer.c optimization patch.
etisserant
parents: 215
diff changeset
    60
	s_timer_entry *row;
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    61
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    62
	/* in order to decide new timer setting we have to run over all timer rows */
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    63
	for(row_number=0, row=timers; row_number <= last_timer_raw + 1 && row_number < MAX_NB_TIMER; row_number++, row++)
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    64
	{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    65
		if (callback && 	/* if something to store */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    66
		   row->state == TIMER_FREE) /* and empty row */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    67
		{	/* just store */
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    68
			TIMEVAL real_timer_value;
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    69
			TIMEVAL elapsed_time;
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    70
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    71
			if (row_number == last_timer_raw + 1) last_timer_raw++;
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    72
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    73
			elapsed_time = getElapsedTime();
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    74
			/* set next wakeup alarm if new entry is sooner than others, or if it is alone */
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    75
			real_timer_value = value;
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    76
			real_timer_value = min_val(real_timer_value, TIMEVAL_MAX);
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    77
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    78
			if (total_sleep_time > elapsed_time && total_sleep_time - elapsed_time > real_timer_value)
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    79
			{
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    80
				total_sleep_time = elapsed_time + real_timer_value;
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    81
				setTimer(real_timer_value);
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    82
			}
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    83
			row->callback = callback;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    84
			row->d = d;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    85
			row->id = id;
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    86
			row->val = value + elapsed_time;
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    87
			row->interval = period;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    88
			row->state = TIMER_ARMED;
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
    89
			return row_number;
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    90
		}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    91
	}
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    92
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    93
	return TIMER_NONE;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    94
}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
    95
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    96
/*!
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    97
**  -----  Use this to remove an alarm ----
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    98
**
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
    99
** @param handle
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   100
**
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   101
** @return
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   102
**/
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   103
TIMER_HANDLE DelAlarm(TIMER_HANDLE handle)
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   104
{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   105
	/* Quick and dirty. system timer will continue to be trigged, but no action will be preformed. */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   106
	MSG_WAR(0x3320, "DelAlarm. handle = ", handle);
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   107
	if(handle != TIMER_NONE)
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   108
	{
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   109
		if(handle == last_timer_raw)
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   110
			last_timer_raw--;
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   111
		timers[handle].state = TIMER_FREE;
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   112
	}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   113
	return TIMER_NONE;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   114
}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   115
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   116
/*!
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   117
** ------  TimeDispatch is called on each timer expiration ----
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   118
**
522
e69d5903a5b2 Fixed serious bug in setAlarm, causing wrong timer duration when setAlarm not called long after timeDispatch.
greg
parents: 470
diff changeset
   119
**/
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   120
int tdcount=0;
470
86ff6646b721 Applied Edwards timer.c optimization patch.
etisserant
parents: 215
diff changeset
   121
void TimeDispatch(void)
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   122
{
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   123
	TIMER_HANDLE i;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   124
	TIMEVAL next_wakeup = TIMEVAL_MAX; /* used to compute when should normaly occur next wakeup */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   125
	/* First run : change timer state depending on time */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   126
	/* Get time since timer signal */
629
b9274b595650 CosateQ contribution.
edouard
parents: 576
diff changeset
   127
	UNS32 overrun = (UNS32)getElapsedTime();
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   128
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   129
	TIMEVAL real_total_sleep_time = total_sleep_time + overrun;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   130
470
86ff6646b721 Applied Edwards timer.c optimization patch.
etisserant
parents: 215
diff changeset
   131
	s_timer_entry *row;
86ff6646b721 Applied Edwards timer.c optimization patch.
etisserant
parents: 215
diff changeset
   132
86ff6646b721 Applied Edwards timer.c optimization patch.
etisserant
parents: 215
diff changeset
   133
	for(i=0, row = timers; i <= last_timer_raw; i++, row++)
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   134
	{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   135
		if (row->state & TIMER_ARMED) /* if row is active */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   136
		{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   137
			if (row->val <= real_total_sleep_time) /* to be trigged */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   138
			{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   139
				if (!row->interval) /* if simply outdated */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   140
				{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   141
					row->state = TIMER_TRIG; /* ask for trig */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   142
				}
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   143
				else /* or period have expired */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   144
				{
629
b9274b595650 CosateQ contribution.
edouard
parents: 576
diff changeset
   145
					/* set val as interval, with 32 bit overrun correction, */
b9274b595650 CosateQ contribution.
edouard
parents: 576
diff changeset
   146
					/* modulo for 64 bit not available on all platforms     */
b9274b595650 CosateQ contribution.
edouard
parents: 576
diff changeset
   147
					row->val = row->interval - (overrun % (UNS32)row->interval);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 48
diff changeset
   148
					row->state = TIMER_TRIG_PERIOD; /* ask for trig, periodic */
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   149
					/* Check if this new timer value is the soonest */
470
86ff6646b721 Applied Edwards timer.c optimization patch.
etisserant
parents: 215
diff changeset
   150
					if(row->val < next_wakeup)
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   151
						next_wakeup = row->val;
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   152
				}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   153
			}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   154
			else
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   155
			{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   156
				/* Each armed timer value in decremented. */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   157
				row->val -= real_total_sleep_time;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   158
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   159
				/* Check if this new timer value is the soonest */
470
86ff6646b721 Applied Edwards timer.c optimization patch.
etisserant
parents: 215
diff changeset
   160
				if(row->val < next_wakeup)
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   161
					next_wakeup = row->val;
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   162
			}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   163
		}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   164
	}
576
b4bc22764a39 fix error in timer.c
greg
parents: 522
diff changeset
   165
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   166
	/* Remember how much time we should sleep. */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   167
	total_sleep_time = next_wakeup;
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   168
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   169
	/* Set timer to soonest occurence */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   170
	setTimer(next_wakeup);
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   171
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   172
	/* Then trig them or not. */
470
86ff6646b721 Applied Edwards timer.c optimization patch.
etisserant
parents: 215
diff changeset
   173
	for(i=0, row = timers; i<=last_timer_raw; i++, row++)
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   174
	{
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   175
		if (row->state & TIMER_TRIG)
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   176
		{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   177
			row->state &= ~TIMER_TRIG; /* reset trig state (will be free if not periodic) */
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
   178
			if(row->callback)
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   179
				(*row->callback)(row->d, row->id); /* trig ! */
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   180
		}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   181
	}
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents: 0
diff changeset
   182
}