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