Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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