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 #include "SerialBase.h"
elessair 0:7e2bd16f80af 17 #include "wait_api.h"
elessair 0:7e2bd16f80af 18
elessair 0:7e2bd16f80af 19 #if DEVICE_SERIAL
elessair 0:7e2bd16f80af 20
elessair 0:7e2bd16f80af 21 namespace mbed {
elessair 0:7e2bd16f80af 22
elessair 0:7e2bd16f80af 23 SerialBase::SerialBase(PinName tx, PinName rx) : _serial(), _baud(9600) {
elessair 0:7e2bd16f80af 24 serial_init(&_serial, tx, rx);
elessair 0:7e2bd16f80af 25 serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this);
elessair 0:7e2bd16f80af 26 }
elessair 0:7e2bd16f80af 27
elessair 0:7e2bd16f80af 28 void SerialBase::baud(int baudrate) {
elessair 0:7e2bd16f80af 29 serial_baud(&_serial, baudrate);
elessair 0:7e2bd16f80af 30 _baud = baudrate;
elessair 0:7e2bd16f80af 31 }
elessair 0:7e2bd16f80af 32
elessair 0:7e2bd16f80af 33 void SerialBase::format(int bits, Parity parity, int stop_bits) {
elessair 0:7e2bd16f80af 34 serial_format(&_serial, bits, (SerialParity)parity, stop_bits);
elessair 0:7e2bd16f80af 35 }
elessair 0:7e2bd16f80af 36
elessair 0:7e2bd16f80af 37 int SerialBase::readable() {
elessair 0:7e2bd16f80af 38 return serial_readable(&_serial);
elessair 0:7e2bd16f80af 39 }
elessair 0:7e2bd16f80af 40
elessair 0:7e2bd16f80af 41
elessair 0:7e2bd16f80af 42 int SerialBase::writeable() {
elessair 0:7e2bd16f80af 43 return serial_writable(&_serial);
elessair 0:7e2bd16f80af 44 }
elessair 0:7e2bd16f80af 45
elessair 0:7e2bd16f80af 46 void SerialBase::attach(void (*fptr)(void), IrqType type) {
elessair 0:7e2bd16f80af 47 if (fptr) {
elessair 0:7e2bd16f80af 48 _irq[type].attach(fptr);
elessair 0:7e2bd16f80af 49 serial_irq_set(&_serial, (SerialIrq)type, 1);
elessair 0:7e2bd16f80af 50 } else {
elessair 0:7e2bd16f80af 51 serial_irq_set(&_serial, (SerialIrq)type, 0);
elessair 0:7e2bd16f80af 52 }
elessair 0:7e2bd16f80af 53 }
elessair 0:7e2bd16f80af 54
elessair 0:7e2bd16f80af 55 void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
elessair 0:7e2bd16f80af 56 SerialBase *handler = (SerialBase*)id;
elessair 0:7e2bd16f80af 57 handler->_irq[irq_type].call();
elessair 0:7e2bd16f80af 58 }
elessair 0:7e2bd16f80af 59
elessair 0:7e2bd16f80af 60 int SerialBase::_base_getc() {
elessair 0:7e2bd16f80af 61 return serial_getc(&_serial);
elessair 0:7e2bd16f80af 62 }
elessair 0:7e2bd16f80af 63
elessair 0:7e2bd16f80af 64 int SerialBase::_base_putc(int c) {
elessair 0:7e2bd16f80af 65 serial_putc(&_serial, c);
elessair 0:7e2bd16f80af 66 return c;
elessair 0:7e2bd16f80af 67 }
elessair 0:7e2bd16f80af 68
elessair 0:7e2bd16f80af 69 void SerialBase::send_break() {
elessair 0:7e2bd16f80af 70 // Wait for 1.5 frames before clearing the break condition
elessair 0:7e2bd16f80af 71 // This will have different effects on our platforms, but should
elessair 0:7e2bd16f80af 72 // ensure that we keep the break active for at least one frame.
elessair 0:7e2bd16f80af 73 // We consider a full frame (1 start bit + 8 data bits bits +
elessair 0:7e2bd16f80af 74 // 1 parity bit + 2 stop bits = 12 bits) for computation.
elessair 0:7e2bd16f80af 75 // One bit time (in us) = 1000000/_baud
elessair 0:7e2bd16f80af 76 // Twelve bits: 12000000/baud delay
elessair 0:7e2bd16f80af 77 // 1.5 frames: 18000000/baud delay
elessair 0:7e2bd16f80af 78 serial_break_set(&_serial);
elessair 0:7e2bd16f80af 79 wait_us(18000000/_baud);
elessair 0:7e2bd16f80af 80 serial_break_clear(&_serial);
elessair 0:7e2bd16f80af 81 }
elessair 0:7e2bd16f80af 82
elessair 0:7e2bd16f80af 83 #if DEVICE_SERIAL_FC
elessair 0:7e2bd16f80af 84 void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) {
elessair 0:7e2bd16f80af 85 FlowControl flow_type = (FlowControl)type;
elessair 0:7e2bd16f80af 86 switch(type) {
elessair 0:7e2bd16f80af 87 case RTS:
elessair 0:7e2bd16f80af 88 serial_set_flow_control(&_serial, flow_type, flow1, NC);
elessair 0:7e2bd16f80af 89 break;
elessair 0:7e2bd16f80af 90
elessair 0:7e2bd16f80af 91 case CTS:
elessair 0:7e2bd16f80af 92 serial_set_flow_control(&_serial, flow_type, NC, flow1);
elessair 0:7e2bd16f80af 93 break;
elessair 0:7e2bd16f80af 94
elessair 0:7e2bd16f80af 95 case RTSCTS:
elessair 0:7e2bd16f80af 96 case Disabled:
elessair 0:7e2bd16f80af 97 serial_set_flow_control(&_serial, flow_type, flow1, flow2);
elessair 0:7e2bd16f80af 98 break;
elessair 0:7e2bd16f80af 99
elessair 0:7e2bd16f80af 100 default:
elessair 0:7e2bd16f80af 101 break;
elessair 0:7e2bd16f80af 102 }
elessair 0:7e2bd16f80af 103 }
elessair 0:7e2bd16f80af 104 #endif
elessair 0:7e2bd16f80af 105
elessair 0:7e2bd16f80af 106 } // namespace mbed
elessair 0:7e2bd16f80af 107
elessair 0:7e2bd16f80af 108 #endif