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