mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

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