summaryrefslogtreecommitdiff
path: root/src/arch/lm4f120h5qr-stellaris/arch.cc
blob: e613e42428943d7b2728ef17cd7ced5bf0f92a92 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright 2021 Daniel Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include "arch.h"

#ifdef TIMER_S
#include "driver/uptime.h"
#endif

extern "C" {
#include "lm4f_cpp_wrapper.h"
};

#ifdef __acweaving
#define __delay_cycles(x)
#endif

void Arch::setup(void)
{
	arch_clock_init();
#if defined(CONFIG_loop)
	arch_init_loop();
#endif
}

#ifdef CONFIG_wakeup
extern void wakeup();
#endif

#if defined(CONFIG_loop)
extern void loop();
extern volatile char run_loop;
#endif

// for 80 MHz
void Arch::delay_us(unsigned int const us)
{
	volatile int x = us * 77;
	while (x--) {
		__asm("nop");
	}
}
void Arch::delay_ms(unsigned int const ms)
{
	for (unsigned int i = 0; i < ms; i++) {
		volatile int x = 10000;
		while (x--) {
			__asm("nop");
		}
	}
}

void Arch::idle_loop(void)
{
	while (1) {
		__asm__("wfi");
#ifdef CONFIG_loop
		if (run_loop) {
#ifdef TIMER_S
			uptime.tick_s();
#endif
			loop();
			run_loop = 0;
		}
#endif
	}
}

void Arch::idle(void)
{
	__asm__("wfi");
#ifdef CONFIG_wakeup
	wakeup();
#endif
}

Arch arch;