1/*
2 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <autoconf.h>
8#include <camkes.h>
9#include <camkes/io.h>
10#include <stdio.h>
11#include <platsupport/plat/pit.h>
12#include <utils/time.h>
13
14#define IRQS_PER_SECOND 100
15
16static pit_t timer;
17
18void irq_handle(void)
19{
20    static int count = 0;
21    static int seconds = 0;
22    if (++count == IRQS_PER_SECOND) {
23        seconds++;
24        printf("%d seconds elapsed\n", seconds);
25        count = 0;
26    }
27    irq_acknowledge();
28}
29
30void pre_init(void)
31{
32    int error;
33    ps_io_port_ops_t ops = {0};
34    error = camkes_io_port_ops(&ops);
35    assert(!error);
36    error = pit_init(&timer, ops);
37    assert(!error);
38    error = pit_set_timeout(&timer, NS_IN_S / IRQS_PER_SECOND, true);
39    assert(!error);
40    irq_acknowledge();
41}
42