Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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