Computer Systems Experiments 22 | Timer Module
Computer Systems Experiments 22 | Timer Module

To start with this experiment, we have to use the code that we have pulled from the clock-starter
repo. The direction of this experiment is,
~/ComputerSysE/environment/include/timer.h
And we need to complete the timer_get_ticks
function in the file src/lib/timer.c
. The other functions timer_delay_us
, timer_delay_ms
, and timer_delay
is already given by the starter code. For this module, note that we only care about the lower 32-bits of the system timer. And this system timer is an onboard read-only peripheral that is initialized to zero when the Pi powers up and is continuously incremented once every microsecond behind the scenes.
To set the address of this lower 32-bits register,
static volatile unsigned int *TIME = (unsigned int *) 0x20003004;
Then to return the time counted, we can use,
unsigned int timer_get_ticks(void) {
return *TIME;
}
Then we uncomment the test_timer();
in the file test_gpio_timer.c
. And run,
$ make test
to test this time.c
script. If the green light is shining, congratulations!