1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017, 2020 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_rcm.h"
10 
11 /* Component ID definition, used by tools. */
12 #ifndef FSL_COMPONENT_ID
13 #define FSL_COMPONENT_ID "platform.drivers.rcm"
14 #endif
15 
16 /*!
17  * brief Configures the reset pin filter.
18  *
19  * This function sets the reset pin filter including the filter source, filter
20  * width, and so on.
21  *
22  * param base RCM peripheral base address.
23  * param config Pointer to the configuration structure.
24  */
RCM_ConfigureResetPinFilter(RCM_Type * base,const rcm_reset_pin_filter_config_t * config)25 void RCM_ConfigureResetPinFilter(RCM_Type *base, const rcm_reset_pin_filter_config_t *config)
26 {
27     assert(NULL != config);
28 
29 #if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
30     uint32_t reg;
31 
32     reg = (((uint32_t)config->enableFilterInStop << RCM_RPC_RSTFLTSS_SHIFT) | (uint32_t)config->filterInRunWait);
33     if (config->filterInRunWait == kRCM_FilterBusClock)
34     {
35         reg |= ((uint32_t)config->busClockFilterCount << RCM_RPC_RSTFLTSEL_SHIFT);
36     }
37     base->RPC = reg;
38 #else
39     base->RPFC = (((uint8_t)config->enableFilterInStop << RCM_RPFC_RSTFLTSS_SHIFT) | (uint8_t)config->filterInRunWait);
40     if (config->filterInRunWait == kRCM_FilterBusClock)
41     {
42         base->RPFW = config->busClockFilterCount;
43     }
44 #endif /* FSL_FEATURE_RCM_REG_WIDTH */
45 }
46 
47 #if (defined(FSL_FEATURE_RCM_HAS_BOOTROM) && FSL_FEATURE_RCM_HAS_BOOTROM)
48 /*!
49  * brief Forces the boot from ROM.
50  *
51  * This function forces booting from ROM during all subsequent system resets.
52  *
53  * param base RCM peripheral base address.
54  * param config   Boot configuration.
55  */
RCM_SetForceBootRomSource(RCM_Type * base,rcm_boot_rom_config_t config)56 void RCM_SetForceBootRomSource(RCM_Type *base, rcm_boot_rom_config_t config)
57 {
58     uint32_t reg;
59 
60     reg = base->FM;
61     reg &= ~RCM_FM_FORCEROM_MASK;
62     reg |= ((uint32_t)config << RCM_FM_FORCEROM_SHIFT);
63 #if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
64     base->FM = reg;
65 #else
66     base->FM = (uint8_t)reg;
67 #endif /* FSL_FEATURE_RCM_REG_WIDTH == 32 */
68 }
69 #endif /* #if FSL_FEATURE_RCM_HAS_BOOTROM */
70