-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectorWindXTC_interrupts.c
137 lines (110 loc) · 3.22 KB
/
vectorWindXTC_interrupts.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
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
#int_timer2 HIGH
/* this timer only runs once booted */
void isr_100us(void) {
static int8 tick=0;
/* anemometer polling state variables */
/* anemometer 0 / PIN_B0 */
short ext0_count;
short ext0_now;
static short ext0_last=0;
static short ext0_state=0;
/* every 100 cycles we tell main() loop to do 10 milisecond activities */
tick++;
if ( 100 == tick ) {
tick=0;
action.now_10millisecond=1;
}
/* count time between falling edges */
if ( ext0_count && 0xffff != timers.pulse_period )
timers.pulse_period++;
/* anemometer 0 / PIN_B0 trigger on falling edge */
ext0_now=input(PIN_B0);
if ( 0 == ext0_now && 1 == ext0_last ) {
current.pulse_count++;
if ( 1 == ext0_state ) {
/* currently counting, time to finish */
ext0_count=0;
current.pulse_period=timers.pulse_period;
if ( current.pulse_period < current.pulse_min_period ) {
current.pulse_min_period=current.pulse_period;
}
ext0_state=0;
}
if ( 0 == ext0_state ) {
/* not counting, time to start */
timers.pulse_period=0;
ext0_count=1;
ext0_state=1;
}
}
ext0_last = ext0_now;
if ( action.now_strobe_counters ) {
action.now_strobe_counters=0;
/* save (strobe) our data */
current.strobed_pulse_period=current.pulse_period;
current.strobed_pulse_min_period=current.pulse_min_period;
current.strobed_pulse_count=current.pulse_count;
/* reset our data */
current.pulse_period=0;
current.pulse_min_period=65535;
current.pulse_count=0;
/* counters are copied, now we can start the rest of the measurements */
action.now_gnss_trigger_start=1;
}
}
#int_rda2
void serial_isr_wireless(void) {
int8 c;
c=fgetc(SERIAL_XTC);
}
#define GNSS_STATE_WAITING 0
#define GNSS_STATE_IN 1
#int_rda
void serial_isr_gnss(void) {
static int1 state=GNSS_STATE_WAITING;
static int8 buff[6];
static int8 pos;
int8 c;
c=fgetc(SERIAL_GNSS);
/* skip adding if ( carriage returns OR line feeds OR buffer full ) */
if ( '\r' != c && '\n' != c && pos < (sizeof(nmea_raw.buff)-2) ) {
/* add to our buffer */
nmea_raw.buff[pos]=c;
pos++;
nmea_raw.buff[pos]='\0';
}
/* capturing data but looking for our trigger so we can set flag */
if ( GNSS_STATE_WAITING == state ) {
/* FIFO */
buff[0]=buff[1]; // '$'
buff[1]=buff[2]; // 'G'
buff[2]=buff[3]; // 'P'
buff[3]=buff[4]; // 'R' or 'H'
buff[4]=buff[5]; // 'M' or 'D'
buff[5]=c; // 'C' or 'T'
if ( '$' == buff[0] && NMEA0183_TRIGGER[0] == buff[1] &&
NMEA0183_TRIGGER[1] == buff[2] &&
NMEA0183_TRIGGER[2] == buff[3] &&
NMEA0183_TRIGGER[3] == buff[4] &&
NMEA0183_TRIGGER[4] == buff[5] ) {
/* matched our 5 character trigger sequence */
action.now_strobe_counters=1;
current.gnss_age=0;
state=GNSS_STATE_IN;
// output_toggle(LED_RED);
}
} else {
/* GNSS_STATE_IN */
/* in our trigger sentence. Look for '\r' or '\n' that ends it */
if ( '\r' == c || '\n' == c ) {
for ( c=0 ; c<pos ; c++ ) {
current.gnss_buff[c]=nmea_raw.buff[c];
}
current.gnss_buff[c]='\0';
current.gnss_length=pos;
action.now_gnss_trigger_done=1;
state=GNSS_STATE_WAITING;
pos=0;
}
}
}