mbed w/ spi bug fig

Dependents:   display-puck

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Nov 20 17:24:08 2012 +0000
Revision:
0:fd0d7bdfcdc2
Child:
2:143cac498751
mbed sources

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:fd0d7bdfcdc2 1 /* mbed Microcontroller Library
mbed_official 0:fd0d7bdfcdc2 2 * Copyright (c) 2006-2012 ARM Limited
mbed_official 0:fd0d7bdfcdc2 3 *
mbed_official 0:fd0d7bdfcdc2 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mbed_official 0:fd0d7bdfcdc2 5 * of this software and associated documentation files (the "Software"), to deal
mbed_official 0:fd0d7bdfcdc2 6 * in the Software without restriction, including without limitation the rights
mbed_official 0:fd0d7bdfcdc2 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbed_official 0:fd0d7bdfcdc2 8 * copies of the Software, and to permit persons to whom the Software is
mbed_official 0:fd0d7bdfcdc2 9 * furnished to do so, subject to the following conditions:
mbed_official 0:fd0d7bdfcdc2 10 *
mbed_official 0:fd0d7bdfcdc2 11 * The above copyright notice and this permission notice shall be included in
mbed_official 0:fd0d7bdfcdc2 12 * all copies or substantial portions of the Software.
mbed_official 0:fd0d7bdfcdc2 13 *
mbed_official 0:fd0d7bdfcdc2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbed_official 0:fd0d7bdfcdc2 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbed_official 0:fd0d7bdfcdc2 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbed_official 0:fd0d7bdfcdc2 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed_official 0:fd0d7bdfcdc2 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 0:fd0d7bdfcdc2 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mbed_official 0:fd0d7bdfcdc2 20 * SOFTWARE.
mbed_official 0:fd0d7bdfcdc2 21 */
mbed_official 0:fd0d7bdfcdc2 22 #include "cmsis.h"
mbed_official 0:fd0d7bdfcdc2 23 #include "semihost_api.h"
mbed_official 0:fd0d7bdfcdc2 24
mbed_official 0:fd0d7bdfcdc2 25 #include <stdint.h>
mbed_official 0:fd0d7bdfcdc2 26 #include <string.h>
mbed_official 0:fd0d7bdfcdc2 27
mbed_official 0:fd0d7bdfcdc2 28 // ARM Semihosting Commands
mbed_official 0:fd0d7bdfcdc2 29 #define SYS_OPEN (0x1)
mbed_official 0:fd0d7bdfcdc2 30 #define SYS_CLOSE (0x2)
mbed_official 0:fd0d7bdfcdc2 31 #define SYS_WRITE (0x5)
mbed_official 0:fd0d7bdfcdc2 32 #define SYS_READ (0x6)
mbed_official 0:fd0d7bdfcdc2 33 #define SYS_ISTTY (0x9)
mbed_official 0:fd0d7bdfcdc2 34 #define SYS_SEEK (0xa)
mbed_official 0:fd0d7bdfcdc2 35 #define SYS_ENSURE (0xb)
mbed_official 0:fd0d7bdfcdc2 36 #define SYS_FLEN (0xc)
mbed_official 0:fd0d7bdfcdc2 37 #define SYS_REMOVE (0xe)
mbed_official 0:fd0d7bdfcdc2 38 #define SYS_RENAME (0xf)
mbed_official 0:fd0d7bdfcdc2 39 #define SYS_EXIT (0x18)
mbed_official 0:fd0d7bdfcdc2 40
mbed_official 0:fd0d7bdfcdc2 41 // mbed Semihosting Commands
mbed_official 0:fd0d7bdfcdc2 42 #define RESERVED_FOR_USER_APPLICATIONS (0x100) // 0x100 - 0x1ff
mbed_official 0:fd0d7bdfcdc2 43 #define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
mbed_official 0:fd0d7bdfcdc2 44 #define USR_UID (RESERVED_FOR_USER_APPLICATIONS + 1)
mbed_official 0:fd0d7bdfcdc2 45 #define USR_RESET (RESERVED_FOR_USER_APPLICATIONS + 2)
mbed_official 0:fd0d7bdfcdc2 46 #define USR_VBUS (RESERVED_FOR_USER_APPLICATIONS + 3)
mbed_official 0:fd0d7bdfcdc2 47 #define USR_POWERDOWN (RESERVED_FOR_USER_APPLICATIONS + 4)
mbed_official 0:fd0d7bdfcdc2 48 #define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5)
mbed_official 0:fd0d7bdfcdc2 49
mbed_official 0:fd0d7bdfcdc2 50 #if DEVICE_LOCALFILESYSTEM
mbed_official 0:fd0d7bdfcdc2 51 FILEHANDLE semihost_open(const char* name, int openmode) {
mbed_official 0:fd0d7bdfcdc2 52 uint32_t args[3];
mbed_official 0:fd0d7bdfcdc2 53 args[0] = (uint32_t)name;
mbed_official 0:fd0d7bdfcdc2 54 args[1] = (uint32_t)openmode;
mbed_official 0:fd0d7bdfcdc2 55 args[2] = (uint32_t)strlen(name);
mbed_official 0:fd0d7bdfcdc2 56 return __semihost(SYS_OPEN, args);
mbed_official 0:fd0d7bdfcdc2 57 }
mbed_official 0:fd0d7bdfcdc2 58
mbed_official 0:fd0d7bdfcdc2 59 int semihost_close(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 60 return __semihost(SYS_CLOSE, &fh);
mbed_official 0:fd0d7bdfcdc2 61 }
mbed_official 0:fd0d7bdfcdc2 62
mbed_official 0:fd0d7bdfcdc2 63 int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode) {
mbed_official 0:fd0d7bdfcdc2 64 uint32_t args[3];
mbed_official 0:fd0d7bdfcdc2 65 args[0] = (uint32_t)fh;
mbed_official 0:fd0d7bdfcdc2 66 args[1] = (uint32_t)buffer;
mbed_official 0:fd0d7bdfcdc2 67 args[2] = (uint32_t)length;
mbed_official 0:fd0d7bdfcdc2 68 return __semihost(SYS_WRITE, args);
mbed_official 0:fd0d7bdfcdc2 69 }
mbed_official 0:fd0d7bdfcdc2 70
mbed_official 0:fd0d7bdfcdc2 71 int semihost_read(FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode) {
mbed_official 0:fd0d7bdfcdc2 72 uint32_t args[3];
mbed_official 0:fd0d7bdfcdc2 73 args[0] = (uint32_t)fh;
mbed_official 0:fd0d7bdfcdc2 74 args[1] = (uint32_t)buffer;
mbed_official 0:fd0d7bdfcdc2 75 args[2] = (uint32_t)length;
mbed_official 0:fd0d7bdfcdc2 76 return __semihost(SYS_READ, args);
mbed_official 0:fd0d7bdfcdc2 77 }
mbed_official 0:fd0d7bdfcdc2 78
mbed_official 0:fd0d7bdfcdc2 79 int semihost_istty(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 80 return __semihost(SYS_ISTTY, &fh);
mbed_official 0:fd0d7bdfcdc2 81 }
mbed_official 0:fd0d7bdfcdc2 82
mbed_official 0:fd0d7bdfcdc2 83 int semihost_seek(FILEHANDLE fh, long position) {
mbed_official 0:fd0d7bdfcdc2 84 uint32_t args[2];
mbed_official 0:fd0d7bdfcdc2 85 args[0] = (uint32_t)fh;
mbed_official 0:fd0d7bdfcdc2 86 args[1] = (uint32_t)position;
mbed_official 0:fd0d7bdfcdc2 87 return __semihost(SYS_SEEK, args);
mbed_official 0:fd0d7bdfcdc2 88 }
mbed_official 0:fd0d7bdfcdc2 89
mbed_official 0:fd0d7bdfcdc2 90 int semihost_ensure(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 91 return __semihost(SYS_ENSURE, &fh);
mbed_official 0:fd0d7bdfcdc2 92 }
mbed_official 0:fd0d7bdfcdc2 93
mbed_official 0:fd0d7bdfcdc2 94 long semihost_flen(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 95 return __semihost(SYS_FLEN, &fh);
mbed_official 0:fd0d7bdfcdc2 96 }
mbed_official 0:fd0d7bdfcdc2 97
mbed_official 0:fd0d7bdfcdc2 98 int semihost_remove(const char *name) {
mbed_official 0:fd0d7bdfcdc2 99 uint32_t args[2];
mbed_official 0:fd0d7bdfcdc2 100 args[0] = (uint32_t)name;
mbed_official 0:fd0d7bdfcdc2 101 args[1] = (uint32_t)strlen(name);
mbed_official 0:fd0d7bdfcdc2 102 return __semihost(SYS_REMOVE, args);
mbed_official 0:fd0d7bdfcdc2 103 }
mbed_official 0:fd0d7bdfcdc2 104
mbed_official 0:fd0d7bdfcdc2 105 int semihost_rename(const char *old_name, const char *new_name) {
mbed_official 0:fd0d7bdfcdc2 106 uint32_t args[4];
mbed_official 0:fd0d7bdfcdc2 107 args[0] = (uint32_t)old_name;
mbed_official 0:fd0d7bdfcdc2 108 args[1] = (uint32_t)strlen(old_name);
mbed_official 0:fd0d7bdfcdc2 109 args[0] = (uint32_t)new_name;
mbed_official 0:fd0d7bdfcdc2 110 args[1] = (uint32_t)strlen(new_name);
mbed_official 0:fd0d7bdfcdc2 111 return __semihost(SYS_RENAME, args);
mbed_official 0:fd0d7bdfcdc2 112 }
mbed_official 0:fd0d7bdfcdc2 113 #endif
mbed_official 0:fd0d7bdfcdc2 114
mbed_official 0:fd0d7bdfcdc2 115 int semihost_exit(void) {
mbed_official 0:fd0d7bdfcdc2 116 uint32_t args[4];
mbed_official 0:fd0d7bdfcdc2 117 return __semihost(SYS_EXIT, args);
mbed_official 0:fd0d7bdfcdc2 118 }
mbed_official 0:fd0d7bdfcdc2 119
mbed_official 0:fd0d7bdfcdc2 120 int semihost_uid(char *uid) {
mbed_official 0:fd0d7bdfcdc2 121 uint32_t args[2];
mbed_official 0:fd0d7bdfcdc2 122 args[0] = (uint32_t)uid;
mbed_official 0:fd0d7bdfcdc2 123 args[1] = 33;
mbed_official 0:fd0d7bdfcdc2 124 return __semihost(USR_UID, &args);
mbed_official 0:fd0d7bdfcdc2 125 }
mbed_official 0:fd0d7bdfcdc2 126
mbed_official 0:fd0d7bdfcdc2 127 int semihost_reset(void) {
mbed_official 0:fd0d7bdfcdc2 128 // Does not normally return, however if used with older firmware versions
mbed_official 0:fd0d7bdfcdc2 129 // that do not support this call it will return -1.
mbed_official 0:fd0d7bdfcdc2 130 return __semihost(USR_RESET, NULL);
mbed_official 0:fd0d7bdfcdc2 131 }
mbed_official 0:fd0d7bdfcdc2 132
mbed_official 0:fd0d7bdfcdc2 133 int semihost_vbus(void) {
mbed_official 0:fd0d7bdfcdc2 134 return __semihost(USR_VBUS, NULL);
mbed_official 0:fd0d7bdfcdc2 135 }
mbed_official 0:fd0d7bdfcdc2 136
mbed_official 0:fd0d7bdfcdc2 137 int semihost_powerdown(void) {
mbed_official 0:fd0d7bdfcdc2 138 return __semihost(USR_POWERDOWN, NULL);
mbed_official 0:fd0d7bdfcdc2 139 }
mbed_official 0:fd0d7bdfcdc2 140
mbed_official 0:fd0d7bdfcdc2 141 #if !(DEVICE_DEBUG_AWARENESS)
mbed_official 0:fd0d7bdfcdc2 142 // These processors cannot know if the interface is connect, assume so:
mbed_official 0:fd0d7bdfcdc2 143 static int is_debugger_attached = 1;
mbed_official 0:fd0d7bdfcdc2 144
mbed_official 0:fd0d7bdfcdc2 145 int semihost_connected(void) {
mbed_official 0:fd0d7bdfcdc2 146 return is_debugger_attached;
mbed_official 0:fd0d7bdfcdc2 147 }
mbed_official 0:fd0d7bdfcdc2 148 #endif
mbed_official 0:fd0d7bdfcdc2 149
mbed_official 0:fd0d7bdfcdc2 150 int semihost_disabledebug(void) {
mbed_official 0:fd0d7bdfcdc2 151 #if !(DEVICE_DEBUG_AWARENESS)
mbed_official 0:fd0d7bdfcdc2 152 is_debugger_attached = 0;
mbed_official 0:fd0d7bdfcdc2 153 #endif
mbed_official 0:fd0d7bdfcdc2 154 return __semihost(USR_DISABLEDEBUG, NULL);
mbed_official 0:fd0d7bdfcdc2 155 }
mbed_official 0:fd0d7bdfcdc2 156