fft

Dependencies:   BSP_DISCO_F746NG SDFileSystem_Warning_Fixed

Committer:
aria19970520
Date:
Fri Mar 06 06:52:14 2020 +0000
Revision:
3:6f7e05dd8d15
Parent:
0:3e46577dc273
fft

Who changed what in which revision?

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