-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterrupts.c
More file actions
87 lines (67 loc) · 1.39 KB
/
interrupts.c
File metadata and controls
87 lines (67 loc) · 1.39 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
/*
Scott - interrupts.c
*/
#include "main.h"
#include "config.h"
#include "speaker.h"
#include "timer.h"
void main_isr();
void timer0_isr();
void rtc_isr();
void speaker_isr();
void interrupt low_priority low_isr()
{
main_isr();
}
void interrupt high_isr()
{
main_isr();
}
void main_isr(void)
{
// TIMER 0 SYSTEM TICK interrupt
if (TMR0IF && TMR0IE)
{
timer0_isr();
}
// REAL TIME CLOCK ISR
if (PIR3bits.RTCCIF)
{
rtc_isr();
}
//PWM update interrupt for speaker
if (TMR4IF && TMR4IE)
{
speaker_isr();
}
}
void timer0_isr()
{
TMR0IF = 0;
//init timer 0 so overflow happens in 1ms.
TMR0H = T0_TMR_VAL_1MS >> 8;
TMR0L = (T0_TMR_VAL_1MS & 0xFF);
SYSTEM_TICKS += 1;
}
void rtc_isr()
{
//alarm has triggered. Beep the thing!
speaker_initiate_alarm();
PIR3bits.RTCCIF = 0;
}
void speaker_isr()
{
//update the sound clip to the next PCM sample
if (speakerstat.sound_in_progress)
{
//update the PWM duty cycle with next sample
CCPR1L = speakerstat.sound_data[speakerstat.sound_idx];
speakerstat.sound_idx++;
if (speakerstat.sound_idx >= speakerstat.sound_idx_max)
{
speakerstat.sound_in_progress = 0;
speakerstat.alarm_end_time = timer_get_ticks();
}
}
TMR4IF = 0;
}