It's "timers" time

9 posts / 0 new
Last post
AmigaBlitter
AmigaBlitter's picture
Offline
Last seen: 6 years 10 months ago
Joined: 2012-02-18 19:55
It's "timers" time

I would like to learn how 'Timers' works on Amiga OS4.
I used Timers in other programming environments and i don't know if i can do (or how to do) the same things with the Amiga SDK in c or c++.
Just for example, in actionscript you can create a timer and program it to execute code at regular time or once.
You can also start, stop and change the update time at runtime.

How can i do this with Amiga OS?

xenic
xenic's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2011-05-07 04:52
If you want to execute code

If you want to execute code at regular intervals in a C program you can use the AmigaDOS Delay() command in a loop; unless you need extremely precise intervals. Refer to SDK:Documentation/Autodocs/dos.doc.

You can execute commands at regular intervals in an AmigaDOS script by using SYS:C/Wait in a loop.

X1000 - OS 4.1FE

salass00
salass00's picture
Offline
Last seen: 7 months 2 weeks ago
Joined: 2011-02-03 11:27
Using the timer.device is

Using the timer.device is very easy and allows more control than just using f.e. Delay() or usleep().

There is documentation and examples on how to use it here:
http://wiki.amigaos.net/index.php/Timer_Device

AmigaBlitter
AmigaBlitter's picture
Offline
Last seen: 6 years 10 months ago
Joined: 2012-02-18 19:55
Thank you for the reply. i

Thank you for the reply.

i already read the documentation, but i need other examples.

I would like to use a timer that call a function at regular time, asynchronously. Is this possible?

salass00
salass00's picture
Offline
Last seen: 7 months 2 weeks ago
Joined: 2011-02-03 11:27
It is explained in the link I

It is explained in the link I posted.

Generally you would do it something like this:

  1. uint32 wait_on_signals; // signals to wait for
  2. uint32 signals; // signals received
  3.  
  4. wait_on_signals = other_signals | timer_signal;
  5.  
  6. StartTimer(timer_io);
  7.  
  8. while (!done) { // program main loop
  9. signals = IExec->Wait(wait_on_signals);
  10.  
  11. if (signals & timer_signal) {
  12. IExec->WaitIO(timer_io);
  13. StartTimer(timer_io);
  14. CallFunction();
  15. }
  16.  
  17. /* add code for handling other signals here */
  18. }
  19.  
  20. AbortTimer(timer_io);

The StartTimer would set up the TimerRequest for the delay you want and then call IExec->SendIO() to start the timer request while AbortTimer() after the loop would just call IExec->AbortIO() and IExec->WaitIO() to stop and cleanup the remaining timer request so you can free the TimerRequest without worries later.

PJS
PJS's picture
Offline
Last seen: 4 years 11 months ago
Joined: 2012-12-09 18:38
@AmigaBlitter FWIW, I've

@AmigaBlitter

FWIW, I've been messing with Timers for the first time last
weekend.

In the process I believe I boiled down a good simple
timer.device example. I added it to the AmigaOS wiki page
as "Simple_Wait.c"...

http://wiki.amigaos.net/index.php/Timer_Device#Simple_Wait_Device_Example

Don't forget to keep track of opening and closing and
deallocating everything.

Good luck,

PJS

trixie
trixie's picture
Offline
Last seen: 7 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: It's "timers" time

@PJS

I've started polishing the wiki timer examples a little. Got rid of ULONGs, initialized local pointers to NULL, declared main() as void (as per the C specification), made the return calls a bit more consistent, etc.

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

AmigaBlitter
AmigaBlitter's picture
Offline
Last seen: 6 years 10 months ago
Joined: 2012-02-18 19:55
Thank you all for the

Thank you all for the info.

Going to study...

hypex
hypex's picture
Offline
Last seen: 4 months 3 weeks ago
Joined: 2011-09-09 16:20
Like the title. :-) Also

Like the title. :-)

Also take a look at a timer.device interrupt in the wiki. That can execute code on a timer pulse. Which sounded like what you were after.

As an alternate, though not usually suggested, you could also try lowlevel.library. This allows you to setup and add timer code similar to timer,device but can be easier to use, especially for timer interrupts.

Log in or register to post comments