@@ -88,6 +88,8 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
88
88
#else
89
89
void serialEvent () __attribute__((weak));
90
90
void serialEvent () {}
91
+ volatile static unsigned char serialEvent_flag = 0 ;
92
+ #define serialEvent_implemented
91
93
#if defined(USART_RX_vect)
92
94
SIGNAL (USART_RX_vect)
93
95
#elif defined(SIG_USART0_RECV)
@@ -108,18 +110,20 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
108
110
#error UDR not defined
109
111
#endif
110
112
store_char (c, &rx_buffer);
111
- serialEvent () ;
113
+ serialEvent_flag = 1 ;
112
114
}
113
115
#endif
114
116
115
117
#if defined(USART1_RX_vect)
116
118
void serialEvent1 () __attribute__((weak));
117
119
void serialEvent1 () {}
120
+ volatile static unsigned char serialEvent1_flag = 0 ;
121
+ #define serialEvent1_implemented
118
122
SIGNAL (USART1_RX_vect)
119
123
{
120
124
unsigned char c = UDR1;
121
125
store_char (c, &rx_buffer1);
122
- serialEvent1 () ;
126
+ serialEvent1_flag = 1 ;
123
127
}
124
128
#elif defined(SIG_USART1_RECV)
125
129
#error SIG_USART1_RECV
@@ -128,11 +132,13 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
128
132
#if defined(USART2_RX_vect) && defined(UDR2)
129
133
void serialEvent2 () __attribute__((weak));
130
134
void serialEvent2 () {}
135
+ volatile static unsigned char serialEvent2_flag = 0 ;
136
+ #define serialEvent2_implemented
131
137
SIGNAL (USART2_RX_vect)
132
138
{
133
139
unsigned char c = UDR2;
134
140
store_char (c, &rx_buffer2);
135
- serialEvent2 () ;
141
+ serialEvent2_flag = 1 ;
136
142
}
137
143
#elif defined(SIG_USART2_RECV)
138
144
#error SIG_USART2_RECV
@@ -141,16 +147,55 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
141
147
#if defined(USART3_RX_vect) && defined(UDR3)
142
148
void serialEvent3 () __attribute__((weak));
143
149
void serialEvent3 () {}
150
+ volatile static unsigned char serialEvent3_flag = 0 ;
151
+ #define serialEvent3_implemented
144
152
SIGNAL (USART3_RX_vect)
145
153
{
146
154
unsigned char c = UDR3;
147
155
store_char (c, &rx_buffer3);
148
- serialEvent3 () ;
156
+ serialEvent3_flag = 1 ;
149
157
}
150
158
#elif defined(SIG_USART3_RECV)
151
159
#error SIG_USART3_RECV
152
160
#endif
153
161
162
+ void serialEventRun (void )
163
+ {
164
+ unsigned char flag, oldSREG;
165
+ #ifdef serialEvent_implemented
166
+ oldSREG = SREG;
167
+ noInterrupts ();
168
+ flag = serialEvent_flag;
169
+ serialEvent_flag = 0 ;
170
+ SREG = oldSREG;
171
+ if (flag) serialEvent ();
172
+ #endif
173
+ #ifdef serialEvent1_implemented
174
+ oldSREG = SREG;
175
+ noInterrupts ();
176
+ flag = serialEvent1_flag;
177
+ serialEvent1_flag = 0 ;
178
+ SREG = oldSREG;
179
+ if (flag) serialEvent1 ();
180
+ #endif
181
+ #ifdef serialEvent2_implemented
182
+ oldSREG = SREG;
183
+ noInterrupts ();
184
+ flag = serialEvent2_flag;
185
+ serialEvent2_flag = 0 ;
186
+ SREG = oldSREG;
187
+ if (flag) serialEvent2 ();
188
+ #endif
189
+ #ifdef serialEvent3_implemented
190
+ oldSREG = SREG;
191
+ noInterrupts ();
192
+ flag = serialEvent3_flag;
193
+ serialEvent3_flag = 0 ;
194
+ SREG = oldSREG;
195
+ if (flag) serialEvent3 ();
196
+ #endif
197
+ }
198
+
154
199
155
200
#if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect)
156
201
#error Don't know what the Data Register Empty vector is called for the first UART
0 commit comments