Just like PIO, the RTT can be controlled using memory-mapped
I/O[1]. Two registers are
defined here:

TIMER_MODE_REGISTER can be used to configure
the RTT before it is being
used[2].

The TIMER_VALUE_REGISTER holds, as its name
suggests, the current value of the
timer[3].

Here's the code that configures the timer using
TIMER_MODE_REGISTER:

*TIMER_MODE_REGISTER = 0x00000020;

The timer mode register consists of two halves (16 bits each):
Only the lower half is of concern to us. It is used to set the
Real-time Timer Prescaler Value (RTPRES).

Here's how that works: The Real-time Timer is powered by a clock
source called Slow Clock
(SCLK)[4], which is the
only permanently running clock in the
system[5]. This means
that while other clocks might be disabled when the system enters
a low-power mode, the slow clock will keep running and can be
used to wake the system up again.

None of this is very relevant for us right now. What we need to
know is that the Slow Clock runs at a frequency of 32,768 Hz.
However, the Real-time timer is not updated at that frequency.
If it were, the timer value register would overflow every ~36
hours[6], which might be
too often, depending on the application.

To solve this problem, the RTT allows us to set the prescaler
value. The update rate is divided by the prescaler value. For
example, a value of 2 gives us overflows roughly every 73 hours
while halving our timer accuracy.

Since our use case is just to blink an LED, we don't need a very
high accuracy. And unless we plan to blink that LED continuously
for many days, neither do we care about an overflow of the timer
register[7]. For
convenience, I opted to set the prescaler value to 32 (0x20 in
hexadecimal[8]). That
gives us a resolution of around one millisecond.

This function computes the value the timer has to reach before
it is allowed to return and then simply keeps checking the timer
until it reaches that value. There are several problems with
this approach:

This technique is called busy waiting and it requires a lot
of power, as the CPU is constantly busy during the wait. It
would be much better to change into a power-saving mode and
wake up via interrupt when the right time has come.

It doesn't take the aforementioned overflow of the timer
value register into
account[9].

It isn't completely accurate. With our prescaler value of
32, the timer value register updates 1024 times a second,
which means the function will wake up a bit too early.

Since all we're doing right now is blink an LED, none of those
shortcomings are really relevant for us. At some point in the
future, we are going to need a more robust implementation of
this function. But for now, it is good enough.

While I'm (currently) quite happy with the generally low quality
of our wait function, I still want to do a tiny bit of cleaning
up. First, let's create a struct for accessing all of the
available RTT registers: