-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterrupt_handlers.c
More file actions
148 lines (132 loc) · 3.59 KB
/
Copy pathinterrupt_handlers.c
File metadata and controls
148 lines (132 loc) · 3.59 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <stdint.h>
#include <stdbool.h>
#include "efm32gg.h"
#include "shared.h"
void sample();
void play_tone(int tones, int tone_length);
void continuePlaying(int tones[], int tone_lengths[], int tones_in_song);
void disableDAC();
void enableDAC();
void disableLETimer();
void resetMelody();
void enableLETimer();
void wakeFromSleep();
void goToSleep();
bool playing;
bool sleeping = false;
int songToPlay = 2;
//Plays the start of the mario theme
int mario_tones[] = {660, -1, 660, -1, 660, -1, 520, -1, 660, -1, 781, -1, 395};
int mario_tone_lengths[] = {5000, 1000, 5000, 5000, 5000, 5000, 5000, 1000, 5000, 5000, 7000, 15000, 5000};
int mario_length = sizeof(mario_tones)/sizeof(int);
//Plays a sound
int victory_tones[] = {130, -1, 311, -1, 520, -1, 700, -1, 520, -1, 900};
int victory_tone_lengths[] = {1000, 100, 1000, 100, 1000, 100, 1000, 100, 2000, 100, 5000};
int victory_length = sizeof(victory_tones)/sizeof(int);
//Plays a sound of someone firing a blaster
int fire_tones[] = {700, 600, 500, 400, 300, 200};
int fire_tone_lengths[] = {600, 600, 600, 600, 600, 600};
int fire_length = sizeof(fire_tone_lengths)/sizeof(int);
//Plays "Lisa gikk til skolen"
int lisa_tone_lengths[] = {20692, 6896, 20692, 6896, 20692, 6896, 20692, 6896, 48282, 6896, 48282, 6896,
20692, 6896, 20692, 6896, 20692, 6896, 20692, 6896, 65800, 28027, 20692, 6896, 20692, 6896,
20692, 6896, 20692, 6896, 48282, 6896, 48282, 6896, 20692, 6896, 20692, 6896, 20692, 6896, 20692, 6896, 65800, 28027};
int lisa_tones[] = {523,-1, 587,-1, 659,-1, 698,-1, 783,-1, 783,-1, 880,-1,
880,-1, 880,-1, 880,-1, 783,-1, 698,-1, 698,-1, 698,-1, 698, -1,
659,-1, 659,-1, 587,-1, 587,-1, 587,-1, 587,-1, 523};
int lisa_length = sizeof(lisa_tone_lengths)/sizeof(int);
/* TIMER1 interrupt handler */
void __attribute__ ((interrupt)) LETIMER0_IRQHandler() {
*LETIMER0_IFC = 1;
if (playing) {
switch(songToPlay) {
case 0:
continuePlaying(victory_tones, victory_tone_lengths, victory_length);
break;
case 1:
continuePlaying(lisa_tones, lisa_tone_lengths, lisa_length);
break;
case 2:
continuePlaying(mario_tones, mario_tone_lengths, mario_length);
break;
case 3:
continuePlaying(fire_tones, fire_tone_lengths, fire_length);
break;
}
}
else {
if (!sleeping) {
goToSleep();
}
}
}
void __attribute__ ((interrupt)) TIMER1_IRQHandler() {
continuePlaying(victory_tones, victory_tone_lengths, victory_length);
}
/* GPIO even pin interrupt handler */
void __attribute__ ((interrupt)) GPIO_EVEN_IRQHandler() {
*GPIO_IFC = 0xff;
*GPIO_PA_DOUT = (*GPIO_PC_DIN << 8);
switch ((*GPIO_PC_DIN)) {
case 0xfe: //SW2
songToPlay = 0;
if (sleeping) {
wakeFromSleep();
}
else if (playing) {
resetMelody();
}
break;
case 0xbf: //SW8
songToPlay = 1;
if (sleeping) {
wakeFromSleep();
}
else if (playing) {
resetMelody();
}
break;
case 0xfb: //SW4
songToPlay = 2;
if (sleeping) {
wakeFromSleep();
}
else if (playing) {
resetMelody();
}
break;
case 0xef:
songToPlay = 3; //SW6
if (sleeping) {
wakeFromSleep();
}
else if (playing) {
resetMelody();
}
break;
}
}
/* GPIO odd pin interrupt handler */
void __attribute__ ((interrupt)) GPIO_ODD_IRQHandler() {
*GPIO_IFC = 0xff;
*GPIO_PA_DOUT = (*GPIO_PC_DIN << 8);
if (sleeping) {
wakeFromSleep();
}
else if (playing) {
resetMelody();
}
}
void goToSleep() {
disableDAC();
resetMelody();
disableLETimer();
playing = false;
sleeping = true;
}
void wakeFromSleep() {
enableDAC();
enableLETimer();
playing = true;
sleeping = false;
}