-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_module.c
More file actions
195 lines (175 loc) · 4.83 KB
/
timer_module.c
File metadata and controls
195 lines (175 loc) · 4.83 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "pic24_all.h"
#include "timer_module.h"
/*********************************************************
*configTimers
*configures all three timers
*@return:none
*********************************************************/
void configTimers(){
configTimerParentPacket();
configTimerChildPacket();
configTimerParentMoved();
configTimerQuarterSecond();
}
/*********************************************************
*configTimerParentPacket
*configures the parent packet timeout timer
*@return:none
*********************************************************/
void configTimerParentPacket(){
T3CON = T3_OFF | T3_IDLE_CON | T3_GATE_OFF | T3_SOURCE_INT | T3_PS_1_256;
PR3 = PARENTPACKETPERIODS << 2;
TMR3 = 0;
_T3IF = 0;
_T3IP = 1;
_T3IE = 0;
}
/*********************************************************
*configTimerChildPacket
*configures the child packet timeout timer
*@return:none
*********************************************************/
void configTimerChildPacket(){
T5CON = T5_OFF | T5_IDLE_CON | T5_GATE_OFF | T5_SOURCE_INT | T5_PS_1_256;
PR5 = CHILDPACKETPERIODS << 2;
TMR5 = 0;
_T5IF = 0;
_T5IP = 1;
_T5IE = 0;
}
/*********************************************************
*configTimerParentMoved
*configures the parent moved timer
*@return:none
*********************************************************/
void configTimerParentMoved(){
T4CON = T4_OFF | T4_IDLE_CON | T4_GATE_OFF | T4_32BIT_MODE_OFF | T4_SOURCE_INT | T4_PS_1_256;
PR4 = PARENTMOVEDPERIODS << 2;
TMR4 = 0;
_T4IF = 0;
_T4IP = 1;
_T4IE = 0;
}
/*********************************************************
*configTimerSecond
*configures one second timer
*@return:none
*********************************************************/
void configTimerQuarterSecond(){
T2CON = T2_OFF | T2_IDLE_CON | T2_GATE_OFF | T2_32BIT_MODE_OFF | T2_SOURCE_INT | T2_PS_1_256;
PR2 = msToU16Ticks(250, getTimerPrescale(T2CONbits))-1;
TMR2 = 0;
_T2IF = 0;
_T2IP = 1;
_T2IE = 0;
}
/*********************************************************
*enableTimers
*enables all three timers
*@return:none
*********************************************************/
void enableTimers(){
enableTimerParentPacket();
enableTimerChildPacket();
enableTimerParentMoved();
}
/*********************************************************
*enableTimerParentPacket
*enables the parent packet timeout timer
*@return:none
*********************************************************/
void enableTimerParentPacket(){
_T3IE = 1;
enableTimerQuarterSecond();
}
/*********************************************************
*enableTimerChildPacket
*enables the child packet timeout timer
*@return:none
*********************************************************/
void enableTimerChildPacket(){
_T5IE = 1;
enableTimerQuarterSecond();
}
/*********************************************************
*enableTimerParentMoved
*enables the parent moved timer
*@return:none
*********************************************************/
void enableTimerParentMoved(){
_T4IE = 1;
enableTimerQuarterSecond();
}
/*********************************************************
*enableTimerSecond
*enables the parent moved timer
*@return:none
*********************************************************/
void enableTimerQuarterSecond(){
T2CONbits.TON = 1;
_T2IE = 1;
}
/*********************************************************
*disableTimers
*disables all three timers
*@return:none
*********************************************************/
void disableTimers(){
disableTimerParentPacket();
disableTimerChildPacket();
disableTimerParentMoved();
}
/*********************************************************
*disableTimerParentPacket
*disables the parent packet timeout timer
*@return:none
*********************************************************/
void disableTimerParentPacket(){
T3CONbits.TON = 0;
}
/*********************************************************
*disableTimerChildPacket
*disables the child packet timeout timer
*@return:none
*********************************************************/
void disableTimerChildPacket(){
T5CONbits.TON = 0;
}
/*********************************************************
*disableTimerParentMoved
*disables the parent moved timer
*@return:none
*********************************************************/
void disableTimerParentMoved(){
T4CONbits.TON = 0;
}
//Interrupt Service Routine for Timer3
void _ISR _T3Interrupt(void){
_T3IF = 0;
TMR3 = 0;
u8_fParentTimeOut = 1;
u8_fScreenChange = 1;
}
//Interrupt Service Routine for Timer5
void _ISR _T5Interrupt(void){
_T5IF = 0;
TMR5 = 0;
u8_fChildTimeOut = 1;
u8_fScreenChange = 1;
}
//Interrupt Service Routine for Timer4
void _ISR _T4Interrupt(void){
_T4IF = 0;
TMR4 = 0;
u8_fParentStationary = 1;
}
//Interrupt Service Routine for Timer6
void _ISR _T2Interrupt(void){
_T2IF = 0;
TMR3++;
TMR5++;
TMR4++;
_T3IF = (PR3 == TMR3);
_T4IF = (PR4 == TMR4);
_T5IF = (PR5 == TMR5);
}