This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPIO_ISR.c
85 lines (78 loc) · 2.29 KB
/
GPIO_ISR.c
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
#include "osObjects.h" // RTOS object definitions
#include "motors.h"
/**
@brief ISR for Left_A encoder
*/
void PORTA_IRQHandler(void){
/* Left A Encoder */
if (LEFT_A_ENCODER_PORT->PCR[LEFT_A_ENCODER_PIN] & PORT_PCR_ISF_MASK){
left_count++;
if (EncFlags & LEFT){
LeftTrackTurnDist--;
if ( LeftTrackTurnDist <= 0 ) {
EncFlags &= ~LEFT;
SetTrackSpeed(LEFT, 0);
if (EncFlags == 0){
osSignalSet(tid_zumoAI,SIG_MOVE_COMPLETE);
}
}
}
LEFT_A_ENCODER_PORT->PCR[LEFT_A_ENCODER_PIN] |= PORT_PCR_ISF_MASK;
}
/* Left B Encoder */
if (LEFT_B_ENCODER_PORT->PCR[LEFT_B_ENCODER_PIN] & PORT_PCR_ISF_MASK){
left_count++;
if (EncFlags & LEFT){
LeftTrackTurnDist--;
if ( LeftTrackTurnDist <= 0 ) {
EncFlags &= ~LEFT;
SetTrackSpeed(LEFT, 0);
if (EncFlags == 0){
osSignalSet(tid_zumoAI,SIG_MOVE_COMPLETE);
}
}
}
LEFT_B_ENCODER_PORT->PCR[LEFT_B_ENCODER_PIN] |= PORT_PCR_ISF_MASK;
}
/* Right B Encoder */
if (RIGHT_B_ENCODER_PORT->PCR[RIGHT_B_ENCODER_PIN] & PORT_PCR_ISF_MASK){
right_count++;
if (EncFlags & RIGHT){
RightTrackTurnDist--;
if ( RightTrackTurnDist <= 0 ) {
EncFlags &= ~RIGHT;
SetTrackSpeed(RIGHT, 0);
if (EncFlags == 0){
osSignalSet(tid_zumoAI,SIG_MOVE_COMPLETE);
}
}
}
RIGHT_B_ENCODER_PORT->PCR[RIGHT_B_ENCODER_PIN] |= PORT_PCR_ISF_MASK;
}
}
/**
@brief ISR for Right_A encoder
*/
void PORTC_PORTD_IRQHandler(void){
/* Check if encoder caused ISR */
if (RIGHT_A_ENCODER_PORT->PCR[RIGHT_A_ENCODER_PIN] & PORT_PCR_ISF_MASK){
right_count++;
if (EncFlags & RIGHT){
RightTrackTurnDist--;
if ( RightTrackTurnDist <= 0 ) {
EncFlags &= ~RIGHT;
SetTrackSpeed(RIGHT, 0);
if (EncFlags == 0){
osSignalSet(tid_zumoAI,SIG_MOVE_COMPLETE);
}
}
}
/* Clear interupt flag */
RIGHT_A_ENCODER_PORT->PCR[RIGHT_A_ENCODER_PIN] |= PORT_PCR_ISF_MASK;
}
/* Check if user button caused interupt */
if (PORTD->PCR[7] & PORT_PCR_ISF_MASK){
osSignalSet(tid_comms,SIG_START_DEBOUNCE_TIMER);
PORTD->PCR[7] |= PORT_PCR_ISF_MASK;
}
}