BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
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 return semihost_connected(); 00030 } 00031 00032 int mbed_interface_reset(void) { 00033 if (mbed_interface_connected()) { 00034 semihost_reset(); 00035 return 0; 00036 } else { 00037 return -1; 00038 } 00039 } 00040 00041 WEAK int mbed_interface_uid(char *uid) { 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 int res; 00052 if (mbed_interface_connected()) { 00053 if ((res = semihost_disabledebug()) != 0) 00054 return res; 00055 while (mbed_interface_connected()); 00056 return 0; 00057 } else { 00058 return -1; 00059 } 00060 } 00061 00062 int mbed_interface_powerdown(void) { 00063 int res; 00064 if (mbed_interface_connected()) { 00065 if ((res = semihost_powerdown()) != 0) 00066 return res; 00067 while (mbed_interface_connected()); 00068 return 0; 00069 } else { 00070 return -1; 00071 } 00072 } 00073 00074 MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function shouldn't be used in new code." 00075 "For system reset funcionality use system_reset()") 00076 void mbed_reset(void) { 00077 mbed_interface_reset(); 00078 } 00079 00080 WEAK int mbed_uid(char *uid) { 00081 return mbed_interface_uid(uid); 00082 } 00083 #endif 00084 00085 WEAK void mbed_mac_address(char *mac) { 00086 #if DEVICE_SEMIHOST 00087 char uid[DEVICE_ID_LENGTH + 1]; 00088 int i; 00089 00090 // if we have a UID, extract the MAC 00091 if (mbed_interface_uid(uid) == 0) { 00092 char *p = uid; 00093 #if defined(DEVICE_MAC_OFFSET) 00094 p += DEVICE_MAC_OFFSET; 00095 #endif 00096 for (i=0; i<6; i++) { 00097 int byte; 00098 sscanf(p, "%2x", &byte); 00099 mac[i] = byte; 00100 p += 2; 00101 } 00102 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b) 00103 } else { // else return a default MAC 00104 #endif 00105 mac[0] = 0x00; 00106 mac[1] = 0x02; 00107 mac[2] = 0xF7; 00108 mac[3] = 0xF0; 00109 mac[4] = 0x00; 00110 mac[5] = 0x00; 00111 #if DEVICE_SEMIHOST 00112 } 00113 #endif 00114 }
Generated on Tue Jul 12 2022 12:22:10 by
