Fork of mbed for KL05Z based smart sensor which has no crystal on the board, so MCG FEI mode is required.

Dependents:   smart-sensor-KL05Z-debug

Fork of mbed-src by Ermanno Brusadin

Committer:
ebrus
Date:
Wed Jul 27 18:35:32 2016 +0000
Revision:
0:0a673c671a56
4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ebrus 0:0a673c671a56 1 /* mbed Microcontroller Library
ebrus 0:0a673c671a56 2 * Copyright (c) 2006-2013 ARM Limited
ebrus 0:0a673c671a56 3 *
ebrus 0:0a673c671a56 4 * Licensed under the Apache License, Version 2.0 (the "License");
ebrus 0:0a673c671a56 5 * you may not use this file except in compliance with the License.
ebrus 0:0a673c671a56 6 * You may obtain a copy of the License at
ebrus 0:0a673c671a56 7 *
ebrus 0:0a673c671a56 8 * http://www.apache.org/licenses/LICENSE-2.0
ebrus 0:0a673c671a56 9 *
ebrus 0:0a673c671a56 10 * Unless required by applicable law or agreed to in writing, software
ebrus 0:0a673c671a56 11 * distributed under the License is distributed on an "AS IS" BASIS,
ebrus 0:0a673c671a56 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ebrus 0:0a673c671a56 13 * See the License for the specific language governing permissions and
ebrus 0:0a673c671a56 14 * limitations under the License.
ebrus 0:0a673c671a56 15 */
ebrus 0:0a673c671a56 16 #ifndef MBED_SERIALBASE_H
ebrus 0:0a673c671a56 17 #define MBED_SERIALBASE_H
ebrus 0:0a673c671a56 18
ebrus 0:0a673c671a56 19 #include "platform.h"
ebrus 0:0a673c671a56 20
ebrus 0:0a673c671a56 21 #if DEVICE_SERIAL
ebrus 0:0a673c671a56 22
ebrus 0:0a673c671a56 23 #include "Stream.h"
ebrus 0:0a673c671a56 24 #include "FunctionPointer.h"
ebrus 0:0a673c671a56 25 #include "serial_api.h"
ebrus 0:0a673c671a56 26
ebrus 0:0a673c671a56 27 namespace mbed {
ebrus 0:0a673c671a56 28
ebrus 0:0a673c671a56 29 /** A base class for serial port implementations
ebrus 0:0a673c671a56 30 * Can't be instantiated directly (use Serial or RawSerial)
ebrus 0:0a673c671a56 31 */
ebrus 0:0a673c671a56 32 class SerialBase {
ebrus 0:0a673c671a56 33
ebrus 0:0a673c671a56 34 public:
ebrus 0:0a673c671a56 35 /** Set the baud rate of the serial port
ebrus 0:0a673c671a56 36 *
ebrus 0:0a673c671a56 37 * @param baudrate The baudrate of the serial port (default = 9600).
ebrus 0:0a673c671a56 38 */
ebrus 0:0a673c671a56 39 void baud(int baudrate);
ebrus 0:0a673c671a56 40
ebrus 0:0a673c671a56 41 enum Parity {
ebrus 0:0a673c671a56 42 None = 0,
ebrus 0:0a673c671a56 43 Odd,
ebrus 0:0a673c671a56 44 Even,
ebrus 0:0a673c671a56 45 Forced1,
ebrus 0:0a673c671a56 46 Forced0
ebrus 0:0a673c671a56 47 };
ebrus 0:0a673c671a56 48
ebrus 0:0a673c671a56 49 enum IrqType {
ebrus 0:0a673c671a56 50 RxIrq = 0,
ebrus 0:0a673c671a56 51 TxIrq
ebrus 0:0a673c671a56 52 };
ebrus 0:0a673c671a56 53
ebrus 0:0a673c671a56 54 enum Flow {
ebrus 0:0a673c671a56 55 Disabled = 0,
ebrus 0:0a673c671a56 56 RTS,
ebrus 0:0a673c671a56 57 CTS,
ebrus 0:0a673c671a56 58 RTSCTS
ebrus 0:0a673c671a56 59 };
ebrus 0:0a673c671a56 60
ebrus 0:0a673c671a56 61 /** Set the transmission format used by the serial port
ebrus 0:0a673c671a56 62 *
ebrus 0:0a673c671a56 63 * @param bits The number of bits in a word (5-8; default = 8)
ebrus 0:0a673c671a56 64 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
ebrus 0:0a673c671a56 65 * @param stop The number of stop bits (1 or 2; default = 1)
ebrus 0:0a673c671a56 66 */
ebrus 0:0a673c671a56 67 void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
ebrus 0:0a673c671a56 68
ebrus 0:0a673c671a56 69 /** Determine if there is a character available to read
ebrus 0:0a673c671a56 70 *
ebrus 0:0a673c671a56 71 * @returns
ebrus 0:0a673c671a56 72 * 1 if there is a character available to read,
ebrus 0:0a673c671a56 73 * 0 otherwise
ebrus 0:0a673c671a56 74 */
ebrus 0:0a673c671a56 75 int readable();
ebrus 0:0a673c671a56 76
ebrus 0:0a673c671a56 77 /** Determine if there is space available to write a character
ebrus 0:0a673c671a56 78 *
ebrus 0:0a673c671a56 79 * @returns
ebrus 0:0a673c671a56 80 * 1 if there is space to write a character,
ebrus 0:0a673c671a56 81 * 0 otherwise
ebrus 0:0a673c671a56 82 */
ebrus 0:0a673c671a56 83 int writeable();
ebrus 0:0a673c671a56 84
ebrus 0:0a673c671a56 85 /** Attach a function to call whenever a serial interrupt is generated
ebrus 0:0a673c671a56 86 *
ebrus 0:0a673c671a56 87 * @param fptr A pointer to a void function, or 0 to set as none
ebrus 0:0a673c671a56 88 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
ebrus 0:0a673c671a56 89 */
ebrus 0:0a673c671a56 90 void attach(void (*fptr)(void), IrqType type=RxIrq);
ebrus 0:0a673c671a56 91
ebrus 0:0a673c671a56 92 /** Attach a member function to call whenever a serial interrupt is generated
ebrus 0:0a673c671a56 93 *
ebrus 0:0a673c671a56 94 * @param tptr pointer to the object to call the member function on
ebrus 0:0a673c671a56 95 * @param mptr pointer to the member function to be called
ebrus 0:0a673c671a56 96 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
ebrus 0:0a673c671a56 97 */
ebrus 0:0a673c671a56 98 template<typename T>
ebrus 0:0a673c671a56 99 void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
ebrus 0:0a673c671a56 100 if((mptr != NULL) && (tptr != NULL)) {
ebrus 0:0a673c671a56 101 _irq[type].attach(tptr, mptr);
ebrus 0:0a673c671a56 102 serial_irq_set(&_serial, (SerialIrq)type, 1);
ebrus 0:0a673c671a56 103 }
ebrus 0:0a673c671a56 104 }
ebrus 0:0a673c671a56 105
ebrus 0:0a673c671a56 106 /** Generate a break condition on the serial line
ebrus 0:0a673c671a56 107 */
ebrus 0:0a673c671a56 108 void send_break();
ebrus 0:0a673c671a56 109
ebrus 0:0a673c671a56 110 #if DEVICE_SERIAL_FC
ebrus 0:0a673c671a56 111 /** Set the flow control type on the serial port
ebrus 0:0a673c671a56 112 *
ebrus 0:0a673c671a56 113 * @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
ebrus 0:0a673c671a56 114 * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
ebrus 0:0a673c671a56 115 * @param flow2 the second flow control pin (CTS for RTSCTS)
ebrus 0:0a673c671a56 116 */
ebrus 0:0a673c671a56 117 void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
ebrus 0:0a673c671a56 118 #endif
ebrus 0:0a673c671a56 119
ebrus 0:0a673c671a56 120 static void _irq_handler(uint32_t id, SerialIrq irq_type);
ebrus 0:0a673c671a56 121
ebrus 0:0a673c671a56 122 protected:
ebrus 0:0a673c671a56 123 SerialBase(PinName tx, PinName rx);
ebrus 0:0a673c671a56 124 virtual ~SerialBase() {
ebrus 0:0a673c671a56 125 }
ebrus 0:0a673c671a56 126
ebrus 0:0a673c671a56 127 int _base_getc();
ebrus 0:0a673c671a56 128 int _base_putc(int c);
ebrus 0:0a673c671a56 129
ebrus 0:0a673c671a56 130 serial_t _serial;
ebrus 0:0a673c671a56 131 FunctionPointer _irq[2];
ebrus 0:0a673c671a56 132 int _baud;
ebrus 0:0a673c671a56 133 };
ebrus 0:0a673c671a56 134
ebrus 0:0a673c671a56 135 } // namespace mbed
ebrus 0:0a673c671a56 136
ebrus 0:0a673c671a56 137 #endif
ebrus 0:0a673c671a56 138
ebrus 0:0a673c671a56 139 #endif