-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtimer.c
More file actions
58 lines (45 loc) · 968 Bytes
/
timer.c
File metadata and controls
58 lines (45 loc) · 968 Bytes
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
#include <or1k-support.h>
#include <or1k-sprs.h>
#include <stdio.h>
#ifdef DE0_NANO
char* gpio_base = (char*) 0x91000000;
unsigned char dat = 0x00;
static void gpio_init() {
/* Set the GPIO to all out */
char dir = 0xff;
*(gpio_base+1) = dir;
/* Initialise with the first data value */
*(gpio_base+0) = dat;
}
static void gpio_increment() {
*(gpio_base+0) = (++dat)%256;
}
#else
static void gpio_init() {
}
static void gpio_increment() {
}
#endif
int main(void)
{
uint32_t ticks = 0;
uint32_t timerstate;
or1k_timer_init(100);
gpio_init();
or1k_timer_enable();
while (1) {
while (ticks == or1k_timer_get_ticks()) { }
ticks++;
timerstate = or1k_timer_disable();
// do something atomar
or1k_timer_restore(timerstate);
if (ticks == 100) {
printf("A second elapsed\n");
// Increment the GPIO counter
gpio_increment();
or1k_timer_reset_ticks();
ticks = 0;
}
}
return 0;
}