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