Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:02dd72d1d465 1 /* mbed Microcontroller Library
borlanic 0:02dd72d1d465 2 * Copyright (c) 2006-2013 ARM Limited
borlanic 0:02dd72d1d465 3 *
borlanic 0:02dd72d1d465 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:02dd72d1d465 5 * you may not use this file except in compliance with the License.
borlanic 0:02dd72d1d465 6 * You may obtain a copy of the License at
borlanic 0:02dd72d1d465 7 *
borlanic 0:02dd72d1d465 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:02dd72d1d465 9 *
borlanic 0:02dd72d1d465 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:02dd72d1d465 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:02dd72d1d465 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:02dd72d1d465 13 * See the License for the specific language governing permissions and
borlanic 0:02dd72d1d465 14 * limitations under the License.
borlanic 0:02dd72d1d465 15 */
borlanic 0:02dd72d1d465 16 #ifndef MBED_SERIAL_H
borlanic 0:02dd72d1d465 17 #define MBED_SERIAL_H
borlanic 0:02dd72d1d465 18
borlanic 0:02dd72d1d465 19 #include "platform/platform.h"
borlanic 0:02dd72d1d465 20
borlanic 0:02dd72d1d465 21 #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY)
borlanic 0:02dd72d1d465 22
borlanic 0:02dd72d1d465 23 #include "Stream.h"
borlanic 0:02dd72d1d465 24 #include "SerialBase.h"
borlanic 0:02dd72d1d465 25 #include "PlatformMutex.h"
borlanic 0:02dd72d1d465 26 #include "serial_api.h"
borlanic 0:02dd72d1d465 27 #include "platform/NonCopyable.h"
borlanic 0:02dd72d1d465 28
borlanic 0:02dd72d1d465 29 namespace mbed {
borlanic 0:02dd72d1d465 30 /** \addtogroup drivers */
borlanic 0:02dd72d1d465 31
borlanic 0:02dd72d1d465 32 /** A serial port (UART) for communication with other serial devices
borlanic 0:02dd72d1d465 33 *
borlanic 0:02dd72d1d465 34 * Can be used for Full Duplex communication, or Simplex by specifying
borlanic 0:02dd72d1d465 35 * one pin as NC (Not Connected)
borlanic 0:02dd72d1d465 36 *
borlanic 0:02dd72d1d465 37 * @note Synchronization level: Thread safe
borlanic 0:02dd72d1d465 38 *
borlanic 0:02dd72d1d465 39 * Example:
borlanic 0:02dd72d1d465 40 * @code
borlanic 0:02dd72d1d465 41 * // Print "Hello World" to the PC
borlanic 0:02dd72d1d465 42 *
borlanic 0:02dd72d1d465 43 * #include "mbed.h"
borlanic 0:02dd72d1d465 44 *
borlanic 0:02dd72d1d465 45 * Serial pc(USBTX, USBRX);
borlanic 0:02dd72d1d465 46 *
borlanic 0:02dd72d1d465 47 * int main() {
borlanic 0:02dd72d1d465 48 * pc.printf("Hello World\n");
borlanic 0:02dd72d1d465 49 * }
borlanic 0:02dd72d1d465 50 * @endcode
borlanic 0:02dd72d1d465 51 * @ingroup drivers
borlanic 0:02dd72d1d465 52 */
borlanic 0:02dd72d1d465 53 class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
borlanic 0:02dd72d1d465 54
borlanic 0:02dd72d1d465 55 public:
borlanic 0:02dd72d1d465 56 #if DEVICE_SERIAL_ASYNCH
borlanic 0:02dd72d1d465 57 using SerialBase::read;
borlanic 0:02dd72d1d465 58 using SerialBase::write;
borlanic 0:02dd72d1d465 59 #endif
borlanic 0:02dd72d1d465 60
borlanic 0:02dd72d1d465 61 /** Create a Serial port, connected to the specified transmit and receive pins
borlanic 0:02dd72d1d465 62 *
borlanic 0:02dd72d1d465 63 * @param tx Transmit pin
borlanic 0:02dd72d1d465 64 * @param rx Receive pin
borlanic 0:02dd72d1d465 65 * @param name The name of the stream associated with this serial port (optional)
borlanic 0:02dd72d1d465 66 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
borlanic 0:02dd72d1d465 67 *
borlanic 0:02dd72d1d465 68 * @note
borlanic 0:02dd72d1d465 69 * Either tx or rx may be specified as NC if unused
borlanic 0:02dd72d1d465 70 */
borlanic 0:02dd72d1d465 71 Serial(PinName tx, PinName rx, const char *name=NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
borlanic 0:02dd72d1d465 72
borlanic 0:02dd72d1d465 73
borlanic 0:02dd72d1d465 74 /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
borlanic 0:02dd72d1d465 75 *
borlanic 0:02dd72d1d465 76 * @param tx Transmit pin
borlanic 0:02dd72d1d465 77 * @param rx Receive pin
borlanic 0:02dd72d1d465 78 * @param baud The baud rate of the serial port
borlanic 0:02dd72d1d465 79 *
borlanic 0:02dd72d1d465 80 * @note
borlanic 0:02dd72d1d465 81 * Either tx or rx may be specified as NC if unused
borlanic 0:02dd72d1d465 82 */
borlanic 0:02dd72d1d465 83 Serial(PinName tx, PinName rx, int baud);
borlanic 0:02dd72d1d465 84
borlanic 0:02dd72d1d465 85 /* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through
borlanic 0:02dd72d1d465 86 * the calls from the SerialBase instead for backwards compatibility. This problem is
borlanic 0:02dd72d1d465 87 * part of why Stream and Serial should be deprecated.
borlanic 0:02dd72d1d465 88 */
borlanic 0:02dd72d1d465 89 bool readable()
borlanic 0:02dd72d1d465 90 {
borlanic 0:02dd72d1d465 91 return SerialBase::readable();
borlanic 0:02dd72d1d465 92 }
borlanic 0:02dd72d1d465 93 bool writable()
borlanic 0:02dd72d1d465 94 {
borlanic 0:02dd72d1d465 95 return SerialBase::writeable();
borlanic 0:02dd72d1d465 96 }
borlanic 0:02dd72d1d465 97 bool writeable()
borlanic 0:02dd72d1d465 98 {
borlanic 0:02dd72d1d465 99 return SerialBase::writeable();
borlanic 0:02dd72d1d465 100 }
borlanic 0:02dd72d1d465 101
borlanic 0:02dd72d1d465 102 protected:
borlanic 0:02dd72d1d465 103 virtual int _getc();
borlanic 0:02dd72d1d465 104 virtual int _putc(int c);
borlanic 0:02dd72d1d465 105 virtual void lock();
borlanic 0:02dd72d1d465 106 virtual void unlock();
borlanic 0:02dd72d1d465 107
borlanic 0:02dd72d1d465 108 PlatformMutex _mutex;
borlanic 0:02dd72d1d465 109 };
borlanic 0:02dd72d1d465 110
borlanic 0:02dd72d1d465 111 } // namespace mbed
borlanic 0:02dd72d1d465 112
borlanic 0:02dd72d1d465 113 #endif
borlanic 0:02dd72d1d465 114
borlanic 0:02dd72d1d465 115 #endif