Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-dev/drivers/Serial.h@2:5acdd8565d02, 2017-02-25 (annotated)
- Committer:
- elmot
- Date:
- Sat Feb 25 00:23:53 2017 +0000
- Revision:
- 2:5acdd8565d02
- Parent:
- 1:d0dfbce63a89
Ready to show
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| elmot | 1:d0dfbce63a89 | 1 | /* mbed Microcontroller Library |
| elmot | 1:d0dfbce63a89 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| elmot | 1:d0dfbce63a89 | 3 | * |
| elmot | 1:d0dfbce63a89 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| elmot | 1:d0dfbce63a89 | 5 | * you may not use this file except in compliance with the License. |
| elmot | 1:d0dfbce63a89 | 6 | * You may obtain a copy of the License at |
| elmot | 1:d0dfbce63a89 | 7 | * |
| elmot | 1:d0dfbce63a89 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| elmot | 1:d0dfbce63a89 | 9 | * |
| elmot | 1:d0dfbce63a89 | 10 | * Unless required by applicable law or agreed to in writing, software |
| elmot | 1:d0dfbce63a89 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| elmot | 1:d0dfbce63a89 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| elmot | 1:d0dfbce63a89 | 13 | * See the License for the specific language governing permissions and |
| elmot | 1:d0dfbce63a89 | 14 | * limitations under the License. |
| elmot | 1:d0dfbce63a89 | 15 | */ |
| elmot | 1:d0dfbce63a89 | 16 | #ifndef MBED_SERIAL_H |
| elmot | 1:d0dfbce63a89 | 17 | #define MBED_SERIAL_H |
| elmot | 1:d0dfbce63a89 | 18 | |
| elmot | 1:d0dfbce63a89 | 19 | #include "platform/platform.h" |
| elmot | 1:d0dfbce63a89 | 20 | |
| elmot | 1:d0dfbce63a89 | 21 | #if DEVICE_SERIAL |
| elmot | 1:d0dfbce63a89 | 22 | |
| elmot | 1:d0dfbce63a89 | 23 | #include "Stream.h" |
| elmot | 1:d0dfbce63a89 | 24 | #include "SerialBase.h" |
| elmot | 1:d0dfbce63a89 | 25 | #include "PlatformMutex.h" |
| elmot | 1:d0dfbce63a89 | 26 | #include "serial_api.h" |
| elmot | 1:d0dfbce63a89 | 27 | |
| elmot | 1:d0dfbce63a89 | 28 | namespace mbed { |
| elmot | 1:d0dfbce63a89 | 29 | /** \addtogroup drivers */ |
| elmot | 1:d0dfbce63a89 | 30 | /** @{*/ |
| elmot | 1:d0dfbce63a89 | 31 | |
| elmot | 1:d0dfbce63a89 | 32 | /** A serial port (UART) for communication with other serial devices |
| elmot | 1:d0dfbce63a89 | 33 | * |
| elmot | 1:d0dfbce63a89 | 34 | * Can be used for Full Duplex communication, or Simplex by specifying |
| elmot | 1:d0dfbce63a89 | 35 | * one pin as NC (Not Connected) |
| elmot | 1:d0dfbce63a89 | 36 | * |
| elmot | 1:d0dfbce63a89 | 37 | * @Note Synchronization level: Thread safe |
| elmot | 1:d0dfbce63a89 | 38 | * |
| elmot | 1:d0dfbce63a89 | 39 | * Example: |
| elmot | 1:d0dfbce63a89 | 40 | * @code |
| elmot | 1:d0dfbce63a89 | 41 | * // Print "Hello World" to the PC |
| elmot | 1:d0dfbce63a89 | 42 | * |
| elmot | 1:d0dfbce63a89 | 43 | * #include "mbed.h" |
| elmot | 1:d0dfbce63a89 | 44 | * |
| elmot | 1:d0dfbce63a89 | 45 | * Serial pc(USBTX, USBRX); |
| elmot | 1:d0dfbce63a89 | 46 | * |
| elmot | 1:d0dfbce63a89 | 47 | * int main() { |
| elmot | 1:d0dfbce63a89 | 48 | * pc.printf("Hello World\n"); |
| elmot | 1:d0dfbce63a89 | 49 | * } |
| elmot | 1:d0dfbce63a89 | 50 | * @endcode |
| elmot | 1:d0dfbce63a89 | 51 | */ |
| elmot | 1:d0dfbce63a89 | 52 | class Serial : public SerialBase, public Stream { |
| elmot | 1:d0dfbce63a89 | 53 | |
| elmot | 1:d0dfbce63a89 | 54 | public: |
| elmot | 1:d0dfbce63a89 | 55 | #if DEVICE_SERIAL_ASYNCH |
| elmot | 1:d0dfbce63a89 | 56 | using SerialBase::read; |
| elmot | 1:d0dfbce63a89 | 57 | using SerialBase::write; |
| elmot | 1:d0dfbce63a89 | 58 | #endif |
| elmot | 1:d0dfbce63a89 | 59 | |
| elmot | 1:d0dfbce63a89 | 60 | /** Create a Serial port, connected to the specified transmit and receive pins |
| elmot | 1:d0dfbce63a89 | 61 | * |
| elmot | 1:d0dfbce63a89 | 62 | * @param tx Transmit pin |
| elmot | 1:d0dfbce63a89 | 63 | * @param rx Receive pin |
| elmot | 1:d0dfbce63a89 | 64 | * @param name The name of the stream associated with this serial port (optional) |
| elmot | 1:d0dfbce63a89 | 65 | * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) |
| elmot | 1:d0dfbce63a89 | 66 | * |
| elmot | 1:d0dfbce63a89 | 67 | * @note |
| elmot | 1:d0dfbce63a89 | 68 | * Either tx or rx may be specified as NC if unused |
| elmot | 1:d0dfbce63a89 | 69 | */ |
| elmot | 1:d0dfbce63a89 | 70 | Serial(PinName tx, PinName rx, const char *name=NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); |
| elmot | 1:d0dfbce63a89 | 71 | |
| elmot | 1:d0dfbce63a89 | 72 | |
| elmot | 1:d0dfbce63a89 | 73 | /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud |
| elmot | 1:d0dfbce63a89 | 74 | * |
| elmot | 1:d0dfbce63a89 | 75 | * @param tx Transmit pin |
| elmot | 1:d0dfbce63a89 | 76 | * @param rx Receive pin |
| elmot | 1:d0dfbce63a89 | 77 | * @param baud The baud rate of the serial port |
| elmot | 1:d0dfbce63a89 | 78 | * |
| elmot | 1:d0dfbce63a89 | 79 | * @note |
| elmot | 1:d0dfbce63a89 | 80 | * Either tx or rx may be specified as NC if unused |
| elmot | 1:d0dfbce63a89 | 81 | */ |
| elmot | 1:d0dfbce63a89 | 82 | Serial(PinName tx, PinName rx, int baud); |
| elmot | 1:d0dfbce63a89 | 83 | |
| elmot | 1:d0dfbce63a89 | 84 | protected: |
| elmot | 1:d0dfbce63a89 | 85 | virtual int _getc(); |
| elmot | 1:d0dfbce63a89 | 86 | virtual int _putc(int c); |
| elmot | 1:d0dfbce63a89 | 87 | virtual void lock(); |
| elmot | 1:d0dfbce63a89 | 88 | virtual void unlock(); |
| elmot | 1:d0dfbce63a89 | 89 | |
| elmot | 1:d0dfbce63a89 | 90 | PlatformMutex _mutex; |
| elmot | 1:d0dfbce63a89 | 91 | }; |
| elmot | 1:d0dfbce63a89 | 92 | |
| elmot | 1:d0dfbce63a89 | 93 | } // namespace mbed |
| elmot | 1:d0dfbce63a89 | 94 | |
| elmot | 1:d0dfbce63a89 | 95 | #endif |
| elmot | 1:d0dfbce63a89 | 96 | |
| elmot | 1:d0dfbce63a89 | 97 | #endif |
| elmot | 1:d0dfbce63a89 | 98 | |
| elmot | 1:d0dfbce63a89 | 99 | /** @}*/ |