Contiki 3.x
fsl_bitaccess.h
1 /*
2 ** ###################################################################
3 ** Version: rev. 2.5, 2015-02-19
4 ** Build: b150224
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 (2012-06-13)
42 ** Initial version.
43 ** - rev. 1.1 (2012-06-21)
44 ** Update according to reference manual rev. 1.
45 ** - rev. 1.2 (2012-08-01)
46 ** Device type UARTLP changed to UART0.
47 ** - rev. 1.3 (2012-10-04)
48 ** Update according to reference manual rev. 3.
49 ** - rev. 1.4 (2012-11-22)
50 ** MCG module - bit LOLS in MCG_S register renamed to LOLS0.
51 ** NV registers - bit EZPORT_DIS in NV_FOPT register removed.
52 ** - rev. 2.0 (2013-10-29)
53 ** Register accessor macros added to the memory map.
54 ** Symbols for Processor Expert memory map compatibility added to the memory map.
55 ** Startup file for gcc has been updated according to CMSIS 3.2.
56 ** System initialization updated.
57 ** - rev. 2.1 (2014-07-16)
58 ** Module access macro module_BASES replaced by module_BASE_PTRS.
59 ** System initialization and startup updated.
60 ** - rev. 2.2 (2014-08-22)
61 ** System initialization updated - default clock config changed.
62 ** - rev. 2.3 (2014-08-28)
63 ** Update of startup files - possibility to override DefaultISR added.
64 ** - rev. 2.4 (2014-10-14)
65 ** Interrupt INT_LPTimer renamed to INT_LPTMR0.
66 ** - rev. 2.5 (2015-02-19)
67 ** Renamed interrupt vector LLW to LLWU.
68 **
69 ** ###################################################################
70 */
71 
72 #ifndef _FSL_BITACCESS_H
73 #define _FSL_BITACCESS_H 1
74 
75 #include <stdint.h>
76 #include <stdlib.h>
77 
78 #define BME_AND_MASK (1<<26)
79 #define BME_OR_MASK (1<<27)
80 #define BME_XOR_MASK (3<<26)
81 #define BME_BFI_MASK(BIT,WIDTH) (1<<28) | (BIT<<23) | ((WIDTH-1)<<19)
82 #define BME_UBFX_MASK(BIT,WIDTH) (1<<28) | (BIT<<23) | ((WIDTH-1)<<19)
83 
84 /* Decorated Store: Logical AND */
85 #define BME_AND8(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_AND_MASK) = wdata)
86 #define BME_AND16(addr, wdata) (*(volatile uint16_t*)((uintptr_t)addr | BME_AND_MASK) = wdata)
87 #define BME_AND32(addr, wdata) (*(volatile uint32_t*)((uintptr_t)addr | BME_AND_MASK) = wdata)
88 
89 /* Decorated Store: Logical OR */
90 #define BME_OR8(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_OR_MASK) = wdata)
91 #define BME_OR16(addr, wdata) (*(volatile uint16_t*)((uintptr_t)addr | BME_OR_MASK) = wdata)
92 #define BME_OR32(addr, wdata) (*(volatile uint32_t*)((uintptr_t)addr | BME_OR_MASK) = wdata)
93 
94 /* Decorated Store: Logical XOR */
95 #define BME_XOR8(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_XOR_MASK) = wdata)
96 #define BME_XOR16(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_XOR_MASK) = wdata)
97 #define BME_XOR32(addr, wdata) (*(volatile uint8_t*)((uintptr_t)addr | BME_XOR_MASK) = wdata)
98 
99 /* Decorated Store: Bit Field Insert */
100 #define BME_BFI8(addr, wdata, bit, width) (*(volatile uint8_t*)((uintptr_t)addr | BME_BFI_MASK(bit,width)) = wdata)
101 #define BME_BFI16(addr, wdata, bit, width) (*(volatile uint16_t*)((uintptr_t)addr | BME_BFI_MASK(bit,width)) = wdata)
102 #define BME_BFI32(addr, wdata, bit, width) (*(volatile uint32_t*)((uintptr_t)addr | BME_BFI_MASK(bit,width)) = wdata)
103 
104 /* Decorated Load: Unsigned Bit Field Extract */
105 #define BME_UBFX8(addr, bit, width) (*(volatile uint8_t*)((uintptr_t)addr | BME_UBFX_MASK(bit,width)))
106 #define BME_UBFX16(addr, bit, width) (*(volatile uint16_t*)((uintptr_t)addr | BME_UBFX_MASK(bit,width)))
107 #define BME_UBFX32(addr, bit, width) (*(volatile uint32_t*)((uintptr_t)addr | BME_UBFX_MASK(bit,width)))
108 
109 #endif /* _FSL_BITACCESS_H */
110 
111 /******************************************************************************/