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