Statistics
| Branch: | Tag: | Revision:

mongoose / examples / PIC32 / mqtt_client / firmware / src / system_config / mx795_CC3100_e16 / framework / system / clk / src / sys_clk_static.c @ eaef5bd1

History | View | Annotate | Download (8.99 KB)

1
/*******************************************************************************
2
  SYS CLK Static Functions for Clock System Service
3

4
  Company:
5
    Microchip Technology Inc.
6

7
  File Name:
8
    sys_clk_static.c
9

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

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

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

27
    Static single-open interfaces also eliminate the need for the open handle.
28
*******************************************************************************/
29

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

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

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

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

    
55
// *****************************************************************************
56
// *****************************************************************************
57
// Section: Include Files
58
// *****************************************************************************
59
// *****************************************************************************
60

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

    
66
// *****************************************************************************
67
// *****************************************************************************
68
// Section: File Scope Functions
69
// *****************************************************************************
70
// *****************************************************************************
71

    
72
// *****************************************************************************
73
/* Function:
74
    void SYS_CLK_Static_Initialize ( const SYS_CLK_INIT const * clkInit )
75

76
  Summary:
77
    Initializes hardware and internal data structure of the System Clock.
78

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

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

90
    The objective is to eliminate the user's need to be knowledgeable in the
91
  function of
92
    the 'configuration bits' to configure the system oscillators.
93
*/
94

    
95
void SYS_CLK_Initialize(const SYS_CLK_INIT const *clkInit) {
96
  SYS_DEVCON_SystemUnlock();
97

    
98
  PLIB_OSC_FRCDivisorSelect(OSC_ID_0, OSC_FRC_DIV_2);
99

    
100
  /* Enable Peripheral Bus 1 */
101
  PLIB_OSC_PBClockDivisorSet(OSC_ID_0, 0, 1);
102

    
103
  SYS_DEVCON_SystemLock();
104
}
105

    
106
//******************************************************************************
107
/* Function:
108
    inline uint32_t SYS_CLK_SystemFrequencyGet ( void )
109

110
  Summary:
111
    Gets the system clock frequency in Hertz.
112

113
  Description:
114
    This function gets the System clock frequency in Hertz.
115

116
  Precondition:
117
    None.
118

119
  Parameters:
120
    None.
121

122
  Returns:
123
    System clock frequency in Hertz.
124

125
  Example:
126
    <code>
127
    uint32_t sysClockHz;
128

129
    sysClockHz = SYS_CLK_SystemFrequencyGet ( );
130
    </code>
131

132
  Remarks:
133
 */
134

    
135
inline uint32_t SYS_CLK_SystemFrequencyGet(void) {
136
  return SYS_CLK_FREQ;
137
}
138

    
139
//******************************************************************************
140
/* Function:
141
    inline uint32_t SYS_CLK_PeripheralFrequencyGet ( CLK_BUSES_PERIPHERAL
142
  peripheralBus )
143

144
  Summary:
145
    Gets the selected clock peripheral bus frequency in Hertz.
146

147
  Description:
148
    This function gets the selected peripheral bus clock frequency in Hertz.
149

150
  Precondition:
151
    None.
152

153
  Parameters:
154
        peripheralBus - Reference clock bus selection. One of the possible value
155
  from
156
                                CLK_BUSES_PERIPHERAL enum. For devices that do
157
  not have multiple
158
                                clock channels for Reference clock,
159
  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
174
  that case,
175
        pass CLK_USB_PERIPHERAL_1 as the bus number.
176
 */
177

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

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

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

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

194
  Precondition:
195
    None.
196

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

206
  Returns:
207
    Clock frequency in Hz.
208

209
  Example:
210
    <code>
211
    unsigned long sysClockOutputHz;
212

213
    sysClockOutputHz = SYS_CLK_ReferenceClockFrequencyGet ( CLK_BUS_REFERENCE_3
214
  );
215
    </code>
216

217
  Remarks:
218
 */
219

    
220
inline uint32_t SYS_CLK_ReferenceClockFrequencyGet(
221
    CLK_BUSES_REFERENCE referenceBus) {
222
  return 0;
223
}
224

    
225
/******************************************************************************
226
  Function:
227
    void SYS_CLK_SecondaryOscillatorEnable ( void )
228

229
  Summary:
230
    Enables the secondary oscillator.
231

232
  Description:
233
    This function enables the secondary oscillator.
234

235
  Remarks:
236
    For more details refer sys_clk.h.
237
*/
238

    
239
void SYS_CLK_SecondaryOscillatorEnable(void) {
240
  /* Check for secondary oscillator status */
241
  if (!PLIB_OSC_SecondaryIsEnabled(OSC_ID_0)) {
242
    /* Unlock and enable secondary oscillator */
243
    SYS_DEVCON_SystemUnlock();
244

    
245
    PLIB_OSC_SecondaryEnable(OSC_ID_0);
246

    
247
    SYS_DEVCON_SystemLock();
248
  }
249
}
250

    
251
/******************************************************************************
252
  Function:
253
    void SYS_CLK_SecondaryOscillatorDisable ( void )
254

255
  Summary:
256
    Disables the secondary oscillator.
257

258
  Description:
259
    This function disables the secondary oscillator.
260

261
  Remarks:
262
    For more details refer sys_clk.h.
263
*/
264

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

    
271
    PLIB_OSC_SecondaryDisable(OSC_ID_0);
272

    
273
    SYS_DEVCON_SystemLock();
274
  }
275
}
276

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

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

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

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

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