mbed library sources. Supersedes mbed-src.

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

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
187:0387e8f68319
mbed library release version 165

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