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 <stdio.h>
elessair 0:7e2bd16f80af 17 #include "mbed_interface.h"
elessair 0:7e2bd16f80af 18
elessair 0:7e2bd16f80af 19 #include "gpio_api.h"
elessair 0:7e2bd16f80af 20 #include "wait_api.h"
elessair 0:7e2bd16f80af 21 #include "semihost_api.h"
elessair 0:7e2bd16f80af 22 #include "mbed_error.h"
elessair 0:7e2bd16f80af 23 #include "toolchain.h"
elessair 0:7e2bd16f80af 24
elessair 0:7e2bd16f80af 25 #if DEVICE_SEMIHOST
elessair 0:7e2bd16f80af 26
elessair 0:7e2bd16f80af 27 // return true if a debugger is attached, indicating mbed interface is connected
elessair 0:7e2bd16f80af 28 int mbed_interface_connected(void) {
elessair 0:7e2bd16f80af 29 return semihost_connected();
elessair 0:7e2bd16f80af 30 }
elessair 0:7e2bd16f80af 31
elessair 0:7e2bd16f80af 32 int mbed_interface_reset(void) {
elessair 0:7e2bd16f80af 33 if (mbed_interface_connected()) {
elessair 0:7e2bd16f80af 34 semihost_reset();
elessair 0:7e2bd16f80af 35 return 0;
elessair 0:7e2bd16f80af 36 } else {
elessair 0:7e2bd16f80af 37 return -1;
elessair 0:7e2bd16f80af 38 }
elessair 0:7e2bd16f80af 39 }
elessair 0:7e2bd16f80af 40
elessair 0:7e2bd16f80af 41 WEAK int mbed_interface_uid(char *uid) {
elessair 0:7e2bd16f80af 42 if (mbed_interface_connected()) {
elessair 0:7e2bd16f80af 43 return semihost_uid(uid); // Returns 0 if successful, -1 on failure
elessair 0:7e2bd16f80af 44 } else {
elessair 0:7e2bd16f80af 45 uid[0] = 0;
elessair 0:7e2bd16f80af 46 return -1;
elessair 0:7e2bd16f80af 47 }
elessair 0:7e2bd16f80af 48 }
elessair 0:7e2bd16f80af 49
elessair 0:7e2bd16f80af 50 int mbed_interface_disconnect(void) {
elessair 0:7e2bd16f80af 51 int res;
elessair 0:7e2bd16f80af 52 if (mbed_interface_connected()) {
elessair 0:7e2bd16f80af 53 if ((res = semihost_disabledebug()) != 0)
elessair 0:7e2bd16f80af 54 return res;
elessair 0:7e2bd16f80af 55 while (mbed_interface_connected());
elessair 0:7e2bd16f80af 56 return 0;
elessair 0:7e2bd16f80af 57 } else {
elessair 0:7e2bd16f80af 58 return -1;
elessair 0:7e2bd16f80af 59 }
elessair 0:7e2bd16f80af 60 }
elessair 0:7e2bd16f80af 61
elessair 0:7e2bd16f80af 62 int mbed_interface_powerdown(void) {
elessair 0:7e2bd16f80af 63 int res;
elessair 0:7e2bd16f80af 64 if (mbed_interface_connected()) {
elessair 0:7e2bd16f80af 65 if ((res = semihost_powerdown()) != 0)
elessair 0:7e2bd16f80af 66 return res;
elessair 0:7e2bd16f80af 67 while (mbed_interface_connected());
elessair 0:7e2bd16f80af 68 return 0;
elessair 0:7e2bd16f80af 69 } else {
elessair 0:7e2bd16f80af 70 return -1;
elessair 0:7e2bd16f80af 71 }
elessair 0:7e2bd16f80af 72 }
elessair 0:7e2bd16f80af 73
elessair 0:7e2bd16f80af 74 // for backward compatibility
elessair 0:7e2bd16f80af 75 void mbed_reset(void) {
elessair 0:7e2bd16f80af 76 mbed_interface_reset();
elessair 0:7e2bd16f80af 77 }
elessair 0:7e2bd16f80af 78
elessair 0:7e2bd16f80af 79 WEAK int mbed_uid(char *uid) {
elessair 0:7e2bd16f80af 80 return mbed_interface_uid(uid);
elessair 0:7e2bd16f80af 81 }
elessair 0:7e2bd16f80af 82 #endif
elessair 0:7e2bd16f80af 83
elessair 0:7e2bd16f80af 84 WEAK void mbed_mac_address(char *mac) {
elessair 0:7e2bd16f80af 85 #if DEVICE_SEMIHOST
elessair 0:7e2bd16f80af 86 char uid[DEVICE_ID_LENGTH + 1];
elessair 0:7e2bd16f80af 87 int i;
elessair 0:7e2bd16f80af 88
elessair 0:7e2bd16f80af 89 // if we have a UID, extract the MAC
elessair 0:7e2bd16f80af 90 if (mbed_interface_uid(uid) == 0) {
elessair 0:7e2bd16f80af 91 char *p = uid;
elessair 0:7e2bd16f80af 92 #if defined(DEVICE_MAC_OFFSET)
elessair 0:7e2bd16f80af 93 p += DEVICE_MAC_OFFSET;
elessair 0:7e2bd16f80af 94 #endif
elessair 0:7e2bd16f80af 95 for (i=0; i<6; i++) {
elessair 0:7e2bd16f80af 96 int byte;
elessair 0:7e2bd16f80af 97 sscanf(p, "%2x", &byte);
elessair 0:7e2bd16f80af 98 mac[i] = byte;
elessair 0:7e2bd16f80af 99 p += 2;
elessair 0:7e2bd16f80af 100 }
elessair 0:7e2bd16f80af 101 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
elessair 0:7e2bd16f80af 102 } else { // else return a default MAC
elessair 0:7e2bd16f80af 103 #endif
elessair 0:7e2bd16f80af 104 mac[0] = 0x00;
elessair 0:7e2bd16f80af 105 mac[1] = 0x02;
elessair 0:7e2bd16f80af 106 mac[2] = 0xF7;
elessair 0:7e2bd16f80af 107 mac[3] = 0xF0;
elessair 0:7e2bd16f80af 108 mac[4] = 0x00;
elessair 0:7e2bd16f80af 109 mac[5] = 0x00;
elessair 0:7e2bd16f80af 110 #if DEVICE_SEMIHOST
elessair 0:7e2bd16f80af 111 }
elessair 0:7e2bd16f80af 112 #endif
elessair 0:7e2bd16f80af 113 }