test

Committer:
elijahsj
Date:
Mon Nov 09 00:02:47 2020 -0500
Revision:
1:8a094db1347f
test

Who changed what in which revision?

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