mbed library sources with internal temperature sensor for nucleo f401

Committer:
elessair
Date:
Sat Jan 17 18:03:58 2015 +0000
Revision:
0:7e2bd16f80af
nucleo f401re internal temperature added

Who changed what in which revision?

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