TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

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