1 /*
2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 
7 /***********************************************************************************************************************
8  * Includes
9  **********************************************************************************************************************/
10 
11 #include "bsp_api.h"
12 #include "hw_sce_trng_private.h"
13 
14 /*******************************************************************************************************************//**
15  * 128bit Random Number Generation
16  * @param      OutData_Text    The out data text
17  * @retval FSP_SUCCESS      The operation completed successfully.
18  **********************************************************************************************************************/
HW_SCE_RNG_Read(uint32_t * OutData_Text)19 fsp_err_t HW_SCE_RNG_Read (uint32_t * OutData_Text) {
20     uint8_t * ptmp = (uint8_t *) OutData_Text;
21     uint32_t  k;
22     for (k = 0; k < 4; k++)            // read 4 words of random data similar (to make this API consistent with S7 and S3 implementation)
23     {
24         /* Set SGCEN bit and SGSTART bit */
25         R_TRNG->TRNGSCR0_b.SGCEN   = 1;
26         R_TRNG->TRNGSCR0_b.SGSTART = 1;
27 
28         /* Wait for RDRDY bit to be set */
29         while (0 == R_TRNG->TRNGSCR0_b.RDRDY)
30         {
31         }
32 
33         /* Read generated random data */
34         *ptmp++ = R_TRNG->TRNGSDR;
35         *ptmp++ = R_TRNG->TRNGSDR;
36         *ptmp++ = R_TRNG->TRNGSDR;
37         *ptmp++ = R_TRNG->TRNGSDR;
38     }
39 
40     return FSP_SUCCESS;
41 }
42