Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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