diff options
author | Ron Evans <[email protected]> | 2019-05-27 15:35:46 +0200 |
---|---|---|
committer | Ayke <[email protected]> | 2019-05-27 18:43:11 +0200 |
commit | 90cd3f8ea57c5be6663e271d3f72db3279e07417 (patch) | |
tree | 493b57241e686b2268d31e520a44fc96091c1254 /tools | |
parent | 2f95a5d452df23234ddd77f238a76aeaf12172dc (diff) | |
download | tinygo-90cd3f8ea57c5be6663e271d3f72db3279e07417.tar.gz tinygo-90cd3f8ea57c5be6663e271d3f72db3279e07417.zip |
tools: generate volatile HasBits() method in device wrappers to simplify bit comparison code
Signed-off-by: Ron Evans <[email protected]>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/gen-device-avr.py | 10 | ||||
-rwxr-xr-x | tools/gen-device-svd.py | 30 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tools/gen-device-avr.py b/tools/gen-device-avr.py index f42691cc7..6656b46fd 100755 --- a/tools/gen-device-avr.py +++ b/tools/gen-device-avr.py @@ -200,6 +200,16 @@ func (r *Register8) ClearBits(value uint8) {{ volatile.StoreUint8(&r.Reg, volatile.LoadUint8(&r.Reg) &^ value) }} +// HasBits reads the register and then checks to see if the passed bits are set. It +// is the volatile equivalent of: +// +// (*r.Reg & value) > 0 +// +//go:inline +func (r *Register8) HasBits(value uint8) bool {{ + return (r.Get() & value) > 0 +}} + // Some information about this device. const ( DEVICE = "{name}" diff --git a/tools/gen-device-svd.py b/tools/gen-device-svd.py index 1f0070c91..5232ce44e 100755 --- a/tools/gen-device-svd.py +++ b/tools/gen-device-svd.py @@ -349,6 +349,16 @@ func (r *Register8) ClearBits(value uint8) {{ volatile.StoreUint8(&r.Reg, volatile.LoadUint8(&r.Reg) &^ value) }} +// HasBits reads the register and then checks to see if the passed bits are set. It +// is the volatile equivalent of: +// +// (*r.Reg & value) > 0 +// +//go:inline +func (r *Register8) HasBits(value uint8) bool {{ + return (r.Get() & value) > 0 +}} + type Register16 struct {{ Reg uint16 }} @@ -391,6 +401,16 @@ func (r *Register16) ClearBits(value uint16) {{ volatile.StoreUint16(&r.Reg, volatile.LoadUint16(&r.Reg) &^ value) }} +// HasBits reads the register and then checks to see if the passed bits are set. It +// is the volatile equivalent of: +// +// (*r.Reg & value) > 0 +// +//go:inline +func (r *Register16) HasBits(value uint16) bool {{ + return (r.Get() & value) > 0 +}} + type Register32 struct {{ Reg uint32 }} @@ -433,6 +453,16 @@ func (r *Register32) ClearBits(value uint32) {{ volatile.StoreUint32(&r.Reg, volatile.LoadUint32(&r.Reg) &^ value) }} +// HasBits reads the register and then checks to see if the passed bits are set. It +// is the volatile equivalent of: +// +// (*r.Reg & value) > 0 +// +//go:inline +func (r *Register32) HasBits(value uint32) bool {{ + return (r.Get() & value) > 0 +}} + // Some information about this device. const ( DEVICE = "{name}" |