USBclock 48Mhz, enable serial4 and serial5.
Fork of mbed-src by
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 "mbed_interface.h" 00018 00019 #include "gpio_api.h" 00020 #include "wait_api.h" 00021 #include "semihost_api.h" 00022 #include "mbed_error.h" 00023 #include "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 // for backward compatibility 00075 void mbed_reset(void) { 00076 mbed_interface_reset(); 00077 } 00078 00079 WEAK int mbed_uid(char *uid) { 00080 return mbed_interface_uid(uid); 00081 } 00082 #endif 00083 00084 WEAK void mbed_mac_address(char *mac) { 00085 #if DEVICE_SEMIHOST 00086 char uid[DEVICE_ID_LENGTH + 1]; 00087 int i; 00088 00089 // if we have a UID, extract the MAC 00090 if (mbed_interface_uid(uid) == 0) { 00091 char *p = uid; 00092 #if defined(DEVICE_MAC_OFFSET) 00093 p += DEVICE_MAC_OFFSET; 00094 #endif 00095 for (i=0; i<6; i++) { 00096 int byte; 00097 sscanf(p, "%2x", &byte); 00098 mac[i] = byte; 00099 p += 2; 00100 } 00101 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b) 00102 } else { // else return a default MAC 00103 #endif 00104 mac[0] = 0x00; 00105 mac[1] = 0x02; 00106 mac[2] = 0xF7; 00107 mac[3] = 0xF0; 00108 mac[4] = 0x00; 00109 mac[5] = 0x00; 00110 #if DEVICE_SEMIHOST 00111 } 00112 #endif 00113 }
Generated on Tue Jul 12 2022 16:19:42 by 1.7.2