1 /*
2 ** ###################################################################
3 **     Processors:          MIMXRT758SGAWAR_hifi1
4 **                          MIMXRT758SGFOA_hifi1
5 **
6 **     Compiler:            Xtensa Compiler
7 **     Reference manual:    iMXRT700RM Rev.2 DraftA, 05/2024
8 **     Version:             rev. 2.0, 2024-05-28
9 **     Build:               b240528
10 **
11 **     Abstract:
12 **         Provides a system configuration function and a global variable that
13 **         contains the system frequency. It configures the device and initializes
14 **         the oscillator (PLL) that is part of the microcontroller device.
15 **
16 **     Copyright 2016 Freescale Semiconductor, Inc.
17 **     Copyright 2016-2024 NXP
18 **     SPDX-License-Identifier: BSD-3-Clause
19 **
20 **     http:                 www.nxp.com
21 **     mail:                 support@nxp.com
22 **
23 **     Revisions:
24 **     - rev. 1.0 (2022-09-15)
25 **         Initial version.
26 **     - rev. 2.0 (2024-05-28)
27 **         Rev2 DraftA.
28 **
29 ** ###################################################################
30 */
31 
32 /*!
33  * @file MIMXRT758S
34  * @version 1.0
35  * @date 2024-05-28
36  * @brief Device specific configuration file for MIMXRT758S (header file)
37  *
38  * Provides a system configuration function and a global variable that contains
39  * the system frequency. It configures the device and initializes the oscillator
40  * (PLL) that is part of the microcontroller device.
41  */
42 
43 #ifndef _SYSTEM_MIMXRT758S_DSP_H_
44 #define _SYSTEM_MIMXRT758S_DSP_H_ /**< Symbol preventing repeated inclusion */
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include <stdint.h>
51 
52 #define DEFAULT_SYSTEM_CLOCK 100000000u /* Default System clock value */
53 #ifndef CLK_XTAL_OSC_CLK
54 #define CLK_XTAL_OSC_CLK 24000000u      /* Default XTAL OSC clock */
55 #endif
56 #define CLK_RTC_32K_CLK 32768u          /* RTC oscillator 32 kHz (32k_clk) */
57 #define CLK_LPOSC_1MHZ  1000000u        /* Low power oscillator 1 MHz (1m_lposc) */
58 #ifndef CLK_EXT_CLKIN
59 #define CLK_EXT_CLKIN 0u                /* Default external CLKIN pin clock */
60 #endif
61 #define CLK_OSC_CLK ((CLK_XTAL_OSC_CLK != 0U) ? CLK_XTAL_OSC_CLK : CLK_EXT_CLKIN)
62 
63 #define CLK_FRO1_MAX_CLK     192000000u /* FRO1 max clock frequency (fro1) */
64 #define CLK_FRO2_DEFAULT_CLK 196000000u /* FRO2 default clock frequency (fro2_max) */
65 
66 #define FRO_TUNER_USED(base) ((base->TEXPCNT.RW & FRO_TEXPCNT_TEXPCNT_MASK) != 0u)
67 /* FRO frequency = TRIMCNT * (divided ref clock frequency) / REFCLKCNT. */
68 #define FRO_FREQ_GET_FROM_TUNER(base)                                                       \
69     ((uint32_t)((uint64_t)(base->TRIMCNT.RW) *                                              \
70                 (uint64_t)(CLK_OSC_CLK / ((base->CNFG1.RW & FRO_CNFG1_REFDIV_MASK) + 1U)) / \
71                 ((base->CNFG1.RW & FRO_CNFG1_RFCLKCNT_MASK) >> FRO_CNFG1_RFCLKCNT_SHIFT)))
72 #define CLK_FRO2_CLK (FRO_TUNER_USED(FRO2) ? FRO_FREQ_GET_FROM_TUNER(FRO2) : CLK_FRO2_DEFAULT_CLK)
73 /**
74  * @brief System clock frequency (core clock)
75  *
76  * The system clock frequency supplied to the SysTick timer and the processor
77  * core clock. This variable can be used by the user application to setup the
78  * SysTick timer or configure other parameters. It may also be used by debugger to
79  * query the frequency of the debug timer or configure the trace clock speed
80  * SystemCoreClock is initialized with a correct predefined value.
81  */
82 extern uint32_t SystemCoreClock;
83 
84 /**
85  * @brief Setup the microcontroller system.
86  *
87  * Typically this function configures the oscillator (PLL) that is part of the
88  * microcontroller device. For systems with variable clock speed it also updates
89  * the variable SystemCoreClock. SystemInit is called from startup_device file.
90  */
91 void SystemInit(void);
92 
93 /**
94  * @brief Updates the SystemCoreClock variable.
95  *
96  * It must be called whenever the core clock is changed during program
97  * execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates
98  * the current core clock.
99  */
100 void SystemCoreClockUpdate(void);
101 
102 /**
103  * @brief SystemInit function hook.
104  *
105  * This weak function allows to call specific initialization code during the
106  * SystemInit() execution.This can be used when an application specific code needs
107  * to be called as close to the reset entry as possible (for example the Multicore
108  * Manager MCMGR_EarlyInit() function call).
109  * NOTE: No global r/w variables can be used in this hook function because the
110  * initialization of these variables happens after this function.
111  */
112 void SystemInitHook(void);
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* _SYSTEM_MIMXRT758S_DSP_H_ */
119