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
common/mbed_interface.c@228:85a676113daa, 2014-06-12 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Jun 12 10:15:07 2014 +0100
- Revision:
- 228:85a676113daa
- Parent:
- 221:8276e3a4886f
- Child:
- 250:a49055e7a707
Synchronized with git revision 0b5a92fbc54f70168b85f7a58bab07c5b787ab13
Full URL: https://github.com/mbedmicro/mbed/commit/0b5a92fbc54f70168b85f7a58bab07c5b787ab13/
Error header inclusion in the error code file - fix.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 13:0645d8841f51 | 1 | /* mbed Microcontroller Library |
bogdanm | 13:0645d8841f51 | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 13:0645d8841f51 | 3 | * |
bogdanm | 13:0645d8841f51 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 13:0645d8841f51 | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 13:0645d8841f51 | 6 | * You may obtain a copy of the License at |
bogdanm | 13:0645d8841f51 | 7 | * |
bogdanm | 13:0645d8841f51 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 13:0645d8841f51 | 9 | * |
bogdanm | 13:0645d8841f51 | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 13:0645d8841f51 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 13:0645d8841f51 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 13:0645d8841f51 | 13 | * See the License for the specific language governing permissions and |
bogdanm | 13:0645d8841f51 | 14 | * limitations under the License. |
bogdanm | 13:0645d8841f51 | 15 | */ |
bogdanm | 13:0645d8841f51 | 16 | #include <stdio.h> |
bogdanm | 13:0645d8841f51 | 17 | #include "mbed_interface.h" |
bogdanm | 13:0645d8841f51 | 18 | |
bogdanm | 13:0645d8841f51 | 19 | #include "gpio_api.h" |
bogdanm | 13:0645d8841f51 | 20 | #include "wait_api.h" |
bogdanm | 13:0645d8841f51 | 21 | #include "semihost_api.h" |
bogdanm | 13:0645d8841f51 | 22 | #include "error.h" |
bogdanm | 13:0645d8841f51 | 23 | #include "toolchain.h" |
bogdanm | 13:0645d8841f51 | 24 | |
bogdanm | 13:0645d8841f51 | 25 | #if DEVICE_SEMIHOST |
bogdanm | 13:0645d8841f51 | 26 | |
bogdanm | 13:0645d8841f51 | 27 | // return true if a debugger is attached, indicating mbed interface is connected |
bogdanm | 13:0645d8841f51 | 28 | int mbed_interface_connected(void) { |
bogdanm | 13:0645d8841f51 | 29 | return semihost_connected(); |
bogdanm | 13:0645d8841f51 | 30 | } |
bogdanm | 13:0645d8841f51 | 31 | |
bogdanm | 13:0645d8841f51 | 32 | int mbed_interface_reset(void) { |
bogdanm | 13:0645d8841f51 | 33 | if (mbed_interface_connected()) { |
bogdanm | 13:0645d8841f51 | 34 | semihost_reset(); |
bogdanm | 13:0645d8841f51 | 35 | return 0; |
bogdanm | 13:0645d8841f51 | 36 | } else { |
bogdanm | 13:0645d8841f51 | 37 | return -1; |
bogdanm | 13:0645d8841f51 | 38 | } |
bogdanm | 13:0645d8841f51 | 39 | } |
bogdanm | 13:0645d8841f51 | 40 | |
bogdanm | 13:0645d8841f51 | 41 | WEAK int mbed_interface_uid(char *uid) { |
bogdanm | 13:0645d8841f51 | 42 | if (mbed_interface_connected()) { |
bogdanm | 13:0645d8841f51 | 43 | return semihost_uid(uid); // Returns 0 if successful, -1 on failure |
bogdanm | 13:0645d8841f51 | 44 | } else { |
bogdanm | 13:0645d8841f51 | 45 | uid[0] = 0; |
bogdanm | 13:0645d8841f51 | 46 | return -1; |
bogdanm | 13:0645d8841f51 | 47 | } |
bogdanm | 13:0645d8841f51 | 48 | } |
bogdanm | 13:0645d8841f51 | 49 | |
bogdanm | 13:0645d8841f51 | 50 | int mbed_interface_disconnect(void) { |
bogdanm | 13:0645d8841f51 | 51 | int res; |
bogdanm | 13:0645d8841f51 | 52 | if (mbed_interface_connected()) { |
bogdanm | 13:0645d8841f51 | 53 | if ((res = semihost_disabledebug()) != 0) |
bogdanm | 13:0645d8841f51 | 54 | return res; |
bogdanm | 13:0645d8841f51 | 55 | while (mbed_interface_connected()); |
bogdanm | 13:0645d8841f51 | 56 | return 0; |
bogdanm | 13:0645d8841f51 | 57 | } else { |
bogdanm | 13:0645d8841f51 | 58 | return -1; |
bogdanm | 13:0645d8841f51 | 59 | } |
bogdanm | 13:0645d8841f51 | 60 | } |
bogdanm | 13:0645d8841f51 | 61 | |
bogdanm | 13:0645d8841f51 | 62 | int mbed_interface_powerdown(void) { |
bogdanm | 13:0645d8841f51 | 63 | int res; |
bogdanm | 13:0645d8841f51 | 64 | if (mbed_interface_connected()) { |
bogdanm | 13:0645d8841f51 | 65 | if ((res = semihost_powerdown()) != 0) |
bogdanm | 13:0645d8841f51 | 66 | return res; |
bogdanm | 13:0645d8841f51 | 67 | while (mbed_interface_connected()); |
bogdanm | 13:0645d8841f51 | 68 | return 0; |
bogdanm | 13:0645d8841f51 | 69 | } else { |
bogdanm | 13:0645d8841f51 | 70 | return -1; |
bogdanm | 13:0645d8841f51 | 71 | } |
bogdanm | 13:0645d8841f51 | 72 | } |
bogdanm | 13:0645d8841f51 | 73 | |
bogdanm | 13:0645d8841f51 | 74 | // for backward compatibility |
bogdanm | 13:0645d8841f51 | 75 | void mbed_reset(void) { |
bogdanm | 13:0645d8841f51 | 76 | mbed_interface_reset(); |
bogdanm | 13:0645d8841f51 | 77 | } |
bogdanm | 13:0645d8841f51 | 78 | |
bogdanm | 13:0645d8841f51 | 79 | WEAK int mbed_uid(char *uid) { |
bogdanm | 13:0645d8841f51 | 80 | return mbed_interface_uid(uid); |
bogdanm | 13:0645d8841f51 | 81 | } |
bogdanm | 13:0645d8841f51 | 82 | #endif |
bogdanm | 13:0645d8841f51 | 83 | |
bogdanm | 13:0645d8841f51 | 84 | WEAK void mbed_mac_address(char *mac) { |
bogdanm | 13:0645d8841f51 | 85 | #if DEVICE_SEMIHOST |
bogdanm | 13:0645d8841f51 | 86 | char uid[DEVICE_ID_LENGTH + 1]; |
bogdanm | 13:0645d8841f51 | 87 | int i; |
mbed_official | 221:8276e3a4886f | 88 | |
bogdanm | 13:0645d8841f51 | 89 | // if we have a UID, extract the MAC |
bogdanm | 13:0645d8841f51 | 90 | if (mbed_interface_uid(uid) == 0) { |
bogdanm | 13:0645d8841f51 | 91 | char *p = uid; |
bogdanm | 13:0645d8841f51 | 92 | #if defined(DEVICE_MAC_OFFSET) |
bogdanm | 13:0645d8841f51 | 93 | p += DEVICE_MAC_OFFSET; |
bogdanm | 13:0645d8841f51 | 94 | #endif |
bogdanm | 13:0645d8841f51 | 95 | for (i=0; i<6; i++) { |
bogdanm | 13:0645d8841f51 | 96 | int byte; |
bogdanm | 13:0645d8841f51 | 97 | sscanf(p, "%2x", &byte); |
bogdanm | 13:0645d8841f51 | 98 | mac[i] = byte; |
bogdanm | 13:0645d8841f51 | 99 | p += 2; |
bogdanm | 13:0645d8841f51 | 100 | } |
bogdanm | 13:0645d8841f51 | 101 | } else { // else return a default MAC |
bogdanm | 13:0645d8841f51 | 102 | #endif |
bogdanm | 13:0645d8841f51 | 103 | mac[0] = 0x00; |
bogdanm | 13:0645d8841f51 | 104 | mac[1] = 0x02; |
bogdanm | 13:0645d8841f51 | 105 | mac[2] = 0xF7; |
bogdanm | 13:0645d8841f51 | 106 | mac[3] = 0xF0; |
bogdanm | 13:0645d8841f51 | 107 | mac[4] = 0x00; |
bogdanm | 13:0645d8841f51 | 108 | mac[5] = 0x00; |
bogdanm | 13:0645d8841f51 | 109 | #if DEVICE_SEMIHOST |
bogdanm | 13:0645d8841f51 | 110 | } |
bogdanm | 13:0645d8841f51 | 111 | #endif |
bogdanm | 13:0645d8841f51 | 112 | } |