-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw.c
More file actions
87 lines (68 loc) · 1.41 KB
/
hw.c
File metadata and controls
87 lines (68 loc) · 1.41 KB
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
80
81
82
83
84
85
86
87
#include "hw.h"
#include "phyAlloc.h"
#include "types.h"
#define CS 0x20003000
#define CLO 0x20003004
#define C0 0x2000300C
#define C1 0x20003010
#define C2 0x20003014
#define C3 0x20003018
#define GPFSEL1 0x20200004
#define GPSET0 0x2020001C
#define GPCLR0 0x20200028
#define INTERVAL 0x00080000
extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
/*
* Timer interrupts
*/
#define ENABLE_TIMER_IRQ() PUT32(CS,2)
#define DISABLE_TIMER_IRQ() PUT32(CS,~2);
void
set_tick_and_enable_timer()
{
unsigned int rx = GET32(CLO);
rx += INTERVAL;
PUT32(C1,rx);
ENABLE_TIMER_IRQ();
}
/*
* LEDs on/off
*/
void
led_off()
{
PUT32(GPSET0,1<<16); //led off
}
void
led_on()
{
PUT32(GPCLR0,1<<16); //led on
}
/*
* Start_hw
*/
void
init_hw()
{
unsigned int ra;
unsigned int rx;
/* Make gpio pin tied to the led an output */
ra=GET32(GPFSEL1);
ra&=~(7<<18);
ra|=1<<18;
PUT32(GPFSEL1,ra);
//led off
PUT32(GPSET0,1<<16);
/* Set up delay before timer interrupt (we use CM1) */
rx=GET32(CLO);
rx += INTERVAL;
PUT32(C1,rx);
/* Enable irq triggering by the *system timer* peripheral */
/* - we use the compare module CM1 */
ENABLE_TIMER_IRQ();
/* Enable interrupt *line* */
PUT32(0x2000B210, 0x00000002);
DISABLE_IRQ();
phyAlloc_init((void *) HEAP_START, 204800);
}