XilinxProcessorIPLib/drivers/trngpsv/examples/xtrngpsv_ptrng_example.c
int Trngpsv_Ptrng_Example(u16 DeviceId)
{
	int Status = XST_SUCCESS;
	XTrngpsv_Config *Config;
	XTrngpsv_UsrCfg UsrCfg = {
			.Mode = XTRNGPSV_PTRNG,
			.SeedLife = 0U,
			.PredResistanceEn = XTRNGPSV_FALSE,
			.DFDisable = XTRNGPSV_TRUE,
			.DFLenMul = 0U,
			.InitSeedPresent =  XTRNGPSV_FALSE,
			.PersStrPresent = XTRNGPSV_FALSE
	};

	/*
	 * Initialize the TRNGPSV driver so that it's ready to use look up
	 * configuration in the config table, then initialize it.
	 */
	Config = XTrngpsv_LookupConfig(DeviceId);
	if (NULL == Config) {
		xil_printf("LookupConfig Failed \n\r");
		goto END;
	}

	/* Initialize the TRNGPSV driver so that it is ready to use. */
	Status = XTrngpsv_CfgInitialize(&Trngpsv, Config, Config->BaseAddress);
	if (Status != XST_SUCCESS) {
		xil_printf("CfgInitialize Failed, Status: 0x%08x\n\r", Status);
		goto END;
	}

	Status = XTrngpsv_RunKAT(&Trngpsv);
	if (Status != XST_SUCCESS) {
		if (Status == XTRNGPSV_ERROR_KAT_MISMATCH) {
			xil_printf("KAT Failed with mismatch error, Status: 0x%08x\n\r", Status);
		}
		else {
			xil_printf("KAT Failed, Status: 0x%08x\n\r", Status);
		}
		goto END;
	}

	Status = XTrngpsv_RunHealthTest(&Trngpsv);
	if (Status != XST_SUCCESS) {
		if ((Status == XTRNGPSV_ERROR_CERTF) ||
				(Status == XTRNGPSV_ERROR_CERTF_SW_A5_PATTERN)) {
			xil_printf("RunHealthTest Failed with CERTF related error, Status: 0x%08x\n\r", Status);
		}
		else {
			xil_printf("RunHealthTest Failed, Status: 0x%08x\n\r", Status);
		}
		goto END;
	}

	/* Instantiate to complete initialization */
	Status = XTrngpsv_Instantiate(&Trngpsv, &UsrCfg);
	if (Status != XST_SUCCESS) {
		xil_printf("Instantiate failed, Status: 0x%08x\n\r", Status);
		goto END;
	}

	/* Invoke Generate twice and print, RandBuf contains random data from last call */
	Status = XTrngpsv_Generate(&Trngpsv, RandBuf, sizeof(RandBuf), XTRNGPSV_FALSE);
	if (Status != XST_SUCCESS) {
		xil_printf("Generate Failed, Status: 0x%08x\n\r", Status);
		goto END;
	}

	xil_printf("Generate 1 Random data:\n\r");
	Trngpsv_PrintBytes(RandBuf, sizeof(RandBuf));

	Status = XTrngpsv_Generate(&Trngpsv, RandBuf, sizeof(RandBuf), XTRNGPSV_FALSE);
	if (Status != XST_SUCCESS) {
		xil_printf("Generate Failed, Status: 0x%08x\n\r", Status);
		goto END;
	}

	xil_printf("Generate 2 Random data:\n\r");
	Trngpsv_PrintBytes(RandBuf, sizeof(RandBuf));

	Status = XTrngpsv_Uninstantiate(&Trngpsv);
	if (Status != XST_SUCCESS) {
		xil_printf("Uninstantiate Failed \n\r");
		goto END;
	}

	Status = XST_SUCCESS;
END:
	return Status;
}
/*************************************************************************************************/
/**
 * @brief
 * This function tests the functioning of the TRNG in PTRNG mode.
 * DFDisable is set TRUE and DFDisable set to 0 for non DF.
 *
 * @param	DeviceId is the XPAR_<TRNG_instance>_DEVICE_ID value from
 *		xparameters.h.
 *
 * @return
 *		- XST_SUCCESS if example runs successfully
 *		- XST_FAILURE otherwise.
 *
 **************************************************************************************************/
@brief
This function tests the functioning of the TRNG in PTRNG mode.
DFDisable is set TRUE and DFDisable set to 0 for non DF.

@param       DeviceId is the XPAR__DEVICE_ID value from
xparameters.h.

