Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
mbed_semihost_api.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "cmsis.h" 00017 #include "platform/mbed_semihost_api.h" 00018 00019 #include <stdint.h> 00020 #include <string.h> 00021 00022 #if DEVICE_SEMIHOST 00023 00024 // ARM Semihosting Commands 00025 #define SYS_OPEN (0x1) 00026 #define SYS_CLOSE (0x2) 00027 #define SYS_WRITE (0x5) 00028 #define SYS_READ (0x6) 00029 #define SYS_ISTTY (0x9) 00030 #define SYS_SEEK (0xa) 00031 #define SYS_ENSURE (0xb) 00032 #define SYS_FLEN (0xc) 00033 #define SYS_REMOVE (0xe) 00034 #define SYS_RENAME (0xf) 00035 #define SYS_EXIT (0x18) 00036 00037 // mbed Semihosting Commands 00038 #define RESERVED_FOR_USER_APPLICATIONS (0x100) // 0x100 - 0x1ff 00039 #define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0) 00040 #define USR_UID (RESERVED_FOR_USER_APPLICATIONS + 1) 00041 #define USR_RESET (RESERVED_FOR_USER_APPLICATIONS + 2) 00042 #define USR_VBUS (RESERVED_FOR_USER_APPLICATIONS + 3) 00043 #define USR_POWERDOWN (RESERVED_FOR_USER_APPLICATIONS + 4) 00044 #define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5) 00045 00046 #if DEVICE_LOCALFILESYSTEM 00047 FILEHANDLE semihost_open(const char *name, int openmode) 00048 { 00049 uint32_t args[3]; 00050 args[0] = (uint32_t)name; 00051 args[1] = (uint32_t)openmode; 00052 args[2] = (uint32_t)strlen(name); 00053 return __semihost(SYS_OPEN, args); 00054 } 00055 00056 int semihost_close(FILEHANDLE fh) 00057 { 00058 return __semihost(SYS_CLOSE, &fh); 00059 } 00060 00061 int semihost_write(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode) 00062 { 00063 if (length == 0) { 00064 return 0; 00065 } 00066 00067 uint32_t args[3]; 00068 args[0] = (uint32_t)fh; 00069 args[1] = (uint32_t)buffer; 00070 args[2] = (uint32_t)length; 00071 return __semihost(SYS_WRITE, args); 00072 } 00073 00074 int semihost_read(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode) 00075 { 00076 uint32_t args[3]; 00077 args[0] = (uint32_t)fh; 00078 args[1] = (uint32_t)buffer; 00079 args[2] = (uint32_t)length; 00080 return __semihost(SYS_READ, args); 00081 } 00082 00083 int semihost_istty(FILEHANDLE fh) 00084 { 00085 return __semihost(SYS_ISTTY, &fh); 00086 } 00087 00088 int semihost_seek(FILEHANDLE fh, long position) 00089 { 00090 uint32_t args[2]; 00091 args[0] = (uint32_t)fh; 00092 args[1] = (uint32_t)position; 00093 return __semihost(SYS_SEEK, args); 00094 } 00095 00096 int semihost_ensure(FILEHANDLE fh) 00097 { 00098 return __semihost(SYS_ENSURE, &fh); 00099 } 00100 00101 long semihost_flen(FILEHANDLE fh) 00102 { 00103 return __semihost(SYS_FLEN, &fh); 00104 } 00105 00106 int semihost_remove(const char *name) 00107 { 00108 uint32_t args[2]; 00109 args[0] = (uint32_t)name; 00110 args[1] = (uint32_t)strlen(name); 00111 return __semihost(SYS_REMOVE, args); 00112 } 00113 00114 int semihost_rename(const char *old_name, const char *new_name) 00115 { 00116 uint32_t args[4]; 00117 args[0] = (uint32_t)old_name; 00118 args[1] = (uint32_t)strlen(old_name); 00119 args[0] = (uint32_t)new_name; 00120 args[1] = (uint32_t)strlen(new_name); 00121 return __semihost(SYS_RENAME, args); 00122 } 00123 #endif 00124 00125 int semihost_exit(void) 00126 { 00127 uint32_t args[4]; 00128 return __semihost(SYS_EXIT, args); 00129 } 00130 00131 int semihost_uid(char *uid) 00132 { 00133 uint32_t args[2]; 00134 args[0] = (uint32_t)uid; 00135 args[1] = DEVICE_ID_LENGTH + 1; 00136 return __semihost(USR_UID, &args); 00137 } 00138 00139 int semihost_reset(void) 00140 { 00141 // Does not normally return, however if used with older firmware versions 00142 // that do not support this call it will return -1. 00143 return __semihost(USR_RESET, NULL); 00144 } 00145 00146 int semihost_vbus(void) 00147 { 00148 return __semihost(USR_VBUS, NULL); 00149 } 00150 00151 int semihost_powerdown(void) 00152 { 00153 return __semihost(USR_POWERDOWN, NULL); 00154 } 00155 00156 #if DEVICE_DEBUG_AWARENESS 00157 00158 int semihost_connected(void) 00159 { 00160 return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? 1 : 0; 00161 } 00162 00163 #else 00164 // These processors cannot know if the interface is connect, assume so: 00165 static int is_debugger_attached = 1; 00166 00167 int semihost_connected(void) 00168 { 00169 return is_debugger_attached; 00170 } 00171 #endif 00172 00173 int semihost_disabledebug(void) 00174 { 00175 uint32_t args[1]; 00176 #if !(DEVICE_DEBUG_AWARENESS) 00177 is_debugger_attached = 0; 00178 #endif 00179 return __semihost(USR_DISABLEDEBUG, &args); 00180 } 00181 00182 #endif 00183
Generated on Tue Jul 12 2022 19:10:22 by
 1.7.2 
    