mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Thu Sep 06 13:40:20 2018 +0100
Revision:
187:0387e8f68319
Parent:
184:08ed48f1de7f
Child:
189:f392fc9709a3
mbed-dev library. Release version 163

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /* mbed Microcontroller Library
<> 149:156823d33999 2 * Copyright (c) 2006-2013 ARM Limited
<> 149:156823d33999 3 *
<> 149:156823d33999 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 5 * you may not use this file except in compliance with the License.
<> 149:156823d33999 6 * You may obtain a copy of the License at
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 9 *
<> 149:156823d33999 10 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 13 * See the License for the specific language governing permissions and
<> 149:156823d33999 14 * limitations under the License.
<> 149:156823d33999 15 */
<> 149:156823d33999 16 #include <stdio.h>
<> 149:156823d33999 17 #include "platform/mbed_interface.h"
<> 149:156823d33999 18
<> 149:156823d33999 19 #include "hal/gpio_api.h"
<> 160:d5399cc887bb 20 #include "platform/mbed_wait_api.h"
<> 160:d5399cc887bb 21 #include "platform/mbed_semihost_api.h"
<> 149:156823d33999 22 #include "platform/mbed_error.h"
<> 160:d5399cc887bb 23 #include "platform/mbed_toolchain.h"
<> 149:156823d33999 24
<> 149:156823d33999 25 #if DEVICE_SEMIHOST
<> 149:156823d33999 26
<> 149:156823d33999 27 // return true if a debugger is attached, indicating mbed interface is connected
AnnaBridge 187:0387e8f68319 28 int mbed_interface_connected(void)
AnnaBridge 187:0387e8f68319 29 {
<> 149:156823d33999 30 return semihost_connected();
<> 149:156823d33999 31 }
<> 149:156823d33999 32
AnnaBridge 187:0387e8f68319 33 int mbed_interface_reset(void)
AnnaBridge 187:0387e8f68319 34 {
<> 149:156823d33999 35 if (mbed_interface_connected()) {
<> 149:156823d33999 36 semihost_reset();
<> 149:156823d33999 37 return 0;
<> 149:156823d33999 38 } else {
<> 149:156823d33999 39 return -1;
<> 149:156823d33999 40 }
<> 149:156823d33999 41 }
<> 149:156823d33999 42
AnnaBridge 187:0387e8f68319 43 WEAK int mbed_interface_uid(char *uid)
AnnaBridge 187:0387e8f68319 44 {
<> 149:156823d33999 45 if (mbed_interface_connected()) {
<> 149:156823d33999 46 return semihost_uid(uid); // Returns 0 if successful, -1 on failure
<> 149:156823d33999 47 } else {
<> 149:156823d33999 48 uid[0] = 0;
<> 149:156823d33999 49 return -1;
<> 149:156823d33999 50 }
<> 149:156823d33999 51 }
<> 149:156823d33999 52
AnnaBridge 187:0387e8f68319 53 int mbed_interface_disconnect(void)
AnnaBridge 187:0387e8f68319 54 {
<> 149:156823d33999 55 int res;
<> 149:156823d33999 56 if (mbed_interface_connected()) {
AnnaBridge 187:0387e8f68319 57 if ((res = semihost_disabledebug()) != 0) {
<> 149:156823d33999 58 return res;
AnnaBridge 187:0387e8f68319 59 }
<> 149:156823d33999 60 while (mbed_interface_connected());
<> 149:156823d33999 61 return 0;
<> 149:156823d33999 62 } else {
<> 149:156823d33999 63 return -1;
<> 149:156823d33999 64 }
<> 149:156823d33999 65 }
<> 149:156823d33999 66
AnnaBridge 187:0387e8f68319 67 int mbed_interface_powerdown(void)
AnnaBridge 187:0387e8f68319 68 {
<> 149:156823d33999 69 int res;
<> 149:156823d33999 70 if (mbed_interface_connected()) {
AnnaBridge 187:0387e8f68319 71 if ((res = semihost_powerdown()) != 0) {
<> 149:156823d33999 72 return res;
AnnaBridge 187:0387e8f68319 73 }
<> 149:156823d33999 74 while (mbed_interface_connected());
<> 149:156823d33999 75 return 0;
<> 149:156823d33999 76 } else {
<> 149:156823d33999 77 return -1;
<> 149:156823d33999 78 }
<> 149:156823d33999 79 }
<> 149:156823d33999 80
AnnaBridge 184:08ed48f1de7f 81 MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function shouldn't be used in new code."
AnnaBridge 187:0387e8f68319 82 "For system reset funcionality use system_reset()")
AnnaBridge 187:0387e8f68319 83 void mbed_reset(void)
AnnaBridge 187:0387e8f68319 84 {
<> 149:156823d33999 85 mbed_interface_reset();
<> 149:156823d33999 86 }
<> 149:156823d33999 87
AnnaBridge 187:0387e8f68319 88 WEAK int mbed_uid(char *uid)
AnnaBridge 187:0387e8f68319 89 {
<> 149:156823d33999 90 return mbed_interface_uid(uid);
<> 149:156823d33999 91 }
<> 149:156823d33999 92 #endif
<> 149:156823d33999 93
AnnaBridge 187:0387e8f68319 94 WEAK void mbed_mac_address(char *mac)
AnnaBridge 187:0387e8f68319 95 {
<> 149:156823d33999 96 #if DEVICE_SEMIHOST
<> 149:156823d33999 97 char uid[DEVICE_ID_LENGTH + 1];
<> 149:156823d33999 98 int i;
<> 149:156823d33999 99
<> 149:156823d33999 100 // if we have a UID, extract the MAC
<> 149:156823d33999 101 if (mbed_interface_uid(uid) == 0) {
<> 149:156823d33999 102 char *p = uid;
<> 149:156823d33999 103 #if defined(DEVICE_MAC_OFFSET)
<> 149:156823d33999 104 p += DEVICE_MAC_OFFSET;
<> 149:156823d33999 105 #endif
AnnaBridge 187:0387e8f68319 106 for (i = 0; i < 6; i++) {
<> 149:156823d33999 107 int byte;
<> 149:156823d33999 108 sscanf(p, "%2x", &byte);
<> 149:156823d33999 109 mac[i] = byte;
<> 149:156823d33999 110 p += 2;
<> 149:156823d33999 111 }
<> 149:156823d33999 112 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
<> 149:156823d33999 113 } else { // else return a default MAC
<> 149:156823d33999 114 #endif
<> 149:156823d33999 115 mac[0] = 0x00;
<> 149:156823d33999 116 mac[1] = 0x02;
<> 149:156823d33999 117 mac[2] = 0xF7;
<> 149:156823d33999 118 mac[3] = 0xF0;
<> 149:156823d33999 119 mac[4] = 0x00;
<> 149:156823d33999 120 mac[5] = 0x00;
<> 149:156823d33999 121 #if DEVICE_SEMIHOST
<> 149:156823d33999 122 }
<> 149:156823d33999 123 #endif
<> 149:156823d33999 124 }