tao_z
2022-06-11 d8a5f3225d105585a4f181ed884adb2a861e0d13
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**
  ******************************************************************************
  * @file     xl_osc.c
  * @author   xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about OSC firmware program 
  ******************************************************************************
  * @attention
    *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
 
/* Includes ---------------------------------------------------------------*/
#include "xl_osc.h"     
 
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup OSC OSC Module 
  * @brief OSC Driver Modules Library
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define CR_CLEAR_Mask       ((uint8_t)0x16)    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/** @defgroup ICS_Private_Functions
  * @{
 */
 
/**
 * @brief ½«OSCÍâÉè¼Ä´æÆ÷»Ö¸´Ä¬ÈÏÖµ
 * @param  OSCx: Ö¸OSCÍâÉè
 * @retval None
 */
void OSC_Deinit(void)
{
    /* Deinitializes to default reset values */
    OSC->CR &= (~0xFFu);
}
 
/**
 * @brief OSC³õʼ»¯
 * @param  OSCx: Ö¸OSCÍâÉè
 * @param  OSC_InitStruct: OSC²ÎÊý½á¹¹Ìå
 * @retval None
 */
void OSC_Init(const OSC_InitTypeDef *OSC_InitStruct)
{
    uint32_t temp;
    
    temp = OSC->CR;
    
    temp &= ~CR_CLEAR_Mask;
    
    temp |= (uint32_t)((uint32_t)OSC_InitStruct->OSC_ModeSelect | (uint32_t)OSC_InitStruct->OSC_OutputSelect | (uint32_t)OSC_InitStruct->OSC_RangeSelect);
    
    OSC->CR = temp;
}
/**
 * @brief  OSCʹÄÜÃüÁî
 * @param  OSCx: Ö¸OSCÍâÉè
 * @param  State: Ê¹ÄÜ״̬
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg ENABLE £ºÊ¹ÄÜOSC
 *            @arg DISABLE £º¹Ø±ÕOSC
 * @retval None
 */
void OSC_EnableCmd(FunctionalState State)
{
    if(State !=DISABLE)
    {
        /* Enable the OSC */
        OSC->CR |= OSC_CR_OSCEN_MASK;
    }
    else 
    {
        /* Disable the OSC */
        OSC->CR &= ~OSC_CR_OSCEN_MASK;
    }
}
 
/**
 * @brief OSCÔÚstopģʽÏÂʹÄÜ
 * @param  OSCx: Ö¸OSCÍâÉè
 * @param  State: Ê¹ÄÜ״̬
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg ENABLE £ºÊ¹ÄÜOSC
 *            @arg DISABLE £º¹Ø±ÕOSC
 * @retval None
 */
void OSC_ModuleInStopModeCmd(FunctionalState NewState)
{
    if(NewState != DISABLE)
    {
        /* Enable the OSC in Stop mode. */
        OSC->CR |= OSC_CR_OSCSTEN_MASK;
    }
    else
    {
        /* Disable the OSC in Stop mode. */
        OSC->CR &= ~OSC_CR_OSCSTEN_MASK;
    }
}
 
/**
 * @brief OSCÍⲿʱÖÓÀ©Õ¹
 * @param  OSCx: Ö¸OSCÍâÉè
 * @param  ExpTime: À©Õ¹µÄclk(1-32767)
 * @retval None
 */
void OSC_SetExtTime(uint32_t ExpTime)
{    
    /* set the extention time */
    OSC->TCR =  OSC_TCR_CV_MASK | (ExpTime-1u);
}
/**
 * @brief OSC³õʼ»¯×´Ì¬
 * @param  OSCx: Ö¸OSCÍâÉè
 * @retval ×´Ì¬½á¹û
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg OSC_INITSTATUS_SUCESS £º³É¹¦
 *            @arg OSC_INITSTATUS_FAILED £ºÊ§°Ü
 */
uint8_t OSC_GetInitStatus(void)
{
    uint8_t sta;
    if((OSC->CR & OSC_CR_OSCINIT_MASK) == OSC_CR_OSCINIT_MASK)
    {
        sta = OSC_INITSTATUS_SUCESS;
    }
    else
    {
        sta = OSC_INITSTATUS_FAILED;
    }
    return sta;
}
 
/**
 * @brief OSC³õʼ»¯×´Ì¬
 * @param  OSCx: Ö¸OSCÍâÉè
 * @retval ×´Ì¬½á¹û
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg OSC_RANGE_HIGH £º4-24M
 *            @arg OSC_RANGE_LOW £º32k
 */
uint8_t OSC_GetRange(void)
{
    uint8_t temp;
    if((OSC->CR & OSC_CR_RANGE_MASK) == OSC_CR_RANGE_MASK)
    {
        temp = OSC_RANGE_HIGH;
    }
    else
    {
        temp = OSC_RANGE_LOW;
    }
    return temp;
}
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
 
#ifdef __cplusplus
}
#endif /* __cplusplus */