1 /*
2  * Copyright 2021-2022, 2024 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef FSL_SYSPM_H_
9 #define FSL_SYSPM_H_
10 
11 #include "fsl_common.h"
12 
13 /*! @addtogroup syspm */
14 /*! @{ */
15 
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 
20 /*! @name Driver version */
21 /*! @{ */
22 /*! @brief SYSPM driver version */
23 #define FSL_SYSPM_DRIVER_VERSION (MAKE_VERSION(2, 3, 0))
24 
25 /*! @} */
26 /*! @brief syspm select control monitor */
27 typedef enum _syspm_monitor
28 {
29     kSYSPM_Monitor0 = 0U, /*!< Monitor 0 */
30 #if (SYSPM_PMCR_COUNT > 1U)
31     kSYSPM_Monitor1 = 1U, /*!< Monitor 1 */
32 #endif
33 } syspm_monitor_t;
34 
35 /*! @brief syspm select event */
36 typedef enum _syspm_event
37 {
38     kSYSPM_Event1 = 0U, /*!< Event 1 */
39     kSYSPM_Event2 = 1U, /*!< Event 2 */
40     kSYSPM_Event3 = 2U, /*!< Event 3 */
41 } syspm_event_t;
42 
43 /*! @brief syspm set count mode */
44 typedef enum _syspm_mode
45 {
46     kSYSPM_BothMode       = 0x00, /*!< count in both modes */
47     kSYSPM_UserMode       = 0x02, /*!< count only in user mode */
48     kSYSPM_PrivilegedMode = 0x03, /*!< count only in privileged mode */
49 } syspm_mode_t;
50 
51 /*! @brief syspm start/stop control */
52 typedef enum _syspm_startstop_control
53 {
54     kSYSPM_Idle               = 0x00, /*!< idle >*/
55     kSYSPM_LocalStop          = 0x01, /*!< local stop */
56     kSYSPM_LocalStart         = 0x02, /*!< local start */
57     KSYSPM_EnableTraceControl = 0x04, /*!< enable global TSTART/TSTOP */
58     kSYSPM_GlobalStart        = 0x05, /*!< global stop */
59     kSYSPM_GlobalStop         = 0x06, /*!< global start */
60 } syspm_startstop_control_t;
61 
62 /*******************************************************************************
63  * API
64  ******************************************************************************/
65 
66 #if defined(__cplusplus)
67 extern "C" {
68 #endif /*_cplusplus. */
69 
70 /*!
71  * @brief Initializes the SYSPM
72  *
73  * This function enables the SYSPM clock.
74  *
75  * @param base  SYSPM peripheral base address.
76  */
77 void SYSPM_Init(SYSPM_Type *base);
78 
79 /*!
80  * @brief Deinitializes the SYSPM
81  *
82  * This function disables the SYSPM clock.
83  *
84  * @param base  SYSPM peripheral base address.
85  */
86 void SYSPM_Deinit(SYSPM_Type *base);
87 
88 /*!
89  * @brief Select event counters
90  *
91  * @param base               SYSPM peripheral base address.
92  * @param event              syspm select event, see to #syspm_event_t.
93  * @param eventCode          select which event to be counted in PMECTRx., see to table Events.
94  */
95 void SYSPM_SelectEvent(SYSPM_Type *base, syspm_monitor_t monitor, syspm_event_t event, uint8_t eventCode);
96 
97 /*!
98  * @brief Reset event counters
99  *
100  * @param base        SYSPM peripheral base address.
101  * @param monitor     syspm control monitor, see to #syspm_monitor_t.
102  */
103 void SYSPM_ResetEvent(SYSPM_Type *base, syspm_monitor_t monitor, syspm_event_t event);
104 
105 #if !((defined(FSL_FEATURE_SYSPM_HAS_PMCR_RICTR) && (FSL_FEATURE_SYSPM_HAS_PMCR_RICTR == 0U)))
106 /*!
107  * @brief Reset Instruction Counter
108  *
109  * @param base        SYSPM peripheral base address.
110  * @param monitor     syspm control monitor, see to #syspm_monitor_t.
111  */
112 void SYSPM_ResetInstructionEvent(SYSPM_Type *base, syspm_monitor_t monitor);
113 #endif
114 
115 /*!
116  * @brief Set count mode
117  *
118  * @param base               SYSPM peripheral base address.
119  * @param monitor            syspm control monitor, see to #syspm_monitor_t.
120  * @param mode               syspm select counter mode, see to #syspm_mode_t.
121  */
122 void SYSPM_SetCountMode(SYSPM_Type *base, syspm_monitor_t monitor, syspm_mode_t mode);
123 
124 /*!
125  * @brief  Set Start/Stop Control
126  *
127  * @param base              SYSPM peripheral base address.
128  * @param monitor           syspm control monitor, see to #syspm_monitor_t.
129  * @param ssc               This 3-bit field provides a three-phase mechanism to start/stop the counters. It includes a
130  *                          prioritized scheme with local start > local stop > global start > global stop > conditional
131  * TSTART > TSTOP. The global and conditional start/stop affect all configured PM/PSAM module concurrently so counters
132  * are "coherent". see to #syspm_startstop_control_t
133  */
134 void SYSPM_SetStartStopControl(SYSPM_Type *base, syspm_monitor_t monitor, syspm_startstop_control_t ssc);
135 
136 #if !((defined(FSL_FEATURE_SYSPM_HAS_PMCR_DCIFSH)) && (FSL_FEATURE_SYSPM_HAS_PMCR_DCIFSH == 0U))
137 /*!
138  * @brief Disable Counters if Stopped or Halted
139  *
140  * @param base              SYSPM peripheral base address.
141  * @param monitor           syspm control monitor, see to #syspm_monitor_t.
142  */
143 void SYSPM_DisableCounter(SYSPM_Type *base, syspm_monitor_t monitor);
144 #endif
145 
146 /*!
147  * @brief This is the the 40-bits of eventx counter.
148          The value in this register increments each time the event
149          selected in PMCRx[SELEVTx] occurs.
150  *
151  * @param base              SYSPM peripheral base address.
152  * @param monitor           syspm control monitor, see to #syspm_monitor_t.
153  * @param event             syspm select event, see to #syspm_event_t.
154  * @return                  get the the 40 bits of eventx counter.
155  */
156 uint64_t SYSPM_GetEventCounter(SYSPM_Type *base, syspm_monitor_t monitor, syspm_event_t event);
157 
158 #if (defined(FSL_FEATURE_SYSPM_HAS_PMICTR) && FSL_FEATURE_SYSPM_HAS_PMICTR)
159 /*!
160  * @brief This is the the 40-bits of instructionx counter.
161          The value in this register increments each time the CPU count
162          signals occurs.
163  *
164  * @param base              SYSPM peripheral base address.
165  * @param monitor           syspm control monitor, see to #syspm_monitor_t.
166  * @return                  get the the 40 bits of instruction counter.
167  */
168 uint64_t SYSPM_GetInstructionCounter(SYSPM_Type *base, syspm_monitor_t monitor);
169 #endif
170 
171 #if defined(__cplusplus)
172 }
173 #endif /* __cplusplus*/
174 
175 /*! @}*/
176 
177 #endif /* FSL_SYSPM_H_*/
178