ibex/examples/sw/simple_system/hello_test/hello_test.c
Tom Roberts 5bb41957ef [examples] Add timer example to simple system
Not particularly useful in the current system, but gives an example of
how to handle interrupts.
2020-01-10 10:18:09 +00:00

41 lines
901 B
C

// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#include "simple_system_common.h"
int main(int argc, char **argv) {
pcount_enable(0);
pcount_reset();
pcount_enable(1);
puts("Hello simple system\n");
puthex(0xDEADBEEF);
putchar('\n');
puthex(0xBAADF00D);
putchar('\n');
pcount_enable(0);
// Enable periodic timer interrupt
// (the actual timebase is a bit meaningless in simulation)
timer_enable(2000);
uint64_t last_elapsed_time = get_elapsed_time();
while (last_elapsed_time <= 4) {
uint64_t cur_time = get_elapsed_time();
if (cur_time != last_elapsed_time) {
last_elapsed_time = cur_time;
if (last_elapsed_time & 1) {
puts("Tick!\n");
} else {
puts("Tock!\n");
}
}
asm volatile("wfi");
}
return 0;
}