Statistics
| Branch: | Tag: | Revision:

mongoose / examples / PIC32 / http_server / firmware / src / system_config / pic32mx_eth_sk2_encx24j600 / framework / system / clk / src / sys_clk_static.c @ eaef5bd1

History | View | Annotate | Download (8.88 KB)

1
/* clang-format off */
2
/*******************************************************************************
3
  SYS CLK Static Functions for Clock System Service
4

5
  Company:
6
    Microchip Technology Inc.
7

8
  File Name:
9
    sys_clk_static.c
10

11
  Summary:
12
    SYS CLK static function implementations for the Clock System Service.
13

14
  Description:
15
    The Clock System Service provides a simple interface to manage the oscillators
16
    on Microchip microcontrollers. This file defines the static implementation for the
17
    Clock System Service.
18

19
  Remarks:
20
    Static functions incorporate all system clock configuration settings as
21
    determined by the user via the Microchip Harmony Configurator GUI.  It provides
22
    static version of the routines, eliminating the need for an object ID or
23
    object handle.
24

25
    Static single-open interfaces also eliminate the need for the open handle.
26
*******************************************************************************/
27

    
28
//DOM-IGNORE-BEGIN
29
/*******************************************************************************
30
Copyright (c) 2014 released Microchip Technology Inc.  All rights reserved.
31

32
Microchip licenses to you the right to use, modify, copy and distribute
33
Software only when embedded on a Microchip microcontroller or digital signal
34
controller that is integrated into your product or third party product
35
(pursuant to the sublicense terms in the accompanying license agreement).
36

37
You should refer to the license agreement accompanying this Software for
38
additional information regarding your rights and obligations.
39

40
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
41
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
42
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
43
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
44
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
45
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
46
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
47
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
48
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
49
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
50
*******************************************************************************/
51
//DOM-IGNORE-END
52

    
53
// *****************************************************************************
54
// *****************************************************************************
55
// Section: Include Files
56
// *****************************************************************************
57
// *****************************************************************************
58

    
59
#include "system_config.h"
60
#include "system_definitions.h"
61
#include "peripheral/osc/plib_osc.h"
62
#include "system/devcon/sys_devcon.h"
63

    
64
// *****************************************************************************
65
// *****************************************************************************
66
// Section: File Scope Functions
67
// *****************************************************************************
68
// *****************************************************************************
69

    
70
// *****************************************************************************
71
/* Function:
72
    void SYS_CLK_Static_Initialize ( const SYS_CLK_INIT const * clkInit )
73

74
  Summary:
75
    Initializes hardware and internal data structure of the System Clock.
76

77
  Description:
78
    This function initializes the hardware and internal data structure of System
79
    Clock Service.
80

81
  Remarks:
82
    This is configuration values for the static version of the Clock System Service
83
    module is determined by the user via the Microchip Harmony Configurator GUI.
84
    This template will build a sys_clk_static.h and sys_clk_static.c file with
85
    the configuration per the user's choice.
86

87
    The objective is to eliminate the user's need to be knowledgeable in the function of
88
    the 'configuration bits' to configure the system oscillators.
89
*/
90

    
91
void SYS_CLK_Initialize( const SYS_CLK_INIT const * clkInit )
92
{
93
    SYS_DEVCON_SystemUnlock ( );
94

    
95
    PLIB_OSC_FRCDivisorSelect( OSC_ID_0, OSC_FRC_DIV_2);
96

    
97
    /* Enable Peripheral Bus 1 */
98
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 0, 1 );
99

    
100

    
101

    
102

    
103

    
104

    
105

    
106
    SYS_DEVCON_SystemLock ( );
107
}
108

    
109
//******************************************************************************
110
/* Function:
111
    inline uint32_t SYS_CLK_SystemFrequencyGet ( void )
112

113
  Summary:
114
    Gets the system clock frequency in Hertz.
115

116
  Description:
117
    This function gets the System clock frequency in Hertz.
118

119
  Precondition:
120
    None.
121

122
  Parameters:
123
    None.
124

125
  Returns:
126
    System clock frequency in Hertz.
127

128
  Example:
129
    <code>
130
    uint32_t sysClockHz;
131

132
    sysClockHz = SYS_CLK_SystemFrequencyGet ( );
133
    </code>
134

135
  Remarks:
136
 */