@return
- XST_SUCCESS if example runs successfully
- XST_FAILURE otherwise.
@brief This function tests the functioning of the TRNG in PTRNG mode . DFDisable is set TRUE and DFDisable set to 0 for non DF . @param DeviceId is the XPAR__DEVICE_ID value from xparameters . h . @return - XST_SUCCESS if example runs successfully - XST_FAILURE otherwise .
int Trngpsv_Ptrng_Example(u16 DeviceId)
{
	int Status = XST_SUCCESS;
	XTrngpsv_Config *Config;
	XTrngpsv_UsrCfg UsrCfg = {
			.Mode = XTRNGPSV_PTRNG,
			.SeedLife = 0U,
			.PredResistanceEn = XTRNGPSV_FALSE,
			.DFDisable = XTRNGPSV_TRUE,
			.DFLenMul = 0U,
			.InitSeedPresent =  XTRNGPSV_FALSE,
			.PersStrPresent = XTRNGPSV_FALSE
	};
	Config = XTrngpsv_LookupConfig(DeviceId);
	if (NULL == Config) {
		xil_printf("LookupConfig Failed \n\r");
		goto END;
	}
	Status = XTrngpsv_CfgInitialize(&Trngpsv, Config, Config->BaseAddress);
	if (Status != XST_SUCCESS) {
		xil_printf("CfgInitialize Failed, Status: 0x%08x\n\r", Status);
		goto END;
	}
	Status = XTrngpsv_RunKAT(&Trngpsv);
	if (Status != XST_SUCCESS) {
		if (Status == XTRNGPSV_ERROR_KAT_MISMATCH) {
			xil_printf("KAT Failed with mismatch error, Status: 0x%08x\n\r", Status);
		}
		else {
			xil_printf("KAT Failed, Status: 0x%08x\n\r", Status);
		}
		goto END;
	}
	Status = XTrngpsv_RunHealthTest(&Trngpsv);
	if (Status != XST_SUCCESS) {
		if ((Status == XTRNGPSV_ERROR_CERTF) ||
				(Status == XTRNGPSV_ERROR_CERTF_SW_A5_PATTERN)) {
			xil_printf("RunHealthTest Failed with CERTF related error, Status: 0x%08x\n\r", Status);
		}
		else {
			xil_printf("RunHealthTest Failed, Status: 0x%08x\n\r", Status);
		}
		goto END;
	}
	Status = XTrngpsv_Instantiate(&Trngpsv, &UsrCfg);
	if (Status != XST_SUCCESS) {
		xil_printf("Instantiate failed, Status: 0x%08x\n\r", Status);
		goto END;
	}
	Status = XTrngpsv_Generate(&Trngpsv, RandBuf, sizeof(RandBuf), XTRNGPSV_FALSE);
	if (Status != XST_SUCCESS) {
		xil_printf("Generate Failed, Status: 0x%08x\n\r", Status);
		goto END;
	}
	xil_printf("Generate 1 Random data:\n\r");
	Trngpsv_PrintBytes(RandBuf, sizeof(RandBuf));
	Status = XTrngpsv_Generate(&Trngpsv, RandBuf, sizeof(RandBuf), XTRNGPSV_FALSE);
	if (Status != XST_SUCCESS) {
		xil_printf("Generate Failed, Status: 0x%08x\n\r", Status);
		goto END;
	}
	xil_printf("Generate 2 Random data:\n\r");
	Trngpsv_PrintBytes(RandBuf, sizeof(RandBuf));
	Status = XTrngpsv_Uninstantiate(&Trngpsv);
	if (Status != XST_SUCCESS) {
		xil_printf("Uninstantiate Failed \n\r");
		goto END;
	}
	Status = XST_SUCCESS;
END:
	return Status;
}
int Trngpsv_Ptrng_Example ( u16 DeviceId ) { int Status = XST_SUCCESS ; XTrngpsv_Config * Config ; XTrngpsv_UsrCfg UsrCfg = { . Mode = XTRNGPSV_PTRNG , . SeedLife = 0U , . PredResistanceEn = XTRNGPSV_FALSE , . DFDisable = XTRNGPSV_TRUE , . DFLenMul = 0U , . InitSeedPresent = XTRNGPSV_FALSE , . PersStrPresent = XTRNGPSV_FALSE } ; Config = XTrngpsv_LookupConfig ( DeviceId ) ; if ( NULL == Config ) { xil_printf ( " \n \r " ) ; goto END ; } Status = XTrngpsv_CfgInitialize ( & Trngpsv , Config , Config -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " \n \r " , Status ) ; goto END ; } Status = XTrngpsv_RunKAT ( & Trngpsv ) ; if ( Status != XST_SUCCESS ) { if ( Status == XTRNGPSV_ERROR_KAT_MISMATCH ) { xil_printf ( " \n \r " , Status ) ; } else { xil_printf ( " \n \r " , Status ) ; } goto END ; } Status = XTrngpsv_RunHealthTest ( & Trngpsv ) ; if ( Status != XST_SUCCESS ) { if ( ( Status == XTRNGPSV_ERROR_CERTF ) || ( Status == XTRNGPSV_ERROR_CERTF_SW_A5_PATTERN ) ) { xil_printf ( " \n \r " , Status ) ; } else { xil_printf ( " \n \r " , Status ) ; } goto END ; } Status = XTrngpsv_Instantiate ( & Trngpsv , & UsrCfg ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " \n \r " , Status ) ; goto END ; } Status = XTrngpsv_Generate ( & Trngpsv , RandBuf , sizeof ( RandBuf ) , XTRNGPSV_FALSE ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " \n \r " , Status ) ; goto END ; } xil_printf ( " \n \r " ) ; Trngpsv_PrintBytes ( RandBuf , sizeof ( RandBuf ) ) ; Status = XTrngpsv_Generate ( & Trngpsv , RandBuf , sizeof ( RandBuf ) , XTRNGPSV_FALSE ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " \n \r " , Status ) ; goto END ; } xil_printf ( " \n \r " ) ; Trngpsv_PrintBytes ( RandBuf , sizeof ( RandBuf ) ) ; Status = XTrngpsv_Uninstantiate ( & Trngpsv ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " \n \r " ) ; goto END ; } Status = XST_SUCCESS ; END : return Status ; }
@brief
 This function tests the functioning of the TRNG in PTRNG mode.
@brief This function tests the functioning of the TRNG in PTRNG mode .
/*
	 * Initialize the TRNGPSV driver so that it's ready to use look up
	 * configuration in the config table, then initialize it.
	 */ /* Initialize the TRNGPSV driver so that it is ready to use. */ /* Instantiate to complete initialization */ /* Invoke Generate twice and print, RandBuf contains random data from last call */