Lancaster University's (short term!) clone of mbed-src for micro:bit. This is a copy of the github branch https://github.com/lancaster-university/mbed-classic

Fork of mbed-src by mbed official

Committer:
emilmont
Date:
Mon Jun 10 16:03:00 2013 +0100
Revision:
9:0ce32e54c9a7
Parent:
capi/mbed_interface.c@2:143cac498751
Child:
10:3bc89ef62ce7
Refactoring of the mbed SDK:
- Provide a well defined HAL and API
- Keep separated the HAL implementations for the different targets

Who changed what in which revision?

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