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