amiga-bootcamp/10_devices/timer.md
Ilia Sharin 21751c0025 docs(amiga): complete AmigaOS 3.1/3.2 developer reference — 172 files across 17 sections
Comprehensive technical documentation covering:
- Hardware: OCS/ECS/AGA custom chip registers, Copper & Blitter deep dives
- Boot sequence: cold boot through startup-sequence
- Binary format: HUNK executable spec, relocation, debug info
- Linking & ABI: .fd files, LVO tables, register calling conventions
- Exec kernel: tasks, interrupts, memory, signals, semaphores
- AmigaDOS: file I/O, FFS/OFS layout, CLI/Shell scripting
- Graphics: planar bitmaps, Copper programming, HAM/EHB modes
- Intuition: screens, windows, IDCMP, BOOPSI
- Devices: trackdisk, SCSI, serial, timer, audio, keyboard
- Libraries: utility, expansion, IFFParse, locale, ARexx
- Networking: bsdsocket API, SANA-II, TCP/IP stack comparison
- Toolchain: GCC, vasm/vlink, SAS/C, NDK, debugging
- Reverse engineering: IDA/Ghidra setup, compiler fingerprints, case studies
- CPU & MMU: 68040/060 emulation libs, PMMU, cache management
- Driver development: SANA-II, Picasso96/RTG, AHI audio

All files include breadcrumb navigation. No local paths or proprietary content.
2026-04-23 12:17:35 -04:00

1.8 KiB

← Home · Devices

timer.device — Timing and Delays

Overview

timer.device provides precise timing services: delays, time-of-day, and high-resolution timestamps. It has two units:

Unit Constant Resolution Use
0 UNIT_MICROHZ ~2µs (E-clock) Short, precise delays
1 UNIT_VBLANK ~20ms (VBlank) Long delays, lower overhead
2 UNIT_ECLOCK CIA E-clock ticks Highest resolution timing (OS 2.0+)
3 UNIT_WAITUNTIL absolute time Wait until specific time (OS 2.0+)
4 UNIT_WAITECLOCK E-clock absolute (OS 2.0+)

struct timeval / timerequest

/* devices/timer.h — NDK39 */
struct timeval {
    ULONG tv_secs;    /* seconds */
    ULONG tv_micro;   /* microseconds */
};

struct timerequest {
    struct IORequest tr_node;
    struct timeval   tr_time;
};

Simple Delay

struct timerequest *tr = (struct timerequest *)
    CreateIORequest(port, sizeof(struct timerequest));
OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)tr, 0);

tr->tr_node.io_Command = TR_ADDREQUEST;
tr->tr_time.tv_secs  = 2;
tr->tr_time.tv_micro = 0;
DoIO((struct IORequest *)tr);   /* blocks for 2 seconds */

CloseDevice((struct IORequest *)tr);
DeleteIORequest((struct IORequest *)tr);

Getting Current Time

tr->tr_node.io_Command = TR_GETSYSTIME;
DoIO((struct IORequest *)tr);
Printf("Time: %lu.%06lu\n", tr->tr_time.tv_secs, tr->tr_time.tv_micro);

High-Resolution Timing

/* Read E-clock (OS 2.0+): */
struct EClockVal eclock;
ULONG freq = ReadEClock(&eclock);  /* returns ticks/second */
/* eclock.ev_hi, eclock.ev_lo = 64-bit tick count */
/* Typical freq: 709379 Hz (PAL) or 715909 Hz (NTSC) */

References

  • NDK39: devices/timer.h
  • ADCD 2.1: timer.device autodocs