Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:59

0001 /*
0002  * Copyright (c) 2015, Freescale Semiconductor, Inc.
0003  * Copyright 2016-2021 NXP
0004  * All rights reserved.
0005  *
0006  * SPDX-License-Identifier: BSD-3-Clause
0007  */
0008 
0009 #include "fsl_gpt.h"
0010 
0011 /* Component ID definition, used by tools. */
0012 #ifndef FSL_COMPONENT_ID
0013 #define FSL_COMPONENT_ID "platform.drivers.gpt"
0014 #endif
0015 
0016 /*******************************************************************************
0017  * Prototypes
0018  ******************************************************************************/
0019 
0020 /*******************************************************************************
0021  * Variables
0022  ******************************************************************************/
0023 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0024 /*! @brief Pointers to GPT bases for each instance. */
0025 static GPT_Type *const s_gptBases[] = GPT_BASE_PTRS;
0026 
0027 /*! @brief Pointers to GPT clocks for each instance. */
0028 static const clock_ip_name_t s_gptClocks[] = GPT_CLOCKS;
0029 
0030 /*******************************************************************************
0031  * Code
0032  ******************************************************************************/
0033 static uint32_t GPT_GetInstance(GPT_Type *base)
0034 {
0035     uint32_t instance;
0036 
0037     /* Find the instance index from base address mappings. */
0038     for (instance = 0U; instance < ARRAY_SIZE(s_gptBases); instance++)
0039     {
0040         if (s_gptBases[instance] == base)
0041         {
0042             break;
0043         }
0044     }
0045 
0046     assert(instance < ARRAY_SIZE(s_gptBases));
0047 
0048     return instance;
0049 }
0050 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0051 
0052 /*!
0053  * brief Initialize GPT to reset state and initialize running mode.
0054  *
0055  * param base GPT peripheral base address.
0056  * param initConfig GPT mode setting configuration.
0057  */
0058 void GPT_Init(GPT_Type *base, const gpt_config_t *initConfig)
0059 {
0060     assert(NULL != initConfig);
0061 
0062 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0063     /* Ungate the GPT clock*/
0064     (void)CLOCK_EnableClock(s_gptClocks[GPT_GetInstance(base)]);
0065 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0066     base->CR = 0U;
0067 
0068     GPT_SoftwareReset(base);
0069 
0070     base->CR =
0071         (initConfig->enableFreeRun ? GPT_CR_FRR_MASK : 0UL) | (initConfig->enableRunInWait ? GPT_CR_WAITEN_MASK : 0UL) |
0072         (initConfig->enableRunInStop ? GPT_CR_STOPEN_MASK : 0UL) |
0073         (initConfig->enableRunInDoze ? GPT_CR_DOZEEN_MASK : 0UL) |
0074         (initConfig->enableRunInDbg ? GPT_CR_DBGEN_MASK : 0UL) | (initConfig->enableMode ? GPT_CR_ENMOD_MASK : 0UL);
0075 
0076     GPT_SetClockSource(base, initConfig->clockSource);
0077     GPT_SetClockDivider(base, initConfig->divider);
0078 }
0079 
0080 /*!
0081  * brief Disables the module and gates the GPT clock.
0082  *
0083  * param base GPT peripheral base address.
0084  */
0085 void GPT_Deinit(GPT_Type *base)
0086 {
0087     /* Disable GPT timers */
0088     base->CR = 0U;
0089 
0090 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0091     /* Gate the GPT clock*/
0092     (void)CLOCK_DisableClock(s_gptClocks[GPT_GetInstance(base)]);
0093 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
0094 }
0095 
0096 /*!
0097  * brief Fills in the GPT configuration structure with default settings.
0098  *
0099  * The default values are:
0100  * code
0101  *    config->clockSource = kGPT_ClockSource_Periph;
0102  *    config->divider = 1U;
0103  *    config->enableRunInStop = true;
0104  *    config->enableRunInWait = true;
0105  *    config->enableRunInDoze = false;
0106  *    config->enableRunInDbg = false;
0107  *    config->enableFreeRun = false;
0108  *    config->enableMode  = true;
0109  * endcode
0110  * param config Pointer to the user configuration structure.
0111  */
0112 void GPT_GetDefaultConfig(gpt_config_t *config)
0113 {
0114     assert(NULL != config);
0115 
0116     /* Initializes the configure structure to zero. */
0117     (void)memset(config, 0, sizeof(*config));
0118 
0119     config->clockSource     = kGPT_ClockSource_Periph;
0120     config->divider         = 1U;
0121     config->enableRunInStop = true;
0122     config->enableRunInWait = true;
0123     config->enableRunInDoze = false;
0124     config->enableRunInDbg  = false;
0125     config->enableFreeRun   = false;
0126     config->enableMode      = true;
0127 }