blob: fa3a3f1afc13703eca95d33ff4eacbc4cd9fe9fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32f20x_rng.c
* Author : WCH
* Version : V1.0.0
* Date : 2021/08/08
* Description : This file provides all the RNG firmware functions.
********************************************************************************/
#include "ch32f20x_rng.h"
#include "ch32f20x_rcc.h"
/*******************************************************************************
* Function Name : RNG_Cmd
* Description : Enables or disables the RNG peripheral.
* Input : NewState: ENABLE or DISABLE.
* Return : None
*******************************************************************************/
void RNG_Cmd(FunctionalState NewState)
{
if (NewState != DISABLE)
{
RNG->CR |= RNG_CR_RNGEN;
}
else
{
RNG->CR &= ~RNG_CR_RNGEN;
}
}
/*******************************************************************************
* Function Name : RNG_GetRandomNumber
* Description : Returns a 32-bit random number.
* Input : None
* Return : 32-bit random number.
*******************************************************************************/
uint32_t RNG_GetRandomNumber(void)
{
return RNG->DR;
}
/*******************************************************************************
* Function Name : RNG_ITConfig
* Description : Enables or disables the RNG interrupt.
* Input : NewState: ENABLE or DISABLE.
* Return : None
*******************************************************************************/
void RNG_ITConfig(FunctionalState NewState)
{
if (NewState != DISABLE)
{
RNG->CR |= RNG_CR_IE;
}
else
{
RNG->CR &= ~RNG_CR_IE;
}
}
/*******************************************************************************
* Function Name : RNG_GetFlagStatus
* Description : Checks whether the specified RNG flag is set or not.
* Input : RNG_FLAG: specifies the RNG flag to check.
* RNG_FLAG_DRDY: Data Ready flag.
* RNG_FLAG_CECS: Clock Error Current flag.
* RNG_FLAG_SECS: Seed Error Current flag.
* Return : bitstatus��SET or RESET.
*******************************************************************************/
FlagStatus RNG_GetFlagStatus(uint8_t RNG_FLAG)
{
FlagStatus bitstatus = RESET;
if ((RNG->SR & RNG_FLAG) != (uint8_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
/*******************************************************************************
* Function Name : RNG_ClearFlag
* Description : Clears the RNG flags.
* Input : RNG_FLAG: specifies the flag to clear.
* RNG_FLAG_CECS: Clock Error Current flag.
* RNG_FLAG_SECS: Seed Error Current flag.
* Return : None
*******************************************************************************/
void RNG_ClearFlag(uint8_t RNG_FLAG)
{
RNG->SR = ~(uint32_t)(((uint32_t)RNG_FLAG) << 4);
}
/*******************************************************************************
* Function Name : RNG_GetFlagStatus
* Description : Checks whether the specified RNG interrupt has occurred or not.
* Input : RNG_IT: specifies the RNG interrupt source to check.
* RNG_IT_CEI: Clock Error Interrupt.
* RNG_IT_SEI: Seed Error Interrupt.
* Return : bitstatus��SET or RESET.
*******************************************************************************/
ITStatus RNG_GetITStatus(uint8_t RNG_IT)
{
ITStatus bitstatus = RESET;
if ((RNG->SR & RNG_IT) != (uint8_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
/*******************************************************************************
* Function Name : RNG_ClearITPendingBit
* Description : Clears the RNG interrupt pending bit(s).
* Input : RNG_IT: specifies the RNG interrupt pending bit(s) to clear.
* RNG_IT_CEI: Clock Error Interrupt.
* RNG_IT_SEI: Seed Error Interrupt.
* Return : None
*******************************************************************************/
void RNG_ClearITPendingBit(uint8_t RNG_IT)
{
RNG->SR = (uint8_t)~RNG_IT;
}
|