Theo/Ludo/Joe / ER2_Labyrinthe_V3

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_semihost_api.h Source File

mbed_semihost_api.h

00001 
00002 /* mbed Microcontroller Library
00003  * Copyright (c) 2006-2013 ARM Limited
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef MBED_SEMIHOST_H
00018 #define MBED_SEMIHOST_H
00019 
00020 #include "device.h"
00021 #include "platform/mbed_toolchain.h"
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 #if DEVICE_SEMIHOST
00028 
00029 #if !defined(__CC_ARM) && !defined(__ARMCC_VERSION)
00030 
00031 #if defined(__ICCARM__)
00032 static inline int __semihost(int reason, const void *arg)
00033 {
00034     return __semihosting(reason, (void *)arg);
00035 }
00036 #else
00037 
00038 #ifdef __thumb__
00039 #   define AngelSWI            0xAB
00040 #   define AngelSWIInsn        "bkpt"
00041 #   define AngelSWIAsm          bkpt
00042 #else
00043 #   define AngelSWI            0x123456
00044 #   define AngelSWIInsn        "swi"
00045 #   define AngelSWIAsm          swi
00046 #endif
00047 
00048 static inline int __semihost(int reason, const void *arg)
00049 {
00050     int value;
00051 
00052     asm volatile(
00053         "mov r0, %1"          "\n\t"
00054         "mov r1, %2"          "\n\t"
00055         AngelSWIInsn " %a3"   "\n\t"
00056         "mov %0, r0"
00057         : "=r"(value)                                          /* output operands             */
00058         : "r"(reason), "r"(arg), "i"(AngelSWI)                 /* input operands              */
00059         : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"   /* list of clobbered registers */
00060     );
00061 
00062     return value;
00063 }
00064 #endif
00065 #endif
00066 
00067 #if DEVICE_LOCALFILESYSTEM
00068 FILEHANDLE semihost_open(const char *name, int openmode);
00069 int semihost_close(FILEHANDLE fh);
00070 int semihost_read(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode);
00071 int semihost_write(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode);
00072 int semihost_ensure(FILEHANDLE fh);
00073 long semihost_flen(FILEHANDLE fh);
00074 int semihost_seek(FILEHANDLE fh, long position);
00075 int semihost_istty(FILEHANDLE fh);
00076 
00077 int semihost_remove(const char *name);
00078 int semihost_rename(const char *old_name, const char *new_name);
00079 #endif
00080 
00081 int semihost_uid(char *uid);
00082 int semihost_reset(void);
00083 int semihost_vbus(void);
00084 int semihost_powerdown(void);
00085 int semihost_exit(void);
00086 
00087 int semihost_connected(void);
00088 int semihost_disabledebug(void);
00089 
00090 #endif
00091 
00092 #ifdef __cplusplus
00093 }
00094 #endif
00095 
00096 #endif
00097 
00098