1 /* 2 ** ################################################################### 3 ** Version: rev. 1.2, 2015-05-07 4 ** Build: b150513 5 ** 6 ** Abstract: 7 ** Register bit field access macros. 8 ** 9 ** Copyright (c) 2015 Freescale Semiconductor, Inc. 10 ** All rights reserved. 11 ** 12 ** Redistribution and use in source and binary forms, with or without modification, 13 ** are permitted provided that the following conditions are met: 14 ** 15 ** o Redistributions of source code must retain the above copyright notice, this list 16 ** of conditions and the following disclaimer. 17 ** 18 ** o Redistributions in binary form must reproduce the above copyright notice, this 19 ** list of conditions and the following disclaimer in the documentation and/or 20 ** other materials provided with the distribution. 21 ** 22 ** o Neither the name of Freescale Semiconductor, Inc. nor the names of its 23 ** contributors may be used to endorse or promote products derived from this 24 ** software without specific prior written permission. 25 ** 26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 27 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 30 ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 33 ** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 ** 37 ** http: www.freescale.com 38 ** mail: support@freescale.com 39 ** 40 ** Revisions: 41 ** - rev. 1.0 (2014-07-17) 42 ** Initial version. 43 ** - rev. 1.1 (2015-03-05) 44 ** Update with reference manual rev 1.0 45 ** - rev. 1.2 (2015-05-07) 46 ** Update with reference manual rev 1.1 47 ** 48 ** ################################################################### 49 */ 50 51 #ifndef _FSL_BITACCESS_H 52 #define _FSL_BITACCESS_H 1 53 54 #include <stdint.h> 55 #include <stdlib.h> 56 57 #define BME_AND_MASK (1<<26) 58 #define BME_OR_MASK (1<<27) 59 #define BME_XOR_MASK (3<<26) 60 #define BME_BFI_MASK(BIT,WIDTH) (1<<28) | (BIT<<23) | ((WIDTH-1)<<19) 61 #define BME_UBFX_MASK(BIT,WIDTH) (1<<28) | (BIT<<23) | ((WIDTH-1)<<19) 62 63 /* Decorated Store: Logical AND */ 64 #define BME_AND8(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_AND_MASK) = wdata) 65 #define BME_AND16(addr, wdata) (*(volatile uint16_t*)((uintptr_t)addr | BME_AND_MASK) = wdata) 66 #define BME_AND32(addr, wdata) (*(volatile uint32_t*)((uintptr_t)addr | BME_AND_MASK) = wdata) 67 68 /* Decorated Store: Logical OR */ 69 #define BME_OR8(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_OR_MASK) = wdata) 70 #define BME_OR16(addr, wdata) (*(volatile uint16_t*)((uintptr_t)addr | BME_OR_MASK) = wdata) 71 #define BME_OR32(addr, wdata) (*(volatile uint32_t*)((uintptr_t)addr | BME_OR_MASK) = wdata) 72 73 /* Decorated Store: Logical XOR */ 74 #define BME_XOR8(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_XOR_MASK) = wdata) 75 #define BME_XOR16(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_XOR_MASK) = wdata) 76 #define BME_XOR32(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_XOR_MASK) = wdata) 77 78 /* Decorated Store: Bit Field Insert */ 79 #define BME_BFI8(addr, wdata, bit, width) (*(volatile uint8_t*)((uintptr_t)addr | BME_BFI_MASK(bit,width)) = wdata) 80 #define BME_BFI16(addr, wdata, bit, width) (*(volatile uint16_t*)((uintptr_t)addr | BME_BFI_MASK(bit,width)) = wdata) 81 #define BME_BFI32(addr, wdata, bit, width) (*(volatile uint32_t*)((uintptr_t)addr | BME_BFI_MASK(bit,width)) = wdata) 82 83 /* Decorated Load: Unsigned Bit Field Extract */ 84 #define BME_UBFX8(addr, bit, width) (*(volatile uint8_t*)((uintptr_t)addr | BME_UBFX_MASK(bit,width))) 85 #define BME_UBFX16(addr, bit, width) (*(volatile uint16_t*)((uintptr_t)addr | BME_UBFX_MASK(bit,width))) 86 #define BME_UBFX32(addr, bit, width) (*(volatile uint32_t*)((uintptr_t)addr | BME_UBFX_MASK(bit,width))) 87 88 #endif /* _FSL_BITACCESS_H */ 89 90 /******************************************************************************/ 91