BA
/
BaBoRo_test2
Backup 1
mbed-os/drivers/RawSerial.h@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New 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_RAW_SERIAL_H |
borlanic | 0:02dd72d1d465 | 17 | #define MBED_RAW_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 "drivers/SerialBase.h" |
borlanic | 0:02dd72d1d465 | 24 | #include "hal/serial_api.h" |
borlanic | 0:02dd72d1d465 | 25 | #include "platform/NonCopyable.h" |
borlanic | 0:02dd72d1d465 | 26 | |
borlanic | 0:02dd72d1d465 | 27 | namespace mbed { |
borlanic | 0:02dd72d1d465 | 28 | /** \addtogroup drivers */ |
borlanic | 0:02dd72d1d465 | 29 | |
borlanic | 0:02dd72d1d465 | 30 | /** A serial port (UART) for communication with other serial devices |
borlanic | 0:02dd72d1d465 | 31 | * This is a variation of the Serial class that doesn't use streams, |
borlanic | 0:02dd72d1d465 | 32 | * thus making it safe to use in interrupt handlers with the RTOS. |
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: Not protected |
borlanic | 0:02dd72d1d465 | 38 | * |
borlanic | 0:02dd72d1d465 | 39 | * Example: |
borlanic | 0:02dd72d1d465 | 40 | * @code |
borlanic | 0:02dd72d1d465 | 41 | * // Send a char to the PC |
borlanic | 0:02dd72d1d465 | 42 | * |
borlanic | 0:02dd72d1d465 | 43 | * #include "mbed.h" |
borlanic | 0:02dd72d1d465 | 44 | * |
borlanic | 0:02dd72d1d465 | 45 | * RawSerial pc(USBTX, USBRX); |
borlanic | 0:02dd72d1d465 | 46 | * |
borlanic | 0:02dd72d1d465 | 47 | * int main() { |
borlanic | 0:02dd72d1d465 | 48 | * pc.putc('A'); |
borlanic | 0:02dd72d1d465 | 49 | * } |
borlanic | 0:02dd72d1d465 | 50 | * @endcode |
borlanic | 0:02dd72d1d465 | 51 | * @ingroup drivers |
borlanic | 0:02dd72d1d465 | 52 | */ |
borlanic | 0:02dd72d1d465 | 53 | class RawSerial: public SerialBase, private NonCopyable<RawSerial> { |
borlanic | 0:02dd72d1d465 | 54 | |
borlanic | 0:02dd72d1d465 | 55 | public: |
borlanic | 0:02dd72d1d465 | 56 | /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud. |
borlanic | 0:02dd72d1d465 | 57 | * |
borlanic | 0:02dd72d1d465 | 58 | * @param tx Transmit pin |
borlanic | 0:02dd72d1d465 | 59 | * @param rx Receive pin |
borlanic | 0:02dd72d1d465 | 60 | * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) |
borlanic | 0:02dd72d1d465 | 61 | * |
borlanic | 0:02dd72d1d465 | 62 | * @note |
borlanic | 0:02dd72d1d465 | 63 | * Either tx or rx may be specified as NC if unused |
borlanic | 0:02dd72d1d465 | 64 | */ |
borlanic | 0:02dd72d1d465 | 65 | RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); |
borlanic | 0:02dd72d1d465 | 66 | |
borlanic | 0:02dd72d1d465 | 67 | /** Write a char to the serial port |
borlanic | 0:02dd72d1d465 | 68 | * |
borlanic | 0:02dd72d1d465 | 69 | * @param c The char to write |
borlanic | 0:02dd72d1d465 | 70 | * |
borlanic | 0:02dd72d1d465 | 71 | * @returns The written char or -1 if an error occurred |
borlanic | 0:02dd72d1d465 | 72 | */ |
borlanic | 0:02dd72d1d465 | 73 | int putc(int c); |
borlanic | 0:02dd72d1d465 | 74 | |
borlanic | 0:02dd72d1d465 | 75 | /** Read a char from the serial port |
borlanic | 0:02dd72d1d465 | 76 | * |
borlanic | 0:02dd72d1d465 | 77 | * @returns The char read from the serial port |
borlanic | 0:02dd72d1d465 | 78 | */ |
borlanic | 0:02dd72d1d465 | 79 | int getc(); |
borlanic | 0:02dd72d1d465 | 80 | |
borlanic | 0:02dd72d1d465 | 81 | /** Write a string to the serial port |
borlanic | 0:02dd72d1d465 | 82 | * |
borlanic | 0:02dd72d1d465 | 83 | * @param str The string to write |
borlanic | 0:02dd72d1d465 | 84 | * |
borlanic | 0:02dd72d1d465 | 85 | * @returns 0 if the write succeeds, EOF for error |
borlanic | 0:02dd72d1d465 | 86 | */ |
borlanic | 0:02dd72d1d465 | 87 | int puts(const char *str); |
borlanic | 0:02dd72d1d465 | 88 | |
borlanic | 0:02dd72d1d465 | 89 | int printf(const char *format, ...); |
borlanic | 0:02dd72d1d465 | 90 | |
borlanic | 0:02dd72d1d465 | 91 | protected: |
borlanic | 0:02dd72d1d465 | 92 | |
borlanic | 0:02dd72d1d465 | 93 | /* Acquire exclusive access to this serial port |
borlanic | 0:02dd72d1d465 | 94 | */ |
borlanic | 0:02dd72d1d465 | 95 | virtual void lock(void); |
borlanic | 0:02dd72d1d465 | 96 | |
borlanic | 0:02dd72d1d465 | 97 | /* Release exclusive access to this serial port |
borlanic | 0:02dd72d1d465 | 98 | */ |
borlanic | 0:02dd72d1d465 | 99 | virtual void unlock(void); |
borlanic | 0:02dd72d1d465 | 100 | }; |
borlanic | 0:02dd72d1d465 | 101 | |
borlanic | 0:02dd72d1d465 | 102 | } // namespace mbed |
borlanic | 0:02dd72d1d465 | 103 | |
borlanic | 0:02dd72d1d465 | 104 | #endif |
borlanic | 0:02dd72d1d465 | 105 | |
borlanic | 0:02dd72d1d465 | 106 | #endif |