1 /**
2 ****************************************************************************************
3 * @file gr55xx_hal_rng.c
4 * @author BLE Driver Team
5 * @brief RNG HAL module driver.
6 ****************************************************************************************
7 * @attention
8 #####Copyright (c) 2019 GOODIX
9 All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 * Neither the name of GOODIX nor the names of its contributors may be used
19 to endorse or promote products derived from this software without
20 specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 ****************************************************************************************
34 */
35
36 /* Includes ------------------------------------------------------------------*/
37 #include "gr55xx_hal.h"
38 #include "gr55xx_rom_symbol.h"
39
40 #if defined(HAL_RNG_MODULE_ENABLED) && (defined(GR5515_D) || defined(GR5515_E))
41
42 /* Private variables ---------------------------------------------------------*/
43
44 static hal_rng_callback_t rng_callback = {
45 .rng_msp_init = hal_rng_msp_init,
46 .rng_msp_deinit = hal_rng_msp_deinit,
47 .rng_ready_data_callback = hal_rng_ready_data_callback
48 };
49
50 /* Private function prototypes -----------------------------------------------*/
51
hal_rng_init(rng_handle_t * p_rng)52 hal_status_t hal_rng_init(rng_handle_t *p_rng)
53 {
54 hal_rng_register_callback(&rng_callback);
55
56 hal_status_t ret;
57 GLOBAL_EXCEPTION_DISABLE();
58 ret = hal_rng_init_ext(p_rng);
59 GLOBAL_EXCEPTION_ENABLE();
60
61 return ret;
62 }
63
hal_rng_deinit(rng_handle_t * p_rng)64 hal_status_t hal_rng_deinit(rng_handle_t *p_rng)
65 {
66 hal_rng_register_callback(&rng_callback);
67
68 hal_status_t ret;
69 GLOBAL_EXCEPTION_DISABLE();
70 ret = hal_rng_deinit_ext(p_rng);
71 GLOBAL_EXCEPTION_ENABLE();
72
73 return ret;
74 }
75
hal_rng_msp_init(rng_handle_t * p_rng)76 __WEAK void hal_rng_msp_init(rng_handle_t *p_rng)
77 {
78 /* Prevent unused argument(s) compilation warning */
79 UNUSED(p_rng);
80
81 /* NOTE: This function should not be modified, when the callback is needed,
82 the hal_rng_msp_init could be implemented in the user file
83 */
84 }
85
hal_rng_msp_deinit(rng_handle_t * p_rng)86 __WEAK void hal_rng_msp_deinit(rng_handle_t *p_rng)
87 {
88 /* Prevent unused argument(s) compilation warning */
89 UNUSED(p_rng);
90
91 /* NOTE: This function should not be modified, when the callback is needed,
92 the hal_rng_msp_init could be implemented in the user file
93 */
94 }
95
hal_rng_ready_data_callback(rng_handle_t * p_rng,uint32_t random32bit)96 __weak void hal_rng_ready_data_callback(rng_handle_t *p_rng, uint32_t random32bit)
97 {
98 UNUSED(p_rng);
99 UNUSED(random32bit);
100 /* NOTE : This function should not be modified. When the callback is needed,
101 function hal_rng_ready_data_callback must be implemented in the user file.
102 */
103 }
104
105 #endif /* HAL_WDT_MODULE_ENABLED */
106