aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/hal/inc/fsl_pcc_hal.h
blob: 53692269c47494415949ea2c5e1c155d6d7632d2 (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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __FSL_PCC_HAL_H__
#define __FSL_PCC_HAL_H__

#include <stdint.h>
#include <stdbool.h>
#include "fsl_device_registers.h"

/*!
 * @addtogroup pcc_hal
 * @{
 */

/******************************************************************************
 * Definitions
 *****************************************************************************/

/* Peripheral index in PCC0. */
#define PCC0_INDEX_DMA0       ( 0x0020U >> 2 )
#define PCC0_INDEX_XRDC0      ( 0x0050U >> 2 )
#define PCC0_INDEX_SEMA0      ( 0x006CU >> 2 )
#define PCC0_INDEX_FLASH0     ( 0x0080U >> 2 )
#define PCC0_INDEX_DMAMUX0    ( 0x0084U >> 2 )
#define PCC0_INDEX_MU0_A      ( 0x008CU >> 2 )
#define PCC0_INDEX_INTMUX0    ( 0x0090U >> 2 )
#define PCC0_INDEX_TPM2       ( 0x00B8U >> 2 )
#define PCC0_INDEX_PIT0       ( 0x00C0U >> 2 )
#define PCC0_INDEX_LPTMR0     ( 0x00D0U >> 2 )
#define PCC0_INDEX_RTC0       ( 0x00E0U >> 2 )
#define PCC0_INDEX_LPSPI2     ( 0x00F8U >> 2 )
#define PCC0_INDEX_LPI2C2     ( 0x0108U >> 2 )
#define PCC0_INDEX_LPUART2    ( 0x0118U >> 2 )
#define PCC0_INDEX_SAI0       ( 0x0130U >> 2 )
#define PCC0_INDEX_EVMSIM0    ( 0x0138U >> 2 )
#define PCC0_INDEX_USBFS0     ( 0x0154U >> 2 )
#define PCC0_INDEX_PORTA      ( 0x0168U >> 2 )
#define PCC0_INDEX_PORTB      ( 0x016CU >> 2 )
#define PCC0_INDEX_PORTC      ( 0x0170U >> 2 )
#define PCC0_INDEX_PORTD      ( 0x0174U >> 2 )
#define PCC0_INDEX_PORTE      ( 0x0178U >> 2 )
#define PCC0_INDEX_TSI0       ( 0x0188U >> 2 )
#define PCC0_INDEX_ADC0       ( 0x0198U >> 2 )
#define PCC0_INDEX_DAC0       ( 0x01A8U >> 2 )
#define PCC0_INDEX_CMP0       ( 0x01B8U >> 2 )
#define PCC0_INDEX_VREF0      ( 0x01C8U >> 2 )
#define PCC0_INDEX_ATX0       ( 0x01CCU >> 2 )
#define PCC0_INDEX_CRC0       ( 0x01E0U >> 2 )

/* Peripheral index in PCC1. */
#define PCC1_INDEX_DMA1       ( 0x0020U >> 2 )
#define PCC1_INDEX_SEMA1      ( 0x006CU >> 2 )
#define PCC1_INDEX_DMAMUX1    ( 0x0084U >> 2 )
#define PCC1_INDEX_MU0_B      ( 0x008CU >> 2 )
#define PCC1_INDEX_INTMUX1    ( 0x0090U >> 2 )
#define PCC1_INDEX_TRNG0      ( 0x0094U >> 2 )
#define PCC1_INDEX_TPM0       ( 0x00B0U >> 2 )
#define PCC1_INDEX_TPM1       ( 0x00B4U >> 2 )
#define PCC1_INDEX_PIT1       ( 0x00C4U >> 2 )
#define PCC1_INDEX_LPTMR1     ( 0x00D4U >> 2 )
#define PCC1_INDEX_LPSPI0     ( 0x00F0U >> 2 )
#define PCC1_INDEX_LPSPI1     ( 0x00F4U >> 2 )
#define PCC1_INDEX_LPI2C0     ( 0x0100U >> 2 )
#define PCC1_INDEX_LPI2C1     ( 0x0104U >> 2 )
#define PCC1_INDEX_LPUART0    ( 0x0110U >> 2 )
#define PCC1_INDEX_LPUART1    ( 0x0114U >> 2 )
#define PCC1_INDEX_FLEXIO0    ( 0x0128U >> 2 )
#define PCC1_INDEX_BBS0_PORT  ( 0x0180U >> 2 )
#define PCC1_INDEX_CMP1       ( 0x01BCU >> 2 )

/*!
 * @brief Clock source for peripherals that support various clock selections.
 */
typedef enum _clock_ip_src
{
    kClockIpSrcNone     = 0U,   /*!< Clock is off or test clock is enabled.  */
    kClockIpSrcSysOsc   = 1U,   /*!< System Oscillator.                      */
    kClockIpSrcSIrc     = 2U,   /*!< Slow IRC (max is 8MHz).                 */
    kClockIpSrcFIrc     = 3U,   /*!< Fast IRC (max is 48MHz).                */
    kClockIpSrcRtcOsc   = 4U,   /*!< RTC OSC.                                */
    kClockIpSrcSysFll   = 5U,   /*!< System FLL DIV3 or DIV2.                */
    kClockIpSrcSysPll   = 6U,   /*!< System PLL DIV3 or DIV2.                */
    kClockIpSrcPerPll   = 7U,   /*!< Perpheral PLL DIV3 or DIV2.             */
    kClockIpSrcMax      = 8U,   /*!< Max value.                              */
} clock_ip_src_t;

#if defined(__cplusplus)
extern "C" {
#endif

/*******************************************************************************
 * API
 ******************************************************************************/

/*!
 * @brief Enable clock for some IP module.
 *
 * This function enable clock for some specific IP module.
 * For example, to enable the DMA0 clock, use like this:
 * @code
   CLOCK_HAL_EnableClock(PCC0_BASE, 8);
 * @endcode
 * or use macro like this:
 * @code
   CLOCK_HAL_EnableClock(PCC0_BASE, PCC0_INDEX_DMA0);
 * @endcode
 *
 * @param base Register base address for the PCC instance.
 * @param index    The control register index for the IP module in PCC.
 */
static inline void CLOCK_HAL_EnableClock(PCC_Type * base, uint8_t index)
{
    /* Make sure this IP is present. */
    assert(PCC_BRD_CLKCFGn_EN(base, index));

    PCC_BWR_CLKCFGn_CGC(base, index, 1U);
}

/*!
 * @brief Disable clock for some IP module.
 *
 * This function disable clock for some specific IP module.
 * For example, to disable the DMA0 clock, use like this:
 * @code
   CLOCK_HAL_DisableClock(PCC0_BASE, 8);
 * @endcode
 * or use macro like this:
 * @code
   CLOCK_HAL_DisableClock(PCC0_BASE, PCC0_INDEX_DMA0);
 * @endcode
 *
 * @param base Register base address for the PCC instance.
 * @param index    The control register index for the IP module in PCC.
 */
static inline void CLOCK_HAL_DisableClock(PCC_Type * base, uint8_t index)
{
    /* Make sure this IP is present. */
    assert(PCC_BRD_CLKCFGn_EN(base, index));

    PCC_BWR_CLKCFGn_CGC(base, index, 0U);
}

/*!
 * @brief Gets the clock gate status on current core for some IP module.
 *
 * This function gets the clock gate status on current core for some IP module.
 * For example, to get the DMA0 clock gate status, use like this:
 * @code
   CLOCK_HAL_GetGateCmd(PCC0_BASE, 8);
 * @endcode
 * or use macro like this:
 * @code
   CLOCK_HAL_GetGateCmd(PCC0_BASE, PCC0_INDEX_DMA0);
 * @endcode
 *
 * @param base Register base address for the PCC instance.
 * @param index    The control register index for the IP module in PCC.
 * @return state true - ungated(Enabled), false - gated (Disabled)
 */
static inline bool CLOCK_HAL_GetGateCmd(PCC_Type * base, uint8_t index)
{
    /* Make sure this IP is present. */
    assert(PCC_BRD_CLKCFGn_EN(base, index));

    return (bool)PCC_BRD_CLKCFGn_CGC(base, index);
}

/*!
 * @brief Gets the clock gate status on other core for some IP module.
 *
 * This function gets the clock gate status on other core for some IP module.
 * For example, to get the DMA0 clock gate status, use like this:
 * @code
   CLOCK_HAL_GetGateCmdOnOtherCore(PCC0_BASE, 8);
 * @endcode
 * or use macro like this:
 * @code
   CLOCK_HAL_GetGateCmdOnOtherCore(PCC0_BASE, PCC0_INDEX_DMA0);
 * @endcode
 *
 * @param base Register base address for the PCC instance.
 * @param index    The control register index for the IP module in PCC.
 * @return state true - ungated(Enabled), false - gated (Disabled)
 */
static inline bool CLOCK_HAL_GetGateCmdOnOtherCore(PCC_Type * base, uint8_t index)
{
    /* Make sure this IP is present. */
    assert(PCC_BRD_CLKCFGn_EN(base, index));

    return (bool)PCC_BRD_CLKCFGn_CGC_ALT(base, index);
}

/*!
 * @brief Sets the clock source for some IP module.
 *
 * This function sets the clock source for some IP module.
 * For example, to set the clock source for USBFS0 to OSCCLK, use like this:
 * @code
   CLOCK_HAL_SetIpSrc(PCC0_BASE, 38, kClockIpSrcSysOsc);
 * @endcode
 * or use macro like this:
 * @code
   CLOCK_HAL_SetIpSrc(PCC0_BASE, PCC0_INDEX_USBFS0, kClockIpSrcSysOsc);
 * @endcode
 *
 * @param base Register base address for the PCC instance.
 * @param index    The control register index for the IP module in PCC.
 * @param src      The clock source to set.
 *
 * @note Not all peripherals support various clock sources, please check the
 *       reference manual for more details.
 */
static inline void CLOCK_HAL_SetIpSrc(PCC_Type * base,
                                      uint8_t index,
                                      clock_ip_src_t src)
{
    /* Make sure this IP is present. */
    assert(PCC_BRD_CLKCFGn_EN(base, index));

    assert(src < kClockIpSrcMax);

    PCC_BWR_CLKCFGn_PCS(base, index, src);
}

/*!
 * @brief Gets the clock source for some IP module.
 *
 * This function gets the clock source for some IP module.
 * For example, to get the clock source for USBFS0 to OSCCLK, use like this:
 * @code
   CLOCK_HAL_GetIpSrc(PCC0_BASE, 38);
 * @endcode
 * or use macro like this:
 * @code
   CLOCK_HAL_GetIpSrc(PCC0_BASE, PCC0_INDEX_USBFS0);
 * @endcode
 *
 * @param base Register base address for the PCC instance.
 * @param index    The control register index for the IP module in PCC.
 * @return Current clock source for this module.
 *
 * @note Not all peripherals support various clock sources, please check the
 *       reference manual for more details.
 */
static inline clock_ip_src_t CLOCK_HAL_GetIpSrc(PCC_Type * base,
                                                uint8_t index)
{
    /* Make sure this IP is present. */
    assert(PCC_BRD_CLKCFGn_EN(base, index));

    return (clock_ip_src_t)PCC_BRD_CLKCFGn_PCS(base, index);
}

/*!
 * @brief Sets the clock divider for some IP module.
 *
 * This function sets the clock divider for some IP module.
 *
 * @param base Register base address for the PCC instance.
 * @param index    The control register index for the IP module in PCC.
 * @param divider  Clock divider for this module.
 *
 * @note Not all peripherals support this feature, please check the
 *       reference manual for more details.
 */
static inline void CLOCK_HAL_SetIpDiv(PCC_Type * base,
                                      uint8_t index,
                                      uint32_t divider)
{
    /* Make sure this IP is present. */
    assert(PCC_BRD_CLKCFGn_EN(base, index));

    PCC_BWR_CLKCFGn_PCD(base, index, divider);
}


/*!
 * @brief Gets the clock divider for some IP module.
 *
 * This function gets the clock divider for some IP module.
 *
 * @param base Register base address for the PCC instance.
 * @param index    The control register index for the IP module in PCC.
 * @return Current clock divider for this module.
 *
 * @note Not all peripherals support this feature, please check the
 *       reference manual for more details.
 */
static inline uint32_t CLOCK_HAL_GetIpDiv(PCC_Type * base,
                                          uint8_t index)
{
    /* Make sure this IP is present. */
    assert(PCC_BRD_CLKCFGn_EN(base, index));

    return (uint32_t)PCC_BRD_CLKCFGn_PCD(base, index);
}

#if defined(__cplusplus)
extern }
#endif

/*!
 * @}
 */

#endif /* __FSL_PCC_HAL_H__ */

/******************************************************************************
 * EOF
 *****************************************************************************/