Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/emlib/inc/em_bitband.h@566:24a7119bd73a, 2015-06-11 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Jun 11 09:15:08 2015 +0100
- Revision:
- 566:24a7119bd73a
- Parent:
- 525:c320967f86b9
Synchronized with git revision 81af347389b2b87a85b1826ac315c8120e1db1a9
Full URL: https://github.com/mbedmicro/mbed/commit/81af347389b2b87a85b1826ac315c8120e1db1a9/
SPI - transfer() unification
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 525:c320967f86b9 | 1 | /***************************************************************************//** |
mbed_official | 525:c320967f86b9 | 2 | * @file em_bitband.h |
mbed_official | 525:c320967f86b9 | 3 | * @brief Bitband Peripheral API |
mbed_official | 525:c320967f86b9 | 4 | * @version 3.20.12 |
mbed_official | 525:c320967f86b9 | 5 | ******************************************************************************* |
mbed_official | 525:c320967f86b9 | 6 | * @section License |
mbed_official | 525:c320967f86b9 | 7 | * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b> |
mbed_official | 525:c320967f86b9 | 8 | ******************************************************************************* |
mbed_official | 525:c320967f86b9 | 9 | * |
mbed_official | 525:c320967f86b9 | 10 | * Permission is granted to anyone to use this software for any purpose, |
mbed_official | 525:c320967f86b9 | 11 | * including commercial applications, and to alter it and redistribute it |
mbed_official | 525:c320967f86b9 | 12 | * freely, subject to the following restrictions: |
mbed_official | 525:c320967f86b9 | 13 | * |
mbed_official | 525:c320967f86b9 | 14 | * 1. The origin of this software must not be misrepresented; you must not |
mbed_official | 525:c320967f86b9 | 15 | * claim that you wrote the original software. |
mbed_official | 525:c320967f86b9 | 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
mbed_official | 525:c320967f86b9 | 17 | * misrepresented as being the original software. |
mbed_official | 525:c320967f86b9 | 18 | * 3. This notice may not be removed or altered from any source distribution. |
mbed_official | 525:c320967f86b9 | 19 | * |
mbed_official | 525:c320967f86b9 | 20 | * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no |
mbed_official | 525:c320967f86b9 | 21 | * obligation to support this Software. Silicon Labs is providing the |
mbed_official | 525:c320967f86b9 | 22 | * Software "AS IS", with no express or implied warranties of any kind, |
mbed_official | 525:c320967f86b9 | 23 | * including, but not limited to, any implied warranties of merchantability |
mbed_official | 525:c320967f86b9 | 24 | * or fitness for any particular purpose or warranties against infringement |
mbed_official | 525:c320967f86b9 | 25 | * of any proprietary rights of a third party. |
mbed_official | 525:c320967f86b9 | 26 | * |
mbed_official | 525:c320967f86b9 | 27 | * Silicon Labs will not be liable for any consequential, incidental, or |
mbed_official | 525:c320967f86b9 | 28 | * special damages, or any other relief, or for any claim by any third party, |
mbed_official | 525:c320967f86b9 | 29 | * arising from your use of this Software. |
mbed_official | 525:c320967f86b9 | 30 | * |
mbed_official | 525:c320967f86b9 | 31 | ******************************************************************************/ |
mbed_official | 525:c320967f86b9 | 32 | |
mbed_official | 525:c320967f86b9 | 33 | |
mbed_official | 525:c320967f86b9 | 34 | #ifndef __SILICON_LABS_EM_BITBAND_H_ |
mbed_official | 525:c320967f86b9 | 35 | #define __SILICON_LABS_EM_BITBAND_H_ |
mbed_official | 525:c320967f86b9 | 36 | |
mbed_official | 525:c320967f86b9 | 37 | #include "em_device.h" |
mbed_official | 525:c320967f86b9 | 38 | #ifdef __cplusplus |
mbed_official | 525:c320967f86b9 | 39 | extern "C" { |
mbed_official | 525:c320967f86b9 | 40 | #endif |
mbed_official | 525:c320967f86b9 | 41 | |
mbed_official | 525:c320967f86b9 | 42 | /***************************************************************************//** |
mbed_official | 525:c320967f86b9 | 43 | * @addtogroup EM_Library |
mbed_official | 525:c320967f86b9 | 44 | * @{ |
mbed_official | 525:c320967f86b9 | 45 | ******************************************************************************/ |
mbed_official | 525:c320967f86b9 | 46 | |
mbed_official | 525:c320967f86b9 | 47 | /***************************************************************************//** |
mbed_official | 525:c320967f86b9 | 48 | * @addtogroup BITBAND |
mbed_official | 525:c320967f86b9 | 49 | * @brief BITBAND Peripheral API |
mbed_official | 525:c320967f86b9 | 50 | * @{ |
mbed_official | 525:c320967f86b9 | 51 | ******************************************************************************/ |
mbed_official | 525:c320967f86b9 | 52 | |
mbed_official | 525:c320967f86b9 | 53 | /***************************************************************************//** |
mbed_official | 525:c320967f86b9 | 54 | * @brief |
mbed_official | 525:c320967f86b9 | 55 | * Perform bit-band operation on peripheral memory location. |
mbed_official | 525:c320967f86b9 | 56 | * |
mbed_official | 525:c320967f86b9 | 57 | * @details |
mbed_official | 525:c320967f86b9 | 58 | * Bit-banding provides atomic read-modify-write cycle for single bit |
mbed_official | 525:c320967f86b9 | 59 | * modification. Please refer to the reference manual for further details |
mbed_official | 525:c320967f86b9 | 60 | * about bit-banding. |
mbed_official | 525:c320967f86b9 | 61 | * |
mbed_official | 525:c320967f86b9 | 62 | * @note |
mbed_official | 525:c320967f86b9 | 63 | * This function is only atomic on cores which fully support bitbanding. |
mbed_official | 525:c320967f86b9 | 64 | * |
mbed_official | 525:c320967f86b9 | 65 | * @param[in] addr Peripheral address location to modify bit in. |
mbed_official | 525:c320967f86b9 | 66 | * |
mbed_official | 525:c320967f86b9 | 67 | * @param[in] bit Bit position to modify, 0-31. |
mbed_official | 525:c320967f86b9 | 68 | * |
mbed_official | 525:c320967f86b9 | 69 | * @param[in] val Value to set bit to, 0 or 1. |
mbed_official | 525:c320967f86b9 | 70 | ******************************************************************************/ |
mbed_official | 525:c320967f86b9 | 71 | __STATIC_INLINE void BITBAND_Peripheral(volatile uint32_t *addr, |
mbed_official | 525:c320967f86b9 | 72 | uint32_t bit, |
mbed_official | 525:c320967f86b9 | 73 | uint32_t val) |
mbed_official | 525:c320967f86b9 | 74 | { |
mbed_official | 525:c320967f86b9 | 75 | #if defined(BITBAND_PER_BASE) |
mbed_official | 525:c320967f86b9 | 76 | uint32_t tmp = |
mbed_official | 525:c320967f86b9 | 77 | BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) * 32) + (bit * 4); |
mbed_official | 525:c320967f86b9 | 78 | |
mbed_official | 525:c320967f86b9 | 79 | *((volatile uint32_t *)tmp) = (uint32_t)val; |
mbed_official | 525:c320967f86b9 | 80 | #else |
mbed_official | 525:c320967f86b9 | 81 | uint32_t tmp = *addr; |
mbed_official | 525:c320967f86b9 | 82 | /* Make sure val is not more than 1, because we only want to set one bit. */ |
mbed_official | 525:c320967f86b9 | 83 | val &= 0x1; |
mbed_official | 525:c320967f86b9 | 84 | *addr = (tmp & ~(1 << bit)) | (val << bit); |
mbed_official | 525:c320967f86b9 | 85 | #endif /* defined(BITBAND_PER_BASE) */ |
mbed_official | 525:c320967f86b9 | 86 | } |
mbed_official | 525:c320967f86b9 | 87 | |
mbed_official | 525:c320967f86b9 | 88 | |
mbed_official | 525:c320967f86b9 | 89 | /***************************************************************************//** |
mbed_official | 525:c320967f86b9 | 90 | * @brief |
mbed_official | 525:c320967f86b9 | 91 | * Perform a read operation on the peripheral bit-band memory location. |
mbed_official | 525:c320967f86b9 | 92 | * |
mbed_official | 525:c320967f86b9 | 93 | * @details |
mbed_official | 525:c320967f86b9 | 94 | * This function reads a single bit from the peripheral bit-band alias region. |
mbed_official | 525:c320967f86b9 | 95 | * Bit-banding provides atomic read-modify-write cycle for single bit |
mbed_official | 525:c320967f86b9 | 96 | * modification. Please refer to the reference manual for further details |
mbed_official | 525:c320967f86b9 | 97 | * about bit-banding. |
mbed_official | 525:c320967f86b9 | 98 | * |
mbed_official | 525:c320967f86b9 | 99 | * @param[in] addr Peripheral address location to read. |
mbed_official | 525:c320967f86b9 | 100 | * |
mbed_official | 525:c320967f86b9 | 101 | * @param[in] bit Bit position to read, 0-31. |
mbed_official | 525:c320967f86b9 | 102 | * |
mbed_official | 525:c320967f86b9 | 103 | * @return Value of the requested bit. |
mbed_official | 525:c320967f86b9 | 104 | ******************************************************************************/ |
mbed_official | 525:c320967f86b9 | 105 | __STATIC_INLINE uint32_t BITBAND_PeripheralRead(volatile uint32_t *addr, |
mbed_official | 525:c320967f86b9 | 106 | uint32_t bit) |
mbed_official | 525:c320967f86b9 | 107 | { |
mbed_official | 525:c320967f86b9 | 108 | #if defined(BITBAND_PER_BASE) |
mbed_official | 525:c320967f86b9 | 109 | uint32_t tmp = |
mbed_official | 525:c320967f86b9 | 110 | BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) * 32) + (bit * 4); |
mbed_official | 525:c320967f86b9 | 111 | |
mbed_official | 525:c320967f86b9 | 112 | return *((volatile uint32_t *)tmp); |
mbed_official | 525:c320967f86b9 | 113 | #else |
mbed_official | 525:c320967f86b9 | 114 | return ((*addr) >> bit) & 1; |
mbed_official | 525:c320967f86b9 | 115 | #endif /* defined(BITBAND_PER_BASE) */ |
mbed_official | 525:c320967f86b9 | 116 | } |
mbed_official | 525:c320967f86b9 | 117 | |
mbed_official | 525:c320967f86b9 | 118 | |
mbed_official | 525:c320967f86b9 | 119 | /***************************************************************************//** |
mbed_official | 525:c320967f86b9 | 120 | * @brief |
mbed_official | 525:c320967f86b9 | 121 | * Perform bit-band operation on SRAM memory location. |
mbed_official | 525:c320967f86b9 | 122 | * |
mbed_official | 525:c320967f86b9 | 123 | * @details |
mbed_official | 525:c320967f86b9 | 124 | * Bit-banding provides atomic read-modify-write cycle for single bit |
mbed_official | 525:c320967f86b9 | 125 | * modification. Please refer to the reference manual for further details |
mbed_official | 525:c320967f86b9 | 126 | * about bit-banding. |
mbed_official | 525:c320967f86b9 | 127 | * |
mbed_official | 525:c320967f86b9 | 128 | * @note |
mbed_official | 525:c320967f86b9 | 129 | * This function is only atomic on cores which fully support bitbanding. |
mbed_official | 525:c320967f86b9 | 130 | * |
mbed_official | 525:c320967f86b9 | 131 | * @param[in] addr SRAM address location to modify bit in. |
mbed_official | 525:c320967f86b9 | 132 | * |
mbed_official | 525:c320967f86b9 | 133 | * @param[in] bit Bit position to modify, 0-31. |
mbed_official | 525:c320967f86b9 | 134 | * |
mbed_official | 525:c320967f86b9 | 135 | * @param[in] val Value to set bit to, 0 or 1. |
mbed_official | 525:c320967f86b9 | 136 | ******************************************************************************/ |
mbed_official | 525:c320967f86b9 | 137 | __STATIC_INLINE void BITBAND_SRAM(uint32_t *addr, uint32_t bit, uint32_t val) |
mbed_official | 525:c320967f86b9 | 138 | { |
mbed_official | 525:c320967f86b9 | 139 | #if defined(BITBAND_RAM_BASE) |
mbed_official | 525:c320967f86b9 | 140 | uint32_t tmp = |
mbed_official | 525:c320967f86b9 | 141 | BITBAND_RAM_BASE + (((uint32_t)addr - RAM_MEM_BASE) * 32) + (bit * 4); |
mbed_official | 525:c320967f86b9 | 142 | |
mbed_official | 525:c320967f86b9 | 143 | *((volatile uint32_t *)tmp) = (uint32_t)val; |
mbed_official | 525:c320967f86b9 | 144 | #else |
mbed_official | 525:c320967f86b9 | 145 | uint32_t tmp = *addr; |
mbed_official | 525:c320967f86b9 | 146 | /* Make sure val is not more than 1, because we only want to set one bit. */ |
mbed_official | 525:c320967f86b9 | 147 | val &= 0x1; |
mbed_official | 525:c320967f86b9 | 148 | *addr = (tmp & ~(1 << bit)) | (val << bit); |
mbed_official | 525:c320967f86b9 | 149 | #endif /* defined(BITBAND_RAM_BASE) */ |
mbed_official | 525:c320967f86b9 | 150 | } |
mbed_official | 525:c320967f86b9 | 151 | |
mbed_official | 525:c320967f86b9 | 152 | |
mbed_official | 525:c320967f86b9 | 153 | /***************************************************************************//** |
mbed_official | 525:c320967f86b9 | 154 | * @brief |
mbed_official | 525:c320967f86b9 | 155 | * Read a single bit from the SRAM bit-band alias region. |
mbed_official | 525:c320967f86b9 | 156 | * |
mbed_official | 525:c320967f86b9 | 157 | * @details |
mbed_official | 525:c320967f86b9 | 158 | * This function reads a single bit from the SRAM bit-band alias region. |
mbed_official | 525:c320967f86b9 | 159 | * Bit-banding provides atomic read-modify-write cycle for single bit |
mbed_official | 525:c320967f86b9 | 160 | * modification. Please refer to the reference manual for further details |
mbed_official | 525:c320967f86b9 | 161 | * about bit-banding. |
mbed_official | 525:c320967f86b9 | 162 | * |
mbed_official | 525:c320967f86b9 | 163 | * @param[in] addr SRAM address location to modify bit in. |
mbed_official | 525:c320967f86b9 | 164 | * |
mbed_official | 525:c320967f86b9 | 165 | * @param[in] bit Bit position to modify, 0-31. |
mbed_official | 525:c320967f86b9 | 166 | * |
mbed_official | 525:c320967f86b9 | 167 | * @return Value of the requested bit. |
mbed_official | 525:c320967f86b9 | 168 | ******************************************************************************/ |
mbed_official | 525:c320967f86b9 | 169 | __STATIC_INLINE uint32_t BITBAND_SRAMRead(uint32_t *addr, uint32_t bit) |
mbed_official | 525:c320967f86b9 | 170 | { |
mbed_official | 525:c320967f86b9 | 171 | #if defined(BITBAND_RAM_BASE) |
mbed_official | 525:c320967f86b9 | 172 | uint32_t tmp = |
mbed_official | 525:c320967f86b9 | 173 | BITBAND_RAM_BASE + (((uint32_t)addr - RAM_MEM_BASE) * 32) + (bit * 4); |
mbed_official | 525:c320967f86b9 | 174 | |
mbed_official | 525:c320967f86b9 | 175 | return *((volatile uint32_t *)tmp); |
mbed_official | 525:c320967f86b9 | 176 | #else |
mbed_official | 525:c320967f86b9 | 177 | return ((*addr) >> bit) & 1; |
mbed_official | 525:c320967f86b9 | 178 | #endif /* defined(BITBAND_RAM_BASE) */ |
mbed_official | 525:c320967f86b9 | 179 | } |
mbed_official | 525:c320967f86b9 | 180 | |
mbed_official | 525:c320967f86b9 | 181 | /** @} (end addtogroup BITBAND) */ |
mbed_official | 525:c320967f86b9 | 182 | /** @} (end addtogroup EM_Library) */ |
mbed_official | 525:c320967f86b9 | 183 | |
mbed_official | 525:c320967f86b9 | 184 | #ifdef __cplusplus |
mbed_official | 525:c320967f86b9 | 185 | } |
mbed_official | 525:c320967f86b9 | 186 | #endif |
mbed_official | 525:c320967f86b9 | 187 | |
mbed_official | 525:c320967f86b9 | 188 | #endif /* __SILICON_LABS_EM_BITBAND_H_ */ |