mbed library for NZ32-SC151

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  * Example:
00036  * @code
00037  * // Send a char to the PC
00038  *
00039  * #include "mbed.h"
00040  *
00041  * RawSerial pc(USBTX, USBRX);
00042  *
00043  * int main() {
00044  *     pc.putc('A');
00045  * }
00046  * @endcode
00047  */
00048 class RawSerial: public SerialBase {
00049 
00050 public:
00051     /** Create a RawSerial port, connected to the specified transmit and receive pins
00052      *
00053      *  @param tx Transmit pin
00054      *  @param rx Receive pin
00055      *
00056      *  @note
00057      *    Either tx or rx may be specified as NC if unused
00058      */
00059     RawSerial(PinName tx, PinName rx);
00060 
00061     /** Write a char to the serial port
00062      *
00063      * @param c The char to write
00064      *
00065      * @returns The written char or -1 if an error occured
00066      */
00067     int putc(int c);
00068 
00069     /** Read a char from the serial port
00070      *
00071      * @returns The char read from the serial port
00072      */
00073     int getc();
00074 
00075     /** Write a string to the serial port
00076      *
00077      * @param str The string to write
00078      *
00079      * @returns 0 if the write succeeds, EOF for error
00080      */
00081     int puts(const char *str);
00082 
00083     int printf(const char *format, ...);
00084 };
00085 
00086 } // namespace mbed
00087 
00088 #endif
00089 
00090 #endif