fix for mbed lib issue 3 (i2c problem) see also https://mbed.org/users/mbed_official/code/mbed/issues/3 affected implementations: LPC812, LPC11U24, LPC1768, LPC2368, LPC4088

Fork of mbed-src by mbed official

Committer:
Shikaneo
Date:
Mon Aug 05 02:27:27 2013 +0000
Revision:
13:bd9ff402dd42
Parent:
10:3bc89ef62ce7
equipped timeout

Who changed what in which revision?

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