Exemple #1
0
/**
 * \internal
 * \brief TRNG callback mode test function
 *
 * This test reads three random data in callback mode and check the result.
 *
 * \param test Current test case.
 */
static void run_trng_callback_read_test(const struct test_case *test)
{
	uint32_t timeout = 84 * 3;
	uint32_t random_result[3];

	/* Register and enable TRNG read callback */
	trng_register_callback(&trng_instance, trng_complete_callback,
			TRNG_CALLBACK_READ_BUFFER);
	trng_enable_callback(&trng_instance, TRNG_CALLBACK_READ_BUFFER);

	/* Start TRNG read job */
	trng_read_buffer_job(&trng_instance, random_result, 3);
	do {
		timeout--;
		if (interrupt_flag) {
			break;
		}
	} while (timeout > 0);
	test_assert_true(test, timeout,
			"Fail to read random data in callback mode.");

	/* Assume there is no probability to read same three
	 * consecutive random number */
	if ((random_result[0] == random_result[1]) &&
			(random_result[0] == random_result[2])) {
		test_assert_true(test, false,
				"Get same random data in polling mode.");
	}

	/* Test done, disable read callback and TRNG instance */
	trng_disable_callback(&trng_instance, TRNG_CALLBACK_READ_BUFFER);
	trng_disable(&trng_instance);
}
Exemple #2
0
/** Deinitialize the TRNG peripheral
 *
 * @param obj The TRNG object
 */
void trng_free(trng_t *obj)
{
    (void)obj;
    trng_disable();
}