mirror of
https://github.com/stnolting/neorv32.git
synced 2025-04-23 21:57:33 -04:00
[sw] update TRNG programs
This commit is contained in:
parent
b19aa98d30
commit
30a104a4da
3 changed files with 8 additions and 32 deletions
|
@ -72,8 +72,9 @@ int main(void) {
|
|||
// enable TRNG
|
||||
neorv32_uart0_printf("\nTRNG FIFO depth: %i\n", neorv32_trng_get_fifo_depth());
|
||||
neorv32_uart0_printf("Starting TRNG...\n");
|
||||
neorv32_trng_enable(0);
|
||||
neorv32_trng_enable();
|
||||
neorv32_cpu_delay_ms(100); // TRNG "warm up"
|
||||
neorv32_trng_fifo_clear(); // discard "warm-up" data
|
||||
|
||||
while(1) {
|
||||
|
||||
|
@ -346,14 +347,13 @@ void compute_rate(void) {
|
|||
|
||||
const uint32_t n_samples = 16*1024;
|
||||
uint32_t i;
|
||||
uint32_t tmp;
|
||||
uint8_t data;
|
||||
|
||||
uint32_t cycles = neorv32_cpu_csr_read(CSR_CYCLE);
|
||||
|
||||
i = 0;
|
||||
while (i<n_samples) {
|
||||
tmp = NEORV32_TRNG->CTRL;
|
||||
if (tmp & (1<<TRNG_CTRL_VALID)) { // valid sample?
|
||||
if (neorv32_trng_get(&data)) { // data available?
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ int main(void) {
|
|||
// check if TRNG was synthesized
|
||||
if (neorv32_trng_available()) {
|
||||
neorv32_uart0_printf("\nTRNG detected. Using TRNG for universe initialization.\n");
|
||||
neorv32_trng_enable(0);
|
||||
neorv32_trng_enable();
|
||||
trng_available = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1004,38 +1004,14 @@ int main() {
|
|||
// Fast interrupt channel 0
|
||||
// ----------------------------------------------------------
|
||||
neorv32_cpu_csr_write(CSR_MCAUSE, mcause_never_c);
|
||||
PRINT_STANDARD("[%i] FIRQ0 (TRNG) ", cnt_test);
|
||||
|
||||
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_TRNG)) {
|
||||
cnt_test++;
|
||||
|
||||
// enable TRNG, trigger IRQ when FIFO is full
|
||||
neorv32_trng_enable(1);
|
||||
|
||||
// enable fast interrupt
|
||||
neorv32_cpu_csr_write(CSR_MIE, 1 << TRNG_FIRQ_ENABLE);
|
||||
|
||||
// sleep until interrupt
|
||||
neorv32_cpu_sleep();
|
||||
|
||||
// no more interrupts
|
||||
neorv32_cpu_csr_write(CSR_MIE, 0);
|
||||
|
||||
if (neorv32_cpu_csr_read(CSR_MCAUSE) == TRNG_TRAP_CODE) {
|
||||
test_ok();
|
||||
}
|
||||
else {
|
||||
test_fail();
|
||||
}
|
||||
}
|
||||
else {
|
||||
PRINT_STANDARD("[n.a.]\n");
|
||||
}
|
||||
PRINT_STANDARD("[%i] FIRQ0 (reserved) ", cnt_test);
|
||||
PRINT_STANDARD("[n.a.]\n");
|
||||
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Fast interrupt channel 1 (CFS)
|
||||
// ----------------------------------------------------------
|
||||
neorv32_cpu_csr_write(CSR_MCAUSE, mcause_never_c);
|
||||
PRINT_STANDARD("[%i] FIRQ1 (CFS) ", cnt_test);
|
||||
PRINT_STANDARD("[n.a.]\n");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue