summaryrefslogtreecommitdiff
path: root/src/app/waittest/main.cc
blob: 7a01ca3da0b8d808604b49b58870fcdc77407d76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright 2020 Daniel Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include "arch.h"
#include "driver/gpio.h"
#include "driver/stdout.h"
#include "driver/timer.h"
#include "driver/uptime.h"

#ifndef F_TIMER
#define F_TIMER 100000
#endif

volatile unsigned char timer_done = 0;

inline void await_timer()
{
	timer_done = 0;
	timer.start(1);
	while (!timer_done) {
		arch.idle();
	}
	timer.stop();
}

void loop(void)
{
	gpio.led_toggle(1);
	kout << "start waiting" << endl;
	await_timer();
	kout << "done waiting" << endl;
}

int main(void)
{
	arch.setup();
	gpio.setup();
	kout.setup();
#if F_TIMER > 999
	timer.setup_khz(F_TIMER / 1000);
#else
	timer.setup_hz(F_TIMER);
#endif

	gpio.led_on(0);
	kout << "Timer set at " << dec << F_TIMER << " Hz" << endl;

	arch.idle_loop();

	return 0;
}

ON_TIMER_INTERRUPT_head
	timer_done = 1;
ON_TIMER_INTERRUPT_tail