Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

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