Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed_interface.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include <stdio.h> 00017 #include "platform/mbed_interface.h" 00018 00019 #include "hal/gpio_api.h" 00020 #include "platform/mbed_wait_api.h" 00021 #include "platform/mbed_semihost_api.h" 00022 #include "platform/mbed_error.h" 00023 #include "platform/mbed_toolchain.h" 00024 00025 #if DEVICE_SEMIHOST 00026 00027 // return true if a debugger is attached, indicating mbed interface is connected 00028 int mbed_interface_connected(void) 00029 { 00030 return semihost_connected(); 00031 } 00032 00033 int mbed_interface_reset(void) 00034 { 00035 if (mbed_interface_connected()) { 00036 semihost_reset(); 00037 return 0; 00038 } else { 00039 return -1; 00040 } 00041 } 00042 00043 WEAK int mbed_interface_uid(char *uid) 00044 { 00045 if (mbed_interface_connected()) { 00046 return semihost_uid(uid); // Returns 0 if successful, -1 on failure 00047 } else { 00048 uid[0] = 0; 00049 return -1; 00050 } 00051 } 00052 00053 int mbed_interface_disconnect(void) 00054 { 00055 int res; 00056 if (mbed_interface_connected()) { 00057 if ((res = semihost_disabledebug()) != 0) { 00058 return res; 00059 } 00060 while (mbed_interface_connected()); 00061 return 0; 00062 } else { 00063 return -1; 00064 } 00065 } 00066 00067 int mbed_interface_powerdown(void) 00068 { 00069 int res; 00070 if (mbed_interface_connected()) { 00071 if ((res = semihost_powerdown()) != 0) { 00072 return res; 00073 } 00074 while (mbed_interface_connected()); 00075 return 0; 00076 } else { 00077 return -1; 00078 } 00079 } 00080 00081 MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function shouldn't be used in new code." 00082 "For system reset funcionality use system_reset()") 00083 void mbed_reset(void) 00084 { 00085 mbed_interface_reset(); 00086 } 00087 00088 WEAK int mbed_uid(char *uid) 00089 { 00090 return mbed_interface_uid(uid); 00091 } 00092 #endif 00093 00094 WEAK void mbed_mac_address(char *mac) 00095 { 00096 #if DEVICE_SEMIHOST 00097 char uid[DEVICE_ID_LENGTH + 1]; 00098 int i; 00099 00100 // if we have a UID, extract the MAC 00101 if (mbed_interface_uid(uid) == 0) { 00102 char *p = uid; 00103 #if defined(DEVICE_MAC_OFFSET) 00104 p += DEVICE_MAC_OFFSET; 00105 #endif 00106 for (i = 0; i < 6; i++) { 00107 int byte; 00108 sscanf(p, "%2x", &byte); 00109 mac[i] = byte; 00110 p += 2; 00111 } 00112 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b) 00113 } else { // else return a default MAC 00114 #endif 00115 mac[0] = 0x00; 00116 mac[1] = 0x02; 00117 mac[2] = 0xF7; 00118 mac[3] = 0xF0; 00119 mac[4] = 0x00; 00120 mac[5] = 0x00; 00121 #if DEVICE_SEMIHOST 00122 } 00123 #endif 00124 }
Generated on Tue Aug 9 2022 00:37:14 by
