summaryrefslogtreecommitdiff
path: root/src/arch/posix/arch.cc
blob: 69dfeace2711213ffb4a1f97704a60c66ffc4b76 (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
/*
 * Copyright 2020 Daniel Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include "arch.h"
#include <time.h>
#include <unistd.h>

#if defined(CONFIG_loop) || defined(TIMER_S)
#include "driver/uptime.h"
void loop();
#endif
#ifdef CONFIG_wakeup
void wakeup();
#endif

void Arch::setup(void) { }

void Arch::idle_loop(void)
{
	while (1) {
		sleep(1);
#ifdef CONFIG_loop
		loop();
#endif
#ifdef CONFIG_wakeup
		wakeup();
#endif
#ifdef TIMER_S
		uptime.tick_s();
#endif
	}
}

void Arch::idle(void)
{
}

void Arch::delay_us(unsigned int const us)
{
	struct timespec ts;
	ts.tv_sec = 0;
	ts.tv_nsec = us * 1000;
	nanosleep(&ts, NULL);
}

void Arch::delay_ms(unsigned int const ms)
{
	struct timespec ts;
	ts.tv_sec = ms / 1000;
	ts.tv_nsec = (ms % 1000) * 1000000;
	nanosleep(&ts, NULL);
}

Arch arch;