mbed.h library with any bug fixes AV finds.

Dependents:   micromouse4_encoder_testing PID_Test Lab1_Test WorkingPID ... more

Committer:
aravindsv
Date:
Mon Nov 02 03:07:12 2015 +0000
Revision:
1:ebce2ad32f95
Parent:
0:ba7650f404af
Changed the RCC timeout value to 500 ms, so total code startup time before program starts running is ~1s. Hopefully no side-effects from lower startup timeouts

Who changed what in which revision?

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