File indexing completed on 2025-05-11 08:22:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "fsl_gpt.h"
0010
0011
0012 #ifndef FSL_COMPONENT_ID
0013 #define FSL_COMPONENT_ID "platform.drivers.gpt"
0014 #endif
0015
0016
0017
0018
0019
0020
0021
0022
0023 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0024
0025 static GPT_Type *const s_gptBases[] = GPT_BASE_PTRS;
0026
0027
0028 static const clock_ip_name_t s_gptClocks[] = GPT_CLOCKS;
0029
0030
0031
0032
0033 static uint32_t GPT_GetInstance(GPT_Type *base)
0034 {
0035 uint32_t instance;
0036
0037
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
0051
0052
0053
0054
0055
0056
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
0064 (void)CLOCK_EnableClock(s_gptClocks[GPT_GetInstance(base)]);
0065 #endif
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
0082
0083
0084
0085 void GPT_Deinit(GPT_Type *base)
0086 {
0087
0088 base->CR = 0U;
0089
0090 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0091
0092 (void)CLOCK_DisableClock(s_gptClocks[GPT_GetInstance(base)]);
0093 #endif
0094 }
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 void GPT_GetDefaultConfig(gpt_config_t *config)
0113 {
0114 assert(NULL != config);
0115
0116
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 }