Loading...
Searching...
No Matches
bme.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Eistec AB
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for more
6 * details.
7 */
8
22#ifndef BME_H
23#define BME_H
24
25#include <stdint.h>
26
27#ifdef __cplusplus
28extern "C"
29{
30#endif
31
35#define BITBAND_FUNCTIONS_PROVIDED 1
36
37#define BME_AND_MASK (1 << 26)
38#define BME_OR_MASK (1 << 27)
39#define BME_XOR_MASK (3 << 26)
40#define BME_LAC1_MASK(BIT) ((1 << 27) | ((BIT) << 21))
41#define BME_LAS1_MASK(BIT) ((3 << 26) | ((BIT) << 21))
49#define BME_BF_MASK(bit, width) ((1 << 28) | ((bit) << 23) | (((width) - 1 ) << 19))
50
63static inline volatile void *bme_bf_addr(volatile void *ptr, uintptr_t bit, uintptr_t width)
64{
65 return (volatile void *)(((uintptr_t)ptr) | BME_BF_MASK(bit, width));
66}
67
83static inline volatile uint32_t *bme_bitfield32(volatile uint32_t *ptr, uint8_t bit, uint8_t width)
84{
85 return (volatile uint32_t *)(bme_bf_addr(ptr, bit, width));
86}
87
103static inline volatile uint16_t *bme_bitfield16(volatile uint16_t *ptr, uint8_t bit, uint8_t width)
104{
105 return (volatile uint16_t *)(bme_bf_addr(ptr, bit, width));
106}
107
123static inline volatile uint8_t *bme_bitfield8(volatile uint8_t *ptr, uint8_t bit, uint8_t width)
124{
125 return (volatile uint8_t *)(bme_bf_addr(ptr, bit, width));
126}
127
128/* For compatibility with the M3/M4 bitbanding macros: */
129
145static inline void bit_set32(volatile uint32_t *ptr, uint8_t bit)
146{
147 *((volatile uint32_t *)(((uintptr_t)ptr) | BME_OR_MASK)) = (uint32_t)((1ul << bit));
148}
149
165static inline void bit_set16(volatile uint16_t *ptr, uint8_t bit)
166{
167 *((volatile uint16_t *)(((uintptr_t)ptr) | BME_OR_MASK)) = (uint16_t)((1ul << bit));
168}
169
185static inline void bit_set8(volatile uint8_t *ptr, uint8_t bit)
186{
187 *((volatile uint8_t *)(((uintptr_t)ptr) | BME_OR_MASK)) = (uint8_t)((1ul << bit));
188}
189
205static inline void bit_clear32(volatile uint32_t *ptr, uint8_t bit)
206{
207 *((volatile uint32_t *)(((uintptr_t)ptr) | BME_AND_MASK)) = (uint32_t)(~(1ul << bit));
208}
209
225static inline void bit_clear16(volatile uint16_t *ptr, uint8_t bit)
226{
227 *((volatile uint16_t *)(((uintptr_t)ptr) | BME_AND_MASK)) = (uint16_t)(~(1ul << bit));
228}
229
245static inline void bit_clear8(volatile uint8_t *ptr, uint8_t bit)
246{
247 *((volatile uint8_t *)(((uintptr_t)ptr) | BME_AND_MASK)) = (uint8_t)(~(1ul << bit));
248}
249
250#ifdef __cplusplus
251}
252#endif
253
254#endif /* BME_H */
255
static void bit_clear8(volatile uint8_t *ptr, uint8_t bit)
Clear a single bit in the 8 bit byte pointed to by ptr.
Definition bme.h:245
#define BME_BF_MASK(bit, width)
Bit field extraction bitmask.
Definition bme.h:49
static void bit_set16(volatile uint16_t *ptr, uint8_t bit)
Set a single bit in the 16 bit word pointed to by ptr.
Definition bme.h:165
#define BME_OR_MASK
OR decoration bitmask.
Definition bme.h:38
static void bit_clear32(volatile uint32_t *ptr, uint8_t bit)
Clear a single bit in the 32 bit word pointed to by ptr.
Definition bme.h:205
static void bit_set8(volatile uint8_t *ptr, uint8_t bit)
Set a single bit in the 8 bit byte pointed to by ptr.
Definition bme.h:185
static volatile void * bme_bf_addr(volatile void *ptr, uintptr_t bit, uintptr_t width)
Bit field address macro.
Definition bme.h:63
static volatile uint8_t * bme_bitfield8(volatile uint8_t *ptr, uint8_t bit, uint8_t width)
Access a bitfield (8 bit load/store)
Definition bme.h:123
static volatile uint16_t * bme_bitfield16(volatile uint16_t *ptr, uint8_t bit, uint8_t width)
Access a bitfield (16 bit load/store)
Definition bme.h:103
static void bit_set32(volatile uint32_t *ptr, uint8_t bit)
Set a single bit in the 32 bit word pointed to by ptr.
Definition bme.h:145
#define BME_AND_MASK
AND decoration bitmask.
Definition bme.h:37
static volatile uint32_t * bme_bitfield32(volatile uint32_t *ptr, uint8_t bit, uint8_t width)
Access a bitfield (32 bit load/store)
Definition bme.h:83
static void bit_clear16(volatile uint16_t *ptr, uint8_t bit)
Clear a single bit in the 16 bit word pointed to by ptr.
Definition bme.h:225