Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Serial.h Source File

Serial.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_SERIAL_H
00017 #define MBED_SERIAL_H
00018 
00019 #include "platform/platform.h"
00020 
00021 #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY)
00022 
00023 #include "Stream.h"
00024 #include "SerialBase.h"
00025 #include "PlatformMutex.h"
00026 #include "serial_api.h"
00027 
00028 namespace mbed {
00029 /** \addtogroup drivers */
00030 
00031 /** A serial port (UART) for communication with other serial devices
00032  *
00033  * Can be used for Full Duplex communication, or Simplex by specifying
00034  * one pin as NC (Not Connected)
00035  *
00036  * @note Synchronization level: Thread safe
00037  *
00038  * Example:
00039  * @code
00040  * // Print "Hello World" to the PC
00041  *
00042  * #include "mbed.h"
00043  *
00044  * Serial pc(USBTX, USBRX);
00045  *
00046  * int main() {
00047  *     pc.printf("Hello World\n");
00048  * }
00049  * @endcode
00050  * @ingroup drivers
00051  */
00052 class Serial : public SerialBase, public Stream {
00053 
00054 public:
00055 #if DEVICE_SERIAL_ASYNCH
00056     using SerialBase::read;
00057     using SerialBase::write;
00058 #endif
00059 
00060     /** Create a Serial port, connected to the specified transmit and receive pins
00061      *
00062      *  @param tx Transmit pin
00063      *  @param rx Receive pin
00064      *  @param name The name of the stream associated with this serial port (optional)
00065      *  @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
00066      *
00067      *  @note
00068      *    Either tx or rx may be specified as NC if unused
00069      */
00070     Serial(PinName tx, PinName rx, const char *name=NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
00071 
00072 
00073     /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
00074      *
00075      *  @param tx Transmit pin
00076      *  @param rx Receive pin
00077      *  @param baud The baud rate of the serial port
00078      *
00079      *  @note
00080      *    Either tx or rx may be specified as NC if unused
00081      */
00082     Serial(PinName tx, PinName rx, int baud);
00083 
00084     /* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through
00085      * the calls from the SerialBase instead for backwards compatibility. This problem is
00086      * part of why Stream and Serial should be deprecated.
00087      */
00088     bool readable()
00089     {
00090         return SerialBase::readable();
00091     }
00092     bool writable()
00093     {
00094         return SerialBase::writeable();
00095     }
00096     bool writeable()
00097     {
00098         return SerialBase::writeable();
00099     }
00100 
00101 protected:
00102     virtual int _getc();
00103     virtual int _putc(int c);
00104     virtual void lock();
00105     virtual void unlock();
00106 
00107     PlatformMutex _mutex;
00108 };
00109 
00110 } // namespace mbed
00111 
00112 #endif
00113 
00114 #endif
00115