]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/api/semihost_api.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[qmk_firmware.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / api / semihost_api.h
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 #ifndef MBED_SEMIHOST_H
17 #define MBED_SEMIHOST_H
18
19 #include "device.h"
20 #include "toolchain.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #if DEVICE_SEMIHOST
27
28 #ifndef __CC_ARM
29
30 #if defined(__ICCARM__)
31 inline int __semihost(int reason, const void *arg) {
32     return __semihosting(reason, (void*)arg);
33 }
34 #else
35
36 #ifdef __thumb__
37 #   define AngelSWI            0xAB
38 #   define AngelSWIInsn        "bkpt"
39 #   define AngelSWIAsm          bkpt
40 #else
41 #   define AngelSWI            0x123456
42 #   define AngelSWIInsn        "swi"
43 #   define AngelSWIAsm          swi
44 #endif
45
46 static inline int __semihost(int reason, const void *arg) {
47     int value;
48
49     asm volatile (
50        "mov r0, %1"          "\n\t"
51        "mov r1, %2"          "\n\t"
52        AngelSWIInsn " %a3"   "\n\t"
53        "mov %0, r0"
54        : "=r" (value)                                         /* output operands             */
55        : "r" (reason), "r" (arg), "i" (AngelSWI)              /* input operands              */
56        : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"   /* list of clobbered registers */
57     );
58
59     return value;
60 }
61 #endif
62 #endif
63
64 #if DEVICE_LOCALFILESYSTEM
65 FILEHANDLE semihost_open(const char* name, int openmode);
66 int semihost_close (FILEHANDLE fh);
67 int semihost_read  (FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode);
68 int semihost_write (FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode);
69 int semihost_ensure(FILEHANDLE fh);
70 long semihost_flen (FILEHANDLE fh);
71 int semihost_seek  (FILEHANDLE fh, long position);
72 int semihost_istty (FILEHANDLE fh);
73
74 int semihost_remove(const char *name);
75 int semihost_rename(const char *old_name, const char *new_name);
76 #endif
77
78 int semihost_uid(char *uid);
79 int semihost_reset(void);
80 int semihost_vbus(void);
81 int semihost_powerdown(void);
82 int semihost_exit(void);
83
84 int semihost_connected(void);
85 int semihost_disabledebug(void);
86
87 #endif
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif