mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

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