Moving serialEvent() calls from RX interrupts to main for() loop (after loop()).
http://code.google.com/p/arduino/issues/detail?id=584
This commit is contained in:
parent
84a0ad9fd3
commit
7b0d88b954
|
@ -88,6 +88,8 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
|
||||||
#else
|
#else
|
||||||
void serialEvent() __attribute__((weak));
|
void serialEvent() __attribute__((weak));
|
||||||
void serialEvent() {}
|
void serialEvent() {}
|
||||||
|
volatile static unsigned char serialEvent_flag = 0;
|
||||||
|
#define serialEvent_implemented
|
||||||
#if defined(USART_RX_vect)
|
#if defined(USART_RX_vect)
|
||||||
SIGNAL(USART_RX_vect)
|
SIGNAL(USART_RX_vect)
|
||||||
#elif defined(SIG_USART0_RECV)
|
#elif defined(SIG_USART0_RECV)
|
||||||
|
@ -108,18 +110,20 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
|
||||||
#error UDR not defined
|
#error UDR not defined
|
||||||
#endif
|
#endif
|
||||||
store_char(c, &rx_buffer);
|
store_char(c, &rx_buffer);
|
||||||
serialEvent();
|
serialEvent_flag = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USART1_RX_vect)
|
#if defined(USART1_RX_vect)
|
||||||
void serialEvent1() __attribute__((weak));
|
void serialEvent1() __attribute__((weak));
|
||||||
void serialEvent1() {}
|
void serialEvent1() {}
|
||||||
|
volatile static unsigned char serialEvent1_flag = 0;
|
||||||
|
#define serialEvent1_implemented
|
||||||
SIGNAL(USART1_RX_vect)
|
SIGNAL(USART1_RX_vect)
|
||||||
{
|
{
|
||||||
unsigned char c = UDR1;
|
unsigned char c = UDR1;
|
||||||
store_char(c, &rx_buffer1);
|
store_char(c, &rx_buffer1);
|
||||||
serialEvent1();
|
serialEvent1_flag = 1;
|
||||||
}
|
}
|
||||||
#elif defined(SIG_USART1_RECV)
|
#elif defined(SIG_USART1_RECV)
|
||||||
#error SIG_USART1_RECV
|
#error SIG_USART1_RECV
|
||||||
|
@ -128,11 +132,13 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
|
||||||
#if defined(USART2_RX_vect) && defined(UDR2)
|
#if defined(USART2_RX_vect) && defined(UDR2)
|
||||||
void serialEvent2() __attribute__((weak));
|
void serialEvent2() __attribute__((weak));
|
||||||
void serialEvent2() {}
|
void serialEvent2() {}
|
||||||
|
volatile static unsigned char serialEvent2_flag = 0;
|
||||||
|
#define serialEvent2_implemented
|
||||||
SIGNAL(USART2_RX_vect)
|
SIGNAL(USART2_RX_vect)
|
||||||
{
|
{
|
||||||
unsigned char c = UDR2;
|
unsigned char c = UDR2;
|
||||||
store_char(c, &rx_buffer2);
|
store_char(c, &rx_buffer2);
|
||||||
serialEvent2();
|
serialEvent2_flag = 1;
|
||||||
}
|
}
|
||||||
#elif defined(SIG_USART2_RECV)
|
#elif defined(SIG_USART2_RECV)
|
||||||
#error SIG_USART2_RECV
|
#error SIG_USART2_RECV
|
||||||
|
@ -141,16 +147,55 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
|
||||||
#if defined(USART3_RX_vect) && defined(UDR3)
|
#if defined(USART3_RX_vect) && defined(UDR3)
|
||||||
void serialEvent3() __attribute__((weak));
|
void serialEvent3() __attribute__((weak));
|
||||||
void serialEvent3() {}
|
void serialEvent3() {}
|
||||||
|
volatile static unsigned char serialEvent3_flag = 0;
|
||||||
|
#define serialEvent3_implemented
|
||||||
SIGNAL(USART3_RX_vect)
|
SIGNAL(USART3_RX_vect)
|
||||||
{
|
{
|
||||||
unsigned char c = UDR3;
|
unsigned char c = UDR3;
|
||||||
store_char(c, &rx_buffer3);
|
store_char(c, &rx_buffer3);
|
||||||
serialEvent3();
|
serialEvent3_flag = 1;
|
||||||
}
|
}
|
||||||
#elif defined(SIG_USART3_RECV)
|
#elif defined(SIG_USART3_RECV)
|
||||||
#error SIG_USART3_RECV
|
#error SIG_USART3_RECV
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void serialEventRun(void)
|
||||||
|
{
|
||||||
|
unsigned char flag, oldSREG;
|
||||||
|
#ifdef serialEvent_implemented
|
||||||
|
oldSREG = SREG;
|
||||||
|
noInterrupts();
|
||||||
|
flag = serialEvent_flag;
|
||||||
|
serialEvent_flag = 0;
|
||||||
|
SREG = oldSREG;
|
||||||
|
if (flag) serialEvent();
|
||||||
|
#endif
|
||||||
|
#ifdef serialEvent1_implemented
|
||||||
|
oldSREG = SREG;
|
||||||
|
noInterrupts();
|
||||||
|
flag = serialEvent1_flag;
|
||||||
|
serialEvent1_flag = 0;
|
||||||
|
SREG = oldSREG;
|
||||||
|
if (flag) serialEvent1();
|
||||||
|
#endif
|
||||||
|
#ifdef serialEvent2_implemented
|
||||||
|
oldSREG = SREG;
|
||||||
|
noInterrupts();
|
||||||
|
flag = serialEvent2_flag;
|
||||||
|
serialEvent2_flag = 0;
|
||||||
|
SREG = oldSREG;
|
||||||
|
if (flag) serialEvent2();
|
||||||
|
#endif
|
||||||
|
#ifdef serialEvent3_implemented
|
||||||
|
oldSREG = SREG;
|
||||||
|
noInterrupts();
|
||||||
|
flag = serialEvent3_flag;
|
||||||
|
serialEvent3_flag = 0;
|
||||||
|
SREG = oldSREG;
|
||||||
|
if (flag) serialEvent3();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect)
|
#if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect)
|
||||||
#error Don't know what the Data Register Empty vector is called for the first UART
|
#error Don't know what the Data Register Empty vector is called for the first UART
|
||||||
|
|
|
@ -74,4 +74,6 @@ class HardwareSerial : public Stream
|
||||||
extern HardwareSerial Serial3;
|
extern HardwareSerial Serial3;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern void serialEventRun(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,8 +7,10 @@ int main(void)
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
for (;;)
|
for (;;) {
|
||||||
loop();
|
loop();
|
||||||
|
serialEventRun();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue