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