aboutsummaryrefslogtreecommitdiff
path: root/libraries/SoftwareSerial/SoftwareSerial.cpp
AgeCommit message (Collapse)Author
2015-01-26In SoftwareSerial::recv, only calculate the new tail onceMatthijs Kooijman
This shortens the generated code a bit more.
2015-01-26In SoftwareSerial, use ISR_ALIASOF to prevent duplicationMatthijs Kooijman
Previously, up to four separate but identical ISR routines were defined, for PCINT0, PCINT1, PCINT2 and PCINT3. Each of these would generate their own function, with a lot of push-popping because another function was called. Now, the ISR_ALIASOF macro from avr-libc is used to declare just the PCINT0 version and make all other ISRs point to that one, saving a lot of program space, as well as some speed because of improved inlining. On an Arduino Uno with gcc 4.3, this saves 168 bytes. With gcc 4.8, this saves 150 bytes.
2015-01-26Optimize SoftwareSerial::recvMatthijs Kooijman
Similar to SoftwareSerial::write, this rewrites the loop to only touch the MSB and then shift those bits up, allowing the compiler to generate more efficient code. Unlike the write function however, it is not needed to put all instance variables used into local variables, for some reason the compiler already does this (and doing it manually even makes the code bigger). On the Arduino Uno using gcc 4.3 this saves 26 bytes. Using gcc 4.8 this saves 30 bytes. Note that this removes the else clause in the code, making the C code unbalanced, which looks like it breaks timing balance. However, looking at the code generated by the compiler, it turns out that the old code was actually unbalanced, while the new code is properly balanced.
2015-01-26Further optimize SoftwareSerial::writeMatthijs Kooijman
This change restructures the loop, to help the compiler generate shorter code (because now only the LSB of the data byte is checked and subsequent bytes are shifted down one by one, it can use th "skip if bit set" instruction). Furthermore, it puts most attributes in local variables, which causes the compiler to put them into registers. This makes the timing-critical part of the code smaller, making it easier to provide accurate timings. On an Arduino uno using gcc 4.3, this saves 58 bytes. On gcc 4.8, this saves 14 bytes.
2015-01-26Simplify SoftwareSerial::writeMatthijs Kooijman
Before, there was nearly identical code for the inverted and regular cases. However, simply inverting the byte in the inverted case allows using the regular code twice, reducing the generated code size by 100 bytes (on an Arduino Uno and gcc 4.3, on gcc 4.8 the reduction is 50 bytes).
2015-01-26Use stopListening() in SoftwareSerial::end()Matthijs Kooijman
stopListening also disabled the interrupt, if needed, so calling that function makes more sense. Since stopListening only disables the interrupt when the current SoftwareSerial is the active object, and that can only be the case when _rx_delay_stopbit is non-zero, there is no need to separately check _rx_delay_stopbit anymore.
2015-01-26Toggle SoftwareSerial interrupts when starting / stopping to listenMatthijs Kooijman
This prevents interrupts from triggering when the SoftwareSerial instance is not even listening. Additionally, this removes the need to disable interrupts in SoftwareSerial::listen, since no interrupts are active while it touches the variables.
2015-01-26Add SoftwareSerial::stopListening()Matthijs Kooijman
This allows one to explicitly stop a SoftwareSerial instance from listening, without having to make another one listening.
2015-01-26Add SoftwareSerial::setRxIntMsk()Matthijs Kooijman
This moves the interrupt mask enabling / disabling code into a separate method, so we can call it from multiple spots next.
2015-01-26Let SoftwareSerial::end also check against _rx_delay_stopbitMatthijs Kooijman
The current check is still always false when the old check was, but additionally it will not disable the interrupts when they were never enabled (which shouldn't matter much, but this is more consistent).
2015-01-26Let SoftwareSerial::listen() fail on invalid rx baud ratesMatthijs Kooijman
In this case, SoftwareSerial::begin will not have enabled the interrupts, so better not allow the SoftwareSerial instance to enter the listening state either.
2015-01-26Clear SoftwareSerial rx delay if no interrupt register is foundMatthijs Kooijman
Before enabling interupts, begin would see if the given receive pin actually has an associated PCINT register. If not, the interrupts would not be enabled. Now, the same check is done, but when no register is available, the rx parameters are not loaded at all (which in turn prevents the interrupt from being enabled). This allows all code to use the same "is rx enabled" (which will be added next).
2014-05-23Merge remote-tracking branch 'arduino/master' into ide-1.5.xCristian Maglie
Conflicts: build/shared/examples/01.Basics/Blink/Blink.ino build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino build/shared/examples/10.StarterKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino hardware/arduino/cores/arduino/HardwareSerial.cpp
2013-11-15Revert "SoftwareSerial library to the new format"Cristian Maglie
This reverts commit 38c3bbbd3c83eda057d4857635fbd78a4785c3a4.
2013-07-03SoftwareSerial library to the new formatFede85
2012-12-10Merged 1.0.3Cristian Maglie
2012-12-10fixed permissions on a lot of text files. see #1116Federico Fissore
2012-01-04Moved libraries folder inside platform folder. Now libraries and examples ↵Cristian Maglie
are searched per board/platform
2009-11-07Moving libraries out of arduino platform / core directory and to top-level.David A. Mellis
2007-10-06Moving libraries out from inside targets and creating bootloaders directory.David A. Mellis