1 //*****************************************************************************
2 //
3 // qei.c - Driver for the Quadrature Encoder with Index.
4 //
5 // Copyright (c) 2005-2017 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the
18 // distribution.
19 //
20 // Neither the name of Texas Instruments Incorporated nor the names of
21 // its contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 2.1.4.178 of the Tiva Peripheral Driver Library.
37 //
38 //*****************************************************************************
39
40 //*****************************************************************************
41 //
42 //! \addtogroup qei_api
43 //! @{
44 //
45 //*****************************************************************************
46
47 #include <stdbool.h>
48 #include <stdint.h>
49 #include "inc/hw_ints.h"
50 #include "inc/hw_memmap.h"
51 #include "inc/hw_qei.h"
52 #include "inc/hw_types.h"
53 #include "inc/hw_sysctl.h"
54 #include "driverlib/debug.h"
55 #include "driverlib/interrupt.h"
56 #include "driverlib/qei.h"
57
58 //*****************************************************************************
59 //
60 //! Enables the quadrature encoder.
61 //!
62 //! \param ui32Base is the base address of the quadrature encoder module.
63 //!
64 //! This function enables operation of the quadrature encoder module. The
65 //! module must be configured before it is enabled.
66 //!
67 //! \sa QEIConfigure()
68 //!
69 //! \return None.
70 //
71 //*****************************************************************************
72 void
QEIEnable(uint32_t ui32Base)73 QEIEnable(uint32_t ui32Base)
74 {
75 //
76 // Check the arguments.
77 //
78 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
79
80 //
81 // Enable the QEI module.
82 //
83 HWREG(ui32Base + QEI_O_CTL) |= QEI_CTL_ENABLE;
84 }
85
86 //*****************************************************************************
87 //
88 //! Disables the quadrature encoder.
89 //!
90 //! \param ui32Base is the base address of the quadrature encoder module.
91 //!
92 //! This function disables operation of the quadrature encoder module.
93 //!
94 //! \return None.
95 //
96 //*****************************************************************************
97 void
QEIDisable(uint32_t ui32Base)98 QEIDisable(uint32_t ui32Base)
99 {
100 //
101 // Check the arguments.
102 //
103 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
104
105 //
106 // Disable the QEI module.
107 //
108 HWREG(ui32Base + QEI_O_CTL) &= ~(QEI_CTL_ENABLE);
109 }
110
111 //*****************************************************************************
112 //
113 //! Configures the quadrature encoder.
114 //!
115 //! \param ui32Base is the base address of the quadrature encoder module.
116 //! \param ui32Config is the configuration for the quadrature encoder. See
117 //! below for a description of this parameter.
118 //! \param ui32MaxPosition specifies the maximum position value.
119 //!
120 //! This function configures the operation of the quadrature encoder. The
121 //! \e ui32Config parameter provides the configuration of the encoder and is
122 //! the logical OR of several values:
123 //!
124 //! - \b QEI_CONFIG_CAPTURE_A or \b QEI_CONFIG_CAPTURE_A_B specify if edges
125 //! on channel A or on both channels A and B should be counted by the
126 //! position integrator and velocity accumulator.
127 //! - \b QEI_CONFIG_NO_RESET or \b QEI_CONFIG_RESET_IDX specify if the
128 //! position integrator should be reset when the index pulse is detected.
129 //! - \b QEI_CONFIG_QUADRATURE or \b QEI_CONFIG_CLOCK_DIR specify if
130 //! quadrature signals are being provided on ChA and ChB, or if a direction
131 //! signal and a clock are being provided instead.
132 //! - \b QEI_CONFIG_NO_SWAP or \b QEI_CONFIG_SWAP to specify if the signals
133 //! provided on ChA and ChB should be swapped before being processed.
134 //!
135 //! \e ui32MaxPosition is the maximum value of the position integrator and is
136 //! the value used to reset the position capture when in index reset mode and
137 //! moving in the reverse (negative) direction.
138 //!
139 //! \return None.
140 //
141 //*****************************************************************************
142 void
QEIConfigure(uint32_t ui32Base,uint32_t ui32Config,uint32_t ui32MaxPosition)143 QEIConfigure(uint32_t ui32Base, uint32_t ui32Config,
144 uint32_t ui32MaxPosition)
145 {
146 //
147 // Check the arguments.
148 //
149 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
150
151 //
152 // Write the new configuration to the hardware.
153 //
154 HWREG(ui32Base + QEI_O_CTL) = ((HWREG(ui32Base + QEI_O_CTL) &
155 ~(QEI_CTL_CAPMODE | QEI_CTL_RESMODE |
156 QEI_CTL_SIGMODE | QEI_CTL_SWAP)) |
157 ui32Config);
158
159 //
160 // Set the maximum position.
161 //
162 HWREG(ui32Base + QEI_O_MAXPOS) = ui32MaxPosition;
163 }
164
165 //*****************************************************************************
166 //
167 //! Gets the current encoder position.
168 //!
169 //! \param ui32Base is the base address of the quadrature encoder module.
170 //!
171 //! This function returns the current position of the encoder. Depending upon
172 //! the configuration of the encoder, and the incident of an index pulse, this
173 //! value may or may not contain the expected data (that is, if in reset on
174 //! index mode, if an index pulse has not been encountered, the position
175 //! counter is not yet aligned with the index pulse).
176 //!
177 //! \return The current position of the encoder.
178 //
179 //*****************************************************************************
180 uint32_t
QEIPositionGet(uint32_t ui32Base)181 QEIPositionGet(uint32_t ui32Base)
182 {
183 //
184 // Check the arguments.
185 //
186 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
187
188 //
189 // Return the current position counter.
190 //
191 return(HWREG(ui32Base + QEI_O_POS));
192 }
193
194 //*****************************************************************************
195 //
196 //! Sets the current encoder position.
197 //!
198 //! \param ui32Base is the base address of the quadrature encoder module.
199 //! \param ui32Position is the new position for the encoder.
200 //!
201 //! This function sets the current position of the encoder; the encoder
202 //! position is then measured relative to this value.
203 //!
204 //! \return None.
205 //
206 //*****************************************************************************
207 void
QEIPositionSet(uint32_t ui32Base,uint32_t ui32Position)208 QEIPositionSet(uint32_t ui32Base, uint32_t ui32Position)
209 {
210 //
211 // Check the arguments.
212 //
213 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
214
215 //
216 // Set the position counter.
217 //
218 HWREG(ui32Base + QEI_O_POS) = ui32Position;
219 }
220
221 //*****************************************************************************
222 //
223 //! Gets the current direction of rotation.
224 //!
225 //! \param ui32Base is the base address of the quadrature encoder module.
226 //!
227 //! This function returns the current direction of rotation. In this case,
228 //! current means the most recently detected direction of the encoder; it may
229 //! not be presently moving but this is the direction it last moved before it
230 //! stopped.
231 //!
232 //! \return Returns 1 if moving in the forward direction or -1 if moving in the
233 //! reverse direction.
234 //
235 //*****************************************************************************
236 int32_t
QEIDirectionGet(uint32_t ui32Base)237 QEIDirectionGet(uint32_t ui32Base)
238 {
239 //
240 // Check the arguments.
241 //
242 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
243
244 //
245 // Return the direction of rotation.
246 //
247 return((HWREG(ui32Base + QEI_O_STAT) & QEI_STAT_DIRECTION) ? -1 : 1);
248 }
249
250 //*****************************************************************************
251 //
252 //! Gets the encoder error indicator.
253 //!
254 //! \param ui32Base is the base address of the quadrature encoder module.
255 //!
256 //! This function returns the error indicator for the quadrature encoder. It
257 //! is an error for both of the signals of the quadrature input to change at
258 //! the same time.
259 //!
260 //! \return Returns \b true if an error has occurred and \b false otherwise.
261 //
262 //*****************************************************************************
263 bool
QEIErrorGet(uint32_t ui32Base)264 QEIErrorGet(uint32_t ui32Base)
265 {
266 //
267 // Check the arguments.
268 //
269 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
270
271 //
272 // Return the error indicator.
273 //
274 return((HWREG(ui32Base + QEI_O_STAT) & QEI_STAT_ERROR) ? true : false);
275 }
276
277 //*****************************************************************************
278 //
279 //! Enables the input filter.
280 //!
281 //! \param ui32Base is the base address of the quadrature encoder module.
282 //!
283 //! This function enables operation of the input filter in the quadrature
284 //! encoder module. The module must be configured before input filter is
285 //! enabled.
286 //!
287 //! \sa QEIFilterConfigure() and QEIEnable()
288 //!
289 //! \return None.
290 //
291 //*****************************************************************************
292 void
QEIFilterEnable(uint32_t ui32Base)293 QEIFilterEnable(uint32_t ui32Base)
294 {
295 //
296 // Check the arguments.
297 //
298 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
299
300 //
301 // Enable the input filter.
302 //
303 HWREG(ui32Base + QEI_O_CTL) |= QEI_CTL_FILTEN;
304 }
305
306 //*****************************************************************************
307 //
308 //! Disables the input filter.
309 //!
310 //! \param ui32Base is the base address of the quadrature encoder module.
311 //!
312 //! This function disables operation of the input filter in the quadrature
313 //! encoder module.
314 //!
315 //! \return None.
316 //
317 //*****************************************************************************
318 void
QEIFilterDisable(uint32_t ui32Base)319 QEIFilterDisable(uint32_t ui32Base)
320 {
321 //
322 // Check the arguments.
323 //
324 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
325
326 //
327 // Disable the input filter.
328 //
329 HWREG(ui32Base + QEI_O_CTL) &= ~(QEI_CTL_FILTEN);
330 }
331
332 //*****************************************************************************
333 //
334 //! Configures the input filter.
335 //!
336 //! \param ui32Base is the base address of the quadrature encoder module.
337 //! \param ui32FiltCnt specifies the filter count applied to the input quadrature
338 //! signal before it is counted; can be one of \b QEI_FILTCNT_2,
339 //! \b QEI_FILTCNT_3, \b QEI_FILTCNT_4, \b QEI_FILTCNT_5, \b QEI_FILTCNT_6,
340 //! \b QEI_FILTCNT_7, \b QEI_FILTCNT_8, \b QEI_FILTCNT_9, \b QEI_FILTCNT_10,
341 //! \b QEI_FILTCNT_11, \b QEI_FILTCNT_12, \b QEI_FILTCNT_13, \b QEI_FILTCNT_14,
342 //! \b QEI_FILTCNT_15, \b QEI_FILTCNT_16 or \b QEI_FILTCNT_17
343 //!
344 //! This function configures the operation of the input filter prescale count.
345 //! as specified by \e ui32FiltCnt before the input signals are sent to the
346 //! quadrature encoder module.
347 //!
348 //! \return None.
349 //
350 //*****************************************************************************
351 void
QEIFilterConfigure(uint32_t ui32Base,uint32_t ui32FiltCnt)352 QEIFilterConfigure(uint32_t ui32Base, uint32_t ui32FiltCnt)
353 {
354 //
355 // Check the arguments.
356 //
357 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
358 ASSERT(!(ui32FiltCnt & ~(QEI_CTL_FILTCNT_M)));
359
360 //
361 // Set the input filter prescale count.
362 //
363 HWREG(ui32Base + QEI_O_CTL) = ((HWREG(ui32Base + QEI_O_CTL) &
364 ~(QEI_CTL_FILTCNT_M)) | ui32FiltCnt);
365 }
366
367 //*****************************************************************************
368 //
369 //! Enables the velocity capture.
370 //!
371 //! \param ui32Base is the base address of the quadrature encoder module.
372 //!
373 //! This function enables operation of the velocity capture in the quadrature
374 //! encoder module. The module must be configured before velocity capture is
375 //! enabled.
376 //!
377 //! \sa QEIVelocityConfigure() and QEIEnable()
378 //!
379 //! \return None.
380 //
381 //*****************************************************************************
382 void
QEIVelocityEnable(uint32_t ui32Base)383 QEIVelocityEnable(uint32_t ui32Base)
384 {
385 //
386 // Check the arguments.
387 //
388 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
389
390 //
391 // Enable the velocity capture.
392 //
393 HWREG(ui32Base + QEI_O_CTL) |= QEI_CTL_VELEN;
394 }
395
396 //*****************************************************************************
397 //
398 //! Disables the velocity capture.
399 //!
400 //! \param ui32Base is the base address of the quadrature encoder module.
401 //!
402 //! This function disables operation of the velocity capture in the quadrature
403 //! encoder module.
404 //!
405 //! \return None.
406 //
407 //*****************************************************************************
408 void
QEIVelocityDisable(uint32_t ui32Base)409 QEIVelocityDisable(uint32_t ui32Base)
410 {
411 //
412 // Check the arguments.
413 //
414 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
415
416 //
417 // Disable the velocity capture.
418 //
419 HWREG(ui32Base + QEI_O_CTL) &= ~(QEI_CTL_VELEN);
420 }
421
422 //*****************************************************************************
423 //
424 //! Configures the velocity capture.
425 //!
426 //! \param ui32Base is the base address of the quadrature encoder module.
427 //! \param ui32PreDiv specifies the predivider applied to the input quadrature
428 //! signal before it is counted; can be one of \b QEI_VELDIV_1,
429 //! \b QEI_VELDIV_2, \b QEI_VELDIV_4, \b QEI_VELDIV_8, \b QEI_VELDIV_16,
430 //! \b QEI_VELDIV_32, \b QEI_VELDIV_64, or \b QEI_VELDIV_128.
431 //! \param ui32Period specifies the number of clock ticks over which to measure
432 //! the velocity; must be non-zero.
433 //!
434 //! This function configures the operation of the velocity capture portion of
435 //! the quadrature encoder. The position increment signal is predivided as
436 //! specified by \e ui32PreDiv before being accumulated by the velocity
437 //! capture. The divided signal is accumulated over \e ui32Period system clock
438 //! before being saved and resetting the accumulator.
439 //!
440 //! \return None.
441 //
442 //*****************************************************************************
443 void
QEIVelocityConfigure(uint32_t ui32Base,uint32_t ui32PreDiv,uint32_t ui32Period)444 QEIVelocityConfigure(uint32_t ui32Base, uint32_t ui32PreDiv,
445 uint32_t ui32Period)
446 {
447 //
448 // Check the arguments.
449 //
450 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
451 ASSERT(!(ui32PreDiv & ~(QEI_CTL_VELDIV_M)));
452 ASSERT(ui32Period != 0);
453
454 //
455 // Set the velocity predivider.
456 //
457 HWREG(ui32Base + QEI_O_CTL) = ((HWREG(ui32Base + QEI_O_CTL) &
458 ~(QEI_CTL_VELDIV_M)) | ui32PreDiv);
459
460 //
461 // Set the timer period.
462 //
463 HWREG(ui32Base + QEI_O_LOAD) = ui32Period - 1;
464 }
465
466 //*****************************************************************************
467 //
468 //! Gets the current encoder speed.
469 //!
470 //! \param ui32Base is the base address of the quadrature encoder module.
471 //!
472 //! This function returns the current speed of the encoder. The value returned
473 //! is the number of pulses detected in the specified time period; this number
474 //! can be multiplied by the number of time periods per second and divided by
475 //! the number of pulses per revolution to obtain the number of revolutions per
476 //! second.
477 //!
478 //! \return Returns the number of pulses captured in the given time period.
479 //
480 //*****************************************************************************
481 uint32_t
QEIVelocityGet(uint32_t ui32Base)482 QEIVelocityGet(uint32_t ui32Base)
483 {
484 //
485 // Check the arguments.
486 //
487 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
488
489 //
490 // Return the speed capture value.
491 //
492 return(HWREG(ui32Base + QEI_O_SPEED));
493 }
494
495 //*****************************************************************************
496 //
497 //! Returns the quadrature encoder interrupt number.
498 //!
499 //! \param ui32Base is the base address of the selected quadrature encoder
500 //!
501 //! This function returns the interrupt number for the quadrature encoder with
502 //! the base address passed in the \e ui32Base parameter.
503 //!
504 //! \return Returns a quadrature encoder interrupt number or 0 if the interrupt
505 //! does not exist.
506 //
507 //*****************************************************************************
508 static uint32_t
_QEIIntNumberGet(uint32_t ui32Base)509 _QEIIntNumberGet(uint32_t ui32Base)
510 {
511 uint32_t ui32Int;
512
513 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
514
515 //
516 // Find the valid interrupt number for this quadrature encoder.
517 //
518 if(CLASS_IS_TM4C123)
519 {
520 if(ui32Base == QEI0_BASE)
521 {
522 ui32Int = INT_QEI0_TM4C123;
523 }
524 else
525 {
526 ui32Int = INT_QEI1_TM4C123;
527 }
528 }
529 else if(CLASS_IS_TM4C129)
530 {
531 if(ui32Base == QEI0_BASE)
532 {
533 ui32Int = INT_QEI0_TM4C129;
534 }
535 else
536 {
537 ui32Int = 0;
538 }
539 }
540 else
541 {
542 ui32Int = 0;
543 }
544
545 return(ui32Int);
546 }
547
548 //*****************************************************************************
549 //
550 //! Registers an interrupt handler for the quadrature encoder interrupt.
551 //!
552 //! \param ui32Base is the base address of the quadrature encoder module.
553 //! \param pfnHandler is a pointer to the function to be called when the
554 //! quadrature encoder interrupt occurs.
555 //!
556 //! This function registers the handler to be called when a quadrature encoder
557 //! interrupt occurs. This function enables the global interrupt in the
558 //! interrupt controller; specific quadrature encoder interrupts must be
559 //! enabled via QEIIntEnable(). It is the interrupt handler's responsibility
560 //! to clear the interrupt source via QEIIntClear().
561 //!
562 //! \sa IntRegister() for important information about registering interrupt
563 //! handlers.
564 //!
565 //! \return None.
566 //
567 //*****************************************************************************
568 void
QEIIntRegister(uint32_t ui32Base,void (* pfnHandler)(void))569 QEIIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
570 {
571 uint32_t ui32Int;
572
573 //
574 // Check the arguments.
575 //
576 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
577
578 //
579 // Determine the interrupt number based on the QEI module.
580 //
581 ui32Int = _QEIIntNumberGet(ui32Base);
582
583 ASSERT(ui32Int != 0);
584
585 //
586 // Register the interrupt handler, returning an error if an error occurs.
587 //
588 IntRegister(ui32Int, pfnHandler);
589
590 //
591 // Enable the quadrature encoder interrupt.
592 //
593 IntEnable(ui32Int);
594 }
595
596 //*****************************************************************************
597 //
598 //! Unregisters an interrupt handler for the quadrature encoder interrupt.
599 //!
600 //! \param ui32Base is the base address of the quadrature encoder module.
601 //!
602 //! This function unregisters the handler to be called when a quadrature
603 //! encoder interrupt occurs. This function also masks off the interrupt in
604 //! the interrupt controller so that the interrupt handler no longer is called.
605 //!
606 //! \sa IntRegister() for important information about registering interrupt
607 //! handlers.
608 //!
609 //! \return None.
610 //
611 //*****************************************************************************
612 void
QEIIntUnregister(uint32_t ui32Base)613 QEIIntUnregister(uint32_t ui32Base)
614 {
615 uint32_t ui32Int;
616
617 //
618 // Check the arguments.
619 //
620 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
621
622 //
623 // Determine the interrupt number based on the QEI module.
624 //
625 ui32Int = _QEIIntNumberGet(ui32Base);
626
627 ASSERT(ui32Int != 0);
628
629 //
630 // Disable the interrupt.
631 //
632 IntDisable(ui32Int);
633
634 //
635 // Unregister the interrupt handler.
636 //
637 IntUnregister(ui32Int);
638 }
639
640 //*****************************************************************************
641 //
642 //! Enables individual quadrature encoder interrupt sources.
643 //!
644 //! \param ui32Base is the base address of the quadrature encoder module.
645 //! \param ui32IntFlags is a bit mask of the interrupt sources to be enabled.
646 //! Can be any of the \b QEI_INTERROR, \b QEI_INTDIR, \b QEI_INTTIMER, or
647 //! \b QEI_INTINDEX values.
648 //!
649 //! This function enables the indicated quadrature encoder interrupt sources.
650 //! Only the sources that are enabled can be reflected to the processor
651 //! interrupt; disabled sources have no effect on the processor.
652 //!
653 //! \return None.
654 //
655 //*****************************************************************************
656 void
QEIIntEnable(uint32_t ui32Base,uint32_t ui32IntFlags)657 QEIIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
658 {
659 //
660 // Check the arguments.
661 //
662 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
663
664 //
665 // Enable the specified interrupts.
666 //
667 HWREG(ui32Base + QEI_O_INTEN) |= ui32IntFlags;
668 }
669
670 //*****************************************************************************
671 //
672 //! Disables individual quadrature encoder interrupt sources.
673 //!
674 //! \param ui32Base is the base address of the quadrature encoder module.
675 //! \param ui32IntFlags is a bit mask of the interrupt sources to be disabled.
676 //! This parameter can be any of the \b QEI_INTERROR, \b QEI_INTDIR,
677 //! \b QEI_INTTIMER, or \b QEI_INTINDEX values.
678 //!
679 //! This function disables the indicated quadrature encoder interrupt sources.
680 //! Only the sources that are enabled can be reflected to the processor
681 //! interrupt; disabled sources have no effect on the processor.
682 //!
683 //! \return None.
684 //
685 //*****************************************************************************
686 void
QEIIntDisable(uint32_t ui32Base,uint32_t ui32IntFlags)687 QEIIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
688 {
689 //
690 // Check the arguments.
691 //
692 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
693
694 //
695 // Disable the specified interrupts.
696 //
697 HWREG(ui32Base + QEI_O_INTEN) &= ~(ui32IntFlags);
698 }
699
700 //*****************************************************************************
701 //
702 //! Gets the current interrupt status.
703 //!
704 //! \param ui32Base is the base address of the quadrature encoder module.
705 //! \param bMasked is false if the raw interrupt status is required and true if
706 //! the masked interrupt status is required.
707 //!
708 //! This function returns the interrupt status for the quadrature encoder
709 //! module. Either the raw interrupt status or the status of interrupts that
710 //! are allowed to reflect to the processor can be returned.
711 //!
712 //! \return Returns the current interrupt status, enumerated as a bit field of
713 //! \b QEI_INTERROR, \b QEI_INTDIR, \b QEI_INTTIMER, and \b QEI_INTINDEX.
714 //
715 //*****************************************************************************
716 uint32_t
QEIIntStatus(uint32_t ui32Base,bool bMasked)717 QEIIntStatus(uint32_t ui32Base, bool bMasked)
718 {
719 //
720 // Check the arguments.
721 //
722 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
723
724 //
725 // Return either the interrupt status or the raw interrupt status as
726 // requested.
727 //
728 if(bMasked)
729 {
730 return(HWREG(ui32Base + QEI_O_ISC));
731 }
732 else
733 {
734 return(HWREG(ui32Base + QEI_O_RIS));
735 }
736 }
737
738 //*****************************************************************************
739 //
740 //! Clears quadrature encoder interrupt sources.
741 //!
742 //! \param ui32Base is the base address of the quadrature encoder module.
743 //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
744 //! This parameter can be any of the \b QEI_INTERROR, \b QEI_INTDIR,
745 //! \b QEI_INTTIMER, or \b QEI_INTINDEX values.
746 //!
747 //! The specified quadrature encoder interrupt sources are cleared, so that
748 //! they no longer assert. This function must be called in the interrupt
749 //! handler to keep the interrupt from being triggered again immediately upon
750 //! exit.
751 //!
752 //! \note Because there is a write buffer in the Cortex-M processor, it may
753 //! take several clock cycles before the interrupt source is actually cleared.
754 //! Therefore, it is recommended that the interrupt source be cleared early in
755 //! the interrupt handler (as opposed to the very last action) to avoid
756 //! returning from the interrupt handler before the interrupt source is
757 //! actually cleared. Failure to do so may result in the interrupt handler
758 //! being immediately reentered (because the interrupt controller still sees
759 //! the interrupt source asserted).
760 //!
761 //! \return None.
762 //
763 //*****************************************************************************
764 void
QEIIntClear(uint32_t ui32Base,uint32_t ui32IntFlags)765 QEIIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
766 {
767 //
768 // Check the arguments.
769 //
770 ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
771
772 //
773 // Clear the requested interrupt sources.
774 //
775 HWREG(ui32Base + QEI_O_ISC) = ui32IntFlags;
776 }
777
778 //*****************************************************************************
779 //
780 // Close the Doxygen group.
781 //! @}
782 //
783 //*****************************************************************************
784