Commit Graph

17 Commits (39ee51a017661bfd7953d2c772e513ffee5aac02)

Author SHA1 Message Date
Kevin Bracey 380b27e741 Fix UARTSerial emergency unbuffered write
The length calculation in UARTSerial::write_unbuffered was wrong,
meaning it would truncate output data to half length.

This would show up if `platform.stdio-buffered-serial` was configured to
true, `platform.stdio-convert-newlines` was still false - `mbed_error`
crashes would be garbled.

This wasn't usually spotted because applications generally have both
settings false or both true, and if newline conversion is on, then
`mbed_error_puts` writes 1 character at a time to FileHandle::write,
avoiding the length error.
2019-04-09 16:15:09 +03:00
Kevin Bracey 649856f3ff Implement enable calls in UARTSerial
Implement enable calls so that reception can be shut down to save
power without closing the device.
2019-02-22 11:01:01 +02:00
Martin Kojtal aec8bb6046 drivers: add spdx license 2018-11-28 10:39:50 +00:00
Thomas Kemmer fdc675441a Clean up UARTSerial.cpp includes. 2018-10-21 15:35:40 +02:00
Kevin Bracey c989845d5a mbed_error_vfprintf -> mbed_error_vprintf
Name vfprintf doesn't make sense - if we have mbed_error_printf, this is
vprintf.
2018-10-17 12:55:20 +03:00
Kevin Bracey 1094c08129 Add support for UARTSerial::write from critical section 2018-10-17 12:55:20 +03:00
Kevin Bracey 1ef213ec89 Clean up Thread deprecation warnings
Static Thread methods and signal methods have been deprecated. Remove
all references in the main code, and most of the tests. Some tests of
the deprecated APIs themselves remain.
2018-10-12 14:57:13 +03:00
Martin Kojtal 700e6df834 drivers: astyle update 2018-06-29 10:36:36 +01:00
Paul Thompson d6c5f16fd3 Eliminate complier warning and remove superfluous call to empty()
Appears when complied with -O3 optimization level

Compile: UARTSerial.cpp
../drivers/UARTSerial.cpp: In member function 'void mbed::UARTSerial::tx_irq()':
../drivers/UARTSerial.cpp:314:31: warning: 'data' may be used uninitialized in this function [-Wmaybe-uninitialized]
         SerialBase::_base_putc(data);
2018-04-16 07:23:47 -07:00
Kevin Bracey 9678c8052e Make UARTSerial send all data when blocking
Previously, write() was somewhat soft - it only ever made one attempt to
wait for buffer space, so it would take as much data as would fit in the
buffer in one call.

This is not the intent of a POSIX filehandle write. It should try to
send everything if blocking, and only send less if interrupted by a
signal:

 - If the O_NONBLOCK flag is clear, write() shall block the calling
   thread until the data can be accepted.

 - If the O_NONBLOCK flag is set, write() shall not block the thread.
   If some data can be written without blocking the thread, write()
   shall write what it can and return the number of bytes written.
   Otherwise, it shall return -1 and set errno to [EAGAIN].

This "send all" behaviour is of slightly limited usefulness in POSIX, as
you still usually have to worry about the interruption possibility:

  - If write() is interrupted by a signal before it writes any data, it
    shall return -1 with errno set to [EINTR].

  - If write() is interrupted by a signal after it successfully writes
    some data, it shall return the number of bytes written.

But as mbed OS does not have the possibility of signal interruption, if we
strengthen write to write everything, we can make applications' lives
easier - they can just do "write(large amount)" confident that it will
all go in one call (if no errors).

So, rework to make multiple writes to the buffer, blocking as necessary,
until all data is written.

This change does not apply to read(), which is correct in only blocking until
some data is available:

 - If O_NONBLOCK is set, read() shall return -1 and set errno to [EAGAIN].

 - If O_NONBLOCK is clear, read() shall block the calling thread until some
   data becomes available.

 - The use of the O_NONBLOCK flag has no effect if there is some data
   available.
2017-11-21 09:51:36 +02:00
Jimmy Brisson 5768693e0d
Merge pull request #5088 from kjbracey-arm/uartserial_flow
UARTSerial: add flow control and format APIs
2017-11-02 10:37:40 -05:00
Kevin Bracey b18332cb4d Avoid wait_ms() spin
System's wait_ms() spins to achieve a precise delay - we don't want this.
Call Thread::wait directly.
2017-09-28 10:45:57 +03:00
Kevin Bracey c262a035f6 UARTSerial: add flow control and format APIs
Add passthrough APIs to enable the flow control and format methods from
SerialBase to be accessed.

Modify the RX data pump so it stops reading data and disables the IRQ
when the buffer is full, to allow UART automatic flow control to work.

In principle it would also be possible as a future enhancement to
provide XON/XOFF flow control, or manual RTS/CTS control using GPIO, but
this commit at least restores the functionality present in Serial,
SerialBase and RawSerial that was missing in UARTSerial.
2017-09-13 15:27:13 +03:00
Jimmy Brisson c1e455c594 Merge pull request #4615 from u-blox/uart_serial_set_baud
Add set_baud() method to UARTSerial().
2017-07-24 10:50:43 -05:00
Rob Meades 89ddfc5beb Add set_baud() method to UARTSerial(). 2017-06-22 12:26:48 +01:00
Hasnain Virk 64a92df455 Avoid lock collision b/w SerialBase & UARTSerial
Fixes issue #4537. SerialBase and UARTSerial happened to have same names
for the mutex locking that confused the system of holding a mutex in interrupt context.
UARTSerial has to change so as to provide empty implementations for lock() and unlock()
becuase it uses SerialBase from interrupt context only or from its own critical section,
so no extra locks required.
Private locks for UARTSerial itself are renamed to api_lock() and api_unlock().
2017-06-13 16:28:31 +03:00
Hasnain Virk 24de27c989 Major Refactoring & extensions
For keep supporting external APIs with the same name (supposedly there are a larger
number of users of those APIs), BufferedSerial and ATParser are being renamed.
BufferedSerial becomes UARTSerial, will complement a  future USBSerial etc.
ATParser becomes ATCmdParser.

* UARTSerial moves to /drivers

* APN_db.h is moved from platform to cellular/util/.

* Original CellularInterface is restored for backward compatability (again, supposedly there
  are users of that).

* A new file, CellularBase is added which will now servce as the base class for all
  upcoming drivers.

* Special restructuring for the driver has been undertaken. This makes a clear cut distinction
  between an on-board or an off-board implementation.
  	- PPPCellularInterface is a generic network interface that works with a generic FileHandle
          and PPP. A derived class is needed to pass that FileHandle.
        - PPPCellularInterface provides some base functionality like network registration, AT setup,
          PPP connection etc. Lower level job is delegated to the derived classes and various modem
          specific APIs are provided which are supposed to be overridden.
        - UARTCellularInterface is derived from PPPCellularInterface. It constructs a FileHandle and
          passes it back to PPPCellularInterface as well as provides modem hangupf functionality.
          In future we could proive a USBInterface that would derive from PPPCellularInterface and could
          pass the FileHandle back.
	- OnboardCellularInterface is derived from UARTCellularInterfae and provides hooks to
          the target provided implementation of onbard_modem_api.h. An off-board modem, i.e, a modem on
          a shield has to override the modem_init(), modem_power_up() etc as it cannot use
          onboard_modem_api.h.
2017-05-31 15:02:11 +03:00