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