drv_trng.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. * 2020-7-4 YCHuang12 First version
  10. * 2022-3-15 Wayne Remove SW rand function
  11. *
  12. ******************************************************************************/
  13. #include <rtconfig.h>
  14. #if (defined(BSP_USING_TRNG) && defined(RT_HWCRYPTO_USING_RNG))
  15. #include <rtdevice.h>
  16. #include "NuMicro.h"
  17. #define NU_CRYPTO_TRNG_NAME "nu_TRNG"
  18. #define LOG_TAG "TRNG"
  19. #define DBG_ENABLE
  20. #define DBG_SECTION_NAME "TRNG"
  21. #define DBG_LEVEL DBG_INFO
  22. #define DBG_COLOR
  23. #include <rtdbg.h>
  24. /* Private variables ------------------------------------------------------------*/
  25. rt_err_t nu_trng_init(void)
  26. {
  27. CLK_EnableModuleClock(TRNG_MODULE);
  28. SYS_ResetModule(TRNG_RST);
  29. TRNG_Open();
  30. return RT_EOK;
  31. }
  32. rt_uint32_t nu_trng_rand(struct hwcrypto_rng *ctx)
  33. {
  34. uint32_t u32RNGValue;
  35. TRNG_GenWord(&u32RNGValue);
  36. return u32RNGValue;
  37. }
  38. #endif //#if (defined(BSP_USING_TRNG) && defined(RT_HWCRYPTO_USING_RNG))