Skip to content

Commit ab36bd5

Browse files
committed
Changing to a simpler mental model for serialEvent (Paul Stoffregen).
http://code.google.com/p/arduino/issues/detail?id=626
1 parent c9d4630 commit ab36bd5

File tree

3 files changed

+6
-35
lines changed

3 files changed

+6
-35
lines changed

hardware/arduino/cores/arduino/HardwareSerial.cpp

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
8888
#else
8989
void serialEvent() __attribute__((weak));
9090
void serialEvent() {}
91-
volatile static unsigned char serialEvent_flag = 0;
9291
#define serialEvent_implemented
9392
#if defined(USART_RX_vect)
9493
SIGNAL(USART_RX_vect)
@@ -110,20 +109,17 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
110109
#error UDR not defined
111110
#endif
112111
store_char(c, &rx_buffer);
113-
serialEvent_flag = 1;
114112
}
115113
#endif
116114

117115
#if defined(USART1_RX_vect)
118116
void serialEvent1() __attribute__((weak));
119117
void serialEvent1() {}
120-
volatile static unsigned char serialEvent1_flag = 0;
121118
#define serialEvent1_implemented
122119
SIGNAL(USART1_RX_vect)
123120
{
124121
unsigned char c = UDR1;
125122
store_char(c, &rx_buffer1);
126-
serialEvent1_flag = 1;
127123
}
128124
#elif defined(SIG_USART1_RECV)
129125
#error SIG_USART1_RECV
@@ -132,13 +128,11 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
132128
#if defined(USART2_RX_vect) && defined(UDR2)
133129
void serialEvent2() __attribute__((weak));
134130
void serialEvent2() {}
135-
volatile static unsigned char serialEvent2_flag = 0;
136131
#define serialEvent2_implemented
137132
SIGNAL(USART2_RX_vect)
138133
{
139134
unsigned char c = UDR2;
140135
store_char(c, &rx_buffer2);
141-
serialEvent2_flag = 1;
142136
}
143137
#elif defined(SIG_USART2_RECV)
144138
#error SIG_USART2_RECV
@@ -147,52 +141,29 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
147141
#if defined(USART3_RX_vect) && defined(UDR3)
148142
void serialEvent3() __attribute__((weak));
149143
void serialEvent3() {}
150-
volatile static unsigned char serialEvent3_flag = 0;
151144
#define serialEvent3_implemented
152145
SIGNAL(USART3_RX_vect)
153146
{
154147
unsigned char c = UDR3;
155148
store_char(c, &rx_buffer3);
156-
serialEvent3_flag = 1;
157149
}
158150
#elif defined(SIG_USART3_RECV)
159151
#error SIG_USART3_RECV
160152
#endif
161153

162154
void serialEventRun(void)
163155
{
164-
unsigned char flag, oldSREG;
165156
#ifdef serialEvent_implemented
166-
oldSREG = SREG;
167-
noInterrupts();
168-
flag = serialEvent_flag;
169-
serialEvent_flag = 0;
170-
SREG = oldSREG;
171-
if (flag) serialEvent();
157+
if (Serial.available()) serialEvent();
172158
#endif
173159
#ifdef serialEvent1_implemented
174-
oldSREG = SREG;
175-
noInterrupts();
176-
flag = serialEvent1_flag;
177-
serialEvent1_flag = 0;
178-
SREG = oldSREG;
179-
if (flag) serialEvent1();
160+
if (Serial1.available()) serialEvent1();
180161
#endif
181162
#ifdef serialEvent2_implemented
182-
oldSREG = SREG;
183-
noInterrupts();
184-
flag = serialEvent2_flag;
185-
serialEvent2_flag = 0;
186-
SREG = oldSREG;
187-
if (flag) serialEvent2();
163+
if (Serial2.available()) serialEvent2();
188164
#endif
189165
#ifdef serialEvent3_implemented
190-
oldSREG = SREG;
191-
noInterrupts();
192-
flag = serialEvent3_flag;
193-
serialEvent3_flag = 0;
194-
SREG = oldSREG;
195-
if (flag) serialEvent3();
166+
if (Serial3.available()) serialEvent3();
196167
#endif
197168
}
198169

hardware/arduino/cores/arduino/HardwareSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ class HardwareSerial : public Stream
7474
extern HardwareSerial Serial3;
7575
#endif
7676

77-
extern void serialEventRun(void);
77+
extern void serialEventRun(void) __attribute__((weak));
7878

7979
#endif

hardware/arduino/cores/arduino/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int main(void)
99

1010
for (;;) {
1111
loop();
12-
serialEventRun();
12+
if (serialEventRun) serialEventRun();
1313
}
1414

1515
return 0;

0 commit comments

Comments
 (0)