hpm_rng_drv.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_RNG_DRV_H
  8. #define HPM_RNG_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_rng_regs.h"
  11. enum {
  12. status_rng_busy = MAKE_STATUS(status_group_rng, 1),
  13. status_rng_selftest_failed = MAKE_STATUS(status_group_rng, 2),
  14. status_rng_not_available = MAKE_STATUS(status_group_rng, 3),
  15. };
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. hpm_stat_t rng_init(RNG_Type *ptr);
  20. hpm_stat_t rng_rand_wait(RNG_Type *ptr, void *buf, uint32_t count_in_byte);
  21. hpm_stat_t rng_rand_no_wait(RNG_Type *ptr, void *buf, uint32_t count_in_byte);
  22. hpm_stat_t rng_feed_rand_to_sdp(RNG_Type *ptr);
  23. hpm_stat_t rng_run_selftest(RNG_Type *ptr);
  24. static inline void rng_sw_reset(RNG_Type *ptr)
  25. {
  26. ptr->CMD |= RNG_CMD_SFTRST_MASK;
  27. }
  28. static inline void rng_clear_interrupt_error(RNG_Type *ptr)
  29. {
  30. ptr->CMD |= RNG_CMD_CLRERR_MASK;
  31. }
  32. static inline void rng_clear_interrupt(RNG_Type *ptr)
  33. {
  34. ptr->CMD |= RNG_CMD_CLRINT_MASK;
  35. }
  36. static inline bool rng_is_busy(RNG_Type *ptr)
  37. {
  38. return ((ptr->STA & RNG_STA_BUSY_MASK) == RNG_STA_BUSY_MASK) ? true : false;
  39. }
  40. static inline bool rng_need_reseed(RNG_Type *ptr)
  41. {
  42. return ((ptr->STA & RNG_STA_RSDREQ_MASK) == RNG_STA_RSDREQ_MASK) ? true : false;
  43. }
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif /* HPM_RNG_DRV_H */