test

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Tue Mar 14 16:40:56 2017 +0000
Revision:
160:d5399cc887bb
Parent:
149:156823d33999
This updates the lib to the mbed lib v138

Who changed what in which revision?

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