50 #include "sw/modules/math/src/32b/math.h"
51 #include "sw/modules/types/src/types.h"
69 #define QEP1_BASE_ADDR (0x00006B00)
71 #define QEP2_BASE_ADDR (0x00006B40)
74 #define QEP_QDECCTL_QSRC (3 << 14)
75 #define QEP_QDECCTL_SOEN (1 << 13)
76 #define QEP_QDECCTL_SPSEL (1 << 12)
77 #define QEP_QDECCTL_XCR (1 << 11)
78 #define QEP_QDECCTL_SWAP (1 << 10)
79 #define QEP_QDECCTL_IGATE (1 << 9)
80 #define QEP_QDECCTL_QAP (1 << 8)
81 #define QEP_QDECCTL_QBP (1 << 7)
82 #define QEP_QDECCTL_QIP (1 << 6)
83 #define QEP_QDECCTL_QSP (1 << 5)
86 #define QEP_QEPCTL_FREESOFT ( 3 << 14)
87 #define QEP_QEPCTL_PCRM ( 3 << 12)
88 #define QEP_QEPCTL_SEI ( 3 << 10)
89 #define QEP_QEPCTL_IEI ( 3 << 8)
90 #define QEP_QEPCTL_SWI ( 1 << 7)
91 #define QEP_QEPCTL_SEL ( 1 << 6)
92 #define QEP_QEPCTL_IEL ( 3 << 4)
93 #define QEP_QEPCTL_QPEN ( 1 << 3)
94 #define QEP_QEPCTL_QCLM ( 1 << 2)
95 #define QEP_QEPCTL_UTE ( 1 << 1)
96 #define QEP_QEPCTL_WDE ( 1 << 0)
99 #define QEP_QPOSCTL_PCSHDW ( 1 << 15)
100 #define QEP_QPOSCTL_PCLOAD ( 1 << 14)
101 #define QEP_QPOSCTL_PCPOL ( 1 << 13)
102 #define QEP_QPOSCTL_PCE ( 1 << 12)
103 #define QEP_QPOSCTL_PCSPW (4095 << 0)
106 #define QEP_QCAPCTL_CEN ( 1 << 15)
107 #define QEP_QCAPCTL_CCPS ( 7 << 4)
108 #define QEP_QCAPCTL_UPPS ( 15 << 0)
111 #define QEP_QEINT_UTO ( 1 << 11)
112 #define QEP_QEINT_IEL ( 1 << 10)
113 #define QEP_QEINT_SEL ( 1 << 9)
114 #define QEP_QEINT_PCM ( 1 << 8)
115 #define QEP_QEINT_PCR ( 1 << 7)
116 #define QEP_QEINT_PCO ( 1 << 6)
117 #define QEP_QEINT_PCU ( 1 << 5)
118 #define QEP_QEINT_WTO ( 1 << 4)
119 #define QEP_QEINT_QDC ( 1 << 3)
120 #define QEP_QEINT_QPE ( 1 << 2)
121 #define QEP_QEINT_PCE ( 1 << 1)
124 #define QEP_QFLG_UTO ( 1 << 11)
125 #define QEP_QFLG_IEL ( 1 << 10)
126 #define QEP_QFLG_SEL ( 1 << 9)
127 #define QEP_QFLG_PCM ( 1 << 8)
128 #define QEP_QFLG_PCR ( 1 << 7)
129 #define QEP_QFLG_PCO ( 1 << 6)
130 #define QEP_QFLG_PCU ( 1 << 5)
131 #define QEP_QFLG_WTO ( 1 << 4)
132 #define QEP_QFLG_QDC ( 1 << 3)
133 #define QEP_QFLG_QPE ( 1 << 2)
134 #define QEP_QFLG_PCE ( 1 << 1)
137 #define QEP_QCLR_UTO ( 1 << 11)
138 #define QEP_QCLR_IEL ( 1 << 10)
139 #define QEP_QCLR_SEL ( 1 << 9)
140 #define QEP_QCLR_PCM ( 1 << 8)
141 #define QEP_QCLR_PCR ( 1 << 7)
142 #define QEP_QCLR_PCO ( 1 << 6)
143 #define QEP_QCLR_PCU ( 1 << 5)
144 #define QEP_QCLR_WTO ( 1 << 4)
145 #define QEP_QCLR_QDC ( 1 << 3)
146 #define QEP_QCLR_QPE ( 1 << 2)
147 #define QEP_QCLR_PCE ( 1 << 1)
150 #define QEP_QFRC_UTO ( 1 << 11)
151 #define QEP_QFRC_IEL ( 1 << 10)
152 #define QEP_QFRC_SEL ( 1 << 9)
153 #define QEP_QFRC_PCM ( 1 << 8)
154 #define QEP_QFRC_PCR ( 1 << 7)
155 #define QEP_QFRC_PCO ( 1 << 6)
156 #define QEP_QFRC_PCU ( 1 << 5)
157 #define QEP_QFRC_WTO ( 1 << 4)
158 #define QEP_QFRC_QDC ( 1 << 3)
159 #define QEP_QFRC_QPE ( 1 << 2)
160 #define QEP_QFRC_PCE ( 1 << 1)
163 #define QEP_QEPSTS_UPEVNT ( 1 << 7)
164 #define QEP_QEPSTS_FDF ( 1 << 6)
165 #define QEP_QEPSTS_QDF ( 1 << 5)
166 #define QEP_QEPSTS_QDLF ( 1 << 4)
167 #define QEP_QEPSTS_COEF ( 1 << 3)
168 #define QEP_QEPSTS_CDEF ( 1 << 2)
169 #define QEP_QEPSTS_FIMF ( 1 << 1)
170 #define QEP_QEPSTS_PCEF ( 1 << 0)
522 qep->
QEINT &= (~QEINT);
698 extern QEP_Handle
QEP_init(
void *pMemory,
const size_t numBytes);
822 qep->
QEPCTL |= QEPCTL_Qclm;
858 qep->
QEPCTL |= QEPCTL_Freesoft;
884 qep->
QEPCTL |= QEPCTL_Iei;
897 qep->
QEPCTL |= QEPCTL_Iel;
933 uint16_t pulse_width_masked;
935 pulse_width_masked = pulse_width & 4095;
937 qep->
QPOSCTL |= pulse_width_masked;
950 qep->
QPOSCTL |= QPOSCTL_Pcload;
963 qep->
QEPCTL |= QEPCTL_Pcrm;
1001 qep->
QEPCTL |= QEPCTL_Swi;
1014 qep->
QEPCTL |= QEPCTL_Sei;
1027 qep->
QEPCTL |= QEPCTL_Sel;
1066 qep->
QPOSCTL |= QPOSCTL_Pcpol;
1078 qep->
QUPRD = unit_period;
1103 qep->
QWDPRD = watchdog_period;
1157 qep->
QEPCTL |= QEPCTL_Sel;
1177 #endif // extern "C"
1180 #endif // end of _QEP_H_ definition
#define QEP_QPOSCTL_PCE
position compare enable/disable
Position counter latched on rising edge of QEPS strobe (QPOSSLAT = POSCCNT)
void QEP_set_select_sync_pin(QEP_Handle qepHandle, const QEP_Spsel_e QEP_SPsel)
Selects whether index or strobe pin is used for sync output.
void QEP_disable_watchdog(QEP_Handle qepHandle)
Disable watchdog timer.
uint16_t QFLG
QEP Interrupt Flag Register.
direction on the first index marker
#define QEP_QDECCTL_SPSEL
sync output pin selection
QEP_Spsel_e
Sync output pin selection.
void QEP_set_emu_control(QEP_Handle qepHandle, const QEPCTL_Freesoft_e QEPCTL_Freesoft)
Sets emulation control.
position compare underflow interrupt enable
2x resolution: count the rising/falling edge
void QEP_set_watchdog_period(QEP_Handle qepHandle, const uint16_t watchdog_period)
Sets watchdog period.
void QEP_disable_gate_index(QEP_Handle qepHandle)
Disable gating of index pulse.
void QEP_enable_watchdog(QEP_Handle qepHandle)
Enable watchdog timer.
void QEP_set_index_polarity(QEP_Handle qepHandle, const QEP_Qip_e QEP_Qip)
Sets index polarity.
#define QEP_QPOSCTL_PCLOAD
position compare shadow load mode
uint16_t QEP_read_status(QEP_Handle qepHandle)
Reads status register.
uint32_t QEP_read_posn_strobe_latch(QEP_Handle qepHandle)
Reads position strobe latch.
uint32_t QUPRD
QEP Unit Period.
uint16_t QEP_read_interrupt_flag(QEP_Handle qepHandle, const QEINT_e QEINT)
Reads interrupt flag value.
quadrature direction change interrupt enable
QEPCTL_Freesoft_e
Emulation control bits.
position counter reset on max position
position, watchdog, unit timer continues until rollover, capture counts until next unit period event ...
QEP_qepsts_e
QEP status bits.
void QEP_write_posn_compare(QEP_Handle qepHandle, const uint32_t posn)
Writes a value to the position compare register.
void QEP_set_posn_compare_shadow_load(QEP_Handle qepHandle, const QPOSCTL_Pcload_e QPOSCTL_Pcload)
Sets position compare shadow load mode.
QEPCTL_Sei_e
Strobe event initialization of position counter.
#define QEP_QDECCTL_QSP
QEPS input polarity.
1x resolution: count the rising edge only
void QEP_set_soft_init(QEP_Handle qepHandle, const QEPCTL_Swi_e QEPCTL_Swi)
Determines if software initialization of position counter enabled.
uint16_t QCAPCTL
QEP Capture Control.
position compare match interrupt enable
uint16_t QCPRDLAT
QEP Capture Period Latch.
initializes on rising edge of QEPS signal
uint32_t QEP_read_posn_latch(QEP_Handle qepHandle)
Reads position counter value.
void QEP_reset_status(QEP_Handle qepHandle, const QEP_qepsts_e qepsts)
Resets the individual QEP status register bits.
QEP_Qsrc_e
QEP counting mode.
uint32_t QPOSLAT
QEP Position Latch.
position compare overflow interrupt enable
void QEP_set_unit_period(QEP_Handle qepHandle, const uint32_t unit_period)
Sets unit timer period.
#define QEP_QEPCTL_SEI
strobe event initialization of position counter
quadrature direction flag
void QEP_set_strobe_event_latch(QEP_Handle qepHandle, const QEPCTL_Sel_e QEPCTL_Sel)
Sets up strobe latch of position counter.
#define QEP_QDECCTL_XCR
external clock rate
#define QEP_QDECCTL_QBP
QEPB input polarity.
QPOSCTL_Pcload_e
Position compare shadow load mode.
position counter reset on unit time event
struct _QEP_Obj_ * QEP_Handle
Defines the QEP handle.
capture direction error flag
position, watchdog, unit timer, capture timer unaffected by emu suspend
#define QEP_QCAPCTL_CEN
enable QEP capture
void QEP_setup_strobe_event_latch(QEP_Handle qepHandle, const QEPCTL_Sel_e QEPCTL_Sel)
QEP strobe latch event.
void QEP_set_capture_prescale(QEP_Handle qepHandle, const QCAPCTL_Ccps_e QCAPCTL_Ccps)
Sets capture pre-scaler.
#define QEP_QEPCTL_SEL
strobe event latch of position counter
uint16_t QEPCTL
QEP Control.
QEPCTL_Pcrm_e
Position counter reset mode.
QEP_Qap_e
Channel A polarity.
#define QEP_QDECCTL_IGATE
index pulse gating option
QPOSCTL_Pcpol_e
Polarity of sync output.
#define QEP_QEPCTL_IEI
index event initialization of position counter
void QEP_disable_capture(QEP_Handle qepHandle)
Disable capture.
#define QEP_QEPCTL_WDE
watchdog timer enable
void QEP_set_posn_compare_pulse_width(QEP_Handle qepHandle, const uint16_t pulse_width)
Sets output pulse width when a match occur.
void QEP_set_unit_posn_prescale(QEP_Handle qepHandle, const QCAPCTL_Upps_e QCAPCTL_Upps)
Sets unit timer prescaling.
void QEP_set_ext_clock_rate(QEP_Handle qepHandle, const QEP_Xcr_e QEP_Xcr)
Sets external clock rate.
void QEP_set_swap_quad_inputs(QEP_Handle qepHandle, QEP_Swap_e QEP_Swap)
Sets up swapping of A/B channels.
#define QEP_QEPCTL_QPEN
quad position counter enable/software reset
QEINT_e
QEP interrupt enable flags.
#define QEP_QEPCTL_IEL
index event latch of position counter (software index marker)
void QEP_disable_interrupt(QEP_Handle qepHandle, const QEINT_e QEINT)
Disable individual interrupt.
struct _QEP_Obj_ QEP_Obj
Defines the QEP object.
uint16_t QCTMRLAT
QEP Capture Timer Latch.
#define QEP_QPOSCTL_PCSHDW
position compare shadow enable
#define QEP_QPOSCTL_PCPOL
load when QPOSCNT = QPOSCMP
void QEP_disable_sync_out(QEP_Handle qepHandle)
Disable output sync pulse.
load when qposcnt = qposcmp
capture overflow error flag
QEPCTL_Iei_e
Index event initialization of position counter.
#define QEP_QDECCTL_QIP
QEPI input polarity.
init position counter (QPOSCNT=QPOSINIT)
uint32_t QEP_read_posn_count(QEP_Handle qepHandle)
Reads position counter.
uint16_t QEPSTS
QEP Status Register.
#define QEP_QDECCTL_SOEN
sync output enable
index pin for sync output
void QEP_set_synch_output_compare_polarity(QEP_Handle qepHandle, const QPOSCTL_Pcpol_e QPOSCTL_Pcpol)
Sets synch output compare polarity.
position counter error flag
void QEP_enable_capture(QEP_Handle qepHandle)
Enable capture.
uint16_t QDECCTL
QEP Decoder Control.
#define QEP_QCAPCTL_CCPS
qep capture timer clock prescaler
uint16_t QWDPRD
QEP Watchdog Period.
void QEP_enable_counter(QEP_Handle qepHandle)
Enable counter.
strobe event latch interrupt enable
#define QEP_QDECCTL_QSRC
position counter source selection
void QEP_set_max_posn_count(QEP_Handle qepHandle, const uint32_t max_count)
Sets max position count.
void QEP_enable_sync_out(QEP_Handle qepHandle)
Enable output sync pulse.
#define QEP_QEPCTL_QCLM
QEP capture latch mode.
disable gating of index pulse
uint16_t QEP_read_capture_period_latch(QEP_Handle qepHandle)
Reads capture period latch.
shadow disabled, load immediate
QEPCTL_Iel_e
Index event latch of position counter (software index marker)
QEP_Handle QEP_init(void *pMemory, const size_t numBytes)
Initializes the QEP object.
#define QEP_QDECCTL_SWAP
swap quadrature clock inputs
uint32_t QPOSCNT
QEP Position Counter.
QCAPCTL_Upps_e
Unit position event prescaler.
QCAPCTL_Ccps_e
QEP capture timer clock prescaler.
#define QEP_QEPCTL_UTE
QEP unit timer enable.
void QEP_set_strobe_event_init(QEP_Handle qepHandle, const QEPCTL_Sei_e QEPCTL_Sei)
Determines strobe initialization of position counter.
Clockwise: position counter latched on rising edge, counter clockwise: latched on falling edge...
void QEP_disable_unit_timer(QEP_Handle qepHandle)
Disable unit timer.
void QEP_reset_counter(QEP_Handle qepHandle)
Resets counter.
void QEP_disable_posn_compare(QEP_Handle qepHandle)
Disable position compare.
void QEP_enable_posn_compare_shadow(QEP_Handle qepHandle)
Enable position compare shadowing.
#define QEP_QCAPCTL_UPPS
unit position event prescaler
void QEP_enable_gate_index(QEP_Handle qepHandle)
Enable gating of index pulse.
#define QEP_QPOSCTL_PCSPW
selection position compare sync output pulse width
uint32_t QEP_read_posn_index_latch(QEP_Handle qepHandle)
Reads position counter value index pulse latch register.
QEP_Xcr_e
External clock rate.
QEP_Qsp_e
Channel S polarity.
uint32_t QPOSSLAT
QEP Strobe Position Latch.
void QEP_set_posn_init_count(QEP_Handle qepHandle, const uint32_t init_count)
Sets initial position counter value.
uint32_t QUTMR
QEP Unit Timer.
unit time out interrupt enable
Contains public interface to various functions related to the central processing unit (CPU) object...
uint16_t QWDTMR
QEP Watchdog Timer.
uint16_t QEINT
QEP Interrupt Enable Register.
ditto on falling edge of index signal
#define QEP_QDECCTL_QAP
QEPA input polarity.
void QEP_set_capture_period(QEP_Handle qepHandle, const uint16_t period)
Sets capture period.
void QEP_set_index_event_init(QEP_Handle qepHandle, const QEPCTL_Iei_e QEPCTL_Iei)
Sets the event which initializes the counter register.
void QEP_set_QEP_source(QEP_Handle qepHandle, const QEP_Qsrc_e QEP_Qsrc)
QEP counting mode.
QEPCTL_Qclm_e
QEP capture latch mode.
strobe pin for sync output
uint32_t QPOSILAT
QEP Index Position Latch.
void QEP_set_B_polarity(QEP_Handle qepHandle, const QEP_Qbp_e QEP_Qbp)
Sets B polarity.
#define QEP_QEPCTL_SWI
software initialization of position counter
void QEP_disable_posn_compare_shadow(QEP_Handle qepHandle)
Disable position compare shadowing.
uint16_t QCTMR
QEP Capture Timer.
initializes on falling edge of QEPS signal
uint16_t QCPRD
QEP Capture Period.
index event latch interrupt enable
uint16_t QCLR
QEP Interrupt Clear Register.
#define QEP_QEPCTL_FREESOFT
emulation control bit
position counter interrupt enable
void QEP_enable_unit_timer(QEP_Handle qepHandle)
Enable unit timer.
QEPCTL_Sel_e
Strobe event latch of position counter.
QEPCTL_Swi_e
Software initialization of position counter.
position counter reset on index event
void QEP_clear_posn_counter(QEP_Handle qepHandle)
Clears the position counter.
void QEP_set_strobe_polarity(QEP_Handle qepHandle, const QEP_Qsp_e QEP_Qsp)
Sets up strobe polarity.
position compare watchdog time out interrupt enable
enable gating of index pulse
void QEP_set_index_event_latch(QEP_Handle qepHandle, const QEPCTL_Iel_e QEPCTL_Iel)
Sets the index event which latches the position counter.
latches position counter on rising edge of index signal
uint32_t QPOSMAX
QEP Maximum Position Count.
#define QEP_QEPCTL_PCRM
emulation control bit
uint16_t QPOSCTL
QEP Position Compare Control.
down count mode for frequency measurement (QCLK=XCLK, QDIR=0)
latch on position counter read by cpu
QEP_Swap_e
Swap A/B channels.
void QEP_disable_all_interrupts(QEP_Handle qepHandle)
Disables all interrupts.
void QEP_set_A_polarity(QEP_Handle qepHandle, const QEP_Qap_e QEP_Qap)
Sets A polarity.
quadrature phase error interrupt enable
void QEP_clear_interrupt_flag(QEP_Handle qepHandle, const QEINT_e QEINT)
Clears a single interrupt flag.
initializes on rising edge of QEPI signal
void QEP_set_posn_count_reset_mode(QEP_Handle qepHandle, const QEPCTL_Pcrm_e QEPCTL_Pcrm)
Sets position counter reset mode.
uint32_t QPOSCMP
QEP Position Compare.
void QEP_force_interrupt(QEP_Handle qepHandle, const QEINT_e QEINT)
Manually force QEP interrupt.
position compare ready interrupt enable
uint32_t QEP_read_posn_compare(QEP_Handle qepHandle)
Reads position compare register.
uint16_t QFRC
QEP Interrupt Force Register.
QPOSCTL_Pcshdw_e
Position compare shadow enable.
initializes on rising/falling edge of QEPS signal
software index marker. See data sheet.
void QEP_set_capture_latch_mode(QEP_Handle qepHandle, const QEPCTL_Qclm_e QEPCTL_Qclm)
Sets capture latch mode.
uint32_t QPOSINIT
QEP Initialization Position Count.
position, watchdog, unit timer, capture timer stops immediately
void QEP_enable_posn_compare(QEP_Handle qepHandle)
Enable position compare.
QEP_Qbp_e
Channel B polarity.
uint16_t QEP_read_capture_timer_latch(QEP_Handle qepHandle)
Reads timer latch.
void QEP_clear_all_interrupt_flags(QEP_Handle qepHandle)
Clears all QEP interrupt flags.
up count mode for frequency measurement (QCLK=XCLK, QDIR=1)
void QEP_enable_interrupt(QEP_Handle qepHandle, const QEINT_e QEINT)
Enable individual interrupt.
position counter reset on first index event