mbed(SerialHalfDuplex入り)
Fork of mbed by
semihost_api.h@57:0480438fc29c, 2013-01-18 (annotated)
- Committer:
- emilmont
- Date:
- Fri Jan 18 10:30:14 2013 +0000
- Revision:
- 57:0480438fc29c
- Parent:
- 55:d722ed6a4237
- Child:
- 59:0883845fe643
Add semihosting support for IAR toolchain
Improve IAR stdio retargeting
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 44:24d45a770a51 | 1 | /* mbed Microcontroller Library |
emilmont | 54:71b101360fb9 | 2 | * Copyright (c) 2006-2013 ARM Limited |
emilmont | 44:24d45a770a51 | 3 | * |
emilmont | 44:24d45a770a51 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
emilmont | 44:24d45a770a51 | 5 | * of this software and associated documentation files (the "Software"), to deal |
emilmont | 44:24d45a770a51 | 6 | * in the Software without restriction, including without limitation the rights |
emilmont | 44:24d45a770a51 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
emilmont | 44:24d45a770a51 | 8 | * copies of the Software, and to permit persons to whom the Software is |
emilmont | 44:24d45a770a51 | 9 | * furnished to do so, subject to the following conditions: |
emilmont | 44:24d45a770a51 | 10 | * |
emilmont | 44:24d45a770a51 | 11 | * The above copyright notice and this permission notice shall be included in |
emilmont | 44:24d45a770a51 | 12 | * all copies or substantial portions of the Software. |
emilmont | 44:24d45a770a51 | 13 | * |
emilmont | 44:24d45a770a51 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
emilmont | 44:24d45a770a51 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
emilmont | 44:24d45a770a51 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
emilmont | 44:24d45a770a51 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
emilmont | 44:24d45a770a51 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
emilmont | 44:24d45a770a51 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
emilmont | 44:24d45a770a51 | 20 | * SOFTWARE. |
emilmont | 44:24d45a770a51 | 21 | */ |
emilmont | 44:24d45a770a51 | 22 | #ifndef MBED_SEMIHOST_H |
emilmont | 44:24d45a770a51 | 23 | #define MBED_SEMIHOST_H |
emilmont | 44:24d45a770a51 | 24 | |
emilmont | 44:24d45a770a51 | 25 | #include "device.h" |
emilmont | 44:24d45a770a51 | 26 | #include "toolchain.h" |
emilmont | 44:24d45a770a51 | 27 | |
emilmont | 44:24d45a770a51 | 28 | #ifdef __cplusplus |
emilmont | 44:24d45a770a51 | 29 | extern "C" { |
emilmont | 44:24d45a770a51 | 30 | #endif |
emilmont | 44:24d45a770a51 | 31 | |
emilmont | 55:d722ed6a4237 | 32 | #if DEVICE_SEMIHOST |
emilmont | 57:0480438fc29c | 33 | |
emilmont | 44:24d45a770a51 | 34 | #ifndef __CC_ARM |
emilmont | 44:24d45a770a51 | 35 | |
emilmont | 57:0480438fc29c | 36 | #if defined(__ICCARM__) |
emilmont | 57:0480438fc29c | 37 | inline int __semihost(int reason, const void *arg) { |
emilmont | 57:0480438fc29c | 38 | return __semihosting(reason, (void*)arg); |
emilmont | 57:0480438fc29c | 39 | } |
emilmont | 57:0480438fc29c | 40 | #else |
emilmont | 57:0480438fc29c | 41 | |
emilmont | 44:24d45a770a51 | 42 | #ifdef __thumb__ |
emilmont | 55:d722ed6a4237 | 43 | # define AngelSWI 0xAB |
emilmont | 55:d722ed6a4237 | 44 | # define AngelSWIInsn "bkpt" |
emilmont | 55:d722ed6a4237 | 45 | # define AngelSWIAsm bkpt |
emilmont | 44:24d45a770a51 | 46 | #else |
emilmont | 55:d722ed6a4237 | 47 | # define AngelSWI 0x123456 |
emilmont | 55:d722ed6a4237 | 48 | # define AngelSWIInsn "swi" |
emilmont | 55:d722ed6a4237 | 49 | # define AngelSWIAsm swi |
emilmont | 44:24d45a770a51 | 50 | #endif |
emilmont | 44:24d45a770a51 | 51 | |
emilmont | 44:24d45a770a51 | 52 | inline int __semihost(int reason, const void *arg) { |
emilmont | 44:24d45a770a51 | 53 | int value; |
emilmont | 57:0480438fc29c | 54 | |
emilmont | 57:0480438fc29c | 55 | asm volatile ( |
emilmont | 57:0480438fc29c | 56 | "mov r0, %1" "\n\t" |
emilmont | 57:0480438fc29c | 57 | "mov r1, %2" "\n\t" |
emilmont | 57:0480438fc29c | 58 | AngelSWIInsn " %a3" "\n\t" |
emilmont | 57:0480438fc29c | 59 | "mov %0, r0" |
emilmont | 57:0480438fc29c | 60 | : "=r" (value) /* output operands */ |
emilmont | 57:0480438fc29c | 61 | : "r" (reason), "r" (arg), "i" (AngelSWI) /* input operands */ |
emilmont | 57:0480438fc29c | 62 | : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" /* list of clobbered registers */ |
emilmont | 57:0480438fc29c | 63 | ); |
emilmont | 57:0480438fc29c | 64 | |
emilmont | 44:24d45a770a51 | 65 | return value; |
emilmont | 44:24d45a770a51 | 66 | } |
emilmont | 57:0480438fc29c | 67 | #endif |
emilmont | 44:24d45a770a51 | 68 | #endif |
emilmont | 44:24d45a770a51 | 69 | |
emilmont | 44:24d45a770a51 | 70 | #if DEVICE_LOCALFILESYSTEM |
emilmont | 44:24d45a770a51 | 71 | FILEHANDLE semihost_open(const char* name, int openmode); |
emilmont | 44:24d45a770a51 | 72 | int semihost_close (FILEHANDLE fh); |
emilmont | 44:24d45a770a51 | 73 | int semihost_read (FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode); |
emilmont | 44:24d45a770a51 | 74 | int semihost_write (FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode); |
emilmont | 44:24d45a770a51 | 75 | int semihost_ensure(FILEHANDLE fh); |
emilmont | 44:24d45a770a51 | 76 | long semihost_flen (FILEHANDLE fh); |
emilmont | 44:24d45a770a51 | 77 | int semihost_seek (FILEHANDLE fh, long position); |
emilmont | 44:24d45a770a51 | 78 | int semihost_istty (FILEHANDLE fh); |
emilmont | 44:24d45a770a51 | 79 | |
emilmont | 44:24d45a770a51 | 80 | int semihost_remove(const char *name); |
emilmont | 44:24d45a770a51 | 81 | int semihost_rename(const char *old_name, const char *new_name); |
emilmont | 44:24d45a770a51 | 82 | #endif |
emilmont | 44:24d45a770a51 | 83 | |
emilmont | 44:24d45a770a51 | 84 | int semihost_uid(char *uid); |
emilmont | 44:24d45a770a51 | 85 | int semihost_reset(void); |
emilmont | 44:24d45a770a51 | 86 | int semihost_vbus(void); |
emilmont | 44:24d45a770a51 | 87 | int semihost_powerdown(void); |
emilmont | 44:24d45a770a51 | 88 | int semihost_exit(void); |
emilmont | 44:24d45a770a51 | 89 | |
emilmont | 44:24d45a770a51 | 90 | int semihost_connected(void); |
emilmont | 44:24d45a770a51 | 91 | int semihost_disabledebug(void); |
emilmont | 44:24d45a770a51 | 92 | |
emilmont | 55:d722ed6a4237 | 93 | #endif |
emilmont | 55:d722ed6a4237 | 94 | |
emilmont | 44:24d45a770a51 | 95 | #ifdef __cplusplus |
emilmont | 44:24d45a770a51 | 96 | } |
emilmont | 44:24d45a770a51 | 97 | #endif |
emilmont | 44:24d45a770a51 | 98 | |
emilmont | 44:24d45a770a51 | 99 | #endif |