-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheqep.h
1782 lines (1658 loc) · 58.6 KB
/
eqep.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//###########################################################################
//
// FILE: eqep.h
//
// TITLE: C28x eQEP driver.
//
//###########################################################################
// $TI Release: F28004x Support Library v1.11.00.00 $
// $Release Date: Sun Oct 4 15:49:15 IST 2020 $
// $Copyright:
// Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef EQEP_H
#define EQEP_H
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
//! \addtogroup eqep_api eQEP
//! @{
//
//*****************************************************************************
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/hw_eqep.h"
#include "inc/hw_types.h"
#include "debug.h"
#ifndef DOXYGEN_PDF_IGNORE
//*****************************************************************************
//
// Values that can be passed to EQEP_setDecoderConfig() as the config
// parameter.
//
//*****************************************************************************
//
// Operation Mode
//
#define EQEP_CONFIG_QUADRATURE 0x0000U //!< Quadrature-clock mode
#define EQEP_CONFIG_CLOCK_DIR 0x4000U //!< Direction-count mode
#define EQEP_CONFIG_UP_COUNT 0x8000U //!< Up-count mode, QDIR = 1
#define EQEP_CONFIG_DOWN_COUNT 0xC000U //!< Down-count mode, QDIR = 0
//
// Resolution
//
#define EQEP_CONFIG_2X_RESOLUTION 0x0000U //!< Count rising and falling edge
#define EQEP_CONFIG_1X_RESOLUTION 0x0800U //!< Count rising edge only
//
// Swap QEPA and QEPB
//
#define EQEP_CONFIG_NO_SWAP 0x0000U //!< Do not swap QEPA and QEPB
#define EQEP_CONFIG_SWAP 0x0400U //!< Swap QEPA and QEPB
//*****************************************************************************
//
// Values that can be passed to EQEP_setCompareConfig() as the config
// parameter.
//
//*****************************************************************************
//
// Sync pulse pin
//
#define EQEP_COMPARE_NO_SYNC_OUT 0x0000U //!< Disable sync output
#define EQEP_COMPARE_IDX_SYNC_OUT 0x2000U //!< Sync output on index pin
#define EQEP_COMPARE_STROBE_SYNC_OUT 0x3000U //!< Sync output on strobe pin
//
// Shadow register use
//
#define EQEP_COMPARE_NO_SHADOW 0x0000U //!< Disable shadow of QPOSCMP
#define EQEP_COMPARE_LOAD_ON_ZERO 0x8000U //!< Load on QPOSCNT = 0
#define EQEP_COMPARE_LOAD_ON_MATCH 0xC000U //!< Load on QPOSCNT = QPOSCMP
//*****************************************************************************
//
// Values that can be passed to EQEP_enableInterrupt(),
// EQEP_disableInterrupt(), and EQEP_clearInterruptStatus() as the
// intFlags parameter and returned by EQEP_clearInterruptStatus().
//
//*****************************************************************************
#define EQEP_INT_GLOBAL 0x0001U //!< Global interrupt flag
#define EQEP_INT_POS_CNT_ERROR 0x0002U //!< Position counter error
#define EQEP_INT_PHASE_ERROR 0x0004U //!< Quadrature phase error
#define EQEP_INT_DIR_CHANGE 0x0008U //!< Quadrature direction change
#define EQEP_INT_WATCHDOG 0x0010U //!< Watchdog time-out
#define EQEP_INT_UNDERFLOW 0x0020U //!< Position counter underflow
#define EQEP_INT_OVERFLOW 0x0040U //!< Position counter overflow
#define EQEP_INT_POS_COMP_READY 0x0080U //!< Position-compare ready
#define EQEP_INT_POS_COMP_MATCH 0x0100U //!< Position-compare match
#define EQEP_INT_STROBE_EVNT_LATCH 0x0200U //!< Strobe event latch
#define EQEP_INT_INDEX_EVNT_LATCH 0x0400U //!< Index event latch
#define EQEP_INT_UNIT_TIME_OUT 0x0800U //!< Unit time-out
#define EQEP_INT_QMA_ERROR 0x1000U //!< QMA error
//*****************************************************************************
//
// Values that can be returned by EQEP_getStatus().
//
//*****************************************************************************
//! Unit position event detected
#define EQEP_STS_UNIT_POS_EVNT 0x0080U
//! Direction was clockwise on first index event
#define EQEP_STS_DIR_ON_1ST_IDX 0x0040U
//! Direction is CW (forward)
#define EQEP_STS_DIR_FLAG 0x0020U
//! Direction was CW on index
#define EQEP_STS_DIR_LATCH 0x0010U
//! Capture timer overflow
#define EQEP_STS_CAP_OVRFLW_ERROR 0x0008U
//! Direction changed between position capture events
#define EQEP_STS_CAP_DIR_ERROR 0x0004U
//! First index pulse occurred
#define EQEP_STS_1ST_IDX_FLAG 0x0002U
//! Position counter error
#define EQEP_STS_POS_CNT_ERROR 0x0001U
//*****************************************************************************
//
// Values that can be passed to EQEP_setLatchMode() as the latchMode parameter.
//
//*****************************************************************************
//
// Position counter latch event
//
#define EQEP_LATCH_CNT_READ_BY_CPU 0x0000U //!< On position counter read
#define EQEP_LATCH_UNIT_TIME_OUT 0x0004U //!< On unit time-out event
//
// Strobe position counter latch event
//
//! On rising edge of strobe
#define EQEP_LATCH_RISING_STROBE 0x0000U
//! On rising edge when clockwise, on falling when counter clockwise
#define EQEP_LATCH_EDGE_DIR_STROBE 0x0040U
//
// Index position counter latch event
//
#define EQEP_LATCH_RISING_INDEX 0x0010U //!< On rising edge of index
#define EQEP_LATCH_FALLING_INDEX 0x0020U //!< On falling edge of index
#define EQEP_LATCH_SW_INDEX_MARKER 0x0030U //!< On software index marker
//*****************************************************************************
//
// Values that can be passed to EQEP_setPositionInitMode() as the initMode
// parameter.
//
//*****************************************************************************
#define EQEP_INIT_DO_NOTHING 0x0000U //!< Action is disabled
//
// Strobe events
//
//! On rising edge of strobe
#define EQEP_INIT_RISING_STROBE 0x0800U
//! On rising edge when clockwise, on falling when counter clockwise
#define EQEP_INIT_EDGE_DIR_STROBE 0x0C00U
//
// Index events
//
#define EQEP_INIT_RISING_INDEX 0x0200U //!< On rising edge of index
#define EQEP_INIT_FALLING_INDEX 0x0300U //!< On falling edge of index
#endif
//*****************************************************************************
//
//! Values that can be passed to EQEP_setPositionCounterConfig() as the \e mode
//! parameter.
//
//*****************************************************************************
typedef enum
{
//! Reset position on index pulse
EQEP_POSITION_RESET_IDX = 0x0000,
//! Reset position on maximum position
EQEP_POSITION_RESET_MAX_POS = 0x1000,
//! Reset position on the first index pulse
EQEP_POSITION_RESET_1ST_IDX = 0x2000,
//! Reset position on a unit time event
EQEP_POSITION_RESET_UNIT_TIME_OUT = 0x3000
} EQEP_PositionResetMode;
//*****************************************************************************
//
//! Values that can be passed to EQEP_setCaptureConfig() as the \e capPrescale
//! parameter. CAPCLK is the capture timer clock frequency.
//
//*****************************************************************************
typedef enum
{
EQEP_CAPTURE_CLK_DIV_1 = 0x00, //!< CAPCLK = SYSCLKOUT/1
EQEP_CAPTURE_CLK_DIV_2 = 0x10, //!< CAPCLK = SYSCLKOUT/2
EQEP_CAPTURE_CLK_DIV_4 = 0x20, //!< CAPCLK = SYSCLKOUT/4
EQEP_CAPTURE_CLK_DIV_8 = 0x30, //!< CAPCLK = SYSCLKOUT/8
EQEP_CAPTURE_CLK_DIV_16 = 0x40, //!< CAPCLK = SYSCLKOUT/16
EQEP_CAPTURE_CLK_DIV_32 = 0x50, //!< CAPCLK = SYSCLKOUT/32
EQEP_CAPTURE_CLK_DIV_64 = 0x60, //!< CAPCLK = SYSCLKOUT/64
EQEP_CAPTURE_CLK_DIV_128 = 0x70 //!< CAPCLK = SYSCLKOUT/128
} EQEP_CAPCLKPrescale;
//*****************************************************************************
//
//! Values that can be passed to EQEP_setCaptureConfig() as the \e evntPrescale
//! parameter. UPEVNT is the unit position event frequency.
//
//*****************************************************************************
typedef enum
{
EQEP_UNIT_POS_EVNT_DIV_1, //!< UPEVNT = QCLK/1
EQEP_UNIT_POS_EVNT_DIV_2, //!< UPEVNT = QCLK/2
EQEP_UNIT_POS_EVNT_DIV_4, //!< UPEVNT = QCLK/4
EQEP_UNIT_POS_EVNT_DIV_8, //!< UPEVNT = QCLK/8
EQEP_UNIT_POS_EVNT_DIV_16, //!< UPEVNT = QCLK/16
EQEP_UNIT_POS_EVNT_DIV_32, //!< UPEVNT = QCLK/32
EQEP_UNIT_POS_EVNT_DIV_64, //!< UPEVNT = QCLK/64
EQEP_UNIT_POS_EVNT_DIV_128, //!< UPEVNT = QCLK/128
EQEP_UNIT_POS_EVNT_DIV_256, //!< UPEVNT = QCLK/256
EQEP_UNIT_POS_EVNT_DIV_512, //!< UPEVNT = QCLK/512
EQEP_UNIT_POS_EVNT_DIV_1024, //!< UPEVNT = QCLK/1024
EQEP_UNIT_POS_EVNT_DIV_2048 //!< UPEVNT = QCLK/2048
} EQEP_UPEVNTPrescale;
//*****************************************************************************
//
//! Values that can be passed to EQEP_setStrobeSource() as the \e strobeSrc
//! parameter.
//
//*****************************************************************************
typedef enum
{
EQEP_STROBE_FROM_GPIO = 0, //!< Strobe signal comes from GPIO
EQEP_STROBE_OR_ADCSOCA = 2, //!< Strobe signal is OR'd with ADCSOCA
EQEP_STROBE_OR_ADCSOCB = 3 //!< Strobe signal is OR'd with ADCSOCB
} EQEP_StrobeSource;
//*****************************************************************************
//
//! Values that can be passed to EQEP_setQMAModuleMode() as the \e qmaMode
//! parameter.
//
//*****************************************************************************
typedef enum
{
EQEP_QMA_MODE_BYPASS, //!< QMA module is bypassed
EQEP_QMA_MODE_1, //!< QMA mode-1 operation is selected
EQEP_QMA_MODE_2 //!< QMA mode-2 operation is selected
} EQEP_QMAMode;
//*****************************************************************************
//
//! Values that can be passed to EQEP_setEmulationMode() as the \e emuMode
//! parameter.
//
//*****************************************************************************
typedef enum
{
EQEP_EMULATIONMODE_STOPIMMEDIATELY, //!< Counters stop immediately
EQEP_EMULATIONMODE_STOPATROLLOVER, //!< Counters stop at period rollover
EQEP_EMULATIONMODE_RUNFREE //!< Counter unaffected by suspend
}EQEP_EmulationMode;
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \internal
//! Checks an eQEP base address.
//!
//! \param base specifies the eQEP module base address.
//!
//! This function determines if a eQEP module base address is valid.
//!
//! \return Returns \b true if the base address is valid and \b false
//! otherwise.
//
//*****************************************************************************
#ifdef DEBUG
static inline bool
EQEP_isBaseValid(uint32_t base)
{
return(
(base == EQEP1_BASE) ||
(base == EQEP2_BASE)
);
}
#endif
//*****************************************************************************
//
//! Enables the eQEP module.
//!
//! \param base is the base address of the eQEP module.
//!
//! This function enables operation of the enhanced quadrature encoder pulse
//! (eQEP) module. The module must be configured before it is enabled.
//!
//! \sa EQEP_setConfig()
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_enableModule(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Enable the eQEP module.
//
HWREGH(base + EQEP_O_QEPCTL) |= EQEP_QEPCTL_QPEN;
}
//*****************************************************************************
//
//! Disables the eQEP module.
//!
//! \param base is the base address of the enhanced quadrature encoder pulse
//! (eQEP) module
//!
//! This function disables operation of the eQEP module.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_disableModule(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Disable the eQEP module.
//
HWREGH(base + EQEP_O_QEPCTL) &= ~(EQEP_QEPCTL_QPEN);
}
//*****************************************************************************
//
//! Configures eQEP module's quadrature decoder unit.
//!
//! \param base is the base address of the eQEP module.
//! \param config is the configuration for the eQEP module decoder unit.
//!
//! This function configures the operation of the eQEP module's quadrature
//! decoder unit. The \e config parameter provides the configuration
//! of the decoder and is the logical OR of several values:
//!
//! - \b EQEP_CONFIG_2X_RESOLUTION or \b EQEP_CONFIG_1X_RESOLUTION specify
//! if both rising and falling edges should be counted or just rising edges.
//! - \b EQEP_CONFIG_QUADRATURE, \b EQEP_CONFIG_CLOCK_DIR,
//! \b EQEP_CONFIG_UP_COUNT, or \b EQEP_CONFIG_DOWN_COUNT specify if
//! quadrature signals are being provided on QEPA and QEPB, if a direction
//! signal and a clock are being provided, or if the direction should be
//! hard-wired for a single direction with QEPA used for input.
//! - \b EQEP_CONFIG_NO_SWAP or \b EQEP_CONFIG_SWAP to specify if the
//! signals provided on QEPA and QEPB should be swapped before being
//! processed.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_setDecoderConfig(uint32_t base, uint16_t config)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Write the new decoder configuration to the hardware.
//
HWREGH(base + EQEP_O_QDECCTL) = (HWREGH(base + EQEP_O_QDECCTL) &
~(EQEP_QDECCTL_SWAP |
EQEP_QDECCTL_XCR |
EQEP_QDECCTL_QSRC_M)) | config;
}
//*****************************************************************************
//
//! Configures eQEP module position counter unit.
//!
//! \param base is the base address of the eQEP module.
//! \param mode is the configuration for the eQEP module position counter.
//! \param maxPosition specifies the maximum position value.
//!
//! This function configures the operation of the eQEP module position
//! counter. The \e mode parameter determines the event on which the position
//! counter gets reset. It should be passed one of the following values:
//! \b EQEP_POSITION_RESET_IDX, \b EQEP_POSITION_RESET_MAX_POS,
//! \b EQEP_POSITION_RESET_1ST_IDX, or \b EQEP_POSITION_RESET_UNIT_TIME_OUT.
//!
//! \e maxPosition is the maximum value of the position counter and is
//! the value used to reset the position capture when moving in the reverse
//! (negative) direction.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_setPositionCounterConfig(uint32_t base, EQEP_PositionResetMode mode,
uint32_t maxPosition)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Write the position counter reset configuration to the hardware.
//
HWREGH(base + EQEP_O_QEPCTL) = (HWREGH(base + EQEP_O_QEPCTL) &
~EQEP_QEPCTL_PCRM_M) | (uint16_t)mode;
//
// Set the maximum position.
//
HWREG(base + EQEP_O_QPOSMAX) = maxPosition;
}
//*****************************************************************************
//
//! Gets the current encoder position.
//!
//! \param base is the base address of the eQEP module.
//!
//! This function returns the current position of the encoder. Depending upon
//! the configuration of the encoder, and the incident of an index pulse, this
//! value may or may not contain the expected data (that is, if in reset on
//! index mode, if an index pulse has not been encountered, the position
//! counter is not yet aligned with the index pulse).
//!
//! \return The current position of the encoder.
//
//*****************************************************************************
static inline uint32_t
EQEP_getPosition(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Return the current position counter.
//
return(HWREG(base + EQEP_O_QPOSCNT));
}
//*****************************************************************************
//
//! Sets the current encoder position.
//!
//! \param base is the base address of the eQEP module.
//! \param position is the new position for the encoder.
//!
//! This function sets the current position of the encoder; the encoder
//! position is then measured relative to this value.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_setPosition(uint32_t base, uint32_t position)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Set the position counter.
//
HWREG(base + EQEP_O_QPOSCNT) = position;
}
//*****************************************************************************
//
//! Gets the current direction of rotation.
//!
//! \param base is the base address of the eQEP module.
//!
//! This function returns the current direction of rotation. In this case,
//! current means the most recently detected direction of the encoder; it may
//! not be presently moving but this is the direction it last moved before it
//! stopped.
//!
//! \return Returns 1 if moving in the forward direction or -1 if moving in the
//! reverse direction.
//
//*****************************************************************************
static inline int16_t
EQEP_getDirection(uint32_t base)
{
int16_t direction;
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Return the direction of rotation.
//
if((HWREGH(base + EQEP_O_QEPSTS) & EQEP_QEPSTS_QDF) != 0U)
{
direction = 1;
}
else
{
direction = -1;
}
return(direction);
}
//*****************************************************************************
//
//! Enables individual eQEP module interrupt sources.
//!
//! \param base is the base address of the eQEP module.
//! \param intFlags is a bit mask of the interrupt sources to be enabled.
//!
//! This function enables eQEP module interrupt sources. The \e intFlags
//! parameter can be any of the following values OR'd together:
//! - \b EQEP_INT_POS_CNT_ERROR - Position counter error
//! - \b EQEP_INT_PHASE_ERROR - Quadrature phase error
//! - \b EQEP_INT_DIR_CHANGE - Quadrature direction change
//! - \b EQEP_INT_WATCHDOG - Watchdog time-out
//! - \b EQEP_INT_UNDERFLOW - Position counter underflow
//! - \b EQEP_INT_OVERFLOW - Position counter overflow
//! - \b EQEP_INT_POS_COMP_READY - Position-compare ready
//! - \b EQEP_INT_POS_COMP_MATCH - Position-compare match
//! - \b EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch
//! - \b EQEP_INT_INDEX_EVNT_LATCH - Index event latch
//! - \b EQEP_INT_UNIT_TIME_OUT - Unit time-out
//! - \b EQEP_INT_QMA_ERROR - QMA error
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_enableInterrupt(uint32_t base, uint16_t intFlags)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Enable the specified interrupts.
//
HWREGH(base + EQEP_O_QEINT) |= intFlags;
}
//*****************************************************************************
//
//! Disables individual eQEP module interrupt sources.
//!
//! \param base is the base address of the eQEP module.
//! \param intFlags is a bit mask of the interrupt sources to be disabled.
//!
//! This function disables eQEP module interrupt sources. The \e intFlags
//! parameter can be any of the following values OR'd together:
//! - \b EQEP_INT_POS_CNT_ERROR - Position counter error
//! - \b EQEP_INT_PHASE_ERROR - Quadrature phase error
//! - \b EQEP_INT_DIR_CHANGE - Quadrature direction change
//! - \b EQEP_INT_WATCHDOG - Watchdog time-out
//! - \b EQEP_INT_UNDERFLOW - Position counter underflow
//! - \b EQEP_INT_OVERFLOW - Position counter overflow
//! - \b EQEP_INT_POS_COMP_READY - Position-compare ready
//! - \b EQEP_INT_POS_COMP_MATCH - Position-compare match
//! - \b EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch
//! - \b EQEP_INT_INDEX_EVNT_LATCH - Index event latch
//! - \b EQEP_INT_UNIT_TIME_OUT - Unit time-out
//! - \b EQEP_INT_QMA_ERROR - QMA error
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_disableInterrupt(uint32_t base, uint16_t intFlags)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Disable the specified interrupts.
//
HWREGH(base + EQEP_O_QEINT) &= ~(intFlags);
}
//*****************************************************************************
//
//! Gets the current interrupt status.
//!
//! \param base is the base address of the eQEP module.
//!
//! This function returns the interrupt status for the eQEP module
//! module.
//!
//! \return Returns the current interrupt status, enumerated as a bit field of
//! the following values:
//! - \b EQEP_INT_GLOBAL - Global interrupt flag
//! - \b EQEP_INT_POS_CNT_ERROR - Position counter error
//! - \b EQEP_INT_PHASE_ERROR - Quadrature phase error
//! - \b EQEP_INT_DIR_CHANGE - Quadrature direction change
//! - \b EQEP_INT_WATCHDOG - Watchdog time-out
//! - \b EQEP_INT_UNDERFLOW - Position counter underflow
//! - \b EQEP_INT_OVERFLOW - Position counter overflow
//! - \b EQEP_INT_POS_COMP_READY - Position-compare ready
//! - \b EQEP_INT_POS_COMP_MATCH - Position-compare match
//! - \b EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch
//! - \b EQEP_INT_INDEX_EVNT_LATCH - Index event latch
//! - \b EQEP_INT_UNIT_TIME_OUT - Unit time-out
//! - \b EQEP_INT_QMA_ERROR - QMA error
//
//*****************************************************************************
static inline uint16_t
EQEP_getInterruptStatus(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
return(HWREGH(base + EQEP_O_QFLG));
}
//*****************************************************************************
//
//! Clears eQEP module interrupt sources.
//!
//! \param base is the base address of the eQEP module.
//! \param intFlags is a bit mask of the interrupt sources to be cleared.
//!
//! This function clears eQEP module interrupt flags. The \e intFlags
//! parameter can be any of the following values OR'd together:
//! - \b EQEP_INT_GLOBAL - Global interrupt flag
//! - \b EQEP_INT_POS_CNT_ERROR - Position counter error
//! - \b EQEP_INT_PHASE_ERROR - Quadrature phase error
//! - \b EQEP_INT_DIR_CHANGE - Quadrature direction change
//! - \b EQEP_INT_WATCHDOG - Watchdog time-out
//! - \b EQEP_INT_UNDERFLOW - Position counter underflow
//! - \b EQEP_INT_OVERFLOW - Position counter overflow
//! - \b EQEP_INT_POS_COMP_READY - Position-compare ready
//! - \b EQEP_INT_POS_COMP_MATCH - Position-compare match
//! - \b EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch
//! - \b EQEP_INT_INDEX_EVNT_LATCH - Index event latch
//! - \b EQEP_INT_UNIT_TIME_OUT - Unit time-out
//! - \b EQEP_INT_QMA_ERROR - QMA error
//!
//! Note that the \b EQEP_INT_GLOBAL value is the global interrupt flag. In
//! order to get any further eQEP interrupts, this flag must be cleared.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_clearInterruptStatus(uint32_t base, uint16_t intFlags)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Clear the requested interrupt sources.
//
HWREGH(base + EQEP_O_QCLR) = intFlags;
}
//*****************************************************************************
//
//! Forces individual eQEP module interrupts.
//!
//! \param base is the base address of the eQEP module.
//! \param intFlags is a bit mask of the interrupt sources to be forced.
//!
//! This function forces eQEP module interrupt flags. The \e intFlags
//! parameter can be any of the following values OR'd together:
//! - \b EQEP_INT_POS_CNT_ERROR
//! - \b EQEP_INT_PHASE_ERROR
//! - \b EQEP_INT_DIR_CHANGE
//! - \b EQEP_INT_WATCHDOG
//! - \b EQEP_INT_UNDERFLOW
//! - \b EQEP_INT_OVERFLOW
//! - \b EQEP_INT_POS_COMP_READY
//! - \b EQEP_INT_POS_COMP_MATCH
//! - \b EQEP_INT_STROBE_EVNT_LATCH
//! - \b EQEP_INT_INDEX_EVNT_LATCH
//! - \b EQEP_INT_UNIT_TIME_OUT
//! - \b EQEP_INT_QMA_ERROR
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_forceInterrupt(uint32_t base, uint16_t intFlags)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Force the specified interrupts.
//
HWREGH(base + EQEP_O_QFRC) |= intFlags;
}
//*****************************************************************************
//
//! Gets the encoder error indicator.
//!
//! \param base is the base address of the eQEP module.
//!
//! This function returns the error indicator for the eQEP module. It is an
//! error for both of the signals of the quadrature input to change at the same
//! time.
//!
//! \return Returns \b true if an error has occurred and \b false otherwise.
//
//*****************************************************************************
static inline bool
EQEP_getError(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Return the error indicator.
//
return((HWREGH(base + EQEP_O_QFLG) & EQEP_QFLG_PHE) != 0U);
}
//*****************************************************************************
//
//! Returns content of the eQEP module status register
//!
//! \param base is the base address of the eQEP module.
//!
//! This function returns the contents of the status register. The value it
//! returns is an OR of the following values:
//!
//! - \b EQEP_STS_UNIT_POS_EVNT - Unit position event detected
//! - \b EQEP_STS_DIR_ON_1ST_IDX - If set, clockwise rotation (forward
//! movement) occurred on the first index event
//! - \b EQEP_STS_DIR_FLAG - If set, movement is clockwise rotation
//! - \b EQEP_STS_DIR_LATCH - If set, clockwise rotation occurred on last
//! index event marker
//! - \b EQEP_STS_CAP_OVRFLW_ERROR - Overflow occurred in eQEP capture timer
//! - \b EQEP_STS_CAP_DIR_ERROR - Direction change occurred between position
//! capture events
//! - \b EQEP_STS_1ST_IDX_FLAG - Set by the occurrence of the first index
//! pulse
//! - \b EQEP_STS_POS_CNT_ERROR - Position counter error occurred
//!
//! \return Returns the value of the QEP status register.
//
//*****************************************************************************
static inline uint16_t
EQEP_getStatus(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Return the status register.
//
return(HWREGH(base + EQEP_O_QEPSTS) & 0x00FFU);
}
//*****************************************************************************
//
//! Clears selected fields of the eQEP module status register
//!
//! \param base is the base address of the eQEP module.
//! \param statusFlags is the bit mask of the status flags to be cleared.
//!
//! This function clears the status register fields indicated by
//! \e statusFlags. The \e statusFlags parameter is the logical OR of any of
//! the following:
//!
//! - \b EQEP_STS_UNIT_POS_EVNT - Unit position event detected
//! - \b EQEP_STS_CAP_OVRFLW_ERROR - Overflow occurred in eQEP capture timer
//! - \b EQEP_STS_CAP_DIR_ERROR - Direction change occurred between position
//! capture events
//! - \b EQEP_STS_1ST_IDX_FLAG - Set by the occurrence of the first index
//! pulse
//!
//! \note Only the above status fields can be cleared. All others are
//! read-only, non-sticky fields.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_clearStatus(uint32_t base, uint16_t statusFlags)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Clear the requested interrupt sources.
//
HWREGH(base + EQEP_O_QEPSTS) = statusFlags;
}
//*****************************************************************************
//
//! Configures eQEP module edge-capture unit.
//!
//! \param base is the base address of the eQEP module.
//! \param capPrescale is the prescaler setting of the eQEP capture timer clk.
//! \param evntPrescale is the prescaler setting of the unit position event
//! frequency.
//!
//! This function configures the operation of the eQEP module edge-capture
//! unit. The \e capPrescale parameter provides the configuration of the eQEP
//! capture timer clock rate. It determines by which power of 2 between 1 and
//! 128 inclusive SYSCLKOUT is divided. The macros for this parameter are in
//! the format of EQEP_CAPTURE_CLK_DIV_X, where X is the divide value. For
//! example, \b EQEP_CAPTURE_CLK_DIV_32 will give a capture timer clock
//! frequency that is SYSCLKOUT/32.
//!
//! The \e evntPrescale parameter determines how frequently a unit position
//! event occurs. The macro that can be passed this parameter is in the format
//! EQEP_UNIT_POS_EVNT_DIV_X, where X is the number of quadrature clock
//! periods between unit position events. For example,
//! \b EQEP_UNIT_POS_EVNT_DIV_16 will result in a unit position event
//! frequency of QCLK/16.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_setCaptureConfig(uint32_t base, EQEP_CAPCLKPrescale capPrescale,
EQEP_UPEVNTPrescale evntPrescale)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Write new prescaler configurations to the appropriate registers.
//
HWREGH(base + EQEP_O_QCAPCTL) =
(HWREGH(base + EQEP_O_QCAPCTL) &
~(EQEP_QCAPCTL_UPPS_M | EQEP_QCAPCTL_CCPS_M)) |
((uint16_t)evntPrescale | (uint16_t)capPrescale);
}
//*****************************************************************************
//
//! Enables the eQEP module edge-capture unit.
//!
//! \param base is the base address of the eQEP module.
//!
//! This function enables operation of the eQEP module's edge-capture unit.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_enableCapture(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Enable edge capture.
//
HWREGH(base + EQEP_O_QCAPCTL) |= EQEP_QCAPCTL_CEN;
}
//*****************************************************************************
//
//! Disables the eQEP module edge-capture unit.
//!
//! \param base is the base address of the eQEP module.
//!
//! This function disables operation of the eQEP module's edge-capture unit.
//!
//! \return None.
//
//*****************************************************************************
static inline void
EQEP_disableCapture(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Disable edge capture.
//
HWREGH(base + EQEP_O_QCAPCTL) &= ~(EQEP_QCAPCTL_CEN);
}
//*****************************************************************************
//
//! Gets the encoder capture period.
//!
//! \param base is the base address of the eQEP module.
//!
//! This function returns the period count value between the last successive
//! eQEP position events.
//!
//! \return The period count value between the last successive position events.
//
//*****************************************************************************
static inline uint16_t
EQEP_getCapturePeriod(uint32_t base)
{
//
// Check the arguments.
//
ASSERT(EQEP_isBaseValid(base));
//
// Return the capture period.
//
return(HWREGH(base + EQEP_O_QCPRD));
}
//*****************************************************************************
//
//! Gets the encoder capture timer value.