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