mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
updated based on mbed-os5.15.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 1:9db0e321a9f4 1 /* mbed Microcontroller Library
kenjiArai 1:9db0e321a9f4 2 * Copyright (c) 2006-2013 ARM Limited
kenjiArai 1:9db0e321a9f4 3 * SPDX-License-Identifier: Apache-2.0
kenjiArai 1:9db0e321a9f4 4 *
kenjiArai 1:9db0e321a9f4 5 * Licensed under the Apache License, Version 2.0 (the "License");
kenjiArai 1:9db0e321a9f4 6 * you may not use this file except in compliance with the License.
kenjiArai 1:9db0e321a9f4 7 * You may obtain a copy of the License at
kenjiArai 1:9db0e321a9f4 8 *
kenjiArai 1:9db0e321a9f4 9 * http://www.apache.org/licenses/LICENSE-2.0
kenjiArai 1:9db0e321a9f4 10 *
kenjiArai 1:9db0e321a9f4 11 * Unless required by applicable law or agreed to in writing, software
kenjiArai 1:9db0e321a9f4 12 * distributed under the License is distributed on an "AS IS" BASIS,
kenjiArai 1:9db0e321a9f4 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kenjiArai 1:9db0e321a9f4 14 * See the License for the specific language governing permissions and
kenjiArai 1:9db0e321a9f4 15 * limitations under the License.
kenjiArai 1:9db0e321a9f4 16 */
kenjiArai 1:9db0e321a9f4 17 #include "cmsis.h"
kenjiArai 1:9db0e321a9f4 18 #include "platform/mbed_semihost_api.h"
kenjiArai 1:9db0e321a9f4 19
kenjiArai 1:9db0e321a9f4 20 #include <stdint.h>
kenjiArai 1:9db0e321a9f4 21 #include <string.h>
kenjiArai 1:9db0e321a9f4 22
kenjiArai 1:9db0e321a9f4 23 #if DEVICE_SEMIHOST
kenjiArai 1:9db0e321a9f4 24
kenjiArai 1:9db0e321a9f4 25 // ARM Semihosting Commands
kenjiArai 1:9db0e321a9f4 26 #define SYS_OPEN (0x1)
kenjiArai 1:9db0e321a9f4 27 #define SYS_CLOSE (0x2)
kenjiArai 1:9db0e321a9f4 28 #define SYS_WRITE (0x5)
kenjiArai 1:9db0e321a9f4 29 #define SYS_READ (0x6)
kenjiArai 1:9db0e321a9f4 30 #define SYS_ISTTY (0x9)
kenjiArai 1:9db0e321a9f4 31 #define SYS_SEEK (0xa)
kenjiArai 1:9db0e321a9f4 32 #define SYS_ENSURE (0xb)
kenjiArai 1:9db0e321a9f4 33 #define SYS_FLEN (0xc)
kenjiArai 1:9db0e321a9f4 34 #define SYS_REMOVE (0xe)
kenjiArai 1:9db0e321a9f4 35 #define SYS_RENAME (0xf)
kenjiArai 1:9db0e321a9f4 36 #define SYS_EXIT (0x18)
kenjiArai 1:9db0e321a9f4 37
kenjiArai 1:9db0e321a9f4 38 // mbed Semihosting Commands
kenjiArai 1:9db0e321a9f4 39 #define RESERVED_FOR_USER_APPLICATIONS (0x100) // 0x100 - 0x1ff
kenjiArai 1:9db0e321a9f4 40 #define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
kenjiArai 1:9db0e321a9f4 41 #define USR_UID (RESERVED_FOR_USER_APPLICATIONS + 1)
kenjiArai 1:9db0e321a9f4 42 #define USR_RESET (RESERVED_FOR_USER_APPLICATIONS + 2)
kenjiArai 1:9db0e321a9f4 43 #define USR_VBUS (RESERVED_FOR_USER_APPLICATIONS + 3)
kenjiArai 1:9db0e321a9f4 44 #define USR_POWERDOWN (RESERVED_FOR_USER_APPLICATIONS + 4)
kenjiArai 1:9db0e321a9f4 45 #define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5)
kenjiArai 1:9db0e321a9f4 46
kenjiArai 1:9db0e321a9f4 47 #if DEVICE_LOCALFILESYSTEM
kenjiArai 1:9db0e321a9f4 48 FILEHANDLE semihost_open(const char *name, int openmode)
kenjiArai 1:9db0e321a9f4 49 {
kenjiArai 1:9db0e321a9f4 50 uint32_t args[3];
kenjiArai 1:9db0e321a9f4 51 args[0] = (uint32_t)name;
kenjiArai 1:9db0e321a9f4 52 args[1] = (uint32_t)openmode;
kenjiArai 1:9db0e321a9f4 53 args[2] = (uint32_t)strlen(name);
kenjiArai 1:9db0e321a9f4 54 return __semihost(SYS_OPEN, args);
kenjiArai 1:9db0e321a9f4 55 }
kenjiArai 1:9db0e321a9f4 56
kenjiArai 1:9db0e321a9f4 57 int semihost_close(FILEHANDLE fh)
kenjiArai 1:9db0e321a9f4 58 {
kenjiArai 1:9db0e321a9f4 59 return __semihost(SYS_CLOSE, &fh);
kenjiArai 1:9db0e321a9f4 60 }
kenjiArai 1:9db0e321a9f4 61
kenjiArai 1:9db0e321a9f4 62 int semihost_write(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode)
kenjiArai 1:9db0e321a9f4 63 {
kenjiArai 1:9db0e321a9f4 64 if (length == 0) {
kenjiArai 1:9db0e321a9f4 65 return 0;
kenjiArai 1:9db0e321a9f4 66 }
kenjiArai 1:9db0e321a9f4 67
kenjiArai 1:9db0e321a9f4 68 uint32_t args[3];
kenjiArai 1:9db0e321a9f4 69 args[0] = (uint32_t)fh;
kenjiArai 1:9db0e321a9f4 70 args[1] = (uint32_t)buffer;
kenjiArai 1:9db0e321a9f4 71 args[2] = (uint32_t)length;
kenjiArai 1:9db0e321a9f4 72 return __semihost(SYS_WRITE, args);
kenjiArai 1:9db0e321a9f4 73 }
kenjiArai 1:9db0e321a9f4 74
kenjiArai 1:9db0e321a9f4 75 int semihost_read(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode)
kenjiArai 1:9db0e321a9f4 76 {
kenjiArai 1:9db0e321a9f4 77 uint32_t args[3];
kenjiArai 1:9db0e321a9f4 78 args[0] = (uint32_t)fh;
kenjiArai 1:9db0e321a9f4 79 args[1] = (uint32_t)buffer;
kenjiArai 1:9db0e321a9f4 80 args[2] = (uint32_t)length;
kenjiArai 1:9db0e321a9f4 81 return __semihost(SYS_READ, args);
kenjiArai 1:9db0e321a9f4 82 }
kenjiArai 1:9db0e321a9f4 83
kenjiArai 1:9db0e321a9f4 84 int semihost_istty(FILEHANDLE fh)
kenjiArai 1:9db0e321a9f4 85 {
kenjiArai 1:9db0e321a9f4 86 return __semihost(SYS_ISTTY, &fh);
kenjiArai 1:9db0e321a9f4 87 }
kenjiArai 1:9db0e321a9f4 88
kenjiArai 1:9db0e321a9f4 89 int semihost_seek(FILEHANDLE fh, long position)
kenjiArai 1:9db0e321a9f4 90 {
kenjiArai 1:9db0e321a9f4 91 uint32_t args[2];
kenjiArai 1:9db0e321a9f4 92 args[0] = (uint32_t)fh;
kenjiArai 1:9db0e321a9f4 93 args[1] = (uint32_t)position;
kenjiArai 1:9db0e321a9f4 94 return __semihost(SYS_SEEK, args);
kenjiArai 1:9db0e321a9f4 95 }
kenjiArai 1:9db0e321a9f4 96
kenjiArai 1:9db0e321a9f4 97 int semihost_ensure(FILEHANDLE fh)
kenjiArai 1:9db0e321a9f4 98 {
kenjiArai 1:9db0e321a9f4 99 return __semihost(SYS_ENSURE, &fh);
kenjiArai 1:9db0e321a9f4 100 }
kenjiArai 1:9db0e321a9f4 101
kenjiArai 1:9db0e321a9f4 102 long semihost_flen(FILEHANDLE fh)
kenjiArai 1:9db0e321a9f4 103 {
kenjiArai 1:9db0e321a9f4 104 return __semihost(SYS_FLEN, &fh);
kenjiArai 1:9db0e321a9f4 105 }
kenjiArai 1:9db0e321a9f4 106
kenjiArai 1:9db0e321a9f4 107 int semihost_remove(const char *name)
kenjiArai 1:9db0e321a9f4 108 {
kenjiArai 1:9db0e321a9f4 109 uint32_t args[2];
kenjiArai 1:9db0e321a9f4 110 args[0] = (uint32_t)name;
kenjiArai 1:9db0e321a9f4 111 args[1] = (uint32_t)strlen(name);
kenjiArai 1:9db0e321a9f4 112 return __semihost(SYS_REMOVE, args);
kenjiArai 1:9db0e321a9f4 113 }
kenjiArai 1:9db0e321a9f4 114
kenjiArai 1:9db0e321a9f4 115 int semihost_rename(const char *old_name, const char *new_name)
kenjiArai 1:9db0e321a9f4 116 {
kenjiArai 1:9db0e321a9f4 117 uint32_t args[4];
kenjiArai 1:9db0e321a9f4 118 args[0] = (uint32_t)old_name;
kenjiArai 1:9db0e321a9f4 119 args[1] = (uint32_t)strlen(old_name);
kenjiArai 1:9db0e321a9f4 120 args[0] = (uint32_t)new_name;
kenjiArai 1:9db0e321a9f4 121 args[1] = (uint32_t)strlen(new_name);
kenjiArai 1:9db0e321a9f4 122 return __semihost(SYS_RENAME, args);
kenjiArai 1:9db0e321a9f4 123 }
kenjiArai 1:9db0e321a9f4 124 #endif
kenjiArai 1:9db0e321a9f4 125
kenjiArai 1:9db0e321a9f4 126 int semihost_exit(void)
kenjiArai 1:9db0e321a9f4 127 {
kenjiArai 1:9db0e321a9f4 128 uint32_t args[4];
kenjiArai 1:9db0e321a9f4 129 return __semihost(SYS_EXIT, args);
kenjiArai 1:9db0e321a9f4 130 }
kenjiArai 1:9db0e321a9f4 131
kenjiArai 1:9db0e321a9f4 132 int semihost_uid(char *uid)
kenjiArai 1:9db0e321a9f4 133 {
kenjiArai 1:9db0e321a9f4 134 uint32_t args[2];
kenjiArai 1:9db0e321a9f4 135 args[0] = (uint32_t)uid;
kenjiArai 1:9db0e321a9f4 136 args[1] = DEVICE_ID_LENGTH + 1;
kenjiArai 1:9db0e321a9f4 137 return __semihost(USR_UID, &args);
kenjiArai 1:9db0e321a9f4 138 }
kenjiArai 1:9db0e321a9f4 139
kenjiArai 1:9db0e321a9f4 140 int semihost_reset(void)
kenjiArai 1:9db0e321a9f4 141 {
kenjiArai 1:9db0e321a9f4 142 // Does not normally return, however if used with older firmware versions
kenjiArai 1:9db0e321a9f4 143 // that do not support this call it will return -1.
kenjiArai 1:9db0e321a9f4 144 return __semihost(USR_RESET, NULL);
kenjiArai 1:9db0e321a9f4 145 }
kenjiArai 1:9db0e321a9f4 146
kenjiArai 1:9db0e321a9f4 147 int semihost_vbus(void)
kenjiArai 1:9db0e321a9f4 148 {
kenjiArai 1:9db0e321a9f4 149 return __semihost(USR_VBUS, NULL);
kenjiArai 1:9db0e321a9f4 150 }
kenjiArai 1:9db0e321a9f4 151
kenjiArai 1:9db0e321a9f4 152 int semihost_powerdown(void)
kenjiArai 1:9db0e321a9f4 153 {
kenjiArai 1:9db0e321a9f4 154 return __semihost(USR_POWERDOWN, NULL);
kenjiArai 1:9db0e321a9f4 155 }
kenjiArai 1:9db0e321a9f4 156
kenjiArai 1:9db0e321a9f4 157 #if DEVICE_DEBUG_AWARENESS
kenjiArai 1:9db0e321a9f4 158
kenjiArai 1:9db0e321a9f4 159 int semihost_connected(void)
kenjiArai 1:9db0e321a9f4 160 {
kenjiArai 1:9db0e321a9f4 161 return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? 1 : 0;
kenjiArai 1:9db0e321a9f4 162 }
kenjiArai 1:9db0e321a9f4 163
kenjiArai 1:9db0e321a9f4 164 #else
kenjiArai 1:9db0e321a9f4 165 // These processors cannot know if the interface is connect, assume so:
kenjiArai 1:9db0e321a9f4 166 static int is_debugger_attached = 1;
kenjiArai 1:9db0e321a9f4 167
kenjiArai 1:9db0e321a9f4 168 int semihost_connected(void)
kenjiArai 1:9db0e321a9f4 169 {
kenjiArai 1:9db0e321a9f4 170 return is_debugger_attached;
kenjiArai 1:9db0e321a9f4 171 }
kenjiArai 1:9db0e321a9f4 172 #endif
kenjiArai 1:9db0e321a9f4 173
kenjiArai 1:9db0e321a9f4 174 int semihost_disabledebug(void)
kenjiArai 1:9db0e321a9f4 175 {
kenjiArai 1:9db0e321a9f4 176 uint32_t args[1];
kenjiArai 1:9db0e321a9f4 177 #if !(DEVICE_DEBUG_AWARENESS)
kenjiArai 1:9db0e321a9f4 178 is_debugger_attached = 0;
kenjiArai 1:9db0e321a9f4 179 #endif
kenjiArai 1:9db0e321a9f4 180 return __semihost(USR_DISABLEDEBUG, &args);
kenjiArai 1:9db0e321a9f4 181 }
kenjiArai 1:9db0e321a9f4 182
kenjiArai 1:9db0e321a9f4 183 #endif