diff options
author | sago35 <[email protected]> | 2022-07-21 16:41:00 +0900 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-07-22 09:27:43 +0200 |
commit | 3047d8f321af7131f6afbbb4d97bb918f6185074 (patch) | |
tree | d48bd1bf49093e62f70ce88de90006339f584287 /src/machine/machine_atsamd51.go | |
parent | 13ed58950f853e2886a572fdb038b98da76f6b3f (diff) | |
download | tinygo-3047d8f321af7131f6afbbb4d97bb918f6185074.tar.gz tinygo-3047d8f321af7131f6afbbb4d97bb918f6185074.zip |
samd51: improve TRNG
Diffstat (limited to 'src/machine/machine_atsamd51.go')
-rw-r--r-- | src/machine/machine_atsamd51.go | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index 6adab95f4..54bd1fc9f 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -2067,18 +2067,16 @@ func (dac DAC) syncDAC() { } } -var rngInitDone = false - // GetRNG returns 32 bits of cryptographically secure random data func GetRNG() (uint32, error) { - if !rngInitDone { + if !sam.MCLK.APBCMASK.HasBits(sam.MCLK_APBCMASK_TRNG_) { // Turn on clock for TRNG sam.MCLK.APBCMASK.SetBits(sam.MCLK_APBCMASK_TRNG_) // enable sam.TRNG.CTRLA.Set(sam.TRNG_CTRLA_ENABLE) - - rngInitDone = true + } + for !sam.TRNG.INTFLAG.HasBits(sam.TRNG_INTFLAG_DATARDY) { } ret := sam.TRNG.DATA.Get() return ret, nil |