,,

Fork of Application by Daniel Sygut

Committer:
Zaitsev
Date:
Thu Feb 15 14:29:23 2018 +0000
Revision:
15:2a20c3d2616e
Parent:
10:41552d038a69
j

Who changed what in which revision?

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