summaryrefslogtreecommitdiff
path: root/include/soc/imx8/fsl_bitaccess.h
blob: 11e71eeb411b049300555e39c143ca4b4eb7006b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Copyright (C) 2016 Freescale Semiconductor, Inc.
 * Copyright 2017 NXP
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

/*!
 * @file  devices/MX8/include/fsl_bitaccess.h
 *
 * Header file containing register access macros.
 *
 * \addtogroup Peripheral_access_layer (HAL) Device Peripheral Access Layer
 *
 * @{
 */

#ifndef _FSL_BITACCESS_H
#define _FSL_BITACCESS_H  1

/*!
 * @addtogroup SCF Register Access Macros
 * @{
 */

/*
 * Macros for single instance registers
 */

#define BF_SET(reg, field)       HW_##reg##_SET(BM_##reg##_##field)
#define BF_CLR(reg, field)       HW_##reg##_CLR(BM_##reg##_##field)
#define BF_TOG(reg, field)       HW_##reg##_TOG(BM_##reg##_##field)

#define BF_SETV(reg, field, v)   HW_##reg##_SET(BF_##reg##_##field(v))
#define BF_CLRV(reg, field, v)   HW_##reg##_CLR(BF_##reg##_##field(v))
#define BF_TOGV(reg, field, v)   HW_##reg##_TOG(BF_##reg##_##field(v))

#define BV_FLD(reg, field, sym)  BF_##reg##_##field(BV_##reg##_##field##__##sym)
#define BV_VAL(reg, field, sym)  BV_##reg##_##field##__##sym

#define BF_RD(reg, field)        HW_##reg.B.field
#define BF_WR(reg, field, v)     BW_##reg##_##field(v)


/*******************************************************************************
 * Macros to create bitfield mask, shift, and width from CMSIS definitions
 ******************************************************************************/

/* Bitfield Mask */
#define SCF_BMSK(bit) (bit ## _MASK)

/* Bitfield Left Shift */
#define SCF_BLSH(bit) (bit ## _SHIFT)

/* Bitfield Width */
#define SCF_BWID(bit) (bit ## _WIDTH)

/* Bitfield Value */
#define SCF_BVAL(bit, val) ((val) << (SCF_BLSH(bit)))


/*******************************************************************************
 * Macros to set, clear, extact, and insert bitfields into register structures
 * or local variables
 ******************************************************************************/

/* Bitfield Set */
#define SCF_BSET(var, bit) (var |= (SCF_BMSK(bit)))

/* Bitfield Clear */
#define SCF_BCLR(var, bit) (var &= (~(SCF_BMSK(bit))))

/* Bitfield Extract */
#define SCF_BEXR(var, bit) ((var & (SCF_BMSK(bit))) >> (SCF_BLSH(bit)))

/* Bitfield Insert */
#define SCF_BINS(var, bit, val) (var = (var & (~(SCF_BMSK(bit)))) | SCF_BVAL(bit, val))


/*******************************************************************************
 * Macros to set, clear, extact, and insert bitfields into register structures
 * that support SCT
 ******************************************************************************/

#ifdef EMUL
/* Emulation does not have SCT hardware and must fallback to non-SCT definitions */

/* SCT Bitfield Set */
#define SCF_SCT_BSET(var, bit) (SCF_BSET(var, bit))

/* SCT Bitfield Clear */
#define SCF_SCT_BCLR(var, bit) (SCF_BCLR(var, bit))

/* SCT Bitfield Insert */
#define SCF_SCT_BINS(var, bit, val) (SCF_BINS(var, bit, val))

#else
/*!  @todo Port macros leverage SCT register access hardware */

/* SCT Bitfield Set */
#define SCF_SCT_BSET(var, bit) (SCF_BSET(var, bit))

/* SCT Bitfield Clear */
#define SCF_SCT_BCLR(var, bit) (SCF_BCLR(var, bit))

/* SCT Bitfield Insert */
#define SCF_SCT_BINS(var, bit, val) (SCF_BINS(var, bit, val))

#endif /* EMUL */

/*!
 * @}
 */ /* end of group SCF */

/*!
 * @}
 */ /* end of group Peripheral_access_layer */

#endif /* _FSL_BITACCESS_H */

/******************************************************************************/