137

    
138
inline uint32_t SYS_CLK_SystemFrequencyGet ( void )
139
{
140
    return SYS_CLK_FREQ;
141
}
142

    
143
//******************************************************************************
144
/* Function:
145
    inline uint32_t SYS_CLK_PeripheralFrequencyGet ( CLK_BUSES_PERIPHERAL peripheralBus )
146

147
  Summary:
148
    Gets the selected clock peripheral bus frequency in Hertz.
149

150
  Description:
151
    This function gets the selected peripheral bus clock frequency in Hertz.
152

153
  Precondition:
154
    None.
155

156
  Parameters:
157
        peripheralBus - Reference clock bus selection. One of the possible value from
158
                                CLK_BUSES_PERIPHERAL enum. For devices that do not have multiple
159
                                clock channels for Reference clock, CLK_BUS_PERIPHERAL_1 should be
160
                                the selection.
161

162
  Returns:
163
    Clock frequency in Hertz.
164

165
  Example:
166
    <code>
167
    unsigned long peripheralClockHz;
168

169
    peripheralClockHz = SYS_CLK_PeripheralFrequencyGet ( CLK_BUS_PERIPHERAL_5 );
170
    </code>
171

172
  Remarks:
173
        Most of the devices doesn't have multiple Peripheral clock buses. In that case,
174
        pass CLK_USB_PERIPHERAL_1 as the bus number.
175
 */
176

    
177
inline uint32_t SYS_CLK_PeripheralFrequencyGet ( CLK_BUSES_PERIPHERAL peripheralBus )
178
{
179
    return SYS_CLK_BUS_PERIPHERAL_1;
180
}
181

    
182

    
183
//******************************************************************************
184
/* Function:
185
    inline uint32_t SYS_CLK_ReferenceClockFrequencyGet ( CLK_BUSES_REFERENCE referenceBus )
186

187
  Summary:
188
    Gets the selected Reference clock bus frequency in Hertz.
189

190
  Description:
191
    This function gets frequency of the selected Reference clock bus in Hertz.
192

193
  Precondition:
194
    None.
195

196
  Parameters:
197
        peripheralBus - Reference clock bus selection. One of the possible value from
198
                                CLK_BUSES_REFERENCE enum. For devices that do not have multiple
199
                                clock channels for Reference clock, CLK_BUS_REFERENCE_1 should be
200
                                the selection.
201

202
  Returns:
203
    Clock frequency in Hz.
204

205
  Example:
206
    <code>
207
    unsigned long sysClockOutputHz;
208

209
    sysClockOutputHz = SYS_CLK_ReferenceClockFrequencyGet ( CLK_BUS_REFERENCE_3 );
210
    </code>
211

212
  Remarks:
213
 */
214

    
215
inline uint32_t SYS_CLK_ReferenceClockFrequencyGet ( CLK_BUSES_REFERENCE referenceBus )
216
{
217
        return 0;
218
}
219

    
220
/******************************************************************************
221
  Function:
222
    void SYS_CLK_SecondaryOscillatorEnable ( void )
223

224
  Summary:
225
    Enables the secondary oscillator.
226

227
  Description:
228
    This function enables the secondary oscillator.
229

230
  Remarks:
231
    For more details refer sys_clk.h.
232
*/
233

    
234
void SYS_CLK_SecondaryOscillatorEnable ( void )
235
{
236
    /* Check for secondary oscillator status */
237
    if (!PLIB_OSC_SecondaryIsEnabled(OSC_ID_0))
238
    {
239
        /* Unlock and enable secondary oscillator */
240
        SYS_DEVCON_SystemUnlock();
241

    
242
        PLIB_OSC_SecondaryEnable(OSC_ID_0);
243

    
244
        SYS_DEVCON_SystemLock();
245
    }
246
}
247

    
248
/******************************************************************************
249
  Function:
250
    void SYS_CLK_SecondaryOscillatorDisable ( void )
251

252
  Summary:
253
    Disables the secondary oscillator.
254

255
  Description:
256
    This function disables the secondary oscillator.
257

258
  Remarks:
259
    For more details refer sys_clk.h.
260
*/
261

    
262
void SYS_CLK_SecondaryOscillatorDisable ( void )
263
{
264
    /* Check for secondary oscillator status */
265
    if (PLIB_OSC_SecondaryIsEnabled(OSC_ID_0))
266
    {
267
        /* Unlock and disable secondary oscillator*/
268
        SYS_DEVCON_SystemUnlock();
269

    
270
        PLIB_OSC_SecondaryDisable(OSC_ID_0);
271

    
272
        SYS_DEVCON_SystemLock();
273
    }
274
}
275

    
276
/******************************************************************************
277
  Function:
278
    bool SYS_CLK_SecondaryOscillatorIsEnabled ( void )
279

280
  Summary:
281
    Identifies whether secondary oscillator is enabled or disabled.
282

283
  Description:
284
    This function identifies whether the secondary oscillator is enabled or
285
    disabled.
286

287
  Remarks:
288
    For more details refer sys_clk.h.
289
*/
290

    
291
bool SYS_CLK_SecondaryOscillatorIsEnabled ( void )
292
{
293
    return (PLIB_OSC_SecondaryIsEnabled(OSC_ID_0));
294
}