drv_trng.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**************************************************************************//**
  2. *
  3. * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2022-3-15 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #include <rtconfig.h>
  13. #if (defined(BSP_USING_TRNG) && defined(RT_HWCRYPTO_USING_RNG))
  14. #include <rtdevice.h>
  15. #include "NuMicro.h"
  16. #define NU_CRYPTO_TRNG_NAME "nu_TRNG"
  17. #define LOG_TAG "TRNG"
  18. #define DBG_ENABLE
  19. #define DBG_SECTION_NAME "TRNG"
  20. #define DBG_LEVEL DBG_INFO
  21. #define DBG_COLOR
  22. #include <rtdbg.h>
  23. /* Private variables ------------------------------------------------------------*/
  24. rt_err_t nu_trng_init(void)
  25. {
  26. CLK_EnableModuleClock(TRNG_MODULE);
  27. SYS_ResetModule(TRNG_RST);
  28. TRNG_Open();
  29. return RT_EOK;
  30. }
  31. rt_uint32_t nu_trng_rand(struct hwcrypto_rng *ctx)
  32. {
  33. uint32_t u32RNGValue;
  34. TRNG_GenWord(&u32RNGValue);
  35. return u32RNGValue;
  36. }
  37. #endif //#if (defined(BSP_USING_TRNG) && defined(RT_HWCRYPTO_USING_RNG))