source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/platform/mbed_semihost_api.c@ 374

Last change on this file since 374 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: 4.3 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 "cmsis.h"
17#include "platform/mbed_semihost_api.h"
18
19#include <stdint.h>
20#include <string.h>
21
22#if DEVICE_SEMIHOST
23
24// ARM Semihosting Commands
25#define SYS_OPEN (0x1)
26#define SYS_CLOSE (0x2)
27#define SYS_WRITE (0x5)
28#define SYS_READ (0x6)
29#define SYS_ISTTY (0x9)
30#define SYS_SEEK (0xa)
31#define SYS_ENSURE (0xb)
32#define SYS_FLEN (0xc)
33#define SYS_REMOVE (0xe)
34#define SYS_RENAME (0xf)
35#define SYS_EXIT (0x18)
36
37// mbed Semihosting Commands
38#define RESERVED_FOR_USER_APPLICATIONS (0x100) // 0x100 - 0x1ff
39#define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
40#define USR_UID (RESERVED_FOR_USER_APPLICATIONS + 1)
41#define USR_RESET (RESERVED_FOR_USER_APPLICATIONS + 2)
42#define USR_VBUS (RESERVED_FOR_USER_APPLICATIONS + 3)
43#define USR_POWERDOWN (RESERVED_FOR_USER_APPLICATIONS + 4)
44#define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5)
45
46#if DEVICE_LOCALFILESYSTEM
47FILEHANDLE semihost_open(const char* name, int openmode)
48{
49 uint32_t args[3];
50 args[0] = (uint32_t)name;
51 args[1] = (uint32_t)openmode;
52 args[2] = (uint32_t)strlen(name);
53 return __semihost(SYS_OPEN, args);
54}
55
56int semihost_close(FILEHANDLE fh)
57{
58 return __semihost(SYS_CLOSE, &fh);
59}
60
61int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode)
62{
63 if (length == 0) {
64 return 0;
65 }
66
67 uint32_t args[3];
68 args[0] = (uint32_t)fh;
69 args[1] = (uint32_t)buffer;
70 args[2] = (uint32_t)length;
71 return __semihost(SYS_WRITE, args);
72}
73
74int semihost_read(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode)
75{
76 uint32_t args[3];
77 args[0] = (uint32_t)fh;
78 args[1] = (uint32_t)buffer;
79 args[2] = (uint32_t)length;
80 return __semihost(SYS_READ, args);
81}
82
83int semihost_istty(FILEHANDLE fh)
84{
85 return __semihost(SYS_ISTTY, &fh);
86}
87
88int semihost_seek(FILEHANDLE fh, long position)
89{
90 uint32_t args[2];
91 args[0] = (uint32_t)fh;
92 args[1] = (uint32_t)position;
93 return __semihost(SYS_SEEK, args);
94}
95
96int semihost_ensure(FILEHANDLE fh)
97{
98 return __semihost(SYS_ENSURE, &fh);
99}
100
101long semihost_flen(FILEHANDLE fh)
102{
103 return __semihost(SYS_FLEN, &fh);
104}
105
106int semihost_remove(const char *name)
107{
108 uint32_t args[2];
109 args[0] = (uint32_t)name;
110 args[1] = (uint32_t)strlen(name);
111 return __semihost(SYS_REMOVE, args);
112}
113
114int semihost_rename(const char *old_name, const char *new_name)
115{
116 uint32_t args[4];
117 args[0] = (uint32_t)old_name;
118 args[1] = (uint32_t)strlen(old_name);
119 args[0] = (uint32_t)new_name;
120 args[1] = (uint32_t)strlen(new_name);
121 return __semihost(SYS_RENAME, args);
122}
123#endif
124
125int semihost_exit(void)
126{
127 uint32_t args[4];
128 return __semihost(SYS_EXIT, args);
129}
130
131int semihost_uid(char *uid)
132{
133 uint32_t args[2];
134 args[0] = (uint32_t)uid;
135 args[1] = DEVICE_ID_LENGTH + 1;
136 return __semihost(USR_UID, &args);
137}
138
139int semihost_reset(void)
140{
141 // Does not normally return, however if used with older firmware versions
142 // that do not support this call it will return -1.
143 return __semihost(USR_RESET, NULL);
144}
145
146int semihost_vbus(void)
147{
148 return __semihost(USR_VBUS, NULL);
149}
150
151int semihost_powerdown(void)
152{
153 return __semihost(USR_POWERDOWN, NULL);
154}
155
156#if DEVICE_DEBUG_AWARENESS
157
158int semihost_connected(void)
159{
160 return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? 1 : 0;
161}
162
163#else
164// These processors cannot know if the interface is connect, assume so:
165static int is_debugger_attached = 1;
166
167int semihost_connected(void)
168{
169 return is_debugger_attached;
170}
171#endif
172
173int semihost_disabledebug(void)
174{
175 uint32_t args[1];
176#if !(DEVICE_DEBUG_AWARENESS)
177 is_debugger_attached = 0;
178#endif
179 return __semihost(USR_DISABLEDEBUG, &args);
180}
181
182#endif
183
Note: See TracBrowser for help on using the repository browser.