• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <common/bk_include.h>
18 #include <driver/trng_types.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 
25 /* @brief Overview about this API header
26  *
27  */
28 
29 /**
30  * @brief TRNG API
31  * @defgroup bk_api_trng TRNG API group
32  * @{
33  */
34 
35 /**
36  * @brief     Init the TRNG driver
37  *
38  * This API init the resoure common:
39  *   - Init TRNG driver control memory
40  *
41  * @attention 1. This API should be called before any other TRNG APIs.
42  *
43  * @return
44  *    - BK_OK: succeed
45  *    - others: other errors.
46  */
47 bk_err_t bk_trng_driver_init(void);
48 
49 /**
50  * @brief     Deinit the TRNG driver
51  *
52  * This API free all resource related to TRNG and disable TRNG.
53  *
54  * @return
55  *    - BK_OK: succeed
56  *    - others: other errors.
57  */
58 bk_err_t bk_trng_driver_deinit(void);
59 
60 /**
61  * @brief     Start the TRNG
62  *
63  * @return
64  *    - BK_OK: succeed
65  *    - BK_ERR_TRNG_DRIVER_NOT_INIT: TRNG driver not init
66  *    - others: other errors.
67  */
68 bk_err_t bk_trng_start(void);
69 
70 /**
71  * @brief     Stop the TRNG
72  *
73  * @return
74  *    - BK_OK: succeed
75  *    - BK_ERR_TRNG_DRIVER_NOT_INIT: TRNG driver not init
76  *    - others: other errors.
77  */
78 bk_err_t bk_trng_stop(void);
79 
80 /**
81  * @brief     Get the random number
82  *
83  * @return random number between 0 and RAND_MAX
84  */
85 int bk_rand(void);
86 
87 /**
88  * @}
89  */
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 
96