AM64x MCU+ SDK  08.02.00
eqep/v0/eqep.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
49 #ifndef EQEP_V0_H_
50 #define EQEP_V0_H_
51 
52 /* ========================================================================== */
53 /* Include Files */
54 /* ========================================================================== */
55 
56 #include <drivers/hw_include/cslr.h>
57 #include <drivers/hw_include/cslr_eqep.h>
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /* ========================================================================== */
64 /* Macros & Typedefs */
65 /* ========================================================================== */
75 #define EQEP_CONFIG_QUADRATURE (0x0000U)
76 
77 #define EQEP_CONFIG_CLOCK_DIR (0x4000U)
78 
79 #define EQEP_CONFIG_UP_COUNT (0x8000U)
80 
81 #define EQEP_CONFIG_DOWN_COUNT (0xC000U)
82 
83 #define EQEP_CONFIG_2X_RESOLUTION (0x0000U)
84 
85 #define EQEP_CONFIG_1X_RESOLUTION (0x0800U)
86 
87 #define EQEP_CONFIG_NO_SWAP (0x0000U)
88 
89 #define EQEP_CONFIG_SWAP (0x0400U)
90 
101 #define EQEP_COMPARE_NO_SYNC_OUT (0x0000U)
102 
103 #define EQEP_COMPARE_IDX_SYNC_OUT (0x2000U)
104 
105 #define EQEP_COMPARE_STROBE_SYNC_OUT (0x3000U)
106 
107 #define EQEP_COMPARE_NO_SHADOW (0x0000U)
108 
109 #define EQEP_COMPARE_LOAD_ON_ZERO (0x8000U)
110 
111 #define EQEP_COMPARE_LOAD_ON_MATCH (0xC000U)
112 
124 #define EQEP_INT_GLOBAL (0x0001U)
125 
126 #define EQEP_INT_POS_CNT_ERROR (0x0002U)
127 
128 #define EQEP_INT_PHASE_ERROR (0x0004U)
129 
130 #define EQEP_INT_DIR_CHANGE (0x0008U)
131 
132 #define EQEP_INT_WATCHDOG (0x0010U)
133 
134 #define EQEP_INT_UNDERFLOW (0x0020U)
135 
136 #define EQEP_INT_OVERFLOW (0x0040U)
137 
138 #define EQEP_INT_POS_COMP_READY (0x0080U)
139 
140 #define EQEP_INT_POS_COMP_MATCH (0x0100U)
141 
142 #define EQEP_INT_STROBE_EVNT_LATCH (0x0200U)
143 
144 #define EQEP_INT_INDEX_EVNT_LATCH (0x0400U)
145 
146 #define EQEP_INT_UNIT_TIME_OUT (0x0800U)
147 
148 #define EQEP_INT_QMA_ERROR (0x1000U)
149 
159 #define EQEP_STS_UNIT_POS_EVNT (0x0080U)
160 
161 #define EQEP_STS_DIR_ON_1ST_IDX (0x0040U)
162 
163 #define EQEP_STS_DIR_FLAG (0x0020U)
164 
165 #define EQEP_STS_DIR_LATCH (0x0010U)
166 
167 #define EQEP_STS_CAP_OVRFLW_ERROR (0x0008U)
168 
169 #define EQEP_STS_CAP_DIR_ERROR (0x0004U)
170 
171 #define EQEP_STS_1ST_IDX_FLAG (0x0002U)
172 
173 #define EQEP_STS_POS_CNT_ERROR (0x0001U)
174 
184 #define EQEP_LATCH_CNT_READ_BY_CPU (0x0000U)
185 
186 #define EQEP_LATCH_UNIT_TIME_OUT (0x0004U)
187 
189 #define EQEP_LATCH_RISING_STROBE (0x0000U)
190 
191 #define EQEP_LATCH_EDGE_DIR_STROBE (0x0040U)
192 
193 #define EQEP_LATCH_RISING_INDEX (0x0010U)
194 
195 #define EQEP_LATCH_FALLING_INDEX (0x0020U)
196 
197 #define EQEP_LATCH_SW_INDEX_MARKER (0x0030U)
198 
209 #define EQEP_INIT_DO_NOTHING (0x0000U)
210 
211 #define EQEP_INIT_RISING_STROBE (0x0800U)
212 
213 #define EQEP_INIT_EDGE_DIR_STROBE (0x0C00U)
214 
215 #define EQEP_INIT_RISING_INDEX (0x0200U)
216 
217 #define EQEP_INIT_FALLING_INDEX (0x0300U)
218 
228 #define EQEP_MOD_FORWARD_DIR (1)
229 
230 #define EQEP_MOD_BACKWARD_DIR (-1)
231 
241 typedef uint32_t eqepPositionResetMode_t;
243 #define EQEP_POSITION_RESET_IDX (0x0000)
244 
245 #define EQEP_POSITION_RESET_MAX_POS (0x1000)
246 
247 #define EQEP_POSITION_RESET_1ST_IDX (0x2000)
248 
249 #define EQEP_POSITION_RESET_UNIT_TIME_OUT (0x3000)
250 
262 typedef uint32_t eqepCapClkPrescale_t;
264 #define EQEP_CAPTURE_CLK_DIV_1 (0x00)
265 
266 #define EQEP_CAPTURE_CLK_DIV_2 (0x10)
267 
268 #define EQEP_CAPTURE_CLK_DIV_4 (0x20)
269 
270 #define EQEP_CAPTURE_CLK_DIV_8 (0x30)
271 
272 #define EQEP_CAPTURE_CLK_DIV_16 (0x40)
273 
274 #define EQEP_CAPTURE_CLK_DIV_32 (0x50)
275 
276 #define EQEP_CAPTURE_CLK_DIV_64 (0x60)
277 
278 #define EQEP_CAPTURE_CLK_DIV_128 (0x070)
279 
291 typedef uint32_t eqeqUpEvntPrescale_t;
293 #define EQEP_UNIT_POS_EVNT_DIV_1 (0)
294 
295 #define EQEP_UNIT_POS_EVNT_DIV_2 (1)
296 
297 #define EQEP_UNIT_POS_EVNT_DIV_4 (2)
298 
299 #define EQEP_UNIT_POS_EVNT_DIV_8 (3)
300 
301 #define EQEP_UNIT_POS_EVNT_DIV_16 (4)
302 
303 #define EQEP_UNIT_POS_EVNT_DIV_32 (5)
304 
305 #define EQEP_UNIT_POS_EVNT_DIV_64 (6)
306 
307 #define EQEP_UNIT_POS_EVNT_DIV_128 (7)
308 
309 #define EQEP_UNIT_POS_EVNT_DIV_256 (8)
310 
311 #define EQEP_UNIT_POS_EVNT_DIV_512 (9)
312 
313 #define EQEP_UNIT_POS_EVNT_DIV_1024 (10)
314 
315 #define EQEP_UNIT_POS_EVNT_DIV_2048 (11)
316 
327 typedef uint32_t eqepStrobeSource_t;
329 #define EQEP_STROBE_FROM_GPIO (0)
330 
331 #define EQEP_STROBE_OR_ADCSOCA (2)
332 
333 #define EQEP_STROBE_OR_ADCSOCB (3)
334 
345 typedef uint32_t eqepQmaMode_t;
347 #define EQEP_QMA_MODE_BYPASS (0)
348 
349 #define EQEP_QMA_MODE_1 (1)
350 
351 #define EQEP_QMA_MODE_2 (2)
352 
363 typedef uint32_t eqepEmulationMode_t;
365 #define EQEP_EMULATIONMODE_STOPIMMEDIATELY (0)
366 
367 #define EQEP_EMULATIONMODE_STOPATROLLOVER (1)
368 
369 #define EQEP_EMULATIONMODE_RUNFREE (2)
370 
378 #define EQEP_DIR_ANTI_CLOCKWISE (CSL_EQEP_QEPSTS_TYPE1_QDF_VAL_QDF_COUNTERCLK)
379 
380 #define EQEP_DIR_CLOCKWISE (CSL_EQEP_QEPSTS_TYPE1_QDF_VAL_QDF_CLK)
381 
383 /* ========================================================================== */
384 /* Structures and Enums */
385 /* ========================================================================== */
386 
387 /* None */
388 
389 /* ========================================================================== */
390 /* Global Variables Declarations */
391 /* ========================================================================== */
392 
393 /* None */
394 
395 /* ========================================================================== */
396 /* Function Declarations */
397 /* ========================================================================== */
398 
408 void EQEP_enableModule(uint32_t baseAddr);
409 
419 void EQEP_disableModule(uint32_t baseAddr);
420 
444 void EQEP_setDecoderConfig(uint32_t baseAddr, uint16_t config);
445 
465 void EQEP_setPositionCounterConfig(uint32_t baseAddr,
467  uint32_t maxPosition);
468 
482 uint32_t EQEP_getPosition(uint32_t baseAddr);
483 
494 void EQEP_setPosition(uint32_t baseAddr, uint32_t position);
495 
510 int32_t EQEP_getDirection(uint32_t baseAddr);
511 
536 void EQEP_enableInterrupt(uint32_t baseAddr, uint16_t intFlags);
537 
562 void EQEP_disableInterrupt(uint32_t baseAddr, uint16_t intFlags);
563 
588 uint16_t EQEP_getEnabledInterrupt(uint32_t baseAddr);
589 
617 uint16_t EQEP_getInterruptStatus(uint32_t baseAddr);
618 
647 void EQEP_clearInterruptStatus(uint32_t baseAddr, uint16_t intFlags);
648 
673 void EQEP_forceInterrupt(uint32_t baseAddr, uint16_t intFlags);
674 
686 Bool EQEP_isErrorSet(uint32_t baseAddr);
687 
713 uint32_t EQEP_getStatus(uint32_t baseAddr);
714 
738 void EQEP_clearStatus(uint32_t baseAddr, uint16_t statusFlags);
739 
766 void EQEP_setCaptureConfig(uint32_t baseAddr,
767  eqepCapClkPrescale_t capPrescale,
768  eqeqUpEvntPrescale_t evntPrescale);
769 
778 void EQEP_enableCapture(uint32_t baseAddr);
779 
788 void EQEP_disableCapture(uint32_t baseAddr);
789 
800 uint32_t EQEP_getCapturePeriod(uint32_t baseAddr);
801 
811 uint32_t EQEP_getCaptureTimer(uint32_t baseAddr);
812 
821 void EQEP_enableCompare(uint32_t baseAddr);
822 
832 void EQEP_disableCompare(uint32_t baseAddr);
833 
849 int32_t EQEP_setComparePulseWidth(uint32_t baseAddr, uint16_t cycles);
850 
862 void EQEP_enableUnitTimer(uint32_t baseAddr, uint32_t period);
863 
873 void EQEP_disableUnitTimer(uint32_t baseAddr);
874 
889 void EQEP_enableWatchdog(uint32_t baseAddr, uint16_t period);
890 
900 void EQEP_disableWatchdog(uint32_t baseAddr);
901 
911 void EQEP_setWatchdogTimerValue(uint32_t baseAddr, uint16_t value);
912 
920 uint32_t EQEP_getWatchdogTimerValue(uint32_t baseAddr);
921 
947 void EQEP_setPositionInitMode(uint32_t baseAddr, uint16_t initMode);
948 
965 void EQEP_setSWPositionInit(uint32_t baseAddr, Bool initialize);
966 
979 void EQEP_setInitialPosition(uint32_t baseAddr, uint32_t position);
980 
1010 void EQEP_setLatchMode(uint32_t baseAddr, uint32_t latchMode);
1011 
1024 uint32_t EQEP_getIndexPositionLatch(uint32_t baseAddr);
1025 
1039 uint32_t EQEP_getStrobePositionLatch(uint32_t baseAddr);
1040 
1052 uint32_t EQEP_getPositionLatch(uint32_t baseAddr);
1053 
1066 uint32_t EQEP_getCaptureTimerLatch(uint32_t baseAddr);
1067 
1080 uint32_t EQEP_getCapturePeriodLatch(uint32_t baseAddr);
1081 
1099 void EQEP_setQMAModuleMode(uint32_t baseAddr, eqepQmaMode_t qmaMode);
1100 
1119 void EQEP_setStrobeSource(uint32_t baseAddr, eqepStrobeSource_t strobeSrc);
1120 
1140 void EQEP_setEmulationMode(uint32_t baseAddr, eqepEmulationMode_t emuMode);
1141 
1174 void EQEP_setCompareConfig(uint32_t baseAddr, uint16_t config,
1175  uint32_t compareValue, uint16_t cycles);
1176 
1191 void EQEP_setInputPolarity(uint32_t baseAddr, Bool invertQEPA, Bool invertQEPB,
1192  Bool invertIndex, Bool invertStrobe);
1193 
1194 #ifdef __cplusplus
1195 }
1196 #endif
1197 
1198 #endif /* #ifndef EQEP_V0_H_ */
1199 
eqeqUpEvntPrescale_t
uint32_t eqeqUpEvntPrescale_t
Enum Values that can be passed to EQEP_setCaptureConfig() as the evntPrescaleparameter.
Definition: eqep/v0/eqep.h:291
EQEP_getCaptureTimerLatch
uint32_t EQEP_getCaptureTimerLatch(uint32_t baseAddr)
Gets the encoder capture timer latch.
EQEP_getDirection
int32_t EQEP_getDirection(uint32_t baseAddr)
Gets the current direction of rotation.
EQEP_setInitialPosition
void EQEP_setInitialPosition(uint32_t baseAddr, uint32_t position)
Sets the init value for the encoder position counter.
EQEP_setDecoderConfig
void EQEP_setDecoderConfig(uint32_t baseAddr, uint16_t config)
Configures eQEP module's quadrature decoder unit.
EQEP_disableUnitTimer
void EQEP_disableUnitTimer(uint32_t baseAddr)
Disables the eQEP module unit timer.
eqepQmaMode_t
uint32_t eqepQmaMode_t
Enum Values that can be passed to EQEP_setQMAModuleMode() as the qmaMode parameter.
Definition: eqep/v0/eqep.h:345
EQEP_isErrorSet
Bool EQEP_isErrorSet(uint32_t baseAddr)
Gets the encoder error indicator.
eqepEmulationMode_t
uint32_t eqepEmulationMode_t
Enum Values that can be passed to EQEP_setEmulationMode() as the emuMode parameter.
Definition: eqep/v0/eqep.h:363
EQEP_getWatchdogTimerValue
uint32_t EQEP_getWatchdogTimerValue(uint32_t baseAddr)
Gets the eQEP module watchdog timer value.
EQEP_getCapturePeriodLatch
uint32_t EQEP_getCapturePeriodLatch(uint32_t baseAddr)
Gets the encoder capture period latch.
EQEP_enableUnitTimer
void EQEP_enableUnitTimer(uint32_t baseAddr, uint32_t period)
Enables the eQEP module unit timer.
EQEP_setInputPolarity
void EQEP_setInputPolarity(uint32_t baseAddr, Bool invertQEPA, Bool invertQEPB, Bool invertIndex, Bool invertStrobe)
Sets the polarity of the eQEP module's input signals.
EQEP_disableCompare
void EQEP_disableCompare(uint32_t baseAddr)
Disables the eQEP module position-compare unit.
EQEP_disableModule
void EQEP_disableModule(uint32_t baseAddr)
Disables the eQEP module.
EQEP_setSWPositionInit
void EQEP_setSWPositionInit(uint32_t baseAddr, Bool initialize)
Sets the software initialization of the encoder position counter.
EQEP_getPosition
uint32_t EQEP_getPosition(uint32_t baseAddr)
Gets the current encoder position.
EQEP_setPosition
void EQEP_setPosition(uint32_t baseAddr, uint32_t position)
Sets the current encoder position.
EQEP_setQMAModuleMode
void EQEP_setQMAModuleMode(uint32_t baseAddr, eqepQmaMode_t qmaMode)
Set the quadrature mode adapter (QMA) module mode.
EQEP_getStatus
uint32_t EQEP_getStatus(uint32_t baseAddr)
Returns content of the eQEP module status register.
EQEP_setEmulationMode
void EQEP_setEmulationMode(uint32_t baseAddr, eqepEmulationMode_t emuMode)
Set the emulation mode of the eQEP module.
EQEP_setWatchdogTimerValue
void EQEP_setWatchdogTimerValue(uint32_t baseAddr, uint16_t value)
Sets the eQEP module watchdog timer value.
EQEP_clearStatus
void EQEP_clearStatus(uint32_t baseAddr, uint16_t statusFlags)
Clears selected fields of the eQEP module status register.
value
uint32_t value
Definition: tisci_otp_revision.h:2
EQEP_enableModule
void EQEP_enableModule(uint32_t baseAddr)
Enables the eQEP module.
EQEP_disableInterrupt
void EQEP_disableInterrupt(uint32_t baseAddr, uint16_t intFlags)
Disables individual eQEP module interrupt sources.
EQEP_clearInterruptStatus
void EQEP_clearInterruptStatus(uint32_t baseAddr, uint16_t intFlags)
Clears eQEP module interrupt sources.
EQEP_enableCompare
void EQEP_enableCompare(uint32_t baseAddr)
Enables the eQEP module position-compare unit.
eqepPositionResetMode_t
uint32_t eqepPositionResetMode_t
Enum Values that can be passed to EQEP_setPositionCounterConfig() as the mode parameter.
Definition: eqep/v0/eqep.h:241
EQEP_getIndexPositionLatch
uint32_t EQEP_getIndexPositionLatch(uint32_t baseAddr)
Gets the encoder position that was latched on an index event.
EQEP_getCaptureTimer
uint32_t EQEP_getCaptureTimer(uint32_t baseAddr)
Gets the encoder capture timer value.
EQEP_setCaptureConfig
void EQEP_setCaptureConfig(uint32_t baseAddr, eqepCapClkPrescale_t capPrescale, eqeqUpEvntPrescale_t evntPrescale)
Configures eQEP module edge-capture unit.
EQEP_getEnabledInterrupt
uint16_t EQEP_getEnabledInterrupt(uint32_t baseAddr)
Get Enabled interrupts of eQEP module.
EQEP_enableCapture
void EQEP_enableCapture(uint32_t baseAddr)
Enables the eQEP module edge-capture unit.
EQEP_getInterruptStatus
uint16_t EQEP_getInterruptStatus(uint32_t baseAddr)
Gets the current interrupt status.
EQEP_disableWatchdog
void EQEP_disableWatchdog(uint32_t baseAddr)
Disables the eQEP module watchdog timer.
EQEP_setStrobeSource
void EQEP_setStrobeSource(uint32_t baseAddr, eqepStrobeSource_t strobeSrc)
Set the strobe input source of the eQEP module.
EQEP_setCompareConfig
void EQEP_setCompareConfig(uint32_t baseAddr, uint16_t config, uint32_t compareValue, uint16_t cycles)
Configures eQEP module position-compare unit.
eqepStrobeSource_t
uint32_t eqepStrobeSource_t
Enum Values that can be passed to EQEP_setStrobeSource() as the strobeSrc parameter.
Definition: eqep/v0/eqep.h:327
EQEP_setPositionInitMode
void EQEP_setPositionInitMode(uint32_t baseAddr, uint16_t initMode)
Configures the mode in which the position counter is initialized.
EQEP_enableInterrupt
void EQEP_enableInterrupt(uint32_t baseAddr, uint16_t intFlags)
Enables individual eQEP module interrupt sources.
EQEP_getPositionLatch
uint32_t EQEP_getPositionLatch(uint32_t baseAddr)
Gets the encoder position that was latched on a unit time-out event.
mode
char mode[32]
Definition: tisci_pm_core.h:1
eqepCapClkPrescale_t
uint32_t eqepCapClkPrescale_t
Enum Values that can be passed to EQEP_setCaptureConfig() as the capPrescale parameter.
Definition: eqep/v0/eqep.h:262
EQEP_setComparePulseWidth
int32_t EQEP_setComparePulseWidth(uint32_t baseAddr, uint16_t cycles)
Configures the position-compare unit's sync output pulse width.
EQEP_disableCapture
void EQEP_disableCapture(uint32_t baseAddr)
Disables the eQEP module edge-capture unit.
EQEP_getCapturePeriod
uint32_t EQEP_getCapturePeriod(uint32_t baseAddr)
Gets the encoder capture period.
EQEP_getStrobePositionLatch
uint32_t EQEP_getStrobePositionLatch(uint32_t baseAddr)
Gets the encoder position that was latched on a strobe event.
EQEP_forceInterrupt
void EQEP_forceInterrupt(uint32_t baseAddr, uint16_t intFlags)
Forces individual eQEP module interrupts.
EQEP_setLatchMode
void EQEP_setLatchMode(uint32_t baseAddr, uint32_t latchMode)
Configures the quadrature modes in which the position count can be latched.
EQEP_enableWatchdog
void EQEP_enableWatchdog(uint32_t baseAddr, uint16_t period)
Enables the eQEP module watchdog timer.
EQEP_setPositionCounterConfig
void EQEP_setPositionCounterConfig(uint32_t baseAddr, eqepPositionResetMode_t mode, uint32_t maxPosition)
Configures eQEP module position counter unit.