aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/HardwareSerial.h
AgeCommit message (Collapse)Author
2014-07-18Add availableForWrite() to HardwareSerialPaulStoffregen
2014-03-24Added support for different size of TX and RX buffer sizes.jantje
Added support for buffer sizes bigger than 256 bytes. Added possibility to overrule the default size. Added support for different size of TX and RX buffer sizes. The default values remain the same. You can however specify a different value for TX and RX buffer Added possibility to overrule the default size. If you want to have different values define SERIAL_TX_BUFFER_SIZE and SERIAL_RX_BUFFER_SIZE on the command line Added support for buffer sizes bigger than 256 bytes. Because of the possibility to change the size of the buffer sizes longer than 256 must be supported. The type of the indexes is decided upon the size of the buffers. So there is no increase in program/data size when the buffers are smaller than 257
2014-03-23This commit contains 2 changes:jantje
Added support for different size of TX and RX buffer sizes. Added support for buffer sizes bigger than 256 bytes. Added support for different size of TX and RX buffer sizes. The default values remain the same. If you want to have different values define SERIAL_TX_BUFFER_SIZE and SERIAL_RX_BUFFER_SIZE on the command line Added support for buffer sizes bigger than 256 bytes. The type of the indexes is decided upon the size of the buffers. So there is no increase in program/data size when the buffers are smaller than 257
2014-02-10Added license for avr/HardwareSerial.Cristian Maglie
See #1847
2014-01-22Inlined HardwareSerial calls to RX ISR.Cristian Maglie
Moreover, declaring pointers-to-registers as const and using initializer list in class constructor allows the compiler to further improve inlining performance. This change recovers about 50 bytes of program space on single-UART devices. See #1711
2014-01-22Centrally decide which hardware UARTS are availableMatthijs Kooijman
Before, this decision was made in few different places, based on sometimes different register defines. Now, HardwareSerial.h decides wich UARTS are available, defines USE_HWSERIALn macros and HardwareSerial.cpp simply checks these macros (together with some #ifs to decide which registers to use for UART 0). For consistency, USBAPI.h also defines a HAVE_CDCSERIAL macro when applicable. For supported targets, this should change any behaviour. For unsupported targets, the error messages might subtly change because some checks are moved or changed. Additionally, this moves the USBAPI.h include form HardareSerial.h into Arduino.h and raises an error when both CDC serial and UART0 are available (previously this would silently use UART0 instead of CDC, but there is not currently any Atmel chip available for which this would occur).
2014-01-22Improve HardwareSerial::flush()Matthijs Kooijman
The flush() method blocks until all characters in the serial buffer have been written to the uart _and_ transmitted. This is checked by waiting until the "TXC" (TX Complete) bit is set by the UART, signalling completion. This bit is cleared by write() when adding a new byte to the buffer and set by the hardware after tranmission ends, so it is always guaranteed to be zero from the moment the first byte in a sequence is queued until the moment the last byte is transmitted, and it is one from the moment the last byte in the buffer is transmitted until the first byte in the next sequence is queued. However, the TXC bit is also zero from initialization to the moment the first byte ever is queued (and then continues to be zero until the first sequence of bytes completes transmission). Unfortunately we cannot manually set the TXC bit during initialization, we can only clear it. To make sure that flush() would not (indefinitely) block when it is called _before_ anything was written to the serial device, the "transmitting" variable was introduced. This variable suggests that it is only true when something is transmitting, which isn't currently the case (it remains true after transmission is complete until flush() is called, for example). Furthermore, there is no need to keep the status of transmission, the only thing needed is to remember if anything has ever been written, so the corner case described above can be detected. This commit improves the code by: - Renaming the "transmitting" variable to _written (making it more clear and following the leading underscore naming convention). - Not resetting the value of _written at the end of flush(), there is no point to this. - Only checking the "_written" value once in flush(), since it can never be toggled off anyway. - Initializing the value of _written in both versions of _begin (though it probably gets initialized to 0 by default anyway, better to be explicit).
2014-01-16Move interrupt handlers into HardwareSerial classMatthijs Kooijman
The actual interrupt vectors are of course defined as before, but they let new methods in the HardwareSerial class do the actual work. This greatly reduces code duplication and prepares for one of my next commits which requires the tx interrupt handler to be called from another context as well. The actual content of the interrupts handlers was pretty much identical, so that remains unchanged (except that store_char was now only needed once, so it was inlined). Now all access to the buffers are inside the HardwareSerial class, the buffer variables can be made private. One would expect a program size reduction from this change (at least with multiple UARTs), but due to the fact that the interrupt handlers now only have indirect access to a few registers (which previously were just hardcoded in the handlers) and because there is some extra function call overhead, the code size on the uno actually increases by around 70 bytes. On the mega, which has four UARTs, the code size decreases by around 70 bytes.
2014-01-16Use constants for register bit positions in HardwareSerialMatthijs Kooijman
Previously, the constants to use for the bit positions of the various UARTs were passed to the HardwareSerial constructor. However, this meant that whenever these values were used, the had to be indirectly loaded, resulting in extra code overhead. Additionally, since there is no instruction to shift a value by a variable amount, the 1 << x expressions (inside _BV and sbi() / cbi()) would be compiled as a loop instead of being evaluated at compiletime. Now, the HardwareSerial class always uses the constants for the bit positions of UART 0 (and some code is present to make sure these constants exist, even for targets that only have a single unnumbered UART or start at UART1). This was already done for the TXC0 constant, for some reason. For the actual register addresses, this approach does not work, since these are of course different between the different UARTs on a single chip. Of course, always using the UART 0 constants is only correct when the constants are actually identical for the different UARTs. It has been verified that this is currently the case for all targets supported by avr-gcc 4.7.2, and the code contains compile-time checks to verify this for the current target, in case a new target is added for which this does not hold. This verification was done using: for i in TXC RXEN TXEN RXCIE UDRIE U2X UPE; do echo $i; grep --no-filename -r "#define $i[0-9]\? " /usr/lib/avr/include/avr/io* | sed "s/#define $i[0-9]\?\s*\(\S\)\+\s*\(\/\*.*\*\/\)\?$/\1/" | sort | uniq ; done This command shows that the above constants are identical for all uarts on all platforms, except for TXC, which is sometimes 6 and sometimes 0. Further investigation shows that it is always 6, except in io90scr100.h, but that file defines TXC0 with value 6 for the UART and uses TXC with value 0 for some USB-related register. This commit reduces program size on the uno by around 120 bytes.
2014-01-16Slightly reduce code utilization by inlining HardwareSerail begin(baud) and ↵Cristian Maglie
operator bool()
2013-07-26Make private members of HardwareSerial protectedMatthijs Kooijman
This allows users to create subclasses. Closes: #947
2013-07-26Move buffers into HardwareSerialMatthijs Kooijman
This removes the need for doing an extra pointer dereference on every access to the buffers, shrinking the code by around 100 bytes. The members for these buffers must be public for now, since the interrupt handlers also need to access them. These can later be made private again. Furthermore, the struct ring_buffer was removed. This allows the all head and tail pointers to be put into the HardwareSerial struct before the actual buffers, so the pointers all end up in the first 32 bytes of the struct that can be accessed using a single instruction (ldd). References: #947
2012-12-08Moving TXCO definition into HardwareSerial.cpp from HardwareSerial.h.David A. Mellis
Otherwise, you get an error when compiling for processors with no serial port because the header file is always compiled. See, for an example of the problem: https://github.com/damellis/attiny/issues/8
2012-11-02HardwareSerial: change byte to uint8_t (since byte definition isn't present).David A. Mellis
2012-08-30Changing setting of the UMSELn bits (for UART mode) and serial config values.David A. Mellis
Before, the UMSELn1 bit was being to set to 1, putting the UART into a reserved mode. Now, we only set the high (0x80) bit to 1 for the ATmega8, which is needed to access UCSRnC (whose i/o address is shared with UBRRH). Also, no longer bitwise-or the new config with the existing register value, because we're actually configuring all the settings in the register. (We're not using UCPOL, but it's supposed to be 0 in asynchronous mode.)
2012-08-30Renaming serial config constants to, e.g., SERIAL_8N1.David A. Mellis
2012-08-30Merge pull request #109 from Alarus/masterDavid A. Mellis
Serial.begin() parameter to set data bits, parity, stop bits.
2012-08-30Fixing Serial.flush() breakage on Leonardo (WestFW).David A. Mellis
http://code.google.com/p/arduino/issues/detail?id=1020
2012-08-29Fixing ATmega8 breakage from flush() change. (WestFW)David A. Mellis
http://code.google.com/p/arduino/issues/detail?id=1019
2012-08-29Adding overloads so Serial.write(0) works.David A. Mellis
http://code.google.com/p/arduino/issues/detail?id=1006
2012-08-28Serial.flush() waits for last character to be transmitted (michele.mazzucchi)David A. Mellis
http://code.google.com/p/arduino/issues/detail?id=871
2012-08-14Update hardware/arduino/cores/arduino/HardwareSerial.hAlarus
New Serial.begin(baud, config);
2012-08-12Update hardware/arduino/cores/arduino/HardwareSerial.hAlarus
Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.
2012-08-12Update hardware/arduino/cores/arduino/HardwareSerial.hAlarus
Adding advanced begin (); with the ability to specify the length of bits, parity, stop bits.
2012-04-01added Boolean operators to HardwareSerial and CDC to test whether the port ↵Zach Eveland
is ready to send data. Mostly useful for Leonardo - simple way to test whether the port is actually opened by an application and ready to receive data. For Serial objects attached to real UARTs always returns true.
2011-10-27Revert "Merge branch 'master' of github.com:arduino/Arduino into ↵Zach Eveland
diskloader_reboot" This reverts commit df9835efafd13685251749bc210c0b96a18a96a5, reversing changes made to ec45af8bfa9222a807c075dd1db4b5aa798bba03. Conflicts: hardware/arduino/variants/mega/pins_arduino.h libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
2011-02-25Small optimization in HardwareSerial.David A. Mellis
begin(long) -> begin(unsigned long)
2010-10-17Making HardwareSerial tests register-based, not CPU-based.David A. Mellis
Mark Sproul's patches, via Christian Maglie. http://code.google.com/p/arduino/issues/detail?id=315
2010-09-081280 -> 1280/2560.David A. Mellis
2010-08-02changing available() to return an int (because the Ethernet Client class or ↵David A. Mellis
another stream might need more than 255 bytes).
2010-07-04Adding a peek() function to Stream and HardwareSerial (Serial).David A. Mellis
2010-05-28Adding a basic Stream interface and modifying HardwareSerial to inherit from it.David A. Mellis
2009-12-23Adding Serial.end().David A. Mellis
2009-11-21Improving third-party hardware support:David A. Mellis
- moving back to multple cores per platform - using target instead of platform - moving per-board and per-programmer preferences out of Preferences.java and into a new Target class - adding a new "target" preference - support for platform:value values in board preferences for bootloader path and core - XXX: need to support platform:value syntax for board upload.using preferences.
2009-11-07Moving things around.David A. Mellis
2009-07-12Clearing the U2Xn bit in Serial.begin() (because it is set on the Pro / Pro ↵David A. Mellis
Mini 328). Fixing some indentation.
2009-06-01First integration of the Arduino code in Processing 5503: PreProcessor and ↵David A. Mellis
Compiler have been integrated with changes to the Sketch. Compilation still has problems (Thread error on success, and can't handle non-pde files in a sketch). Modified the Mac OS X make.sh to copy the hardware, avr tools, and example over. Removing some of the antlr stuff. Disabling the Commander (command-line execution) for now. Added Library, LibraryManager, and Target. Added support for prefixed preferences (e.g. for boards and programmers).