Skip to content

Commit 90cd3f8

Browse files
deadprogramaykevl
authored andcommitted
tools: generate volatile HasBits() method in device wrappers to simplify bit comparison code
Signed-off-by: Ron Evans <[email protected]>
1 parent 2f95a5d commit 90cd3f8

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tools/gen-device-avr.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ def writeGo(outdir, device):
200200
volatile.StoreUint8(&r.Reg, volatile.LoadUint8(&r.Reg) &^ value)
201201
}}
202202
203+
// HasBits reads the register and then checks to see if the passed bits are set. It
204+
// is the volatile equivalent of:
205+
//
206+
// (*r.Reg & value) > 0
207+
//
208+
//go:inline
209+
func (r *Register8) HasBits(value uint8) bool {{
210+
return (r.Get() & value) > 0
211+
}}
212+
203213
// Some information about this device.
204214
const (
205215
DEVICE = "{name}"

tools/gen-device-svd.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ def writeGo(outdir, device):
349349
volatile.StoreUint8(&r.Reg, volatile.LoadUint8(&r.Reg) &^ value)
350350
}}
351351
352+
// HasBits reads the register and then checks to see if the passed bits are set. It
353+
// is the volatile equivalent of:
354+
//
355+
// (*r.Reg & value) > 0
356+
//
357+
//go:inline
358+
func (r *Register8) HasBits(value uint8) bool {{
359+
return (r.Get() & value) > 0
360+
}}
361+
352362
type Register16 struct {{
353363
Reg uint16
354364
}}
@@ -391,6 +401,16 @@ def writeGo(outdir, device):
391401
volatile.StoreUint16(&r.Reg, volatile.LoadUint16(&r.Reg) &^ value)
392402
}}
393403
404+
// HasBits reads the register and then checks to see if the passed bits are set. It
405+
// is the volatile equivalent of:
406+
//
407+
// (*r.Reg & value) > 0
408+
//
409+
//go:inline
410+
func (r *Register16) HasBits(value uint16) bool {{
411+
return (r.Get() & value) > 0
412+
}}
413+
394414
type Register32 struct {{
395415
Reg uint32
396416
}}
@@ -433,6 +453,16 @@ def writeGo(outdir, device):
433453
volatile.StoreUint32(&r.Reg, volatile.LoadUint32(&r.Reg) &^ value)
434454
}}
435455
456+
// HasBits reads the register and then checks to see if the passed bits are set. It
457+
// is the volatile equivalent of:
458+
//
459+
// (*r.Reg & value) > 0
460+
//
461+
//go:inline
462+
func (r *Register32) HasBits(value uint32) bool {{
463+
return (r.Get() & value) > 0
464+
}}
465+
436466
// Some information about this device.
437467
const (
438468
DEVICE = "{name}"

0 commit comments

Comments
 (0)