Skip to content

Commit cf044cd

Browse files
committed
Adding serialEvent(), serialEvent1(), etc.
Called from within the serial receive interrupt. These are implemented as an empty weak function in the core that be overridden by the user's sketch. http://code.google.com/p/arduino/issues/detail?id=263
1 parent c740778 commit cf044cd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

hardware/arduino/cores/arduino/HardwareSerial.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
8686
!defined(SIG_UART_RECV)
8787
#error Don't know what the Data Received vector is called for the first UART
8888
#else
89+
void serialEvent() __attribute__((weak));
90+
void serialEvent() {}
8991
#if defined(USART_RX_vect)
9092
SIGNAL(USART_RX_vect)
9193
#elif defined(SIG_USART0_RECV)
@@ -106,36 +108,44 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
106108
#error UDR not defined
107109
#endif
108110
store_char(c, &rx_buffer);
111+
serialEvent();
109112
}
110113
#endif
111114

112-
//#if defined(SIG_USART1_RECV)
113115
#if defined(USART1_RX_vect)
114-
//SIGNAL(SIG_USART1_RECV)
116+
void serialEvent1() __attribute__((weak));
117+
void serialEvent1() {}
115118
SIGNAL(USART1_RX_vect)
116119
{
117120
unsigned char c = UDR1;
118121
store_char(c, &rx_buffer1);
122+
serialEvent1();
119123
}
120124
#elif defined(SIG_USART1_RECV)
121125
#error SIG_USART1_RECV
122126
#endif
123127

124128
#if defined(USART2_RX_vect) && defined(UDR2)
129+
void serialEvent2() __attribute__((weak));
130+
void serialEvent2() {}
125131
SIGNAL(USART2_RX_vect)
126132
{
127133
unsigned char c = UDR2;
128134
store_char(c, &rx_buffer2);
135+
serialEvent2();
129136
}
130137
#elif defined(SIG_USART2_RECV)
131138
#error SIG_USART2_RECV
132139
#endif
133140

134141
#if defined(USART3_RX_vect) && defined(UDR3)
142+
void serialEvent3() __attribute__((weak));
143+
void serialEvent3() {}
135144
SIGNAL(USART3_RX_vect)
136145
{
137146
unsigned char c = UDR3;
138147
store_char(c, &rx_buffer3);
148+
serialEvent3();
139149
}
140150
#elif defined(SIG_USART3_RECV)
141151
#error SIG_USART3_RECV

0 commit comments

Comments
 (0)