@alfkil
Your code is missing a call to WaitIO to clean up the request sent by SendIO.
Also it makes absolutely no sense to use WaitPort on an I/O port. If you want to wait for an IORequest only, you can use WaitIO instead of WaitPort. If you want to wait for multiple signals, you have to use Wait anyway.
Finally, if you use WaitIO immediately after SendIO, you can as well replace both by one call to DoIO.
Use this as an example for an asynchronous timer:
#define __USE_OLD_TIMEVAL__ 1 // for compatibility with OS 3.x and below
#include <proto/exec.h>
#include <proto/dos.h>
#include <devices/timer.h>
int main (void)
{
struct MsgPort *port;
struct timerequest *timer;
BOOL running;
ULONG timersig;
ULONG received;
ULONG counter;
port = CreateMsgPort();
if (port)
{
timer = (struct timerequest *) CreateIORequest (port,sizeof(struct timerequest));
if (timer)
{
if (!OpenDevice ("timer.device",UNIT_VBLANK,(struct IORequest *)timer,0))
{
timersig = 1L << port->mp_SigBit;
timer->tr_node.io_Command = TR_ADDREQUEST;
timer->tr_time.tv_secs = 1;
timer->tr_time.tv_micro = 0;
SendIO ((struct IORequest *)timer);
counter = 5;
running = TRUE;
do {
Printf ("Please press Ctrl-C (%lu seconds to go)\n",counter);
received = Wait (timersig | SIGBREAKF_CTRL_C);
if (received & SIGBREAKF_CTRL_C)
{
Printf ("Ctrl-C received; timer stopping.\n");
running = FALSE;
}
if (received & timersig)
{
WaitIO ((struct IORequest *)timer);
counter --;
if (counter == 0)
{
Printf ("Timeout; no Ctrl-C received.\n");
running = FALSE;
}
else
{
timer->tr_node.io_Command = TR_ADDREQUEST;
timer->tr_time.tv_secs = 1;
timer->tr_time.tv_micro = 0;
SendIO ((struct IORequest *)timer);
}
}
}
while (running);
if (counter > 0)
{
if (!CheckIO ((struct IORequest *)timer))
AbortIO ((struct IORequest *)timer);
WaitIO ((struct IORequest *)timer);
}
CloseDevice ((struct IORequest *)timer);
}
DeleteIORequest ((struct IORequest *)timer);
}
DeleteMsgPort (port);
}
return (0);
}
Using UNIT_MICROHZ for long-term intervals is a waste of timer hardware and inaccurate also. There is a discussion about the different units in the beginning of the timer.device autodocs.