游戏王对战板,目前code还是空的

Committer:
WFKnight
Date:
Thu Jun 21 13:51:43 2018 +0000
Revision:
0:9b3d4731edbb
UART, RTOS, LED

Who changed what in which revision?

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