Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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