Eralt / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Suggestion: HardwareSerial interrupt optimization #391

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

HardwareSerial interrupt optimization.

Why?

More higher baud rate (over 115.2k) to use.
and, four serials(Mega1280/2560) to simultaneously use.

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?

No.

Similarity) http://code.google.com/p/arduino/issues/detail?id=56

--------------------------------------------------

HardwareSerial.cpp(0021) store_char() line 53
>  int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE;

disassemble
> LDS       R30,0x0192     ; R31:30 <- rx_buffer->head
> LDS       R31,0x0193
> MOVW      R24,R30        ; R25:24 <- R31:30
> ADIW      R24,0x01       ; R25:24 <- R25:24 + 1
> LDI       R22,0x80       ; R23:22 <- 128
> LDI       R23,0x00
> CALL      0x00000213     ; call modulus subroutine(about 200clk)

Signed a power of two modulus is not optimized (bitwise AND).

Cast to unsigned, to be optimized.

modified
>  int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE;

disassemble
> LDS       R30,0x0192     ; R31:30 <- rx_buffer->head
> LDS       R31,0x0193
> ADIW      R30,0x01       ; R31:30 <- R31:30 + 1
> MOVW      R18,R30        ; R19:18 <- R31:30
> ANDI      R18,0x7F       ; R19:18 <- R19:18 AND 0x007f
> ANDI      R19,0x00

SIGNAL(SIG_UART_RECV) processing time is about 330clk(20us) -> 80clk(5us).

available() and read() is also.

Original issue reported on code.google.com by j...@su-u.jp on 5 Nov 2010 at 10:19

Attachments:

GoogleCodeExporter commented 9 years ago
https://github.com/arduino/Arduino/commit/a403c19adeb0b02bf070b4bdc33a3d1c87a3fb
d8

Original comment by dmel...@gmail.com on 12 Nov 2010 at 4:32

GoogleCodeExporter commented 9 years ago
Why are ring_buffer's head and tail ints and not unsigned chars (and the above 
cast also unsigned char) ?

It reduces code size and should also run faster. Only impact is that the ring 
buffer size cannot be increased beyond the current 128 (if that's important a 
conditional typedef could be used).

Original comment by jc@wippler.nl on 12 Jun 2011 at 1:16