Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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