[comp.sys.amiga.tech] Timer device blues

glamdrng@pnet51.cts.com (Rocky Lhotka) (07/05/89)

I am having some problems getting the timer device to work...  Specifically, I
can do a GETSYSTIME with no problem, but an ADDREQUEST always locks up the
computer...  I have tried several examples from several books and none of them
work either (are they all THAT bad???).  Here is my latest attempt, where the
GETSYSTIME works, but it locks up on the second DoIO when I try to perform an
ADDREQUEST.  Any help would be VERY VERY appreciated!!

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

#define msgblock tr.tr_node.io_Message

struct timerequest tr;

main()
{
    int error;

    error = OpenDevice(TIMERNAME,UNIT_VBLANK,&tr,0);
    msgblock.mn_Node.ln_Type = NT_MESSAGE;
    msgblock.mn_Node.ln_Pri = 0;
    msgblock.mn_Node.ln_Name = NULL;
    msgblock.mn_ReplyPort = NULL;

    tr.tr_node.io_Command = TR_GETSYSTIME;
    DoIO(&tr);
    printf("\nSystem Time is:\n");
    printf("Seconds Microseconds\n");
    printf("%10ld %10ld\n",tr.tr_time.tv_secs,tr.tr_time.tv_micro);

    tr.tr_node.io_Command = TR_ADDREQUEST;
    tr.tr_time.tv_secs=10;
    tr.tr_time.tv_micro=0;
    DoIO(&tr);

    tr.tr_node.io_Command = TR_GETSYSTIME;
    DoIO(&tr);
    printf("\nSystem Time is:\n");
    printf("Seconds Microseconds\n");
    printf("%10ld %10ld\n",tr.tr_time.tv_secs,tr.tr_time.tv_micro);
    CloseDevice(&tr);
}


Rocky Lhotka
Glamdring, Sword of Mithrandir

UUCP: {amdahl!bungia, uunet!rosevax, chinet, killer}!orbit!pnet51!glamdrng
ARPA: crash!orbit!pnet51!glamdrng@nosc.mil
INET: glamdrng@pnet51.cts.com

adam@cbmvax.UUCP (Adam Levin - CATS) (07/07/89)

In article <738@orbit.UUCP> glamdrng@pnet51.cts.com (Rocky Lhotka) writes:
>I am having some problems getting the timer device to work...  Specifically, I
>can do a GETSYSTIME with no problem, but an ADDREQUEST always locks up the
>computer...  I have tried several examples from several books and none of them
>work either (are they all THAT bad???).  Here is my latest attempt, where the
>GETSYSTIME works, but it locks up on the second DoIO when I try to perform an
>ADDREQUEST.  Any help would be VERY VERY appreciated!!
>

(code deleted)

Your example program neglected to create a reply port.
Read the large listing in the RKM just following the one you
based your code on.  Your program will get control back after
the TR_ADDREQUEST is satisfied once there is a reply port available.

In the very simplest case, change the line that reads:
	msgblock.mn_ReplyPort = NULL;
to:
	msgblock.mn_ReplyPort = (struct ReplyPort *)CreatePort(0,0);

It is good programming practice to check that the port was actually created.

-- 
     Adam Keith Levin  --  CATS   Commodore-Amiga Technical Support
     1200 Wilson Drive / West Chester, PA  19380     (215) 431-9180
     BIX: aklevin        UUCP: ...{amiga|rutgers|uunet}!cbmvax!adam