Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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