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