[net.micro.amiga] timer driver in C

richr@iddic.UUCP (Rich Rodgers) (11/27/85)

/*  
*
         The following code is a C code example of how to set up and
use the timer device.  The main section of code shows how to call and use the 
timer.  This code ,in general, shows how to use most of the many devices that
the Amiga uses. EX. printer, serial, parallel, timer, narrator...
Please use this code as much as possible.  Do not include my name with it if
you do not want to.  And sell it if you find anyone stupid enough to buy it.

                                 RDS Software
                                 9140 SW Locust St.
                                 Tigard, OR  97223
                                 (503) 246-9258

                 Makers of the most unique terminal emulation
                      software the Amiga will ever see!!!

*
*/

#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/ports.h"
#include "exec/tasks.h"
#include "exec/io.h"
#include "devices/timer.h"

struct timerequest TimerIO;
struct MsgPort TimerMsgPort;

int tOpen()    /* Open the serial device */
{
   int error;

   if ((error = OpenDevice(TIMERNAME, UNIT_VBLANK, &TimerIO, 0)) != 0)
      return(error);

   /* Set up the message port in the I/O request */
   TimerMsgPort.mp_Node.ln_Type = NT_MSGPORT;
   TimerMsgPort.mp_Node.ln_Name = "vt-timer";
   TimerMsgPort.mp_Flags = 0;
   TimerMsgPort.mp_SigBit = AllocSignal(-1);
   TimerMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
   AddPort(&TimerMsgPort);

   TimerIO.tr_node.io_Message.mn_ReplyPort = &TimerMsgPort;
   return(0);
}

tClose()
{
   CloseDevice(&TimerIO);
   RemPort(&TimerMsgPort);
}

StartTimer(seconds, micros)
ULONG seconds, micros;
{
   TimerIO.tr_node.io_Command = TR_ADDREQUEST;
   TimerIO.tr_node.io_Flags = IOF_QUICK;
   TimerIO.tr_time.tv_secs = seconds;
   TimerIO.tr_time.tv_micro = micros;
   SendIO(&TimerIO);
}

main()
{
   int check;

   check = tOpen();
   if (check != 0)
   {
      printf("Timer device not available for use, Try next year!");
      exit(0);
   }
   printf("starting to wait 3 seconds\n");
   StartTimer(3, 0);
   Wait(1 << TimerMsgPort.mp_SigBit);
   printf("3 seconds up\n");
   printf("starting to wait 10 seconds\n");
   StartTimer(10, 0);
   Wait(1 << TimerMsgPort.mp_SigBit);
   printf("10 seconds up\n");
   printf("starting to wait 10 seconds\n");
   StartTimer(10, 0);
   AbortIO(&TimerIO);
   Wait(1 << TimerMsgPort.mp_SigBit);
   printf("Timer Aborted with wait\n");
   printf("starting to wait 10 seconds\n");
   StartTimer(10, 0);
   Wait(1 << TimerMsgPort.mp_SigBit);
   printf("10 seconds up\n");
   tClose();
}

-- 
                                 RDS Software
                                 9140 SW Locust St.
                                 Tigard, OR  97223
                                 (503) 246-9258

                 Makers of the most unique terminal emulation
                      software the Amiga will ever see!!!