Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/embedded/chip/rp_rng"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
| Alias | Package | Source file |
|---|---|---|
cortex_m |
std/embedded/cortex_m |
rp_rng.dodo |
hal |
std/embedded/hal |
rp_rng.dodo |
RP2040_RANDOMBIT
Constant · Source
The ring oscillator’s RANDOMBIT register, from the block’s base.
pub const RP2040_RANDOMBIT: usize = 0x1C
RP2350_RANDOMBIT
Constant · Source
pub const RP2350_RANDOMBIT: usize = 0x20
SAMPLE_SPACING
Constant · Source
Reads of RANDOMBIT that space two samples: about 10 us on a 125 MHz RP2040, as in the Pico SDK, so the oscillator gathers jitter between them.
pub const SAMPLE_SPACING: u32 = 128
RoscSource
Struct · Source
Random bytes from the ring oscillator’s RANDOMBIT register. Implements hal.Rng.
pub struct RoscSource<R: hal.Registers>: hal.Rng {
// Private implementation fields omitted.
}
RoscSource.new
Function · Source
The generator over the ring oscillator
registers, whose RANDOMBIT register is atrandombit: RP2040_RANDOMBIT or RP2350_RANDOMBIT. It only reads that register. SAFETY:registersmust be a running ring oscillator’s, and while the generator exists nothing may change its frequency, run clk_sys from it, or stop it except while the cores are stopped too, as a dormant state does.
pub unsafe fn new(registers: R, randombit: usize) -> RoscSource<R>
Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.
RoscSource.fill
Function · Source
Fill
byteswith debiased samples. Timeout if the oscillator has stopped, Bus if its samples repeat.
pub fn fill(&mut self, bytes: &mut[u8]) -> void!hal.Error
RoscSource.release
Function · Source
Give back the registers.
pub fn release(self) -> R
SAMPLE_COUNT
Constant · Source
Cycles of clk_sys between two samples of the TRNG’s oscillator. The datasheet suggests 20 to 25, but embassy-rp measured that the health tests then fail while the core sleeps; 200 passes either way, at about 1 ms for 192 bits at 150 MHz.
pub const SAMPLE_COUNT: u32 = 200
BLOCK_BYTES
Constant · Source
Bytes the TRNG produces at a time.
pub const BLOCK_BYTES: usize = 24
start
Function · Source
Reset the TRNG and configure it with every health test enabled; it stays idle until a TrngSource fills a buffer. Timeout if it stays in reset.
pub fn start<R: hal.Registers>(registers: &mut R) -> void!hal.Error
TrngSource
Struct · Source
Random bytes from the RP2350’s TRNG. Implements hal.Rng. The TRNG runs only while
filldoes. Bytes of a block that a fill does not use are kept for the next, so small draws, such as hal.random_u32, mostly cost no wait.
pub struct TrngSource<R: hal.Registers>: hal.Rng {
// Private implementation fields omitted.
}
TrngSource.new
Function · Source
The generator over the TRNG
registers, configured withstart. SAFETY:registersmust be the TRNG’s, and only this generator may use them.
pub unsafe fn new(registers: R) -> TrngSource<R>
Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.
TrngSource.fill
Function · Source
Fill
bytesfrom the TRNG. Bits that fail a health test are discarded; Bus if the autocorrelation test keeps failing after 100 restarts, Timeout if no block arrives.
pub fn fill(&mut self, bytes: &mut[u8]) -> void!hal.Error
TrngSource.release
Function · Source
Give back the registers; the TRNG is idle between fills.
pub fn release(self) -> R
Rosc
Struct · Source
The ring oscillator generator on the chip: a RoscSource over the oscillator’s registers, which the RP2040 package hands out. Implements hal.Rng.
pub struct Rosc: hal.Rng {
// Private implementation fields omitted.
}
Rosc.at
Function · Source
RoscSource.new over the ring oscillator at
base. SAFETY: as for RoscSource.new, withbasethe oscillator’s base address.
pub unsafe fn at(base: usize, randombit: usize) -> Rosc
Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.
Rosc.fill
Function · Source
pub fn fill(&mut self, bytes: &mut[u8]) -> void!hal.Error
Trng
Struct · Source
The TRNG on the chip: a TrngSource over its registers, which the RP2350 package hands out. Implements hal.Rng.
pub struct Trng: hal.Rng {
// Private implementation fields omitted.
}
Trng.at
Function · Source
start, then TrngSource.new, over the TRNG atbase, whose interrupt isirq. Timeout if it stays in reset. SAFETY: as for TrngSource.new, withbasethe TRNG’s base address, out of reset in the RESETS block.
pub unsafe fn at(base: usize, irq: u32) -> Trng!hal.Error
Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.
Trng.fill
Function · Source
pub fn fill(&mut self, bytes: &mut[u8]) -> void!hal.Error