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
9#pragma once
10
23
24#include <stdint.h>
25
26#ifdef __cplusplus
27extern "C"
28{
29#endif
30
34#define BITBAND_FUNCTIONS_PROVIDED 1
35
36#define BME_AND_MASK (1 << 26)
37#define BME_OR_MASK (1 << 27)
38#define BME_XOR_MASK (3 << 26)
39#define BME_LAC1_MASK(BIT) ((1 << 27) | ((BIT) << 21))
40#define BME_LAS1_MASK(BIT) ((3 << 26) | ((BIT) << 21))
41
48#define BME_BF_MASK(bit, width) ((1 << 28) | ((bit) << 23) | (((width) - 1 ) << 19))
49
62static inline volatile void *bme_bf_addr(volatile void *ptr, uintptr_t bit, uintptr_t width)
63{
64 return (volatile void *)(((uintptr_t)ptr) | BME_BF_MASK(bit, width));
65}
66
82static inline volatile uint32_t *bme_bitfield32(volatile uint32_t *ptr, uint8_t bit, uint8_t width)
83{
84 return (volatile uint32_t *)(bme_bf_addr(ptr, bit, width));
85}
86
102static inline volatile uint16_t *bme_bitfield16(volatile uint16_t *ptr, uint8_t bit, uint8_t width)
103{
104 return (volatile uint16_t *)(bme_bf_addr(ptr, bit, width));
105}
106
122static inline volatile uint8_t *bme_bitfield8(volatile uint8_t *ptr, uint8_t bit, uint8_t width)
123{
124 return (volatile uint8_t *)(bme_bf_addr(ptr, bit, width));
125}
126
127/* For compatibility with the M3/M4 bitbanding macros: */
128
144static inline void bit_set32(volatile uint32_t *ptr, uint8_t bit)
145{
146 *((volatile uint32_t *)(((uintptr_t)ptr) | BME_OR_MASK)) = (uint32_t)((1ul << bit));
147}
148
164static inline void bit_set16(volatile uint16_t *ptr, uint8_t bit)
165{
166 *((volatile uint16_t *)(((uintptr_t)ptr) | BME_OR_MASK)) = (uint16_t)((1ul << bit));
167}
168
184static inline void bit_set8(volatile uint8_t *ptr, uint8_t bit)
185{
186 *((volatile uint8_t *)(((uintptr_t)ptr) | BME_OR_MASK)) = (uint8_t)((1ul << bit));
187}
188
204static inline void bit_clear32(volatile uint32_t *ptr, uint8_t bit)
205{
206 *((volatile uint32_t *)(((uintptr_t)ptr) | BME_AND_MASK)) = (uint32_t)(~(1ul << bit));
207}
208
224static inline void bit_clear16(volatile uint16_t *ptr, uint8_t bit)
225{
226 *((volatile uint16_t *)(((uintptr_t)ptr) | BME_AND_MASK)) = (uint16_t)(~(1ul << bit));
227}
228
244static inline void bit_clear8(volatile uint8_t *ptr, uint8_t bit)
245{
246 *((volatile uint8_t *)(((uintptr_t)ptr) | BME_AND_MASK)) = (uint8_t)(~(1ul << bit));
247}
248
249#ifdef __cplusplus
250}
251#endif
252
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:244
#define BME_BF_MASK(bit, width)
Bit field extraction bitmask.
Definition bme.h:48
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:164
#define BME_OR_MASK
OR decoration bitmask.
Definition bme.h:37
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:204
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:184
static volatile void * bme_bf_addr(volatile void *ptr, uintptr_t bit, uintptr_t width)
Bit field address macro.
Definition bme.h:62
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:122
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:102
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:144
#define BME_AND_MASK
AND decoration bitmask.
Definition bme.h:36
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:82
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:224