/*
    Copyright 2000 (c) by Reto Gaehler, George Fankhauser
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public 
    Licence. A full copy of the GNU GPL is provided in the file COPYING 
    found in the development root of Topsy.
*/
/*
    File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Threads/TMTimer.h,v $
    Author(s):             
    Affiliation:           ETH Zuerich, TIK
    Version:               $Revision: 2935 $
    Creation Date:         
    Last Date of Change:   $Date: 2007-03-21 11:58:17 +0100 (Mit, 21 Mär 2007) $      by: $Author: baderma $
 
*/
#ifndef __TMTIMER_H
#define __TMTIMER_H

#include <Topsy.h>
#include <Syscall.h>

#define TIMER_FAILED			-1
#define TIMER_OK				1
#define TIMER_GRANULARITY		10		//ms

#define TIMER_MAX_EVENTS		20

typedef void (*tmCallBackProc)(void *pParam,long n32Param,void *pMsg1,void *pMsg2,unsigned long u32Msg);

/* A timer delta list entry */

typedef struct tqent
{
  long int		tq_entrytime;			/* time when inserted in queue	*/
  int				tq_timeleft;			/* time to expire (1/100 secs)	*/
  int				tq_interval;
  tmCallBackProc	tq_fire;       			/* will be executed as soon as a timer expires */
  void			*tq_pParam;				/* param 1 to send when expired	*/
  long			tq_n32Param;			/* param 2 to send when expired	*/
  void			*tq_pMsg1;				/* data 1 to send when expired	*/
  void			*tq_pMsg2;				/* data 2 to send when expired	*/
  unsigned long	tq_u32Msg;				/* user parameter send when expired	*/
  struct	tqent	*tq_next;				/* next in the list	*/
}
tqent, *tqentptr;

void tmTimerInit();

long int tmGetTickCount();

//	timer interrupt service routine (called every 10ms)
void tmTimerInterrupt();

//	returns the remaining time of a timer queue element
int tmLeftTimer(tmCallBackProc fire,void *pParam, long n32Param,
                void *pMsg1,void *pMsg2,unsigned long u32Msg);

//	removes a timer queue element
int tmClearTimer(	tmCallBackProc fire,void *pParam, long n32Param,
                  void *pMsg1,void *pMsg2,unsigned long u32Msg);

//	inserts a timer queue element
int tmSetTimer(	tmCallBackProc fire, void *pParam, long n32Param,
                void *pMsg1,void *pMsg2,unsigned long u32Msg,int time,Boolean bRepeat);


#endif
