summaryrefslogtreecommitdiffstats
path: root/bsps/arm/imxrt/mcux-sdk/devices/MIMXRT1166/drivers/fsl_soc_src.c
blob: 36fe004d3d34555f1d0530cc5bac9f2e90ef6c53 (plain) (blame)
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
/*
 * Copyright 2019-2021 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "fsl_soc_src.h"

/* Component ID definition, used by tools. */
#ifndef FSL_COMPONENT_ID
#define FSL_COMPONENT_ID "platform.drivers.soc_src"
#endif

/*******************************************************************************
 * Definitions
 ******************************************************************************/
#define SRC_GLOBAL_SYSTEM_RESET_BEHAVIOR_MASK (0x3U)
#define SRC_GLOBAL_SYSTEM_RESET_BEHAVIOR_CONFIG(resetSource, resetMode) \
    ((uint32_t)(resetMode) << (uint32_t)(resetSource))

#define SRC_SLICE_CTRL_SW_RESET_MASK (0x1U)

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*******************************************************************************
 * Code
 ******************************************************************************/

/*!
 * brief Release related core reset operation.
 *
 * The core reset will be held until boot core to release it.
 *
 * param base SRC peripheral base address.
 * param coreName The name of the reset core to be released.
 */
void SRC_ReleaseCoreReset(SRC_Type *base, src_core_name_t coreName)
{
    uint32_t coreMaskArray[] = {SRC_SCR_BT_RELEASE_M7_MASK, SRC_SCR_BT_RELEASE_M4_MASK};
    uint32_t regValue;

    regValue = base->SCR;

    if ((regValue & coreMaskArray[((uint32_t)coreName) - 1UL]) == 0UL)
    {
        base->SCR |= coreMaskArray[((uint32_t)coreName) - 1UL];
    }
}

/*!
 * brief Sets the reset mode of global system reset source.
 *
 * This function sets the selected mode of the input global system reset sources. This function will return as soon as
 * the reset if finished.
 *
 * param base SRC peripheral base address.
 * param resetSource The global system reset source. See @ref src_global_system_reset_source_t for more details.
 * param resetMode The reset mode of each reset source. See @ref src_global_system_reset_mode_t for more details.
 */
void SRC_SetGlobalSystemResetMode(SRC_Type *base,
                                  src_global_system_reset_source_t resetSource,
                                  src_global_system_reset_mode_t resetMode)
{
    uint32_t regValue;

    regValue = base->SRMR;
    regValue &= ~SRC_GLOBAL_SYSTEM_RESET_BEHAVIOR_CONFIG(resetSource, SRC_GLOBAL_SYSTEM_RESET_BEHAVIOR_MASK);
    regValue |= SRC_GLOBAL_SYSTEM_RESET_BEHAVIOR_CONFIG(resetSource, resetMode);

    base->SRMR = regValue;
}

/*!
 * brief Asserts software reset for the selected slice.
 *
 * param base SRC peripheral base address.
 * param sliceName The selected reset slice. See @ref src_reset_slice_name_t for more details.
 */
void SRC_AssertSliceSoftwareReset(SRC_Type *base, src_reset_slice_name_t sliceName)
{
    uint32_t regAddress;
    uint32_t sliceStatusRegAddress;

    regAddress            = SRC_GET_SLICE_REGISTER_ADDRESS(base, sliceName, SRC_SLICE_CONTROL_REGISTER_OFFSET);
    sliceStatusRegAddress = SRC_GET_SLICE_REGISTER_ADDRESS(base, sliceName, SRC_SLICE_STATUS_REGISTER_OFFSET);

    *(volatile uint32_t *)regAddress |= SRC_SLICE_CTRL_SW_RESET_MASK;

    while (((*(volatile uint32_t *)sliceStatusRegAddress) & SRC_SLICE_STAT_UNDER_RST_MASK) != 0UL)
    {
        ;
    }
}

/*!
 * brief Locks the value of SETPOINT_MODE and DOMAIN_MODE for the selected reset slice.
 *
 * param base SRC peripheral base address.
 * param sliceName The selected reset slice. See @ref src_reset_slice_name_t for more details.
 */
void SRC_LockSliceMode(SRC_Type *base, src_reset_slice_name_t sliceName)
{
    uint32_t authenticationRegAddress;

    authenticationRegAddress =
        SRC_GET_SLICE_REGISTER_ADDRESS(base, sliceName, SRC_SLICE_AUTHENTICATION_REGISTER_OFFSET);

    *(volatile uint32_t *)authenticationRegAddress |= SRC_SLICE_AUTHEN_LOCK_MODE_MASK;
}

/*!
 * brief Sets setpoint configuration for the selected reset slice.
 *
 * param base SRC peripheral base address.
 * param sliceName The selected reset slice. See @ref src_reset_slice_name_t for more details.
 * param setPointConfig The logic OR'ed value of @ref _src_setpoint_selection. When the system in the selected setpoint
 * slice reset will be assert.
 */
void SRC_SetSliceSetPointConfig(SRC_Type *base, src_reset_slice_name_t sliceName, uint32_t setpointConfig)
{
    uint32_t setpointConfigRegAddress;

    setpointConfigRegAddress =
        SRC_GET_SLICE_REGISTER_ADDRESS(base, sliceName, SRC_SLICE_SETPOINT_CONFIG_REGISTER_OFFSET);

    if (setpointConfig != 0UL)
    {
        *(volatile uint32_t *)setpointConfigRegAddress = setpointConfig;
    }
}

/*!
 * brief Sets domain mode configuration for the selected reset slice.
 *
 * param base SRC peripheral base address.
 * param sliceName The selected reset slice. See src_reset_slice_name_t for more details.
 * param domainConfig The logic OR'ed value of _src_domain_mode_selection.
 */
void SRC_SetSliceDomainModeConfig(SRC_Type *base, src_reset_slice_name_t sliceName, uint32_t domainConfig)
{
    uint32_t domainConfigRegAddress;

    domainConfigRegAddress = SRC_GET_SLICE_REGISTER_ADDRESS(base, sliceName, SRC_SLICE_DOMAIN_CONFIG_REGISTER_OFFSET);

    if (domainConfig != 0UL)
    {
        *(volatile uint32_t *)domainConfigRegAddress = domainConfig;
    }
}

/*!
 * brief Gets the reset state of the selected slice.
 *
 * param base SRC peripheral base address.
 * param sliceName The selected slice. See @ref src_reset_slice_name_t for more details.
 * retval kSRC_SliceResetInProcess The reset is in process.
 * retval kSRC_SliceResetFinished  The reset is finished.
 */
src_slice_reset_state_t SRC_GetSliceResetState(SRC_Type *base, src_reset_slice_name_t sliceName)
{
    uint32_t statusRegAddress;
    src_slice_reset_state_t ret;

    statusRegAddress = SRC_GET_SLICE_REGISTER_ADDRESS(base, sliceName, SRC_SLICE_STATUS_REGISTER_OFFSET);

    if (((*(uint32_t *)statusRegAddress) & SRC_SLICE_STAT_UNDER_RST_MASK) != 0UL)
    {
        ret = kSRC_SliceResetInProcess;
    }
    else
    {
        ret = kSRC_SliceResetFinished;
    }

    return ret;
}