machine/samd51: implement TRNG for randomness
Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
		
							родитель
							
								
									5159eab694
								
							
						
					
					
						коммит
						2ebaa9f520
					
				
					 2 изменённых файлов: 20 добавлений и 2 удалений
				
			
		|  | @ -1,5 +1,5 @@ | |||
| //go:build stm32wlx | ||||
| // +build stm32wlx | ||||
| //go:build stm32wlx || (sam && atsamd51) || (sam && atsame5x) | ||||
| // +build stm32wlx sam,atsamd51 sam,atsame5x | ||||
| 
 | ||||
| package rand | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,3 +1,4 @@ | |||
| //go:build (sam && atsamd51) || (sam && atsame5x) | ||||
| // +build sam,atsamd51 sam,atsame5x | ||||
| 
 | ||||
| // Peripheral abstraction layer for the atsamd51. | ||||
|  | @ -2733,3 +2734,20 @@ func syncDAC() { | |||
| 	for sam.DAC.SYNCBUSY.HasBits(sam.DAC_SYNCBUSY_DATA0) { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| var rngInitDone = false | ||||
| 
 | ||||
| // GetRNG returns 32 bits of cryptographically secure random data | ||||
| func GetRNG() (uint32, error) { | ||||
| 	if !rngInitDone { | ||||
| 		// Turn on clock for TRNG | ||||
| 		sam.MCLK.APBCMASK.SetBits(sam.MCLK_APBCMASK_TRNG_) | ||||
| 
 | ||||
| 		// enable | ||||
| 		sam.TRNG.CTRLA.Set(sam.TRNG_CTRLA_ENABLE) | ||||
| 
 | ||||
| 		rngInitDone = true | ||||
| 	} | ||||
| 	ret := sam.TRNG.DATA.Get() | ||||
| 	return ret, nil | ||||
| } | ||||
|  |  | |||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 deadprogram
						deadprogram