1 /***************************************************************************//**
2 * @file
3 * @brief Bitband Peripheral API
4 * @author Energy Micro AS
5 * @version 3.0.0
6 *******************************************************************************
7 * @section License
8 * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
9 *******************************************************************************
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 *
21 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
22 * obligation to support this Software. Energy Micro AS is providing the
23 * Software "AS IS", with no express or implied warranties of any kind,
24 * including, but not limited to, any implied warranties of merchantability
25 * or fitness for any particular purpose or warranties against infringement
26 * of any proprietary rights of a third party.
27 *
28 * Energy Micro AS will not be liable for any consequential, incidental, or
29 * special damages, or any other relief, or for any claim by any third party,
30 * arising from your use of this Software.
31 *
32 ******************************************************************************/
33 #ifndef __EM_BITBAND_H
34 #define __EM_BITBAND_H
35
36 #include "em_part.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /***************************************************************************//**
43 * @addtogroup EM_Library
44 * @{
45 ******************************************************************************/
46
47 /***************************************************************************//**
48 * @addtogroup BITBAND
49 * @brief BITBAND Peripheral API
50 * @{
51 ******************************************************************************/
52
53 /***************************************************************************//**
54 * @brief
55 * Perform bit-band operation on peripheral memory location.
56 *
57 * @details
58 * Bit-banding provides atomic read-modify-write cycle for single bit
59 * modification. Please refer to the reference manual for further details
60 * about bit-banding.
61 *
62 * @param[in,out] addr Peripheral address location to modify bit in.
63 *
64 * @param[in] bit Bit position to modify, 0-31.
65 *
66 * @param[in] val Value to set bit to, 0 or 1.
67 ******************************************************************************/
BITBAND_Peripheral(volatile uint32_t * addr,uint32_t bit,uint32_t val)68 __STATIC_INLINE void BITBAND_Peripheral(volatile uint32_t *addr,
69 uint32_t bit,
70 uint32_t val)
71 {
72 uint32_t tmp = BITBAND_PER_BASE + (((uint32_t)addr - PER_MEM_BASE) * 32) + (bit * 4);
73
74 *((volatile uint32_t *)tmp) = (uint32_t)val;
75 }
76
77
78 /***************************************************************************//**
79 * @brief
80 * Perform bit-band operation on SRAM memory location.
81 *
82 * @details
83 * Bit-banding provides atomic read-modify-write cycle for single bit
84 * modification. Please refer to the reference manual for further details
85 * about bit-banding.
86 *
87 * @param[in,out] addr SRAM address location to modify bit in.
88 *
89 * @param[in] bit Bit position to modify, 0-31.
90 *
91 * @param[in] val Value to set bit to, 0 or 1.
92 ******************************************************************************/
BITBAND_SRAM(uint32_t * addr,uint32_t bit,uint32_t val)93 __STATIC_INLINE void BITBAND_SRAM(uint32_t *addr, uint32_t bit, uint32_t val)
94 {
95 uint32_t tmp = BITBAND_RAM_BASE + (((uint32_t)addr - RAM_MEM_BASE) * 32) + (bit * 4);
96
97 *((volatile uint32_t *)tmp) = (uint32_t)val;
98 }
99
100
101 /** @} (end addtogroup BITBAND) */
102 /** @} (end addtogroup EM_Library) */
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif /* __EM_BITBAND_H */
109