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