mbed library sources: Modified to operate FRDM-KL25Z at 48MHz from internal 32kHz oscillator (nothing else changed).
Fork of mbed-src by
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 "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 WEAK int mbed_interface_uid(char *uid) { 00043 if (mbed_interface_connected()) { 00044 return semihost_uid(uid); // Returns 0 if successful, -1 on failure 00045 } else { 00046 uid[0] = 0; 00047 return -1; 00048 } 00049 } 00050 00051 int mbed_interface_disconnect(void) { 00052 int res; 00053 if (mbed_interface_connected()) { 00054 if ((res = semihost_disabledebug()) != 0) 00055 return res; 00056 while (mbed_interface_connected()); 00057 return 0; 00058 } else { 00059 return -1; 00060 } 00061 } 00062 00063 int mbed_interface_powerdown(void) { 00064 int res; 00065 if (mbed_interface_connected()) { 00066 if ((res = semihost_powerdown()) != 0) 00067 return res; 00068 while (mbed_interface_connected()); 00069 return 0; 00070 } else { 00071 return -1; 00072 } 00073 } 00074 00075 // for backward compatibility 00076 void mbed_reset(void) { 00077 mbed_interface_reset(); 00078 } 00079 00080 WEAK int mbed_uid(char *uid); 00081 WEAK int mbed_uid(char *uid) { 00082 return mbed_interface_uid(uid); 00083 } 00084 #endif 00085 00086 WEAK void mbed_mac_address(char *mac); 00087 WEAK void mbed_mac_address(char *mac) { 00088 #if DEVICE_SEMIHOST 00089 char uid[DEVICE_ID_LENGTH + 1]; 00090 int i; 00091 00092 // if we have a UID, extract the MAC 00093 if (mbed_interface_uid(uid) == 0) { 00094 char *p = uid; 00095 #if defined(DEVICE_MAC_OFFSET) 00096 p += DEVICE_MAC_OFFSET; 00097 #endif 00098 for (i=0; i<6; i++) { 00099 int byte; 00100 sscanf(p, "%2x", &byte); 00101 mac[i] = byte; 00102 p += 2; 00103 } 00104 } else { // else return a default MAC 00105 #endif 00106 mac[0] = 0x00; 00107 mac[1] = 0x02; 00108 mac[2] = 0xF7; 00109 mac[3] = 0xF0; 00110 mac[4] = 0x00; 00111 mac[5] = 0x00; 00112 #if DEVICE_SEMIHOST 00113 } 00114 #endif 00115 }
Generated on Wed Jul 13 2022 19:29:54 by 1.7.2