BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 /* mbed Microcontroller Library
borlanic 0:fbdae7e6d805 2 * Copyright (c) 2006-2013 ARM Limited
borlanic 0:fbdae7e6d805 3 *
borlanic 0:fbdae7e6d805 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:fbdae7e6d805 5 * you may not use this file except in compliance with the License.
borlanic 0:fbdae7e6d805 6 * You may obtain a copy of the License at
borlanic 0:fbdae7e6d805 7 *
borlanic 0:fbdae7e6d805 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:fbdae7e6d805 9 *
borlanic 0:fbdae7e6d805 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:fbdae7e6d805 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:fbdae7e6d805 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:fbdae7e6d805 13 * See the License for the specific language governing permissions and
borlanic 0:fbdae7e6d805 14 * limitations under the License.
borlanic 0:fbdae7e6d805 15 */
borlanic 0:fbdae7e6d805 16 #include <stdio.h>
borlanic 0:fbdae7e6d805 17 #include "platform/mbed_interface.h"
borlanic 0:fbdae7e6d805 18
borlanic 0:fbdae7e6d805 19 #include "hal/gpio_api.h"
borlanic 0:fbdae7e6d805 20 #include "platform/mbed_wait_api.h"
borlanic 0:fbdae7e6d805 21 #include "platform/mbed_semihost_api.h"
borlanic 0:fbdae7e6d805 22 #include "platform/mbed_error.h"
borlanic 0:fbdae7e6d805 23 #include "platform/mbed_toolchain.h"
borlanic 0:fbdae7e6d805 24
borlanic 0:fbdae7e6d805 25 #if DEVICE_SEMIHOST
borlanic 0:fbdae7e6d805 26
borlanic 0:fbdae7e6d805 27 // return true if a debugger is attached, indicating mbed interface is connected
borlanic 0:fbdae7e6d805 28 int mbed_interface_connected(void) {
borlanic 0:fbdae7e6d805 29 return semihost_connected();
borlanic 0:fbdae7e6d805 30 }
borlanic 0:fbdae7e6d805 31
borlanic 0:fbdae7e6d805 32 int mbed_interface_reset(void) {
borlanic 0:fbdae7e6d805 33 if (mbed_interface_connected()) {
borlanic 0:fbdae7e6d805 34 semihost_reset();
borlanic 0:fbdae7e6d805 35 return 0;
borlanic 0:fbdae7e6d805 36 } else {
borlanic 0:fbdae7e6d805 37 return -1;
borlanic 0:fbdae7e6d805 38 }
borlanic 0:fbdae7e6d805 39 }
borlanic 0:fbdae7e6d805 40
borlanic 0:fbdae7e6d805 41 WEAK int mbed_interface_uid(char *uid) {
borlanic 0:fbdae7e6d805 42 if (mbed_interface_connected()) {
borlanic 0:fbdae7e6d805 43 return semihost_uid(uid); // Returns 0 if successful, -1 on failure
borlanic 0:fbdae7e6d805 44 } else {
borlanic 0:fbdae7e6d805 45 uid[0] = 0;
borlanic 0:fbdae7e6d805 46 return -1;
borlanic 0:fbdae7e6d805 47 }
borlanic 0:fbdae7e6d805 48 }
borlanic 0:fbdae7e6d805 49
borlanic 0:fbdae7e6d805 50 int mbed_interface_disconnect(void) {
borlanic 0:fbdae7e6d805 51 int res;
borlanic 0:fbdae7e6d805 52 if (mbed_interface_connected()) {
borlanic 0:fbdae7e6d805 53 if ((res = semihost_disabledebug()) != 0)
borlanic 0:fbdae7e6d805 54 return res;
borlanic 0:fbdae7e6d805 55 while (mbed_interface_connected());
borlanic 0:fbdae7e6d805 56 return 0;
borlanic 0:fbdae7e6d805 57 } else {
borlanic 0:fbdae7e6d805 58 return -1;
borlanic 0:fbdae7e6d805 59 }
borlanic 0:fbdae7e6d805 60 }
borlanic 0:fbdae7e6d805 61
borlanic 0:fbdae7e6d805 62 int mbed_interface_powerdown(void) {
borlanic 0:fbdae7e6d805 63 int res;
borlanic 0:fbdae7e6d805 64 if (mbed_interface_connected()) {
borlanic 0:fbdae7e6d805 65 if ((res = semihost_powerdown()) != 0)
borlanic 0:fbdae7e6d805 66 return res;
borlanic 0:fbdae7e6d805 67 while (mbed_interface_connected());
borlanic 0:fbdae7e6d805 68 return 0;
borlanic 0:fbdae7e6d805 69 } else {
borlanic 0:fbdae7e6d805 70 return -1;
borlanic 0:fbdae7e6d805 71 }
borlanic 0:fbdae7e6d805 72 }
borlanic 0:fbdae7e6d805 73
borlanic 0:fbdae7e6d805 74 MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function shouldn't be used in new code."
borlanic 0:fbdae7e6d805 75 "For system reset funcionality use system_reset()")
borlanic 0:fbdae7e6d805 76 void mbed_reset(void) {
borlanic 0:fbdae7e6d805 77 mbed_interface_reset();
borlanic 0:fbdae7e6d805 78 }
borlanic 0:fbdae7e6d805 79
borlanic 0:fbdae7e6d805 80 WEAK int mbed_uid(char *uid) {
borlanic 0:fbdae7e6d805 81 return mbed_interface_uid(uid);
borlanic 0:fbdae7e6d805 82 }
borlanic 0:fbdae7e6d805 83 #endif
borlanic 0:fbdae7e6d805 84
borlanic 0:fbdae7e6d805 85 WEAK void mbed_mac_address(char *mac) {
borlanic 0:fbdae7e6d805 86 #if DEVICE_SEMIHOST
borlanic 0:fbdae7e6d805 87 char uid[DEVICE_ID_LENGTH + 1];
borlanic 0:fbdae7e6d805 88 int i;
borlanic 0:fbdae7e6d805 89
borlanic 0:fbdae7e6d805 90 // if we have a UID, extract the MAC
borlanic 0:fbdae7e6d805 91 if (mbed_interface_uid(uid) == 0) {
borlanic 0:fbdae7e6d805 92 char *p = uid;
borlanic 0:fbdae7e6d805 93 #if defined(DEVICE_MAC_OFFSET)
borlanic 0:fbdae7e6d805 94 p += DEVICE_MAC_OFFSET;
borlanic 0:fbdae7e6d805 95 #endif
borlanic 0:fbdae7e6d805 96 for (i=0; i<6; i++) {
borlanic 0:fbdae7e6d805 97 int byte;
borlanic 0:fbdae7e6d805 98 sscanf(p, "%2x", &byte);
borlanic 0:fbdae7e6d805 99 mac[i] = byte;
borlanic 0:fbdae7e6d805 100 p += 2;
borlanic 0:fbdae7e6d805 101 }
borlanic 0:fbdae7e6d805 102 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
borlanic 0:fbdae7e6d805 103 } else { // else return a default MAC
borlanic 0:fbdae7e6d805 104 #endif
borlanic 0:fbdae7e6d805 105 mac[0] = 0x00;
borlanic 0:fbdae7e6d805 106 mac[1] = 0x02;
borlanic 0:fbdae7e6d805 107 mac[2] = 0xF7;
borlanic 0:fbdae7e6d805 108 mac[3] = 0xF0;
borlanic 0:fbdae7e6d805 109 mac[4] = 0x00;
borlanic 0:fbdae7e6d805 110 mac[5] = 0x00;
borlanic 0:fbdae7e6d805 111 #if DEVICE_SEMIHOST
borlanic 0:fbdae7e6d805 112 }
borlanic 0:fbdae7e6d805 113 #endif
borlanic 0:fbdae7e6d805 114 }