source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/platform/mbed_interface.c

Last change on this file was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

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