Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RawSerial.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_RAW_SERIAL_H 00017 #define MBED_RAW_SERIAL_H 00018 00019 #include "platform/platform.h" 00020 00021 #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY) 00022 00023 #include "drivers/SerialBase.h" 00024 #include "hal/serial_api.h" 00025 #include "platform/NonCopyable.h" 00026 00027 namespace mbed { 00028 /** \addtogroup drivers */ 00029 00030 /** A serial port (UART) for communication with other serial devices 00031 * This is a variation of the Serial class that doesn't use streams, 00032 * thus making it safe to use in interrupt handlers with the RTOS. 00033 * 00034 * Can be used for Full Duplex communication, or Simplex by specifying 00035 * one pin as NC (Not Connected) 00036 * 00037 * @note Synchronization level: Not protected 00038 * 00039 * Example: 00040 * @code 00041 * // Send a char to the PC 00042 * 00043 * #include "mbed.h" 00044 * 00045 * RawSerial pc(USBTX, USBRX); 00046 * 00047 * int main() { 00048 * pc.putc('A'); 00049 * } 00050 * @endcode 00051 * @ingroup drivers 00052 */ 00053 class RawSerial: public SerialBase, private NonCopyable<RawSerial> { 00054 00055 public: 00056 /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud. 00057 * 00058 * @param tx Transmit pin 00059 * @param rx Receive pin 00060 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) 00061 * 00062 * @note 00063 * Either tx or rx may be specified as NC if unused 00064 */ 00065 RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); 00066 00067 /** Write a char to the serial port 00068 * 00069 * @param c The char to write 00070 * 00071 * @returns The written char or -1 if an error occurred 00072 */ 00073 int putc(int c); 00074 00075 /** Read a char from the serial port 00076 * 00077 * @returns The char read from the serial port 00078 */ 00079 int getc(); 00080 00081 /** Write a string to the serial port 00082 * 00083 * @param str The string to write 00084 * 00085 * @returns 0 if the write succeeds, EOF for error 00086 */ 00087 int puts(const char *str); 00088 00089 int printf(const char *format, ...); 00090 00091 protected: 00092 00093 /* Acquire exclusive access to this serial port 00094 */ 00095 virtual void lock(void); 00096 00097 /* Release exclusive access to this serial port 00098 */ 00099 virtual void unlock(void); 00100 }; 00101 00102 } // namespace mbed 00103 00104 #endif 00105 00106 #endif
Generated on Tue Jul 12 2022 14:24:32 by
