IEEE802.15.4e needs a timer to:

In the OpenWSN stack, this timer driver is implemented in

You can see the Doxygen HTML output of the inline comments at:

Crash course

In a typical micro-controller, a hardware timer consists of:

In the image below, the counter is at value b1010110000010110=0xac16=44054. The compare register it at value b1010110000011000=0xac18=44056, i.e. it will generate an interrupt in 2 ticks. The capture register is at value b1010110000010100=0xac14=44052, i.e. a trigger caused the register to capture the counter's value 2 ticks ago.

Requirements

On the clock source

Speed. The synchronization accuracy depends on the speed at which the counter in your timer increments. A timer timestamps events within a clock tick. If your timer is clocked by a 32kHz crystal, the event you timestamp will fall somewhere within a 30us window. The faster your clock, the more accurate the timestamp.

Synchronization accuracy depends entirely on:

With a 32kHz crystal, both these events will be at most 30us off; so your synchronization will be at most 60us off. This should be easy to see on a scope:

Drift. As detailed in TschSynchronization, a mote can spend tens of seconds without communicating, giving it lots of time to drift off and potentially desynchronize from your network. It is therefore important to have a clock source with a very consistent speed.

Given those two constraints, one typically uses a 32kHz crystal as the time clock source. This yields a timestamp accuracy of 30us while maintaining a small drift (10ppm is typical). Moreover, since that clock needs to run all the time, its a very energy-efficient solution.

On the counter

The width of the counter (i.e. the number of bits it contains) specifies the maximum duration is can count up. For the IEEE802.15.4e implementation, we need it to be able to count a slot length. With a 10ms slot and counter clocked by a 32kHz crystal, the counter needs to count up to 328.

We also need the counter to be able to count to a certain value, then roll over and generate an interrupt.

on the capture/compare registers

For the IEEE802.15.4e implementation, we need 1 compare register and 1 capture register.

OpenWSN implementation

Take a look at the source files lister above. The OpenWSN implementation dedicates a timer to IEEE802.15.4e. This timer is configured as follows:

Every time the timer rolls over, TschFsm#ti1 (or TschFsm#ri1 which are the same) is executed. Part of their execution is to configure the compare register. When the counter reaches the value of the compare register, another activity of the state machine gets executed. A state variable is kept in the IEEE802.15.4e implementation to associate a compare interrupt which a particular activity.