/*
** ppc.library emulation
** (c)1998-99 Frank Wille <frank@phoenix.owl.de>
**
** TimerObject emulation
**
** V0.4b (05.01.1999) phx
**       created
*/

#ifndef TIMEROBJECT_H
#define TIMEROBJECT_H

#ifndef EXEC_NODES_H
#include <exec/nodes.h>
#endif

#ifndef POWERPC_TASKSPPC_H
#include <powerpc/tasksPPC.h>
#endif

#ifndef POWERPC_PORTSPPC_H
#include <powerpc/portsPPC.h>
#endif

#ifndef DEVICES_TIMER_H
#include <devices/timer.h>
#endif


#define TO_TICK 20000           /* 1 tick = 20ms (50 Hz) */
#define TO_1S 1000000           /* 1 second = 1000000 us */


struct PPCTimerObject {
  struct MinNode to_Node;
  ULONG StartTime[2];           /* set by PPCTIMERTAG_START */
  ULONG StopTime[2];            /* set by PPCTIMERTAG_STOP */
  ULONG WaitPeriod[2];          /* set by PPCTIMERTAG_50HZ */
  ULONG to_Flags;
  struct TaskPPC *NotifTask;
  ULONG NotifMask;
  struct MsgPortPPC *replyport;
};

/* to_Flags */
#define TOB_50Hz 0      
#define TOF_50Hz (1<<0)         /* 50Hz notification timer */
#define TOB_AutoRemove 1
#define TOF_AutoRemove (1<<1)   /* disable 50Hz timer after use */
#define TOB_Enqueued 16
#define TOF_Enqueued (1<<16)    /* 50Hz timer active and waiting for notif. */


/* Message will be sent to TimerObject server for PPCTimerObjects of */
/* the type PPCTIMERTAG_50HZ. */

struct TimObjSrvMsg {
  struct Message to_Msg;
  struct PPCTimerObject *to_Ptr;
  UWORD to_Cmd;         /* TOCMD_xxx */
};

/* to_Cmd: TimerObject Server Commands */
#define TOCMD_EXIT 0    /* terminate server task, to_Ptr is irrelevant */
#define TOCMD_ADD 1     /* add a new timer object */
#define TOCMD_REM 2     /* remove this timer object */


extern const char *TimerObjSrvName;
extern struct MsgPortPPC *InitTOMsg(struct PPCBase *,struct TimObjSrvMsg *,
                                    struct PPCTimerObject *,UWORD);
extern void GetPPCTime(struct PPCBase *,ULONG *);
extern void GetDiffTime(struct PPCTimerObject *,ULONG *);
BOOL SendTOMsg(struct PPCBase *,struct PPCTimerObject *,UWORD);
extern struct PPCTimerObject *CreateTimObj(struct PPCBase *,ULONG,ULONG *);
extern void DeleteTimObj(struct PPCBase *,struct PPCTimerObject *);
extern void TimerObjectServer(struct PPCLibBase *,struct TaskPPC *,ULONG);


#endif
