This fork captures the mbed lib v125 for ease of integration into older projects.

Fork of mbed-dev by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RawSerial.h Source File

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.h"
00020 
00021 #if DEVICE_SERIAL
00022 
00023 #include "SerialBase.h"
00024 #include "serial_api.h"
00025 
00026 namespace mbed {
00027 
00028 /** A serial port (UART) for communication with other serial devices
00029  * This is a variation of the Serial class that doesn't use streams,
00030  * thus making it safe to use in interrupt handlers with the RTOS.
00031  *
00032  * Can be used for Full Duplex communication, or Simplex by specifying
00033  * one pin as NC (Not Connected)
00034  *
00035  * @Note Synchronization level: Not protected
00036  *
00037  * Example:
00038  * @code
00039  * // Send a char to the PC
00040  *
00041  * #include "mbed.h"
00042  *
00043  * RawSerial pc(USBTX, USBRX);
00044  *
00045  * int main() {
00046  *     pc.putc('A');
00047  * }
00048  * @endcode
00049  */
00050 class RawSerial: public SerialBase {
00051 
00052 public:
00053     /** Create a RawSerial port, connected to the specified transmit and receive pins
00054      *
00055      *  @param tx Transmit pin
00056      *  @param rx Receive pin
00057      *
00058      *  @note
00059      *    Either tx or rx may be specified as NC if unused
00060      */
00061     RawSerial(PinName tx, PinName rx);
00062 
00063     /** Write a char to the serial port
00064      *
00065      * @param c The char to write
00066      *
00067      * @returns The written char or -1 if an error occured
00068      */
00069     int putc(int c);
00070 
00071     /** Read a char from the serial port
00072      *
00073      * @returns The char read from the serial port
00074      */
00075     int getc();
00076 
00077     /** Write a string to the serial port
00078      *
00079      * @param str The string to write
00080      *
00081      * @returns 0 if the write succeeds, EOF for error
00082      */
00083     int puts(const char *str);
00084 
00085     int printf(const char *format, ...);
00086 
00087 protected:
00088 
00089     /** Acquire exclusive access to this serial port
00090      */
00091     virtual void lock(void);
00092 
00093     /** Release exclusive access to this serial port
00094      */
00095     virtual void unlock(void);
00096 };
00097 
00098 } // namespace mbed
00099 
00100 #endif
00101 
00102 #endif