1 /*
2  * Copyright (c) 2020 Nuvoton Technology Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _NUVOTON_NPCX_REG_ACCESS_H
8 #define _NUVOTON_NPCX_REG_ACCESS_H
9 
10 /*
11  * NPCX register bit/field access operations
12  */
13 #define IS_BIT_SET(reg, bit)        (((reg >> bit) & (0x1)) != 0)
14 
15 #define GET_POS_FIELD(pos, size)    pos
16 #define GET_SIZE_FIELD(pos, size)   size
17 #define FIELD_POS(field)            GET_POS_##field
18 #define FIELD_SIZE(field)           GET_SIZE_##field
19 
20 #define GET_FIELD(reg, field) \
21 	_GET_FIELD_(reg, FIELD_POS(field), FIELD_SIZE(field))
22 #define _GET_FIELD_(reg, f_pos, f_size) (((reg)>>(f_pos)) & ((1<<(f_size))-1))
23 
24 #define SET_FIELD(reg, field, value) \
25 	_SET_FIELD_(reg, FIELD_POS(field), FIELD_SIZE(field), value)
26 #define _SET_FIELD_(reg, f_pos, f_size, value) \
27 	((reg) = ((reg) & (~(((1 << (f_size))-1) << (f_pos)))) \
28 			| ((value) << (f_pos)))
29 
30 #endif /* _NUVOTON_NPCX_REG_ACCESS_H */
31