Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

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