diff options
| author | Felipe Balbi <[email protected]> | 2025-12-11 09:44:35 -0800 |
|---|---|---|
| committer | Felipe Balbi <[email protected]> | 2025-12-11 09:48:15 -0800 |
| commit | af02ef481498441289a6decfe3baf7f3878f7871 (patch) | |
| tree | 6e6a8e5d5bc030619b572d98069fd2fd56c4855b /examples/mcxa/src | |
| parent | b99a7213126db708553143bb18e64bdcb76bb447 (diff) | |
trng: Add dedicated constructors without configuration
These three constructors guarantee TRNG will work for the requested
amount of entropy samples.
Diffstat (limited to 'examples/mcxa/src')
| -rw-r--r-- | examples/mcxa/src/bin/trng.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/examples/mcxa/src/bin/trng.rs b/examples/mcxa/src/bin/trng.rs index 95b4d0a88..bdd1f1041 100644 --- a/examples/mcxa/src/bin/trng.rs +++ b/examples/mcxa/src/bin/trng.rs | |||
| @@ -21,8 +21,26 @@ async fn main(_spawner: Spawner) { | |||
| 21 | 21 | ||
| 22 | defmt::info!("TRNG example"); | 22 | defmt::info!("TRNG example"); |
| 23 | 23 | ||
| 24 | let mut trng = Trng::new_128(p.TRNG0.reborrow()); | ||
| 25 | let rand = trng.blocking_next_u32(); | ||
| 26 | defmt::info!("128-bit {}", rand); | ||
| 27 | |||
| 28 | drop(trng); | ||
| 29 | |||
| 30 | let mut trng = Trng::new_256(p.TRNG0.reborrow()); | ||
| 31 | let rand = trng.blocking_next_u32(); | ||
| 32 | defmt::info!("256-bit {}", rand); | ||
| 33 | |||
| 34 | drop(trng); | ||
| 35 | |||
| 36 | let mut trng = Trng::new_512(p.TRNG0.reborrow()); | ||
| 37 | let rand = trng.blocking_next_u32(); | ||
| 38 | defmt::info!("512-bit {}", rand); | ||
| 39 | |||
| 40 | drop(trng); | ||
| 41 | |||
| 24 | let config = trng::Config::default(); | 42 | let config = trng::Config::default(); |
| 25 | let mut trng = Trng::new(p.TRNG0.reborrow(), config); | 43 | let mut trng = Trng::new_with_custom_config(p.TRNG0.reborrow(), config); |
| 26 | 44 | ||
| 27 | defmt::info!("========== BLOCKING =========="); | 45 | defmt::info!("========== BLOCKING =========="); |
| 28 | 46 | ||
| @@ -57,7 +75,7 @@ async fn main(_spawner: Spawner) { | |||
| 57 | 75 | ||
| 58 | defmt::info!("========== ASYNC =========="); | 76 | defmt::info!("========== ASYNC =========="); |
| 59 | 77 | ||
| 60 | let mut trng = AsyncTrng::new(p.TRNG0.reborrow(), Irqs, config); | 78 | let mut trng = AsyncTrng::new_with_custom_config(p.TRNG0.reborrow(), Irqs, config); |
| 61 | 79 | ||
| 62 | defmt::info!("Generate 10 u32"); | 80 | defmt::info!("Generate 10 u32"); |
| 63 | for _ in 0..10 { | 81 | for _ in 0..10 { |
