1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "mbed_interface.h"
21 #include "semihost_api.h"
22 #include "mbed_error.h"
23 #include "toolchain.h"
27 // return true if a debugger is attached, indicating mbed interface is connected
28 int mbed_interface_connected(void) {
29 return semihost_connected();
32 int mbed_interface_reset(void) {
33 if (mbed_interface_connected()) {
41 WEAK int mbed_interface_uid(char *uid) {
42 if (mbed_interface_connected()) {
43 return semihost_uid(uid); // Returns 0 if successful, -1 on failure
50 int mbed_interface_disconnect(void) {
52 if (mbed_interface_connected()) {
53 if ((res = semihost_disabledebug()) != 0)
55 while (mbed_interface_connected());
62 int mbed_interface_powerdown(void) {
64 if (mbed_interface_connected()) {
65 if ((res = semihost_powerdown()) != 0)
67 while (mbed_interface_connected());
74 // for backward compatibility
75 void mbed_reset(void) {
76 mbed_interface_reset();
79 WEAK int mbed_uid(char *uid) {
80 return mbed_interface_uid(uid);
84 WEAK void mbed_mac_address(char *mac) {
86 char uid[DEVICE_ID_LENGTH + 1];
89 // if we have a UID, extract the MAC
90 if (mbed_interface_uid(uid) == 0) {
92 #if defined(DEVICE_MAC_OFFSET)
93 p += DEVICE_MAC_OFFSET;
97 sscanf(p, "%2x", &byte);
101 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
102 } else { // else return a default MAC