diff --git a/TESTS/mbed_drivers/dev_null/main.cpp b/TESTS/mbed_drivers/dev_null/main.cpp index 34671fa..0a1cd46 100644 --- a/TESTS/mbed_drivers/dev_null/main.cpp +++ b/TESTS/mbed_drivers/dev_null/main.cpp @@ -16,6 +16,7 @@ */ #include "mbed.h" +#include "platform/Stream.h" #include "greentea-client/test_env.h" class DevNull : public Stream { diff --git a/drivers/RawSerial.h b/drivers/RawSerial.h deleted file mode 100644 index 55f8122..0000000 --- a/drivers/RawSerial.h +++ /dev/null @@ -1,133 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MBED_RAW_SERIAL_H -#define MBED_RAW_SERIAL_H - -#include "platform/platform.h" - -#if DEVICE_SERIAL || defined(DOXYGEN_ONLY) - -#include "platform/mbed_toolchain.h" -#include "drivers/SerialBase.h" -#include "platform/NonCopyable.h" -#include - -namespace mbed { - -/** - * \defgroup drivers_RawSerial RawSerial class - * \ingroup drivers-public-api-uart - * @{ - */ - -/** @deprecated - * A serial port (UART) for communication with other serial devices - * This is a variation of the Serial class that doesn't use streams, - * thus making it safe to use in interrupt handlers with the RTOS. - * - * Can be used for Full Duplex communication, or Simplex by specifying - * one pin as NC (Not Connected) - * - * @note Synchronization level: Not protected - * - * Example: - * @code - * // Send a char to the PC - * - * #include "mbed.h" - * - * RawSerial pc(USBTX, USBRX); - * - * int main() { - * pc.putc('A'); - * } - * @endcode - */ -class - MBED_DEPRECATED_SINCE( - "mbed-os-6.0.0", - "Use UnbufferedSerial instead." - ) RawSerial: public SerialBase, private NonCopyable { - -public: - /** @deprecated - * Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud. - * - * @param tx Transmit pin - * @param rx Receive pin - * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) - * - * @note - * Either tx or rx may be specified as NC if unused - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); - - /** @deprecated - * Write a char to the serial port - * - * @param c The char to write - * - * @returns The written char or -1 if an error occurred - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - int putc(int c); - - /** @deprecated - * Read a char from the serial port - * - * @returns The char read from the serial port - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - int getc(); - - /** @deprecated - * Write a string to the serial port - * - * @param str The string to write - * - * @returns 0 if the write succeeds, EOF for error - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - int puts(const char *str); - - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2); - - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - int vprintf(const char *format, std::va_list arg); - -#if !(DOXYGEN_ONLY) -protected: - - /* Acquire exclusive access to this serial port - */ - virtual void lock(void); - - /* Release exclusive access to this serial port - */ - virtual void unlock(void); -#endif -}; - -/** @}*/ - -} // namespace mbed - -#endif - -#endif diff --git a/drivers/Serial.h b/drivers/Serial.h deleted file mode 100644 index b7ceaa3..0000000 --- a/drivers/Serial.h +++ /dev/null @@ -1,168 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MBED_SERIAL_H -#define MBED_SERIAL_H - -#include "platform/platform.h" - -#if DEVICE_SERIAL || defined(DOXYGEN_ONLY) - -#include "platform/Stream.h" -#include "drivers/SerialBase.h" -#include "platform/PlatformMutex.h" -#include "platform/NonCopyable.h" - -namespace mbed { -/** - * \defgroup drivers_Serial Serial class - * \ingroup drivers-public-api-uart - * @{ - */ - -/** @deprecated - * A serial port (UART) for communication with other serial devices - * - * Can be used for Full Duplex communication, or Simplex by specifying - * one pin as NC (Not Connected) - * - * @note Synchronization level: Thread safe - * - * Example: - * @code - * // Print "Hello World" to the PC - * - * #include "mbed.h" - * - * Serial pc(USBTX, USBRX); - * - * int main() { - * pc.printf("Hello World\n"); - * } - * @endcode - */ -class - MBED_DEPRECATED_SINCE( - "mbed-os-6.0.0", - "Use printf and puts instead to access the console, BufferedSerial for blocking applications or UnbufferedSerial if bypassing locks in IRQ or short of RAM." - ) Serial : public SerialBase, public Stream, private NonCopyable { - -public: -#if DEVICE_SERIAL_ASYNCH - using SerialBase::read; - using SerialBase::write; -#endif - - /** Resolve ambiguities in SerialBase and FileHandle - * (for enable_input and enable_output) - */ - using SerialBase::enable_input; - using SerialBase::enable_output; - - /** @deprecated - * Create a Serial port, connected to the specified transmit and receive pins - * - * @param tx Transmit pin - * @param rx Receive pin - * @param name The name of the stream associated with this serial port (optional) - * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE or 9600) - * - * @note - * Either tx or rx may be specified as NC (Not Connected) if unused - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - Serial(PinName tx, PinName rx, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); - - /** @deprecated - * Create a Serial port, connected to the specified transmit and receive pins - * - * @param static_pinmap reference to structure which holds static pinmap. - * @param name The name of the stream associated with this serial port (optional) - * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE or 9600) - * - * @note - * Either tx or rx may be specified as NC (Not Connected) if unused - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - Serial(const serial_pinmap_t &static_pinmap, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - Serial(const serial_pinmap_t &&, const char * = NULL, int = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) = delete; // prevent passing of temporary objects - - /** @deprecated - * Create a Serial port, connected to the specified transmit and receive pins, with the specified baud - * - * @param tx Transmit pin - * @param rx Receive pin - * @param baud The baud rate of the serial port - * - * @note - * Either tx or rx may be specified as NC (Not Connected) if unused - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - Serial(PinName tx, PinName rx, int baud); - - /** @deprecated - * Create a Serial port, connected to the specified transmit and receive pins, with the specified baud - * - * @param static_pinmap reference to structure which holds static pinmap. - * @param baud The baud rate of the serial port - * - * @note - * Either tx or rx may be specified as NC (Not Connected) if unused - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - Serial(const serial_pinmap_t &static_pinmap, int baud); - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - Serial(const serial_pinmap_t &&, int) = delete; // prevent passing of temporary objects - - /* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through - * the calls from the SerialBase instead for backwards compatibility. This problem is - * part of why Stream and Serial should be deprecated. - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - bool readable() - { - return SerialBase::readable(); - } - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - bool writable() - { - return SerialBase::writeable(); - } - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - bool writeable() - { - return SerialBase::writeable(); - } - -#if !(DOXYGEN_ONLY) -protected: - virtual int _getc(); - virtual int _putc(int c); - virtual void lock(); - virtual void unlock(); - - PlatformMutex _mutex; -#endif -}; - -/** @}*/ - -} // namespace mbed - -#endif - -#endif diff --git a/drivers/SerialBase.h b/drivers/SerialBase.h index 83f449d..9288c27 100644 --- a/drivers/SerialBase.h +++ b/drivers/SerialBase.h @@ -105,42 +105,6 @@ */ void attach(Callback func, IrqType type = RxIrq); - /** Attach a member function to call whenever a serial interrupt is generated - * - * @param obj pointer to the object to call the member function on - * @param method pointer to the member function to be called - * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) - * @deprecated - * The attach function does not support cv-qualifiers. Replaced by - * attach(callback(obj, method), type). - */ - template - MBED_DEPRECATED_SINCE("mbed-os-5.1", - "The attach function does not support cv-qualifiers. Replaced by " - "attach(callback(obj, method), type).") - void attach(T *obj, void (T::*method)(), IrqType type = RxIrq) - { - attach(callback(obj, method), type); - } - - /** Attach a member function to call whenever a serial interrupt is generated - * - * @param obj pointer to the object to call the member function on - * @param method pointer to the member function to be called - * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) - * @deprecated - * The attach function does not support cv-qualifiers. Replaced by - * attach(callback(obj, method), type). - */ - template - MBED_DEPRECATED_SINCE("mbed-os-5.1", - "The attach function does not support cv-qualifiers. Replaced by " - "attach(callback(obj, method), type).") - void attach(T *obj, void (*method)(T *), IrqType type = RxIrq) - { - attach(callback(obj, method), type); - } - /** Generate a break condition on the serial line * NOTE: Clear break needs to run at least one frame after set_break is called */ diff --git a/drivers/UARTSerial.h b/drivers/UARTSerial.h deleted file mode 100644 index d876a55..0000000 --- a/drivers/UARTSerial.h +++ /dev/null @@ -1,383 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MBED_UARTSERIAL_H -#define MBED_UARTSERIAL_H - -#include "platform/platform.h" - -#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) - -#include "platform/FileHandle.h" -#include "drivers/SerialBase.h" -#include "drivers/InterruptIn.h" -#include "platform/PlatformMutex.h" -#include "platform/CircularBuffer.h" -#include "platform/NonCopyable.h" - -#ifndef MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE -#define MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE 256 -#endif - -#ifndef MBED_CONF_DRIVERS_UART_SERIAL_TXBUF_SIZE -#define MBED_CONF_DRIVERS_UART_SERIAL_TXBUF_SIZE 256 -#endif - -namespace mbed { -/** - * \defgroup drivers_UARTSerial UARTSerial class - * \ingroup drivers-public-api-uart - * @{ - */ - -/** Class providing buffered UART communication functionality using separate circular buffer for send and receive channels - * - */ - -class - MBED_DEPRECATED_SINCE( - "mbed-os-6.0.0", - "Use BufferedSerial instead." - ) UARTSerial : private SerialBase, public FileHandle, private NonCopyable { - -public: - - /** @deprecated - * Create a UARTSerial port, connected to the specified transmit and receive pins, with a particular baud rate. - * @param tx Transmit pin - * @param rx Receive pin - * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - UARTSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); - - /** @deprecated - * Create a UARTSerial port, connected to the specified transmit and receive pins, with a particular baud rate. - * @param static_pinmap reference to structure which holds static pinmap - * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - UARTSerial(const serial_pinmap_t &static_pinmap, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); - - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual ~UARTSerial(); - - /** @deprecated - * Equivalent to POSIX poll(). Derived from FileHandle. - * Provides a mechanism to multiplex input/output over a set of file handles. - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual short poll(short events) const; - - /* Resolve ambiguities versus our private SerialBase - * (for writable, spelling differs, but just in case) - */ - using FileHandle::readable; - using FileHandle::writable; - - /** @deprecated - * Write the contents of a buffer to a file - * - * Follows POSIX semantics: - * - * * if blocking, block until all data is written - * * if no data can be written, and non-blocking set, return -EAGAIN - * * if some data can be written, and non-blocking set, write partial - * - * @param buffer The buffer to write from - * @param length The number of bytes to write - * @return The number of bytes written, negative error on failure - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual ssize_t write(const void *buffer, size_t length); - - /** @deprecated - * Read the contents of a file into a buffer - * - * Follows POSIX semantics: - * - * * if no data is available, and non-blocking set return -EAGAIN - * * if no data is available, and blocking set, wait until data is available - * * If any data is available, call returns immediately - * - * @param buffer The buffer to read in to - * @param length The number of bytes to read - * @return The number of bytes read, 0 at end of file, negative error on failure - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual ssize_t read(void *buffer, size_t length); - - /** @deprecated - * Close a file - * - * @return 0 on success, negative error code on failure - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual int close(); - - /** @deprecated - * Check if the file in an interactive terminal device - * - * @return True if the file is a terminal - * @return False if the file is not a terminal - * @return Negative error code on failure - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual int isatty(); - - /** @deprecated - * Move the file position to a given offset from from a given location - * - * Not valid for a device type FileHandle like UARTSerial. - * In case of UARTSerial, returns ESPIPE - * - * @param offset The offset from whence to move to - * @param whence The start of where to seek - * SEEK_SET to start from beginning of file, - * SEEK_CUR to start from current position in file, - * SEEK_END to start from end of file - * @return The new offset of the file, negative error code on failure - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual off_t seek(off_t offset, int whence); - - /** @deprecated - * Flush any buffers associated with the file - * - * @return 0 on success, negative error code on failure - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual int sync(); - - /** @deprecated - * Set blocking or non-blocking mode - * The default is blocking. - * - * @param blocking true for blocking mode, false for non-blocking mode. - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual int set_blocking(bool blocking) - { - _blocking = blocking; - return 0; - } - - /** @deprecated - * Check current blocking or non-blocking mode for file operations. - * - * @return true for blocking mode, false for non-blocking mode. - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual bool is_blocking() const - { - return _blocking; - } - - /** @deprecated - * Enable or disable input - * - * Control enabling of device for input. This is primarily intended - * for temporary power-saving; the overall ability of the device to operate for - * input and/or output may be fixed at creation time, but this call can - * allow input to be temporarily disabled to permit power saving without - * losing device state. - * - * @param enabled true to enable input, false to disable. - * - * @return 0 on success - * @return Negative error code on failure - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual int enable_input(bool enabled); - - /** @deprecated - * Enable or disable output - * - * Control enabling of device for output. This is primarily intended - * for temporary power-saving; the overall ability of the device to operate for - * input and/or output may be fixed at creation time, but this call can - * allow output to be temporarily disabled to permit power saving without - * losing device state. - * - * @param enabled true to enable output, false to disable. - * - * @return 0 on success - * @return Negative error code on failure - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual int enable_output(bool enabled); - - /** @deprecated - * Register a callback on state change of the file. - * - * The specified callback will be called on state changes such as when - * the file can be written to or read from. - * - * The callback may be called in an interrupt context and should not - * perform expensive operations. - * - * Note! This is not intended as an attach-like asynchronous api, but rather - * as a building block for constructing such functionality. - * - * The exact timing of when the registered function - * is called is not guaranteed and susceptible to change. It should be used - * as a cue to make read/write/poll calls to find the current state. - * - * @param func Function to call on state change - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - virtual void sigio(Callback func); - - /** @deprecated - * Setup interrupt handler for DCD line - * - * If DCD line is connected, an IRQ handler will be setup. - * Does nothing if DCD is NC, i.e., not connected. - * - * @param dcd_pin Pin-name for DCD - * @param active_high a boolean set to true if DCD polarity is active low - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - void set_data_carrier_detect(PinName dcd_pin, bool active_high = false); - - /** @deprecated - * Set the baud rate - * - * @param baud The baud rate - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - void set_baud(int baud); - - // Expose private SerialBase::Parity as UARTSerial::Parity - using SerialBase::Parity; - // In C++11, we wouldn't need to also have using directives for each value - using SerialBase::None; - using SerialBase::Odd; - using SerialBase::Even; - using SerialBase::Forced1; - using SerialBase::Forced0; - - /** @deprecated - * Set the transmission format used by the serial port - * - * @param bits The number of bits in a word (5-8; default = 8) - * @param parity The parity used (None, Odd, Even, Forced1, Forced0; default = None) - * @param stop_bits The number of stop bits (1 or 2; default = 1) - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - void set_format(int bits = 8, Parity parity = UARTSerial::None, int stop_bits = 1); - -#if DEVICE_SERIAL_FC - // For now use the base enum - but in future we may have extra options - // such as XON/XOFF or manual GPIO RTSCTS. - using SerialBase::Flow; - // In C++11, we wouldn't need to also have using directives for each value - using SerialBase::Disabled; - using SerialBase::RTS; - using SerialBase::CTS; - using SerialBase::RTSCTS; - - /** @deprecated - * Set the flow control type on the serial port - * - * @param type the flow control type (Disabled, RTS, CTS, RTSCTS) - * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS) - * @param flow2 the second flow control pin (CTS for RTSCTS) - */ - MBED_DEPRECATED("The class has been deprecated and will be removed in the future.") - void set_flow_control(Flow type, PinName flow1 = NC, PinName flow2 = NC); -#endif - -private: - - /** @deprecated - * SerialBase lock override - */ - virtual void lock(void); - - /** @deprecated - * SerialBase unlock override - */ - virtual void unlock(void); - - /** @deprecated - * Acquire mutex - */ - virtual void api_lock(void); - - /** @deprecated - * Release mutex - */ - virtual void api_unlock(void); - - /** @deprecated - * Unbuffered write - invoked when write called from critical section - */ - ssize_t write_unbuffered(const char *buf_ptr, size_t length); - - void enable_rx_irq(); - void disable_rx_irq(); - void enable_tx_irq(); - void disable_tx_irq(); - - /** @deprecated - * Software serial buffers - * By default buffer size is 256 for TX and 256 for RX. Configurable through mbed_app.json - */ - CircularBuffer _rxbuf; - CircularBuffer _txbuf; - - PlatformMutex _mutex; - - Callback _sigio_cb; - - bool _blocking; - bool _tx_irq_enabled; - bool _rx_irq_enabled; - bool _tx_enabled; - bool _rx_enabled; - InterruptIn *_dcd_irq; - - /** @deprecated - * Device Hanged up - * Determines if the device hanged up on us. - * - * @return True, if hanged up - */ - bool hup() const; - - /** @deprecated - * ISRs for serial - * Routines to handle interrupts on serial pins. - * Copies data into Circular Buffer. - * Reports the state change to File handle. - */ - void tx_irq(void); - void rx_irq(void); - - void wake(void); - - void dcd_irq(void); - -}; - -/** @}*/ - -} //namespace mbed - -#endif //(DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) -#endif //MBED_UARTSERIAL_H diff --git a/drivers/source/RawSerial.cpp b/drivers/source/RawSerial.cpp deleted file mode 100644 index 8fab077..0000000 --- a/drivers/source/RawSerial.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "drivers/RawSerial.h" -#include - - -#if DEVICE_SERIAL - -#define STRING_STACK_LIMIT 120 - -namespace mbed { - -RawSerial::RawSerial(PinName tx, PinName rx, int baud) : SerialBase(tx, rx, baud) -{ - // No lock needed in the constructor -} - -int RawSerial::getc() -{ - lock(); - int ret = _base_getc(); - unlock(); - return ret; -} - -int RawSerial::putc(int c) -{ - lock(); - int ret = _base_putc(c); - unlock(); - return ret; -} - -int RawSerial::puts(const char *str) -{ - lock(); - while (*str) { - putc(*str ++); - } - unlock(); - return 0; -} - -// Experimental support for printf in RawSerial. No Stream inheritance -// means we can't call printf() directly, so we use sprintf() instead. -// We only call malloc() for the sprintf() buffer if the buffer -// length is above a certain threshold, otherwise we use just the stack. -int RawSerial::printf(const char *format, ...) -{ - std::va_list arg; - va_start(arg, format); - int len = this->vprintf(format, arg); - va_end(arg); - return len; -} - -int RawSerial::vprintf(const char *format, std::va_list arg) -{ - lock(); - // ARMCC microlib does not properly handle a size of 0. - // As a workaround supply a dummy buffer with a size of 1. - char dummy_buf[1]; - int len = vsnprintf(dummy_buf, sizeof(dummy_buf), format, arg); - if (len < STRING_STACK_LIMIT) { - char temp[STRING_STACK_LIMIT]; - vsprintf(temp, format, arg); - puts(temp); - } else { - char *temp = new char[len + 1]; - vsprintf(temp, format, arg); - puts(temp); - delete[] temp; - } - unlock(); - return len; -} - -/** Acquire exclusive access to this serial port - */ -void RawSerial::lock() -{ - // No lock used - external synchronization required -} - -/** Release exclusive access to this serial port - */ -void RawSerial::unlock() -{ - // No lock used - external synchronization required -} - -} // namespace mbed - -#endif diff --git a/drivers/source/Serial.cpp b/drivers/source/Serial.cpp deleted file mode 100644 index d76672d..0000000 --- a/drivers/source/Serial.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "drivers/Serial.h" - -#if DEVICE_SERIAL - -namespace mbed { - -Serial::Serial(PinName tx, PinName rx, const char *name, int baud) : SerialBase(tx, rx, baud), Stream(name) -{ -} - -Serial::Serial(const serial_pinmap_t &static_pinmap, const char *name, int baud) : SerialBase(static_pinmap, baud), Stream(name) -{ -} - -Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream() -{ -} - -Serial::Serial(const serial_pinmap_t &static_pinmap, int baud): SerialBase(static_pinmap, baud), Stream() -{ -} - -int Serial::_getc() -{ - // Mutex is already held - return _base_getc(); -} - -int Serial::_putc(int c) -{ - // Mutex is already held - return _base_putc(c); -} - -void Serial::lock() -{ - _mutex.lock(); -} - -void Serial::unlock() -{ - _mutex.unlock(); -} - -} // namespace mbed - -#endif diff --git a/drivers/source/UARTSerial.cpp b/drivers/source/UARTSerial.cpp deleted file mode 100644 index e9036e3..0000000 --- a/drivers/source/UARTSerial.cpp +++ /dev/null @@ -1,400 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "drivers/UARTSerial.h" - -#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) - -#include "platform/mbed_poll.h" -#include "platform/mbed_thread.h" - -namespace mbed { - -UARTSerial::UARTSerial(PinName tx, PinName rx, int baud) : - SerialBase(tx, rx, baud), - _blocking(true), - _tx_irq_enabled(false), - _rx_irq_enabled(false), - _tx_enabled(true), - _rx_enabled(true), - _dcd_irq(NULL) -{ - /* Attatch IRQ routines to the serial device. */ - enable_rx_irq(); -} - -UARTSerial::UARTSerial(const serial_pinmap_t &static_pinmap, int baud) : - SerialBase(static_pinmap, baud), - _blocking(true), - _tx_irq_enabled(false), - _rx_irq_enabled(false), - _tx_enabled(true), - _rx_enabled(true), - _dcd_irq(NULL) -{ - /* Attatch IRQ routines to the serial device. */ - enable_rx_irq(); -} - -UARTSerial::~UARTSerial() -{ - delete _dcd_irq; -} - -void UARTSerial::dcd_irq() -{ - wake(); -} - -void UARTSerial::set_baud(int baud) -{ - SerialBase::baud(baud); -} - -void UARTSerial::set_data_carrier_detect(PinName dcd_pin, bool active_high) -{ - delete _dcd_irq; - _dcd_irq = nullptr; - - if (dcd_pin != NC) { - _dcd_irq = new InterruptIn(dcd_pin); - if (active_high) { - _dcd_irq->fall(callback(this, &UARTSerial::dcd_irq)); - } else { - _dcd_irq->rise(callback(this, &UARTSerial::dcd_irq)); - } - } -} - -void UARTSerial::set_format(int bits, Parity parity, int stop_bits) -{ - api_lock(); - SerialBase::format(bits, parity, stop_bits); - api_unlock(); -} - -#if DEVICE_SERIAL_FC -void UARTSerial::set_flow_control(Flow type, PinName flow1, PinName flow2) -{ - api_lock(); - SerialBase::set_flow_control(type, flow1, flow2); - api_unlock(); -} -#endif - -int UARTSerial::close() -{ - /* Does not let us pass a file descriptor. So how to close ? - * Also, does it make sense to close a device type file descriptor*/ - return 0; -} - -int UARTSerial::isatty() -{ - return 1; - -} - -off_t UARTSerial::seek(off_t offset, int whence) -{ - /*XXX lseek can be done theoratically, but is it sane to mark positions on a dynamically growing/shrinking - * buffer system (from an interrupt context) */ - return -ESPIPE; -} - -int UARTSerial::sync() -{ - api_lock(); - - while (!_txbuf.empty()) { - api_unlock(); - // Doing better than wait would require TxIRQ to also do wake() when becoming empty. Worth it? - thread_sleep_for(1); - api_lock(); - } - - api_unlock(); - - return 0; -} - -void UARTSerial::sigio(Callback func) -{ - core_util_critical_section_enter(); - _sigio_cb = func; - if (_sigio_cb) { - short current_events = poll(0x7FFF); - if (current_events) { - _sigio_cb(); - } - } - core_util_critical_section_exit(); -} - -/* Special synchronous write designed to work from critical section, such - * as in mbed_error_vprintf. - */ -ssize_t UARTSerial::write_unbuffered(const char *buf_ptr, size_t length) -{ - while (!_txbuf.empty()) { - tx_irq(); - } - - for (size_t data_written = 0; data_written < length; data_written++) { - SerialBase::_base_putc(*buf_ptr++); - } - - return length; -} - -ssize_t UARTSerial::write(const void *buffer, size_t length) -{ - size_t data_written = 0; - const char *buf_ptr = static_cast(buffer); - - if (length == 0) { - return 0; - } - - if (core_util_in_critical_section()) { - return write_unbuffered(buf_ptr, length); - } - - api_lock(); - - // Unlike read, we should write the whole thing if blocking. POSIX only - // allows partial as a side-effect of signal handling; it normally tries to - // write everything if blocking. Without signals we can always write all. - while (data_written < length) { - - if (_txbuf.full()) { - if (!_blocking) { - break; - } - do { - api_unlock(); - thread_sleep_for(1); // XXX todo - proper wait? - api_lock(); - } while (_txbuf.full()); - } - - while (data_written < length && !_txbuf.full()) { - _txbuf.push(*buf_ptr++); - data_written++; - } - - core_util_critical_section_enter(); - if (_tx_enabled && !_tx_irq_enabled) { - UARTSerial::tx_irq(); // only write to hardware in one place - if (!_txbuf.empty()) { - enable_tx_irq(); - } - } - core_util_critical_section_exit(); - } - - api_unlock(); - - return data_written != 0 ? (ssize_t) data_written : (ssize_t) - EAGAIN; -} - -ssize_t UARTSerial::read(void *buffer, size_t length) -{ - size_t data_read = 0; - - char *ptr = static_cast(buffer); - - if (length == 0) { - return 0; - } - - api_lock(); - - while (_rxbuf.empty()) { - if (!_blocking) { - api_unlock(); - return -EAGAIN; - } - api_unlock(); - thread_sleep_for(1); // XXX todo - proper wait? - api_lock(); - } - - while (data_read < length && !_rxbuf.empty()) { - _rxbuf.pop(*ptr++); - data_read++; - } - - core_util_critical_section_enter(); - if (_rx_enabled && !_rx_irq_enabled) { - UARTSerial::rx_irq(); // only read from hardware in one place - if (!_rxbuf.full()) { - enable_rx_irq(); - } - } - core_util_critical_section_exit(); - - api_unlock(); - - return data_read; -} - -bool UARTSerial::hup() const -{ - return _dcd_irq && _dcd_irq->read() != 0; -} - -void UARTSerial::wake() -{ - if (_sigio_cb) { - _sigio_cb(); - } -} - -short UARTSerial::poll(short events) const -{ - - short revents = 0; - /* Check the Circular Buffer if space available for writing out */ - - - if (!_rxbuf.empty()) { - revents |= POLLIN; - } - - /* POLLHUP and POLLOUT are mutually exclusive */ - if (hup()) { - revents |= POLLHUP; - } else if (!_txbuf.full()) { - revents |= POLLOUT; - } - - /*TODO Handle other event types */ - - return revents; -} - -void UARTSerial::lock() -{ - // This is the override for SerialBase. - // No lock required as we only use SerialBase from interrupt or from - // inside our own critical section. -} - -void UARTSerial::unlock() -{ - // This is the override for SerialBase. -} - -void UARTSerial::api_lock(void) -{ - _mutex.lock(); -} - -void UARTSerial::api_unlock(void) -{ - _mutex.unlock(); -} - -void UARTSerial::rx_irq(void) -{ - bool was_empty = _rxbuf.empty(); - - /* Fill in the receive buffer if the peripheral is readable - * and receive buffer is not full. */ - while (!_rxbuf.full() && SerialBase::readable()) { - char data = SerialBase::_base_getc(); - _rxbuf.push(data); - } - - if (_rx_irq_enabled && _rxbuf.full()) { - disable_rx_irq(); - } - - /* Report the File handler that data is ready to be read from the buffer. */ - if (was_empty && !_rxbuf.empty()) { - wake(); - } -} - -// Also called from write to start transfer -void UARTSerial::tx_irq(void) -{ - bool was_full = _txbuf.full(); - char data; - - /* Write to the peripheral if there is something to write - * and if the peripheral is available to write. */ - while (SerialBase::writeable() && _txbuf.pop(data)) { - SerialBase::_base_putc(data); - } - - if (_tx_irq_enabled && _txbuf.empty()) { - disable_tx_irq(); - } - - /* Report the File handler that data can be written to peripheral. */ - if (was_full && !_txbuf.full() && !hup()) { - wake(); - } -} - -/* These are all called from critical section */ -void UARTSerial::enable_rx_irq() -{ - SerialBase::attach(callback(this, &UARTSerial::rx_irq), RxIrq); - _rx_irq_enabled = true; -} - -void UARTSerial::disable_rx_irq() -{ - SerialBase::attach(nullptr, RxIrq); - _rx_irq_enabled = false; -} - -void UARTSerial::enable_tx_irq() -{ - SerialBase::attach(callback(this, &UARTSerial::tx_irq), TxIrq); - _tx_irq_enabled = true; -} - -void UARTSerial::disable_tx_irq() -{ - SerialBase::attach(nullptr, TxIrq); - _tx_irq_enabled = false; -} - -int UARTSerial::enable_input(bool enabled) -{ - api_lock(); - SerialBase::enable_input(enabled); - api_unlock(); - - return 0; -} - -int UARTSerial::enable_output(bool enabled) -{ - api_lock(); - SerialBase::enable_output(enabled); - api_unlock(); - - return 0; -} - -} //namespace mbed - -#endif //(DEVICE_SERIAL && DEVICE_INTERRUPTIN) diff --git a/features/FEATURE_BLE/targets/TARGET_Maxim/MaximBLE.cpp b/features/FEATURE_BLE/targets/TARGET_Maxim/MaximBLE.cpp index 619c514..b0d08cb 100644 --- a/features/FEATURE_BLE/targets/TARGET_Maxim/MaximBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_Maxim/MaximBLE.cpp @@ -79,7 +79,6 @@ static DigitalIn _cts(BT_RTS); static DigitalIn _clk(BT_CLK); static DigitalOut _shutdown(BT_RST, 0); -static Serial _uart(BT_TX, BT_RX, 115200); #else /* Current mbed SPI API does not support HW slave selects. Configured in HCI driver. */ static DigitalOut _csn(HCI_CSN, 1); diff --git a/mbed.h b/mbed.h index 350826c..7c8da3c 100644 --- a/mbed.h +++ b/mbed.h @@ -62,15 +62,12 @@ #include "drivers/AnalogIn.h" #include "drivers/AnalogOut.h" #include "drivers/PwmOut.h" -#include "drivers/Serial.h" #include "drivers/SPI.h" #include "drivers/SPISlave.h" #include "drivers/I2C.h" #include "drivers/I2CSlave.h" #include "drivers/CAN.h" -#include "drivers/RawSerial.h" #include "drivers/UnbufferedSerial.h" -#include "drivers/UARTSerial.h" #include "drivers/BufferedSerial.h" #include "drivers/FlashIAP.h" #include "drivers/MbedCRC.h"