mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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