This fork captures the mbed lib v125 for ease of integration into older projects.

Fork of mbed-dev by mbed official

Committer:
apluscw
Date:
Fri Jul 20 21:24:42 2018 +0000
Revision:
187:92cbb9eec47b
Mbed library with source code from mbed lib v125. Posted to ease integration with some older projects.

Who changed what in which revision?

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