hw/registerfields: add `FIELDx_1CLEAR()` macro
RFC v2 1/1 hw/registerfields: add `FIELDx_1CLEAR()` macro
From: Wilfred Mallawa <[email protected]>
Changes from V1:
* Instead of needing all field bits to be set we clear the field if any are set. If the field is 0/clear then no change.
Adds a helper macro that implements the register w1c functionality.
Ex:
uint32_t data = FIELD32_1CLEAR(val, REG, FIELD);
If ANY bits of the specified FIELD is set
then the respective field is cleared and returned to data.
If the field is cleared (0), then no change and
val is returned.
--- include/hw/registerfields.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
include/hw/registerfields.h +22 -0
@@ -115,6 +115,28 @@ R_ ## reg ## _ ## field ## _LENGTH, _v.v); \ _d; }) +/* +* Clear the specified field in reg_val if +* any field bits are set, else no changes made. Implements +* single/multi-bit `w1c` +* +*/ +#define FIELD8_1CLEAR (reg_val, reg, field) \ + (FIELD_EX8(reg_val, reg, field) ? \ + FIELD_DP8(reg_val, reg, field, 0x00) : reg_val) + +#define FIELD16_1CLEAR (reg_val, reg, field) \ + (FIELD_EX16(reg_val, reg, field) ? \ + FIELD_DP16(reg_val, reg, field, 0x00) : reg_val) + +#define FIELD32_1CLEAR (reg_val, reg, field) \ + (FIELD_EX32(reg_val, reg, field) ? \ + FIELD_DP32(reg_val, reg, field, 0x00) : reg_val) + +#define FIELD64_1CLEAR (reg_val, reg, field) \ + (FIELD_EX64(reg_val, reg, field) ? \ + FIELD_DP64(reg_val, reg, field, 0x00) : reg_val) +#define FIELD_SDP8 (storage, reg, field, val) ({ \ struct { \ signed int v:R_ ## reg ## _ ## field ## _LENGTH; \
Signature · 1 line
2.37.3
Quoted 7 lines · Wilfred Mallawa
From: Wilfred Mallawa <[email protected]>
Changes from V1:
* Instead of needing all field bits to be set we clear the field if any are set. If the field is 0/clear then no change.
The changelog should go
Quoted 7 lines
Adds a helper macro that implements the register
w1cfunctionality.Ex:
uint32_tdata =FIELD32_1CLEAR(val, REG, FIELD);
Quoted 8 lines
If ANY bits of the specified
FIELDis set
then the respective field is cleared and returned todata.If the field is cleared (0), then no change and
val is returned.Signed-off-by Wilfred Mallawa <[email protected]>---
Below this line.
Otherwise the patch looks good. Do you mind adding it to a series that converts the OT SPI to use these macros?
Quoted 8 lines
include/hw/registerfields.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)include/hw/registerfields.h +0
-0
include/hw/registerfields.h line 124
Quoted 10 lines
include/hw/registerfields.h +7
-0@@ -115,6 +115,28 @@ R_ ## reg ## _ ## field ## _LENGTH, _v.v); \ _d; }) +/* +* Clear the specified field in reg_val if +* any field bits are set, else no changes made. Implements +* single/multi-bit `w1c` +* +*/ +#define FIELD8_1CLEAR (reg_val, reg, field) \
These should probably match the other macros with:
(storage, reg, field)
Alistair
Quoted 25 lines · Alistair Francis
Quoted 7 lines · Wilfred Mallawa
From: Wilfred Mallawa <[email protected]>
Changes from V1:
* Instead of needing all field bits to be set we clear the field if any are set. If the field is 0/clear then no change.The changelog should go
Quoted 13 lines
Adds a helper macro that implements the register
w1cfunctionality.Ex:
uint32_tdata =FIELD32_1CLEAR(val, REG, FIELD);If ANY bits of the specified
FIELDis set
then the respective field is cleared and returned todata.If the field is cleared (0), then no change and
val is returned.
Quoted 9 lines
Quoted 2 lines
Signed-off-by Wilfred Mallawa <[email protected]>---
Below this line.
Otherwise the patch looks good. Do you mind adding it to a series that
converts the OT SPI to use these macros?
Yep, that sounds good. I'll send a new series with this + SPI changes with the macro implemented.
Quoted 24 lines
Quoted 11 lines
include/hw/registerfields.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)include/hw/registerfields.h +0
-0@@ -115,6 +115,28 @@ R_ ## reg ## _ ## field ## _LENGTH, _v.v); \include/hw/registerfields.h line 126
Quoted 10 lines
include/hw/registerfields.h +7
-0_d; }) +/* +* Clear the specified field in reg_val if +* any field bits are set, else no changes made. Implements +* single/multi-bit `w1c` +* +*/ +#define FIELD8_1CLEAR (reg_val, reg, field) \These should probably match the other macros with:
Quoted 2 lines
(storage, reg, field)
Will do!
Quoted 1 line
Alistair
Wilferd