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