inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NYX 0:85b3fd62ea1a 1
NYX 0:85b3fd62ea1a 2 /** \addtogroup platform */
NYX 0:85b3fd62ea1a 3 /** @{*/
NYX 0:85b3fd62ea1a 4 /* mbed Microcontroller Library
NYX 0:85b3fd62ea1a 5 * Copyright (c) 2006-2013 ARM Limited
NYX 0:85b3fd62ea1a 6 *
NYX 0:85b3fd62ea1a 7 * Licensed under the Apache License, Version 2.0 (the "License");
NYX 0:85b3fd62ea1a 8 * you may not use this file except in compliance with the License.
NYX 0:85b3fd62ea1a 9 * You may obtain a copy of the License at
NYX 0:85b3fd62ea1a 10 *
NYX 0:85b3fd62ea1a 11 * http://www.apache.org/licenses/LICENSE-2.0
NYX 0:85b3fd62ea1a 12 *
NYX 0:85b3fd62ea1a 13 * Unless required by applicable law or agreed to in writing, software
NYX 0:85b3fd62ea1a 14 * distributed under the License is distributed on an "AS IS" BASIS,
NYX 0:85b3fd62ea1a 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
NYX 0:85b3fd62ea1a 16 * See the License for the specific language governing permissions and
NYX 0:85b3fd62ea1a 17 * limitations under the License.
NYX 0:85b3fd62ea1a 18 */
NYX 0:85b3fd62ea1a 19 #ifndef MBED_SEMIHOST_H
NYX 0:85b3fd62ea1a 20 #define MBED_SEMIHOST_H
NYX 0:85b3fd62ea1a 21
NYX 0:85b3fd62ea1a 22 #include "device.h"
NYX 0:85b3fd62ea1a 23 #include "platform/mbed_toolchain.h"
NYX 0:85b3fd62ea1a 24
NYX 0:85b3fd62ea1a 25 #ifdef __cplusplus
NYX 0:85b3fd62ea1a 26 extern "C" {
NYX 0:85b3fd62ea1a 27 #endif
NYX 0:85b3fd62ea1a 28
NYX 0:85b3fd62ea1a 29 #if DEVICE_SEMIHOST
NYX 0:85b3fd62ea1a 30
NYX 0:85b3fd62ea1a 31 #if !defined(__CC_ARM) && !defined(__ARMCC_VERSION)
NYX 0:85b3fd62ea1a 32
NYX 0:85b3fd62ea1a 33 #if defined(__ICCARM__)
NYX 0:85b3fd62ea1a 34 static inline int __semihost(int reason, const void *arg) {
NYX 0:85b3fd62ea1a 35 return __semihosting(reason, (void*)arg);
NYX 0:85b3fd62ea1a 36 }
NYX 0:85b3fd62ea1a 37 #else
NYX 0:85b3fd62ea1a 38
NYX 0:85b3fd62ea1a 39 #ifdef __thumb__
NYX 0:85b3fd62ea1a 40 # define AngelSWI 0xAB
NYX 0:85b3fd62ea1a 41 # define AngelSWIInsn "bkpt"
NYX 0:85b3fd62ea1a 42 # define AngelSWIAsm bkpt
NYX 0:85b3fd62ea1a 43 #else
NYX 0:85b3fd62ea1a 44 # define AngelSWI 0x123456
NYX 0:85b3fd62ea1a 45 # define AngelSWIInsn "swi"
NYX 0:85b3fd62ea1a 46 # define AngelSWIAsm swi
NYX 0:85b3fd62ea1a 47 #endif
NYX 0:85b3fd62ea1a 48
NYX 0:85b3fd62ea1a 49 static inline int __semihost(int reason, const void *arg) {
NYX 0:85b3fd62ea1a 50 int value;
NYX 0:85b3fd62ea1a 51
NYX 0:85b3fd62ea1a 52 asm volatile (
NYX 0:85b3fd62ea1a 53 "mov r0, %1" "\n\t"
NYX 0:85b3fd62ea1a 54 "mov r1, %2" "\n\t"
NYX 0:85b3fd62ea1a 55 AngelSWIInsn " %a3" "\n\t"
NYX 0:85b3fd62ea1a 56 "mov %0, r0"
NYX 0:85b3fd62ea1a 57 : "=r" (value) /* output operands */
NYX 0:85b3fd62ea1a 58 : "r" (reason), "r" (arg), "i" (AngelSWI) /* input operands */
NYX 0:85b3fd62ea1a 59 : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" /* list of clobbered registers */
NYX 0:85b3fd62ea1a 60 );
NYX 0:85b3fd62ea1a 61
NYX 0:85b3fd62ea1a 62 return value;
NYX 0:85b3fd62ea1a 63 }
NYX 0:85b3fd62ea1a 64 #endif
NYX 0:85b3fd62ea1a 65 #endif
NYX 0:85b3fd62ea1a 66
NYX 0:85b3fd62ea1a 67 #if DEVICE_LOCALFILESYSTEM
NYX 0:85b3fd62ea1a 68 FILEHANDLE semihost_open(const char* name, int openmode);
NYX 0:85b3fd62ea1a 69 int semihost_close (FILEHANDLE fh);
NYX 0:85b3fd62ea1a 70 int semihost_read (FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode);
NYX 0:85b3fd62ea1a 71 int semihost_write (FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode);
NYX 0:85b3fd62ea1a 72 int semihost_ensure(FILEHANDLE fh);
NYX 0:85b3fd62ea1a 73 long semihost_flen (FILEHANDLE fh);
NYX 0:85b3fd62ea1a 74 int semihost_seek (FILEHANDLE fh, long position);
NYX 0:85b3fd62ea1a 75 int semihost_istty (FILEHANDLE fh);
NYX 0:85b3fd62ea1a 76
NYX 0:85b3fd62ea1a 77 int semihost_remove(const char *name);
NYX 0:85b3fd62ea1a 78 int semihost_rename(const char *old_name, const char *new_name);
NYX 0:85b3fd62ea1a 79 #endif
NYX 0:85b3fd62ea1a 80
NYX 0:85b3fd62ea1a 81 int semihost_uid(char *uid);
NYX 0:85b3fd62ea1a 82 int semihost_reset(void);
NYX 0:85b3fd62ea1a 83 int semihost_vbus(void);
NYX 0:85b3fd62ea1a 84 int semihost_powerdown(void);
NYX 0:85b3fd62ea1a 85 int semihost_exit(void);
NYX 0:85b3fd62ea1a 86
NYX 0:85b3fd62ea1a 87 int semihost_connected(void);
NYX 0:85b3fd62ea1a 88 int semihost_disabledebug(void);
NYX 0:85b3fd62ea1a 89
NYX 0:85b3fd62ea1a 90 #endif
NYX 0:85b3fd62ea1a 91
NYX 0:85b3fd62ea1a 92 #ifdef __cplusplus
NYX 0:85b3fd62ea1a 93 }
NYX 0:85b3fd62ea1a 94 #endif
NYX 0:85b3fd62ea1a 95
NYX 0:85b3fd62ea1a 96 #endif
NYX 0:85b3fd62ea1a 97
NYX 0:85b3fd62ea1a 98 /** @}*/