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