-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.c
More file actions
210 lines (182 loc) · 6.37 KB
/
Clock.c
File metadata and controls
210 lines (182 loc) · 6.37 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*******************************************************************************
* File Name: Clock.c
* Version 2.20
*
* Description:
* Provides system API for the clocking, interrupts and watchdog timer.
*
* Note:
* Documentation of the API's in this file is located in the
* System Reference Guide provided with PSoC Creator.
*
********************************************************************************
* Copyright 2008-2012, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/
#include <cydevice_trm.h>
#include "Clock.h"
#if defined CYREG_PERI_DIV_CMD
/*******************************************************************************
* Function Name: Clock_StartEx
********************************************************************************
*
* Summary:
* Starts the clock, aligned to the specified running clock.
*
* Parameters:
* alignClkDiv: The divider to which phase alignment is performed when the
* clock is started.
*
* Returns:
* None
*
*******************************************************************************/
void Clock_StartEx(uint32 alignClkDiv)
{
/* Make sure any previous start command has finished. */
while((Clock_CMD_REG & Clock_CMD_ENABLE_MASK) != 0u)
{
}
/* Specify the target divider and it's alignment divider, and enable. */
Clock_CMD_REG =
((uint32)Clock__DIV_ID << Clock_CMD_DIV_SHIFT)|
(alignClkDiv << Clock_CMD_PA_DIV_SHIFT) |
(uint32)Clock_CMD_ENABLE_MASK;
}
#else
/*******************************************************************************
* Function Name: Clock_Start
********************************************************************************
*
* Summary:
* Starts the clock.
*
* Parameters:
* None
*
* Returns:
* None
*
*******************************************************************************/
void Clock_Start(void)
{
/* Set the bit to enable the clock. */
Clock_ENABLE_REG |= Clock__ENABLE_MASK;
}
#endif /* CYREG_PERI_DIV_CMD */
/*******************************************************************************
* Function Name: Clock_Stop
********************************************************************************
*
* Summary:
* Stops the clock and returns immediately. This API does not require the
* source clock to be running but may return before the hardware is actually
* disabled.
*
* Parameters:
* None
*
* Returns:
* None
*
*******************************************************************************/
void Clock_Stop(void)
{
#if defined CYREG_PERI_DIV_CMD
/* Make sure any previous start command has finished. */
while((Clock_CMD_REG & Clock_CMD_ENABLE_MASK) != 0u)
{
}
/* Specify the target divider and it's alignment divider, and disable. */
Clock_CMD_REG =
((uint32)Clock__DIV_ID << Clock_CMD_DIV_SHIFT)|
((uint32)Clock_CMD_DISABLE_MASK);
#else
/* Clear the bit to disable the clock. */
Clock_ENABLE_REG &= (uint32)(~Clock__ENABLE_MASK);
#endif /* CYREG_PERI_DIV_CMD */
}
/*******************************************************************************
* Function Name: Clock_SetFractionalDividerRegister
********************************************************************************
*
* Summary:
* Modifies the clock divider and the fractional divider.
*
* Parameters:
* clkDivider: Divider register value (0-65535). This value is NOT the
* divider; the clock hardware divides by clkDivider plus one. For example,
* to divide the clock by 2, this parameter should be set to 1.
* fracDivider: Fractional Divider register value (0-31).
* Returns:
* None
*
*******************************************************************************/
void Clock_SetFractionalDividerRegister(uint16 clkDivider, uint8 clkFractional)
{
uint32 maskVal;
uint32 regVal;
#if defined (Clock__FRAC_MASK) || defined (CYREG_PERI_DIV_CMD)
/* get all but divider bits */
maskVal = Clock_DIV_REG &
(uint32)(~(uint32)(Clock_DIV_INT_MASK | Clock_DIV_FRAC_MASK));
/* combine mask and new divider vals into 32-bit value */
regVal = maskVal |
((uint32)((uint32)clkDivider << Clock_DIV_INT_SHIFT) & Clock_DIV_INT_MASK) |
((uint32)((uint32)clkFractional << Clock_DIV_FRAC_SHIFT) & Clock_DIV_FRAC_MASK);
#else
/* get all but integer divider bits */
maskVal = Clock_DIV_REG & (uint32)(~(uint32)Clock__DIVIDER_MASK);
/* combine mask and new divider val into 32-bit value */
regVal = clkDivider | maskVal;
#endif /* Clock__FRAC_MASK || CYREG_PERI_DIV_CMD */
Clock_DIV_REG = regVal;
}
/*******************************************************************************
* Function Name: Clock_GetDividerRegister
********************************************************************************
*
* Summary:
* Gets the clock divider register value.
*
* Parameters:
* None
*
* Returns:
* Divide value of the clock minus 1. For example, if the clock is set to
* divide by 2, the return value will be 1.
*
*******************************************************************************/
uint16 Clock_GetDividerRegister(void)
{
return (uint16)((Clock_DIV_REG & Clock_DIV_INT_MASK)
>> Clock_DIV_INT_SHIFT);
}
/*******************************************************************************
* Function Name: Clock_GetFractionalDividerRegister
********************************************************************************
*
* Summary:
* Gets the clock fractional divider register value.
*
* Parameters:
* None
*
* Returns:
* Fractional Divide value of the clock
* 0 if the fractional divider is not in use.
*
*******************************************************************************/
uint8 Clock_GetFractionalDividerRegister(void)
{
#if defined (Clock__FRAC_MASK)
/* return fractional divider bits */
return (uint8)((Clock_DIV_REG & Clock_DIV_FRAC_MASK)
>> Clock_DIV_FRAC_SHIFT);
#else
return 0u;
#endif /* Clock__FRAC_MASK */
}
/* [] END OF FILE */