RTEMS 6.1-rc1
fsl_gpt.h
1/*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_GPT_H_
10#define _FSL_GPT_H_
11
12#include "fsl_common.h"
13
19/*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
25#define FSL_GPT_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
33{
41
44{
48
51{
57
60{
65
68{
75
78{
86
88typedef enum _gpt_status_flag
89{
90 kGPT_OutputCompare1Flag = GPT_SR_OF1_MASK,
91 kGPT_OutputCompare2Flag = GPT_SR_OF2_MASK,
92 kGPT_OutputCompare3Flag = GPT_SR_OF3_MASK,
93 kGPT_InputCapture1Flag = GPT_SR_IF1_MASK,
94 kGPT_InputCapture2Flag = GPT_SR_IF2_MASK,
95 kGPT_RollOverFlag = GPT_SR_ROV_MASK,
97
99typedef struct _gpt_init_config
100{
102 uint32_t divider;
111
112/*******************************************************************************
113 * API
114 ******************************************************************************/
115
116#if defined(__cplusplus)
117extern "C" {
118#endif
119
131void GPT_Init(GPT_Type *base, const gpt_config_t *initConfig);
132
138void GPT_Deinit(GPT_Type *base);
139
157
168static inline void GPT_SoftwareReset(GPT_Type *base)
169{
170 base->CR |= GPT_CR_SWR_MASK;
171 /* Wait reset finished. */
172 while ((base->CR & GPT_CR_SWR_MASK) == GPT_CR_SWR_MASK)
173 {
174 }
175}
176
188static inline void GPT_SetClockSource(GPT_Type *base, gpt_clock_source_t gptClkSource)
189{
190 if (gptClkSource == kGPT_ClockSource_Osc)
191 {
192 base->CR = (base->CR & ~GPT_CR_CLKSRC_MASK) | GPT_CR_EN_24M_MASK | GPT_CR_CLKSRC(gptClkSource);
193 }
194 else
195 {
196 base->CR = (base->CR & ~(GPT_CR_CLKSRC_MASK | GPT_CR_EN_24M_MASK)) | GPT_CR_CLKSRC(gptClkSource);
197 }
198}
199
206static inline gpt_clock_source_t GPT_GetClockSource(GPT_Type *base)
207{
208 return (gpt_clock_source_t)(uint8_t)((base->CR & GPT_CR_CLKSRC_MASK) >> GPT_CR_CLKSRC_SHIFT);
209}
210
217static inline void GPT_SetClockDivider(GPT_Type *base, uint32_t divider)
218{
219 assert(divider - 1U <= GPT_PR_PRESCALER_MASK);
220
221 base->PR = (base->PR & ~GPT_PR_PRESCALER_MASK) | GPT_PR_PRESCALER(divider - 1U);
222}
223
230static inline uint32_t GPT_GetClockDivider(GPT_Type *base)
231{
232 return ((base->PR & GPT_PR_PRESCALER_MASK) >> GPT_PR_PRESCALER_SHIFT) + 1U;
233}
234
241static inline void GPT_SetOscClockDivider(GPT_Type *base, uint32_t divider)
242{
243 assert(divider - 1U <= (GPT_PR_PRESCALER24M_MASK >> GPT_PR_PRESCALER24M_SHIFT));
244
245 base->PR = (base->PR & ~GPT_PR_PRESCALER24M_MASK) | GPT_PR_PRESCALER24M(divider - 1U);
246}
247
254static inline uint32_t GPT_GetOscClockDivider(GPT_Type *base)
255{
256 return ((base->PR & GPT_PR_PRESCALER24M_MASK) >> GPT_PR_PRESCALER24M_SHIFT) + 1U;
257}
258
270static inline void GPT_StartTimer(GPT_Type *base)
271{
272 base->CR |= GPT_CR_EN_MASK;
273}
274
280static inline void GPT_StopTimer(GPT_Type *base)
281{
282 base->CR &= ~GPT_CR_EN_MASK;
283}
284
296static inline uint32_t GPT_GetCurrentTimerCount(GPT_Type *base)
297{
298 return base->CNT;
299}
300
315static inline void GPT_SetInputOperationMode(GPT_Type *base,
318{
319 assert(channel <= kGPT_InputCapture_Channel2);
320
321 base->CR =
322 (base->CR & ~(GPT_CR_IM1_MASK << ((uint32_t)channel * 2UL))) | (GPT_CR_IM1(mode) << ((uint32_t)channel * 2UL));
323}
324
332static inline gpt_input_operation_mode_t GPT_GetInputOperationMode(GPT_Type *base, gpt_input_capture_channel_t channel)
333{
334 assert(channel <= kGPT_InputCapture_Channel2);
335
336 return (gpt_input_operation_mode_t)(uint8_t)((base->CR >> (GPT_CR_IM1_SHIFT + (uint32_t)channel * 2UL)) &
337 (GPT_CR_IM1_MASK >> GPT_CR_IM1_SHIFT));
338}
339
347static inline uint32_t GPT_GetInputCaptureValue(GPT_Type *base, gpt_input_capture_channel_t channel)
348{
349 assert(channel <= kGPT_InputCapture_Channel2);
350
351 return base->ICR[(uint32_t)channel];
352}
353
361static inline void GPT_SetOutputOperationMode(GPT_Type *base,
364{
365 assert(channel <= kGPT_OutputCompare_Channel3);
366
367 base->CR =
368 (base->CR & ~(GPT_CR_OM1_MASK << ((uint32_t)channel * 3UL))) | (GPT_CR_OM1(mode) << ((uint32_t)channel * 3UL));
369}
370
378static inline gpt_output_operation_mode_t GPT_GetOutputOperationMode(GPT_Type *base,
380{
381 assert(channel <= kGPT_OutputCompare_Channel3);
382
383 return (gpt_output_operation_mode_t)(uint8_t)((base->CR >> (GPT_CR_OM1_SHIFT + (uint32_t)channel * 3UL)) &
384 (GPT_CR_OM1_MASK >> GPT_CR_OM1_SHIFT));
385}
386
394static inline void GPT_SetOutputCompareValue(GPT_Type *base, gpt_output_compare_channel_t channel, uint32_t value)
395{
396 assert(channel <= kGPT_OutputCompare_Channel3);
397
398 base->OCR[(uint32_t)channel] = value;
399}
400
408static inline uint32_t GPT_GetOutputCompareValue(GPT_Type *base, gpt_output_compare_channel_t channel)
409{
410 assert(channel <= kGPT_OutputCompare_Channel3);
411
412 return base->OCR[(uint32_t)channel];
413}
414
421static inline void GPT_ForceOutput(GPT_Type *base, gpt_output_compare_channel_t channel)
422{
423 assert(channel <= kGPT_OutputCompare_Channel3);
424
425 base->CR |= (GPT_CR_FO1_MASK << (uint32_t)channel);
426}
427
442static inline void GPT_EnableInterrupts(GPT_Type *base, uint32_t mask)
443{
444 base->IR |= mask;
445}
446
454static inline void GPT_DisableInterrupts(GPT_Type *base, uint32_t mask)
455{
456 base->IR &= ~mask;
457}
458
467static inline uint32_t GPT_GetEnabledInterrupts(GPT_Type *base)
468{
469 return (base->IR & (GPT_IR_OF1IE_MASK | GPT_IR_OF2IE_MASK | GPT_IR_OF3IE_MASK | GPT_IR_IF1IE_MASK |
470 GPT_IR_IF2IE_MASK | GPT_IR_ROVIE_MASK));
471}
472
485static inline uint32_t GPT_GetStatusFlags(GPT_Type *base, gpt_status_flag_t flags)
486{
487 return base->SR & (uint32_t)flags;
488}
489
496static inline void GPT_ClearStatusFlags(GPT_Type *base, gpt_status_flag_t flags)
497{
498 base->SR = (uint32_t)flags;
499}
500
503#if defined(__cplusplus)
504}
505#endif
506
509#endif /* _FSL_GPT_H_ */
#define GPT_PR_PRESCALER(x)
Definition: MIMXRT1052.h:23137
#define GPT_PR_PRESCALER24M(x)
Definition: MIMXRT1052.h:23146
#define GPT_CR_CLKSRC(x)
Definition: MIMXRT1052.h:23051
void GPT_GetDefaultConfig(gpt_config_t *config)
Fills in the GPT configuration structure with default settings.
Definition: fsl_gpt.c:112
enum _gpt_interrupt_enable gpt_interrupt_enable_t
List of GPT interrupts.
_gpt_output_operation_mode
List of output compare operation mode.
Definition: fsl_gpt.h:68
enum _gpt_clock_source gpt_clock_source_t
List of clock sources.
_gpt_interrupt_enable
List of GPT interrupts.
Definition: fsl_gpt.h:78
bool enableRunInWait
Definition: fsl_gpt.h:104
enum _gpt_input_capture_channel gpt_input_capture_channel_t
List of input capture channel number.
void GPT_Init(GPT_Type *base, const gpt_config_t *initConfig)
Initialize GPT to reset state and initialize running mode.
Definition: fsl_gpt.c:58
enum _gpt_input_operation_mode gpt_input_operation_mode_t
List of input capture operation mode.
void GPT_Deinit(GPT_Type *base)
Disables the module and gates the GPT clock.
Definition: fsl_gpt.c:85
bool enableRunInDoze
Definition: fsl_gpt.h:106
gpt_clock_source_t clockSource
Definition: fsl_gpt.h:101
_gpt_input_capture_channel
List of input capture channel number.
Definition: fsl_gpt.h:44
_gpt_clock_source
List of clock sources.
Definition: fsl_gpt.h:33
_gpt_status_flag
Status flag.
Definition: fsl_gpt.h:89
bool enableMode
Definition: fsl_gpt.h:108
bool enableRunInStop
Definition: fsl_gpt.h:105
enum _gpt_status_flag gpt_status_flag_t
Status flag.
enum _gpt_output_compare_channel gpt_output_compare_channel_t
List of output compare channel number.
enum _gpt_output_operation_mode gpt_output_operation_mode_t
List of output compare operation mode.
struct _gpt_init_config gpt_config_t
Structure to configure the running mode.
_gpt_input_operation_mode
List of input capture operation mode.
Definition: fsl_gpt.h:51
uint32_t divider
Definition: fsl_gpt.h:102
_gpt_output_compare_channel
List of output compare channel number.
Definition: fsl_gpt.h:60
bool enableFreeRun
Definition: fsl_gpt.h:103
bool enableRunInDbg
Definition: fsl_gpt.h:107
@ kGPT_OutputOperation_Activelow
Definition: fsl_gpt.h:73
@ kGPT_OutputOperation_Set
Definition: fsl_gpt.h:72
@ kGPT_OutputOperation_Clear
Definition: fsl_gpt.h:71
@ kGPT_OutputOperation_Toggle
Definition: fsl_gpt.h:70
@ kGPT_OutputOperation_Disconnected
Definition: fsl_gpt.h:69
@ kGPT_InputCapture1InterruptEnable
Definition: fsl_gpt.h:82
@ kGPT_RollOverFlagInterruptEnable
Definition: fsl_gpt.h:84
@ kGPT_OutputCompare2InterruptEnable
Definition: fsl_gpt.h:80
@ kGPT_OutputCompare3InterruptEnable
Definition: fsl_gpt.h:81
@ kGPT_OutputCompare1InterruptEnable
Definition: fsl_gpt.h:79
@ kGPT_InputCapture2InterruptEnable
Definition: fsl_gpt.h:83
@ kGPT_InputCapture_Channel1
Definition: fsl_gpt.h:45
@ kGPT_InputCapture_Channel2
Definition: fsl_gpt.h:46
@ kGPT_ClockSource_HighFreq
Definition: fsl_gpt.h:36
@ kGPT_ClockSource_Off
Definition: fsl_gpt.h:34
@ kGPT_ClockSource_Periph
Definition: fsl_gpt.h:35
@ kGPT_ClockSource_Osc
Definition: fsl_gpt.h:39
@ kGPT_ClockSource_Ext
Definition: fsl_gpt.h:37
@ kGPT_ClockSource_LowFreq
Definition: fsl_gpt.h:38
@ kGPT_OutputCompare1Flag
Definition: fsl_gpt.h:90
@ kGPT_InputCapture2Flag
Definition: fsl_gpt.h:94
@ kGPT_OutputCompare2Flag
Definition: fsl_gpt.h:91
@ kGPT_OutputCompare3Flag
Definition: fsl_gpt.h:92
@ kGPT_RollOverFlag
Definition: fsl_gpt.h:95
@ kGPT_InputCapture1Flag
Definition: fsl_gpt.h:93
@ kGPT_InputOperation_RiseEdge
Definition: fsl_gpt.h:53
@ kGPT_InputOperation_BothEdge
Definition: fsl_gpt.h:55
@ kGPT_InputOperation_FallEdge
Definition: fsl_gpt.h:54
@ kGPT_InputOperation_Disabled
Definition: fsl_gpt.h:52
@ kGPT_OutputCompare_Channel2
Definition: fsl_gpt.h:62
@ kGPT_OutputCompare_Channel3
Definition: fsl_gpt.h:63
@ kGPT_OutputCompare_Channel1
Definition: fsl_gpt.h:61
Definition: MIMXRT1052.h:22971
Structure to configure the running mode.
Definition: fsl_gpt.h:100
Definition: deflate.c:114