The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:20e0c61e0684 1 /**************************************************************************//**
ganlikun 0:20e0c61e0684 2 * @file core_cmSecureAccess.h
ganlikun 0:20e0c61e0684 3 * @brief CMSIS Cortex-M Core Secure Access Header File
ganlikun 0:20e0c61e0684 4 * @version XXX
ganlikun 0:20e0c61e0684 5 * @date 10. June 2016
ganlikun 0:20e0c61e0684 6 *
ganlikun 0:20e0c61e0684 7 * @note
ganlikun 0:20e0c61e0684 8 *
ganlikun 0:20e0c61e0684 9 ******************************************************************************/
ganlikun 0:20e0c61e0684 10 /* Copyright (c) 2016 ARM LIMITED
ganlikun 0:20e0c61e0684 11
ganlikun 0:20e0c61e0684 12 All rights reserved.
ganlikun 0:20e0c61e0684 13 Redistribution and use in source and binary forms, with or without
ganlikun 0:20e0c61e0684 14 modification, are permitted provided that the following conditions are met:
ganlikun 0:20e0c61e0684 15 - Redistributions of source code must retain the above copyright
ganlikun 0:20e0c61e0684 16 notice, this list of conditions and the following disclaimer.
ganlikun 0:20e0c61e0684 17 - Redistributions in binary form must reproduce the above copyright
ganlikun 0:20e0c61e0684 18 notice, this list of conditions and the following disclaimer in the
ganlikun 0:20e0c61e0684 19 documentation and/or other materials provided with the distribution.
ganlikun 0:20e0c61e0684 20 - Neither the name of ARM nor the names of its contributors may be used
ganlikun 0:20e0c61e0684 21 to endorse or promote products derived from this software without
ganlikun 0:20e0c61e0684 22 specific prior written permission.
ganlikun 0:20e0c61e0684 23 *
ganlikun 0:20e0c61e0684 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:20e0c61e0684 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:20e0c61e0684 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ganlikun 0:20e0c61e0684 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
ganlikun 0:20e0c61e0684 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
ganlikun 0:20e0c61e0684 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
ganlikun 0:20e0c61e0684 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ganlikun 0:20e0c61e0684 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
ganlikun 0:20e0c61e0684 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ganlikun 0:20e0c61e0684 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
ganlikun 0:20e0c61e0684 34 POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:20e0c61e0684 35 ---------------------------------------------------------------------------*/
ganlikun 0:20e0c61e0684 36
ganlikun 0:20e0c61e0684 37
ganlikun 0:20e0c61e0684 38 #ifndef __CORE_CM_SECURE_ACCESS_H
ganlikun 0:20e0c61e0684 39 #define __CORE_CM_SECURE_ACCESS_H
ganlikun 0:20e0c61e0684 40
ganlikun 0:20e0c61e0684 41
ganlikun 0:20e0c61e0684 42 /* ########################### Core Secure Access ########################### */
ganlikun 0:20e0c61e0684 43
ganlikun 0:20e0c61e0684 44 #ifdef FEATURE_UVISOR
ganlikun 0:20e0c61e0684 45 #include "uvisor-lib/uvisor-lib.h"
ganlikun 0:20e0c61e0684 46
ganlikun 0:20e0c61e0684 47 /* Secure uVisor implementation. */
ganlikun 0:20e0c61e0684 48
ganlikun 0:20e0c61e0684 49 /** Set the value at the target address.
ganlikun 0:20e0c61e0684 50 *
ganlikun 0:20e0c61e0684 51 * Equivalent to: `*address = value`.
ganlikun 0:20e0c61e0684 52 * @param address[in] Target address
ganlikun 0:20e0c61e0684 53 * @param value[in] Value to write at the address location.
ganlikun 0:20e0c61e0684 54 */
ganlikun 0:20e0c61e0684 55 #define SECURE_WRITE(address, value) \
ganlikun 0:20e0c61e0684 56 uvisor_write(public_box, UVISOR_RGW_SHARED, address, value, UVISOR_RGW_OP_WRITE, 0xFFFFFFFFUL)
ganlikun 0:20e0c61e0684 57
ganlikun 0:20e0c61e0684 58 /** Get the value at the target address.
ganlikun 0:20e0c61e0684 59 *
ganlikun 0:20e0c61e0684 60 * @param address[in] Target address
ganlikun 0:20e0c61e0684 61 * @returns The value `*address`.
ganlikun 0:20e0c61e0684 62 */
ganlikun 0:20e0c61e0684 63 #define SECURE_READ(address) \
ganlikun 0:20e0c61e0684 64 uvisor_read(public_box, UVISOR_RGW_SHARED, address, UVISOR_RGW_OP_READ, 0xFFFFFFFFUL)
ganlikun 0:20e0c61e0684 65
ganlikun 0:20e0c61e0684 66 /** Get the selected bits at the target address.
ganlikun 0:20e0c61e0684 67 *
ganlikun 0:20e0c61e0684 68 * @param address[in] Target address
ganlikun 0:20e0c61e0684 69 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 70 * @returns The value `*address & mask`.
ganlikun 0:20e0c61e0684 71 */
ganlikun 0:20e0c61e0684 72 #define SECURE_BITS_GET(address, mask) \
ganlikun 0:20e0c61e0684 73 UVISOR_BITS_GET(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:20e0c61e0684 74
ganlikun 0:20e0c61e0684 75 /** Check the selected bits at the target address.
ganlikun 0:20e0c61e0684 76 *
ganlikun 0:20e0c61e0684 77 * @param address[in] Address at which to check the bits
ganlikun 0:20e0c61e0684 78 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 79 * @returns The value `((*address & mask) == mask)`.
ganlikun 0:20e0c61e0684 80 */
ganlikun 0:20e0c61e0684 81 #define SECURE_BITS_CHECK(address, mask) \
ganlikun 0:20e0c61e0684 82 UVISOR_BITS_CHECK(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:20e0c61e0684 83
ganlikun 0:20e0c61e0684 84 /** Set the selected bits to 1 at the target address.
ganlikun 0:20e0c61e0684 85 *
ganlikun 0:20e0c61e0684 86 * Equivalent to: `*address |= mask`.
ganlikun 0:20e0c61e0684 87 * @param address[in] Target address
ganlikun 0:20e0c61e0684 88 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 89 */
ganlikun 0:20e0c61e0684 90 #define SECURE_BITS_SET(address, mask) \
ganlikun 0:20e0c61e0684 91 UVISOR_BITS_SET(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:20e0c61e0684 92
ganlikun 0:20e0c61e0684 93 /** Clear the selected bits at the target address.
ganlikun 0:20e0c61e0684 94 *
ganlikun 0:20e0c61e0684 95 * Equivalent to: `*address &= ~mask`.
ganlikun 0:20e0c61e0684 96 * @param address[in] Target address
ganlikun 0:20e0c61e0684 97 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 98 */
ganlikun 0:20e0c61e0684 99 #define SECURE_BITS_CLEAR(address, mask) \
ganlikun 0:20e0c61e0684 100 UVISOR_BITS_CLEAR(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:20e0c61e0684 101
ganlikun 0:20e0c61e0684 102 /** Set the selected bits at the target address to the given value.
ganlikun 0:20e0c61e0684 103 *
ganlikun 0:20e0c61e0684 104 * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
ganlikun 0:20e0c61e0684 105 * @param address[in] Target address
ganlikun 0:20e0c61e0684 106 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 107 * @param value[in] Value to write at the address location. Note: The value
ganlikun 0:20e0c61e0684 108 * must be already shifted to the correct bit position
ganlikun 0:20e0c61e0684 109 */
ganlikun 0:20e0c61e0684 110 #define SECURE_BITS_SET_VALUE(address, mask, value) \
ganlikun 0:20e0c61e0684 111 UVISOR_BITS_SET_VALUE(public_box, UVISOR_RGW_SHARED, address, mask, value)
ganlikun 0:20e0c61e0684 112
ganlikun 0:20e0c61e0684 113 /** Toggle the selected bits at the target address.
ganlikun 0:20e0c61e0684 114 *
ganlikun 0:20e0c61e0684 115 * Equivalent to: `*address ^= mask`.
ganlikun 0:20e0c61e0684 116 * @param address[in] Target address
ganlikun 0:20e0c61e0684 117 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 118 */
ganlikun 0:20e0c61e0684 119 #define SECURE_BITS_TOGGLE(address, mask) \
ganlikun 0:20e0c61e0684 120 UVISOR_BITS_TOGGLE(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:20e0c61e0684 121
ganlikun 0:20e0c61e0684 122 #else
ganlikun 0:20e0c61e0684 123
ganlikun 0:20e0c61e0684 124 /* Insecure fallback implementation. */
ganlikun 0:20e0c61e0684 125
ganlikun 0:20e0c61e0684 126 /** Set the value at the target address.
ganlikun 0:20e0c61e0684 127 *
ganlikun 0:20e0c61e0684 128 * Equivalent to: `*address = value`.
ganlikun 0:20e0c61e0684 129 * @param address[in] Target address
ganlikun 0:20e0c61e0684 130 * @param value[in] Value to write at the address location.
ganlikun 0:20e0c61e0684 131 */
ganlikun 0:20e0c61e0684 132 #define SECURE_WRITE(address, value) \
ganlikun 0:20e0c61e0684 133 *(address) = (value)
ganlikun 0:20e0c61e0684 134
ganlikun 0:20e0c61e0684 135 /** Get the value at the target address.
ganlikun 0:20e0c61e0684 136 *
ganlikun 0:20e0c61e0684 137 * @param address[in] Target address
ganlikun 0:20e0c61e0684 138 * @returns The value `*address`.
ganlikun 0:20e0c61e0684 139 */
ganlikun 0:20e0c61e0684 140 #define SECURE_READ(address) \
ganlikun 0:20e0c61e0684 141 (*(address))
ganlikun 0:20e0c61e0684 142
ganlikun 0:20e0c61e0684 143 /** Get the selected bits at the target address.
ganlikun 0:20e0c61e0684 144 *
ganlikun 0:20e0c61e0684 145 * @param address[in] Target address
ganlikun 0:20e0c61e0684 146 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 147 * @returns The value `*address & mask`.
ganlikun 0:20e0c61e0684 148 */
ganlikun 0:20e0c61e0684 149 #define SECURE_BITS_GET(address, mask) \
ganlikun 0:20e0c61e0684 150 (*(address) & (mask))
ganlikun 0:20e0c61e0684 151
ganlikun 0:20e0c61e0684 152 /** Check the selected bits at the target address.
ganlikun 0:20e0c61e0684 153 *
ganlikun 0:20e0c61e0684 154 * @param address[in] Address at which to check the bits
ganlikun 0:20e0c61e0684 155 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 156 * @returns The value `((*address & mask) == mask)`.
ganlikun 0:20e0c61e0684 157 */
ganlikun 0:20e0c61e0684 158 #define SECURE_BITS_CHECK(address, mask) \
ganlikun 0:20e0c61e0684 159 ((*(address) & (mask)) == (mask))
ganlikun 0:20e0c61e0684 160
ganlikun 0:20e0c61e0684 161 /** Set the selected bits to 1 at the target address.
ganlikun 0:20e0c61e0684 162 *
ganlikun 0:20e0c61e0684 163 * Equivalent to: `*address |= mask`.
ganlikun 0:20e0c61e0684 164 * @param address[in] Target address
ganlikun 0:20e0c61e0684 165 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 166 */
ganlikun 0:20e0c61e0684 167 #define SECURE_BITS_SET(address, mask) \
ganlikun 0:20e0c61e0684 168 *(address) |= (mask)
ganlikun 0:20e0c61e0684 169
ganlikun 0:20e0c61e0684 170 /** Clear the selected bits at the target address.
ganlikun 0:20e0c61e0684 171 *
ganlikun 0:20e0c61e0684 172 * Equivalent to: `*address &= ~mask`.
ganlikun 0:20e0c61e0684 173 * @param address[in] Target address
ganlikun 0:20e0c61e0684 174 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 175 */
ganlikun 0:20e0c61e0684 176 #define SECURE_BITS_CLEAR(address, mask) \
ganlikun 0:20e0c61e0684 177 *(address) &= ~(mask)
ganlikun 0:20e0c61e0684 178
ganlikun 0:20e0c61e0684 179 /** Set the selected bits at the target address to the given value.
ganlikun 0:20e0c61e0684 180 *
ganlikun 0:20e0c61e0684 181 * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
ganlikun 0:20e0c61e0684 182 * @param address[in] Target address
ganlikun 0:20e0c61e0684 183 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 184 * @param value[in] Value to write at the address location. Note: The value
ganlikun 0:20e0c61e0684 185 * must be already shifted to the correct bit position
ganlikun 0:20e0c61e0684 186 */
ganlikun 0:20e0c61e0684 187 #define SECURE_BITS_SET_VALUE(address, mask, value) \
ganlikun 0:20e0c61e0684 188 *(address) = (*(address) & ~(mask)) | ((value) & (mask))
ganlikun 0:20e0c61e0684 189
ganlikun 0:20e0c61e0684 190 /** Toggle the selected bits at the target address.
ganlikun 0:20e0c61e0684 191 *
ganlikun 0:20e0c61e0684 192 * Equivalent to: `*address ^= mask`.
ganlikun 0:20e0c61e0684 193 * @param address[in] Target address
ganlikun 0:20e0c61e0684 194 * @param mask[in] Bits to select out of the target address
ganlikun 0:20e0c61e0684 195 */
ganlikun 0:20e0c61e0684 196 #define SECURE_BITS_TOGGLE(address, mask) \
ganlikun 0:20e0c61e0684 197 *(address) ^= (mask)
ganlikun 0:20e0c61e0684 198
ganlikun 0:20e0c61e0684 199 #endif
ganlikun 0:20e0c61e0684 200
ganlikun 0:20e0c61e0684 201 #endif /* __CORE_CM_SECURE_ACCESS_H */
ganlikun 0:20e0c61e0684 202