Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2006-2013 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:380207fcb5c1 5 * you may not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 6 * You may obtain a copy of the License at
borlanic 0:380207fcb5c1 7 *
borlanic 0:380207fcb5c1 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 9 *
borlanic 0:380207fcb5c1 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:380207fcb5c1 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 13 * See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 14 * limitations under the License.
borlanic 0:380207fcb5c1 15 */
borlanic 0:380207fcb5c1 16 #ifndef MBED_RAW_SERIAL_H
borlanic 0:380207fcb5c1 17 #define MBED_RAW_SERIAL_H
borlanic 0:380207fcb5c1 18
borlanic 0:380207fcb5c1 19 #include "platform/platform.h"
borlanic 0:380207fcb5c1 20
borlanic 0:380207fcb5c1 21 #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY)
borlanic 0:380207fcb5c1 22
borlanic 0:380207fcb5c1 23 #include "drivers/SerialBase.h"
borlanic 0:380207fcb5c1 24 #include "hal/serial_api.h"
borlanic 0:380207fcb5c1 25 #include "platform/NonCopyable.h"
borlanic 0:380207fcb5c1 26
borlanic 0:380207fcb5c1 27 namespace mbed {
borlanic 0:380207fcb5c1 28 /** \addtogroup drivers */
borlanic 0:380207fcb5c1 29
borlanic 0:380207fcb5c1 30 /** A serial port (UART) for communication with other serial devices
borlanic 0:380207fcb5c1 31 * This is a variation of the Serial class that doesn't use streams,
borlanic 0:380207fcb5c1 32 * thus making it safe to use in interrupt handlers with the RTOS.
borlanic 0:380207fcb5c1 33 *
borlanic 0:380207fcb5c1 34 * Can be used for Full Duplex communication, or Simplex by specifying
borlanic 0:380207fcb5c1 35 * one pin as NC (Not Connected)
borlanic 0:380207fcb5c1 36 *
borlanic 0:380207fcb5c1 37 * @note Synchronization level: Not protected
borlanic 0:380207fcb5c1 38 *
borlanic 0:380207fcb5c1 39 * Example:
borlanic 0:380207fcb5c1 40 * @code
borlanic 0:380207fcb5c1 41 * // Send a char to the PC
borlanic 0:380207fcb5c1 42 *
borlanic 0:380207fcb5c1 43 * #include "mbed.h"
borlanic 0:380207fcb5c1 44 *
borlanic 0:380207fcb5c1 45 * RawSerial pc(USBTX, USBRX);
borlanic 0:380207fcb5c1 46 *
borlanic 0:380207fcb5c1 47 * int main() {
borlanic 0:380207fcb5c1 48 * pc.putc('A');
borlanic 0:380207fcb5c1 49 * }
borlanic 0:380207fcb5c1 50 * @endcode
borlanic 0:380207fcb5c1 51 * @ingroup drivers
borlanic 0:380207fcb5c1 52 */
borlanic 0:380207fcb5c1 53 class RawSerial: public SerialBase, private NonCopyable<RawSerial> {
borlanic 0:380207fcb5c1 54
borlanic 0:380207fcb5c1 55 public:
borlanic 0:380207fcb5c1 56 /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
borlanic 0:380207fcb5c1 57 *
borlanic 0:380207fcb5c1 58 * @param tx Transmit pin
borlanic 0:380207fcb5c1 59 * @param rx Receive pin
borlanic 0:380207fcb5c1 60 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
borlanic 0:380207fcb5c1 61 *
borlanic 0:380207fcb5c1 62 * @note
borlanic 0:380207fcb5c1 63 * Either tx or rx may be specified as NC if unused
borlanic 0:380207fcb5c1 64 */
borlanic 0:380207fcb5c1 65 RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
borlanic 0:380207fcb5c1 66
borlanic 0:380207fcb5c1 67 /** Write a char to the serial port
borlanic 0:380207fcb5c1 68 *
borlanic 0:380207fcb5c1 69 * @param c The char to write
borlanic 0:380207fcb5c1 70 *
borlanic 0:380207fcb5c1 71 * @returns The written char or -1 if an error occurred
borlanic 0:380207fcb5c1 72 */
borlanic 0:380207fcb5c1 73 int putc(int c);
borlanic 0:380207fcb5c1 74
borlanic 0:380207fcb5c1 75 /** Read a char from the serial port
borlanic 0:380207fcb5c1 76 *
borlanic 0:380207fcb5c1 77 * @returns The char read from the serial port
borlanic 0:380207fcb5c1 78 */
borlanic 0:380207fcb5c1 79 int getc();
borlanic 0:380207fcb5c1 80
borlanic 0:380207fcb5c1 81 /** Write a string to the serial port
borlanic 0:380207fcb5c1 82 *
borlanic 0:380207fcb5c1 83 * @param str The string to write
borlanic 0:380207fcb5c1 84 *
borlanic 0:380207fcb5c1 85 * @returns 0 if the write succeeds, EOF for error
borlanic 0:380207fcb5c1 86 */
borlanic 0:380207fcb5c1 87 int puts(const char *str);
borlanic 0:380207fcb5c1 88
borlanic 0:380207fcb5c1 89 int printf(const char *format, ...);
borlanic 0:380207fcb5c1 90
borlanic 0:380207fcb5c1 91 protected:
borlanic 0:380207fcb5c1 92
borlanic 0:380207fcb5c1 93 /* Acquire exclusive access to this serial port
borlanic 0:380207fcb5c1 94 */
borlanic 0:380207fcb5c1 95 virtual void lock(void);
borlanic 0:380207fcb5c1 96
borlanic 0:380207fcb5c1 97 /* Release exclusive access to this serial port
borlanic 0:380207fcb5c1 98 */
borlanic 0:380207fcb5c1 99 virtual void unlock(void);
borlanic 0:380207fcb5c1 100 };
borlanic 0:380207fcb5c1 101
borlanic 0:380207fcb5c1 102 } // namespace mbed
borlanic 0:380207fcb5c1 103
borlanic 0:380207fcb5c1 104 #endif
borlanic 0:380207fcb5c1 105
borlanic 0:380207fcb5c1 106 #endif