Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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