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