Christian Weiß / Mbed 2 deprecated Diplomarbeit_MW_CW

Dependencies:   mbed

Committer:
Wizo
Date:
Thu Nov 15 17:57:01 2018 +0000
Revision:
1:dfa0f59e8d2c
Parent:
0:afeca64a6543
Diplomarbeit_MW_CW

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martwerl 0:afeca64a6543 1 /* mbed Microcontroller Library
martwerl 0:afeca64a6543 2 * Copyright (c) 2006-2013 ARM Limited
martwerl 0:afeca64a6543 3 *
martwerl 0:afeca64a6543 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
martwerl 0:afeca64a6543 5 * of this software and associated documentation files (the "Software"), to deal
martwerl 0:afeca64a6543 6 * in the Software without restriction, including without limitation the rights
martwerl 0:afeca64a6543 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
martwerl 0:afeca64a6543 8 * copies of the Software, and to permit persons to whom the Software is
martwerl 0:afeca64a6543 9 * furnished to do so, subject to the following conditions:
martwerl 0:afeca64a6543 10 *
martwerl 0:afeca64a6543 11 * The above copyright notice and this permission notice shall be included in
martwerl 0:afeca64a6543 12 * all copies or substantial portions of the Software.
martwerl 0:afeca64a6543 13 *
martwerl 0:afeca64a6543 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
martwerl 0:afeca64a6543 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
martwerl 0:afeca64a6543 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
martwerl 0:afeca64a6543 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
martwerl 0:afeca64a6543 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
martwerl 0:afeca64a6543 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
martwerl 0:afeca64a6543 20 * SOFTWARE.
martwerl 0:afeca64a6543 21 */
martwerl 0:afeca64a6543 22 #ifndef MBED_SERIAL_H
martwerl 0:afeca64a6543 23 #define MBED_SERIAL_H
martwerl 0:afeca64a6543 24
martwerl 0:afeca64a6543 25 #include "platform.h"
martwerl 0:afeca64a6543 26
martwerl 0:afeca64a6543 27 #if DEVICE_SERIAL
martwerl 0:afeca64a6543 28
martwerl 0:afeca64a6543 29 #include "Stream.h"
martwerl 0:afeca64a6543 30 #include "FunctionPointer.h"
martwerl 0:afeca64a6543 31 #include "serial_api.h"
martwerl 0:afeca64a6543 32
martwerl 0:afeca64a6543 33 namespace mbed {
martwerl 0:afeca64a6543 34
martwerl 0:afeca64a6543 35 /** A serial port (UART) for communication with other serial devices
martwerl 0:afeca64a6543 36 *
martwerl 0:afeca64a6543 37 * Can be used for Full Duplex communication, or Simplex by specifying
martwerl 0:afeca64a6543 38 * one pin as NC (Not Connected)
martwerl 0:afeca64a6543 39 *
martwerl 0:afeca64a6543 40 * Example:
martwerl 0:afeca64a6543 41 * @code
martwerl 0:afeca64a6543 42 * // Print "Hello World" to the PC
martwerl 0:afeca64a6543 43 *
martwerl 0:afeca64a6543 44 * #include "mbed.h"
martwerl 0:afeca64a6543 45 *
martwerl 0:afeca64a6543 46 * Serial pc(USBTX, USBRX);
martwerl 0:afeca64a6543 47 *
martwerl 0:afeca64a6543 48 * int main() {
martwerl 0:afeca64a6543 49 * pc.printf("Hello World\n");
martwerl 0:afeca64a6543 50 * }
martwerl 0:afeca64a6543 51 * @endcode
martwerl 0:afeca64a6543 52 */
martwerl 0:afeca64a6543 53 class Serial : public Stream {
martwerl 0:afeca64a6543 54
martwerl 0:afeca64a6543 55 public:
martwerl 0:afeca64a6543 56 /** Create a Serial port, connected to the specified transmit and receive pins
martwerl 0:afeca64a6543 57 *
martwerl 0:afeca64a6543 58 * @param tx Transmit pin
martwerl 0:afeca64a6543 59 * @param rx Receive pin
martwerl 0:afeca64a6543 60 *
martwerl 0:afeca64a6543 61 * @note
martwerl 0:afeca64a6543 62 * Either tx or rx may be specified as NC if unused
martwerl 0:afeca64a6543 63 */
martwerl 0:afeca64a6543 64 Serial(PinName tx, PinName rx, const char *name=NULL);
martwerl 0:afeca64a6543 65
martwerl 0:afeca64a6543 66 /** Set the baud rate of the serial port
martwerl 0:afeca64a6543 67 *
martwerl 0:afeca64a6543 68 * @param baudrate The baudrate of the serial port (default = 9600).
martwerl 0:afeca64a6543 69 */
martwerl 0:afeca64a6543 70 void baud(int baudrate);
martwerl 0:afeca64a6543 71
martwerl 0:afeca64a6543 72 enum Parity {
martwerl 0:afeca64a6543 73 None = 0,
martwerl 0:afeca64a6543 74 Odd,
martwerl 0:afeca64a6543 75 Even,
martwerl 0:afeca64a6543 76 Forced1,
martwerl 0:afeca64a6543 77 Forced0
martwerl 0:afeca64a6543 78 };
martwerl 0:afeca64a6543 79
martwerl 0:afeca64a6543 80 enum IrqType {
martwerl 0:afeca64a6543 81 RxIrq = 0,
martwerl 0:afeca64a6543 82 TxIrq
martwerl 0:afeca64a6543 83 };
martwerl 0:afeca64a6543 84
martwerl 0:afeca64a6543 85 /** Set the transmission format used by the Serial port
martwerl 0:afeca64a6543 86 *
martwerl 0:afeca64a6543 87 * @param bits The number of bits in a word (5-8; default = 8)
martwerl 0:afeca64a6543 88 * @param parity The parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None)
martwerl 0:afeca64a6543 89 * @param stop The number of stop bits (1 or 2; default = 1)
martwerl 0:afeca64a6543 90 */
martwerl 0:afeca64a6543 91 void format(int bits = 8, Parity parity=Serial::None, int stop_bits=1);
martwerl 0:afeca64a6543 92
martwerl 0:afeca64a6543 93 /** Determine if there is a character available to read
martwerl 0:afeca64a6543 94 *
martwerl 0:afeca64a6543 95 * @returns
martwerl 0:afeca64a6543 96 * 1 if there is a character available to read,
martwerl 0:afeca64a6543 97 * 0 otherwise
martwerl 0:afeca64a6543 98 */
martwerl 0:afeca64a6543 99 int readable();
martwerl 0:afeca64a6543 100
martwerl 0:afeca64a6543 101 /** Determine if there is space available to write a character
martwerl 0:afeca64a6543 102 *
martwerl 0:afeca64a6543 103 * @returns
martwerl 0:afeca64a6543 104 * 1 if there is space to write a character,
martwerl 0:afeca64a6543 105 * 0 otherwise
martwerl 0:afeca64a6543 106 */
martwerl 0:afeca64a6543 107 int writeable();
martwerl 0:afeca64a6543 108
martwerl 0:afeca64a6543 109 /** Attach a function to call whenever a serial interrupt is generated
martwerl 0:afeca64a6543 110 *
martwerl 0:afeca64a6543 111 * @param fptr A pointer to a void function, or 0 to set as none
martwerl 0:afeca64a6543 112 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
martwerl 0:afeca64a6543 113 */
martwerl 0:afeca64a6543 114 void attach(void (*fptr)(void), IrqType type=RxIrq);
martwerl 0:afeca64a6543 115
martwerl 0:afeca64a6543 116 /** Attach a member function to call whenever a serial interrupt is generated
martwerl 0:afeca64a6543 117 *
martwerl 0:afeca64a6543 118 * @param tptr pointer to the object to call the member function on
martwerl 0:afeca64a6543 119 * @param mptr pointer to the member function to be called
martwerl 0:afeca64a6543 120 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
martwerl 0:afeca64a6543 121 */
martwerl 0:afeca64a6543 122 template<typename T>
martwerl 0:afeca64a6543 123 void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
martwerl 0:afeca64a6543 124 if((mptr != NULL) && (tptr != NULL)) {
martwerl 0:afeca64a6543 125 _irq[type].attach(tptr, mptr);
martwerl 0:afeca64a6543 126 serial_irq_set(&_serial, (SerialIrq)type, 1);
martwerl 0:afeca64a6543 127 }
martwerl 0:afeca64a6543 128 }
martwerl 0:afeca64a6543 129
martwerl 0:afeca64a6543 130 static void _irq_handler(uint32_t id, SerialIrq irq_type);
martwerl 0:afeca64a6543 131
martwerl 0:afeca64a6543 132 protected:
martwerl 0:afeca64a6543 133 virtual int _getc();
martwerl 0:afeca64a6543 134 virtual int _putc(int c);
martwerl 0:afeca64a6543 135
martwerl 0:afeca64a6543 136 serial_t _serial;
martwerl 0:afeca64a6543 137 FunctionPointer _irq[2];
martwerl 0:afeca64a6543 138 };
martwerl 0:afeca64a6543 139
martwerl 0:afeca64a6543 140 } // namespace mbed
martwerl 0:afeca64a6543 141
martwerl 0:afeca64a6543 142 #endif
martwerl 0:afeca64a6543 143
martwerl 0:afeca64a6543 144 #endif
martwerl 0:afeca64a6543 145