mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-11-16 19:04:53 +08:00
The driver declared a cycle time of 10 nanoseconds, which is 100 MHz, while the tick timer of Qemu counts at 20 MHz for the or1k-sim and the virtual machine alike. See TIMER_PERIOD in hw/or1k/cputimer.c. The timecounter therefore ran at a fifth of the real rate. The period was a constant of 0x09ED9 counts and ignored the configured microseconds per tick, so the system time advanced at a rate which had nothing to do with the configuration. Derive it from the configured value and the timer frequency. The result is computed once, because the tick handler must not need a 64-bit division. The timer ran in restart mode, which resets the counter at every period, and it did not run at all until the driver programmed it. An application without a clock driver read a counter which never moved, and _CPU_Counter_frequency() was the no_cpu placeholder and claimed 1 GHz. Run the timer in continue mode, so that the counter is free running, and start it from a system initialization item of its own. The counter is the CPU counter and the timecounter of this BSP. The timer compares the time period with the low 28 bits of the counter. A time period which the counter passed matches only after the counter runs through the field, which takes 13 s at this frequency. Take the counter as the base of the next tick when the handler is late. Hold the interrupts off while the handler reads the counter and writes the period, so that nothing extends the distance between the two. Update #5684. Assisted-by: Claude:claude-opus-5 claude-code Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>