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