RTEMS 6.1-rc4
Loading...
Searching...
No Matches
fsl_enc.h
1/*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2021 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_ENC_H_
10#define _FSL_ENC_H_
11
12#include "fsl_common.h"
13
18/*******************************************************************************
19 * Definitions
20 ******************************************************************************/
21#define FSL_ENC_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
22
27{
32#if !(defined(FSL_FEATURE_ENC_HAS_NO_CTRL2_SAB_INT) && FSL_FEATURE_ENC_HAS_NO_CTRL2_SAB_INT)
34 (1U << 4U),
35#endif
38};
39
46{
48 kENC_INDEXPulseFlag = (1U << 1U),
51#if !(defined(FSL_FEATURE_ENC_HAS_NO_CTRL2_SAB_INT) && FSL_FEATURE_ENC_HAS_NO_CTRL2_SAB_INT)
53#endif
57};
58
65{
66 kENC_RawHOMEStatusFlag = ENC_IMR_HOME_MASK,
67 kENC_RawINDEXStatusFlag = ENC_IMR_INDEX_MASK,
68 kENC_RawPHBStatusFlag = ENC_IMR_PHB_MASK,
69 kENC_RawPHAEXStatusFlag = ENC_IMR_PHA_MASK,
70 kENC_FilteredHOMEStatusFlag = ENC_IMR_FHOM_MASK,
71 kENC_FilteredINDEXStatusFlag = ENC_IMR_FIND_MASK,
72 kENC_FilteredPHBStatusFlag = ENC_IMR_FPHB_MASK,
73 kENC_FilteredPHAStatusFlag = ENC_IMR_FPHA_MASK,
74};
75
82{
87
94{
99
109{
114
119{
124
129{
134
139{
143
144#if (defined(FSL_FEATURE_ENC_HAS_CTRL3) && FSL_FEATURE_ENC_HAS_CTRL3)
151typedef enum _enc_prescaler
152{
153 kENC_ClockDiv1 = 0,
154 kENC_ClockDiv2 = 1,
155 kENC_ClockDiv4 = 2,
156 kENC_ClockDiv8 = 3,
157 kENC_ClockDiv16 = 4,
158 kENC_ClockDiv32 = 5,
159 kENC_ClockDiv64 = 6,
160 kENC_ClockDiv128 = 7,
161 kENC_ClockDiv256 = 8,
162 kENC_ClockDiv512 = 9,
163 kENC_ClockDiv1024 = 10,
164 kENC_ClockDiv2048 = 11,
165 kENC_ClockDiv4096 = 12,
166 kENC_ClockDiv8192 = 13,
167 kENC_ClockDiv16384 = 14,
168 kENC_ClockDiv32768 = 15,
169} enc_prescaler_t;
170#endif
171
175typedef struct _enc_config
176{
177 /* Basic counter. */
181 /* Signal detection. */
188 /* Watchdog. */
194 /* Filter for PHASEA, PHASEB, INDEX and HOME. */
195 uint16_t filterCount;
205 /* Position compare. */
209 /* Modulus counting. */
216#if (defined(FSL_FEATURE_ENC_HAS_CTRL3) && FSL_FEATURE_ENC_HAS_CTRL3)
217 /* Prescaler. */
218 bool enablePeriodMeasurementFunction;
219 enc_prescaler_t prescalerValue;
220#endif
222
230{
232 uint16_t signalCount;
233 uint16_t signalPeriod;
236
237#if defined(__cplusplus)
238extern "C" {
239#endif
240
241/*******************************************************************************
242 * API
243 ******************************************************************************/
244
261void ENC_Init(ENC_Type *base, const enc_config_t *config);
262
272void ENC_Deinit(ENC_Type *base);
273
301
311
323
330void ENC_EnableWatchdog(ENC_Type *base, bool enable);
331
338void ENC_SetInitialPositionValue(ENC_Type *base, uint32_t value);
339
340/* @} */
341
353uint32_t ENC_GetStatusFlags(ENC_Type *base);
354
361void ENC_ClearStatusFlags(ENC_Type *base, uint32_t mask);
362
370static inline uint16_t ENC_GetSignalStatusFlags(ENC_Type *base)
371{
372 return base->IMR;
373}
374/* @} */
375
387void ENC_EnableInterrupts(ENC_Type *base, uint32_t mask);
388
395void ENC_DisableInterrupts(ENC_Type *base, uint32_t mask);
396
404uint32_t ENC_GetEnabledInterrupts(ENC_Type *base);
405
406/* @} */
407
420uint32_t ENC_GetPositionValue(ENC_Type *base);
421
433uint32_t ENC_GetHoldPositionValue(ENC_Type *base);
434
442static inline uint16_t ENC_GetPositionDifferenceValue(ENC_Type *base)
443{
444 return base->POSD;
445}
446
458static inline uint16_t ENC_GetHoldPositionDifferenceValue(ENC_Type *base)
459{
460 return base->POSDH;
461}
462
470static inline uint16_t ENC_GetRevolutionValue(ENC_Type *base)
471{
472 return base->REV;
473}
474
486static inline uint16_t ENC_GetHoldRevolutionValue(ENC_Type *base)
487{
488 return base->REVH;
489}
490
491#if (defined(FSL_FEATURE_ENC_HAS_LASTEDGE) && FSL_FEATURE_ENC_HAS_LASTEDGE)
499static inline uint16_t ENC_GetLastEdgeTimeValue(ENC_Type *base)
500{
501 return base->LASTEDGE;
502}
503
511static inline uint16_t ENC_GetHoldLastEdgeTimeValue(ENC_Type *base)
512{
513 return base->LASTEDGEH;
514}
515#endif
516
517#if (defined(FSL_FEATURE_ENC_HAS_POSDPER) && FSL_FEATURE_ENC_HAS_POSDPER)
525static inline uint16_t ENC_GetPositionDifferencePeriodValue(ENC_Type *base)
526{
527 return base->POSDPER;
528}
529
537static inline uint16_t ENC_GetPositionDifferencePeriodBufferValue(ENC_Type *base)
538{
539 return base->POSDPERBFR;
540}
541
549static inline uint16_t ENC_GetHoldPositionDifferencePeriodValue(ENC_Type *base)
550{
551 return base->POSDPERH;
552}
553#endif
554/* @} */
555
556#if defined(__cplusplus)
557}
558#endif
559
560/* @} */
561
562#endif /* _FSL_ENC_H_ */
_enc_interrupt_enable
Interrupt enable/disable mask.
Definition: fsl_enc.h:27
void ENC_EnableWatchdog(ENC_Type *base, bool enable)
Enable watchdog for ENC module.
Definition: fsl_enc.c:306
bool enableWatchdog
Definition: fsl_enc.h:189
enc_position_match_mode_t positionMatchMode
Definition: fsl_enc.h:206
_enc_status_flags
Status flag mask.
Definition: fsl_enc.h:46
uint32_t ENC_GetPositionValue(ENC_Type *base)
Get the current position counter's value.
Definition: fsl_enc.c:594
uint16_t signalPeriod
Definition: fsl_enc.h:233
enc_index_trigger_mode_t INDEXTriggerMode
Definition: fsl_enc.h:183
uint16_t filterSamplePeriod
Definition: fsl_enc.h:200
_enc_index_trigger_mode
Define INDEX signal's trigger mode.
Definition: fsl_enc.h:94
enum _enc_position_match_mode enc_position_match_mode_t
Define type for the condition of POSMATCH pulses.
enum _enc_self_test_direction enc_self_test_direction_t
Define type for direction of self test generated signal.
uint32_t ENC_GetEnabledInterrupts(ENC_Type *base)
Get the enabled interrupts' flags.
Definition: fsl_enc.c:536
void ENC_Init(ENC_Type *base, const enc_config_t *config)
Initialization for the ENC module.
Definition: fsl_enc.c:80
void ENC_ClearStatusFlags(ENC_Type *base, uint32_t mask)
Clear the status flags.
Definition: fsl_enc.c:375
enum _enc_revolution_count_condition enc_revolution_count_condition_t
Define type for determining how the revolution counter (REV) is incremented/decremented.
void ENC_EnableInterrupts(ENC_Type *base, uint32_t mask)
Enable the interrupts.
Definition: fsl_enc.c:429
_enc_home_trigger_mode
Define HOME signal's trigger mode.
Definition: fsl_enc.h:82
void ENC_SetInitialPositionValue(ENC_Type *base, uint32_t value)
Set initial position value for ENC module.
Definition: fsl_enc.c:581
enum _enc_decoder_work_mode enc_decoder_work_mode_t
Define type for decoder work mode.
enc_home_trigger_mode_t HOMETriggerMode
Definition: fsl_enc.h:182
uint16_t filterCount
Definition: fsl_enc.h:195
_enc_self_test_direction
Define type for direction of self test generated signal.
Definition: fsl_enc.h:139
enc_revolution_count_condition_t revolutionCountCondition
Definition: fsl_enc.h:210
bool enableTRIGGERClearPositionCounter
Definition: fsl_enc.h:184
void ENC_GetDefaultConfig(enc_config_t *config)
Get an available pre-defined settings for ENC's configuration.
Definition: fsl_enc.c:224
void ENC_DoSoftwareLoadInitialPositionValue(ENC_Type *base)
Load the initial position value to position counter.
Definition: fsl_enc.c:261
bool enableTRIGGERClearHoldPositionCounter
Definition: fsl_enc.h:185
uint16_t signalCount
Definition: fsl_enc.h:232
uint16_t watchdogTimeoutValue
Definition: fsl_enc.h:190
bool enableModuloCountMode
Definition: fsl_enc.h:211
struct _enc_self_test_config enc_self_test_config_t
Define configuration structure for self test module.
enum _enc_home_trigger_mode enc_home_trigger_mode_t
Define HOME signal's trigger mode.
uint32_t positionCompareValue
Definition: fsl_enc.h:207
_enc_decoder_work_mode
Define type for decoder work mode.
Definition: fsl_enc.h:109
void ENC_SetSelfTestConfig(ENC_Type *base, const enc_self_test_config_t *config)
Enable and configure the self test function.
Definition: fsl_enc.c:279
uint32_t ENC_GetHoldPositionValue(ENC_Type *base)
Get the hold position counter's value.
Definition: fsl_enc.c:616
_enc_signal_status_flags
Signal status flag mask.
Definition: fsl_enc.h:65
enc_decoder_work_mode_t decoderWorkMode
Definition: fsl_enc.h:179
uint32_t ENC_GetStatusFlags(ENC_Type *base)
Get the status flags.
Definition: fsl_enc.c:324
struct _enc_config enc_config_t
Define user configuration structure for ENC module.
uint32_t positionModulusValue
Definition: fsl_enc.h:212
bool enableReverseDirection
Definition: fsl_enc.h:178
uint32_t positionInitialValue
Definition: fsl_enc.h:214
enum _enc_index_trigger_mode enc_index_trigger_mode_t
Define INDEX signal's trigger mode.
_enc_position_match_mode
Define type for the condition of POSMATCH pulses.
Definition: fsl_enc.h:119
_enc_revolution_count_condition
Define type for determining how the revolution counter (REV) is incremented/decremented.
Definition: fsl_enc.h:129
void ENC_Deinit(ENC_Type *base)
De-initialization for the ENC module.
Definition: fsl_enc.c:190
enc_self_test_direction_t signalDirection
Definition: fsl_enc.h:231
void ENC_DisableInterrupts(ENC_Type *base, uint32_t mask)
Disable the interrupts.
Definition: fsl_enc.c:482
@ kENC_PositionCompareInerruptEnable
Definition: fsl_enc.h:31
@ kENC_INDEXPulseInterruptEnable
Definition: fsl_enc.h:29
@ kENC_SimultBothPhaseChangeInterruptEnable
Definition: fsl_enc.h:33
@ kENC_HOMETransitionInterruptEnable
Definition: fsl_enc.h:28
@ kENC_PositionRollOverInterruptEnable
Definition: fsl_enc.h:36
@ kENC_PositionRollUnderInterruptEnable
Definition: fsl_enc.h:37
@ kENC_WatchdogTimeoutInterruptEnable
Definition: fsl_enc.h:30
@ kENC_INDEXPulseFlag
Definition: fsl_enc.h:48
@ kENC_SimultBothPhaseChangeFlag
Definition: fsl_enc.h:52
@ kENC_PositionRollOverFlag
Definition: fsl_enc.h:54
@ kENC_PositionRollUnderFlag
Definition: fsl_enc.h:55
@ kENC_WatchdogTimeoutFlag
Definition: fsl_enc.h:49
@ kENC_PositionCompareFlag
Definition: fsl_enc.h:50
@ kENC_HOMETransitionFlag
Definition: fsl_enc.h:47
@ kENC_LastCountDirectionFlag
Definition: fsl_enc.h:56
@ kENC_INDEXTriggerOnFallingEdge
Definition: fsl_enc.h:97
@ kENC_INDEXTriggerOnRisingEdge
Definition: fsl_enc.h:96
@ kENC_INDEXTriggerDisabled
Definition: fsl_enc.h:95
@ kENC_HOMETriggerDisabled
Definition: fsl_enc.h:83
@ kENC_HOMETriggerOnRisingEdge
Definition: fsl_enc.h:84
@ kENC_HOMETriggerOnFallingEdge
Definition: fsl_enc.h:85
@ kENC_SelfTestDirectionNegative
Definition: fsl_enc.h:141
@ kENC_SelfTestDirectionPositive
Definition: fsl_enc.h:140
@ kENC_DecoderWorkAsSignalPhaseCountMode
Definition: fsl_enc.h:111
@ kENC_DecoderWorkAsNormalMode
Definition: fsl_enc.h:110
@ kENC_RawPHBStatusFlag
Definition: fsl_enc.h:68
@ kENC_FilteredPHBStatusFlag
Definition: fsl_enc.h:72
@ kENC_RawINDEXStatusFlag
Definition: fsl_enc.h:67
@ kENC_RawHOMEStatusFlag
Definition: fsl_enc.h:66
@ kENC_FilteredPHAStatusFlag
Definition: fsl_enc.h:73
@ kENC_RawPHAEXStatusFlag
Definition: fsl_enc.h:69
@ kENC_FilteredINDEXStatusFlag
Definition: fsl_enc.h:71
@ kENC_FilteredHOMEStatusFlag
Definition: fsl_enc.h:70
@ kENC_POSMATCHOnPositionCounterEqualToComapreValue
Definition: fsl_enc.h:120
@ kENC_POSMATCHOnReadingAnyPositionCounter
Definition: fsl_enc.h:122
@ kENC_RevolutionCountOnRollOverModulus
Definition: fsl_enc.h:131
@ kENC_RevolutionCountOnINDEXPulse
Definition: fsl_enc.h:130
Definition: MIMXRT1052.h:17946
Define user configuration structure for ENC module.
Definition: fsl_enc.h:176
Define configuration structure for self test module.
Definition: fsl_enc.h:230
Definition: deflate.c:114