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