RTEMS 6.1-rc5
Loading...
Searching...
No Matches
qep.h
Go to the documentation of this file.
1
9/*
10 * SPDX-License-Identifier: BSD-2-Clause
11 *
12 * Copyright (c) 2020, 2021 James Fitzsimons <james.fitzsimons@gmail.com>
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
65#ifndef LIBBSP_ARM_BEAGLE_QEP_H
66#define LIBBSP_ARM_BEAGLE_QEP_H
67
68#ifdef __cplusplus
69extern "C" {
70#endif /* __cplusplus */
71
72#define AM335X_EQEP_REGS (0x00000180)
73#define AM335X_EQEP_0_REGS (AM335X_PWMSS0_MMAP_ADDR + AM335X_EQEP_REGS)
74#define AM335X_EQEP_1_REGS (AM335X_PWMSS1_MMAP_ADDR + AM335X_EQEP_REGS)
75#define AM335X_EQEP_2_REGS (AM335X_PWMSS2_MMAP_ADDR + AM335X_EQEP_REGS)
76
77/* eQEP registers of the PWMSS modules - see page 1672 of the TRM for details */
78#define AM335x_EQEP_QPOSCNT 0x0 /* eQEP Position Counter */
79#define AM335x_EQEP_QPOSINIT 0x4 /* eQEP Position Counter Initialization */
80#define AM335x_EQEP_QPOSMAX 0x8 /* eQEP Maximum Position Count */
81#define AM335x_EQEP_QPOSCMP 0xC /* eQEP Position-Compare */
82#define AM335x_EQEP_QPOSILAT 0x10 /* eQEP Index Position Latch */
83#define AM335x_EQEP_QPOSSLAT 0x14 /* eQEP Strobe Position Latch */
84#define AM335x_EQEP_QPOSLAT 0x18 /* eQEP Position Counter Latch */
85#define AM335x_EQEP_QUTMR 0x1C /* eQEP Unit Timer */
86#define AM335x_EQEP_QUPRD 0x20 /* eQEP Unit Period */
87#define AM335x_EQEP_QWDTMR 0x24 /* eQEP Watchdog Timer */
88#define AM335x_EQEP_QWDPRD 0x26 /* eQEP Watchdog Period */
89#define AM335x_EQEP_QDECCTL 0x28 /* eQEP Decoder Control */
90#define AM335x_EQEP_QEPCTL 0x2A /* eQEP Control */
91#define AM335x_EQEP_QCAPCTL 0x2C /* eQEP Capture Control */
92#define AM335x_EQEP_QPOSCTL 0x2E /* eQEP Position-Compare Control */
93#define AM335x_EQEP_QEINT 0x30 /* eQEP Interrupt Enable */
94#define AM335x_EQEP_QFLG 0x32 /* eQEP Interrupt Flag */
95#define AM335x_EQEP_QCLR 0x34 /* eQEP Interrupt Clear */
96#define AM335x_EQEP_QFRC 0x36 /* eQEP Interrupt Force */
97#define AM335x_EQEP_QEPSTS 0x38 /* eQEP Status */
98#define AM335x_EQEP_QCTMR 0x3A /* eQEP Capture Timer */
99#define AM335x_EQEP_QCPRD 0x3C /* eQEP Capture Period */
100#define AM335x_EQEP_QCTMRLAT 0x3E /* eQEP Capture Timer Latch */
101#define AM335x_EQEP_QCPRDLAT 0x40 /* eQEP Capture Period Latch */
102#define AM335x_EQEP_REVID 0x5C /* eQEP Revision ID */
103
104/* bitmasks for eQEP registers */
105#define AM335x_EQEP_QEPCTL_UTE (1 << 1)
106#define AM335x_EQEP_QEPCTL_QCLM (1 << 2)
107#define AM335x_EQEP_QEPCTL_PHEN (1 << 3)
108#define AM335x_EQEP_QEPCTL_IEL (1 << 4)
109#define AM335x_EQEP_QEPCTL_SWI (1 << 7)
110#define AM335x_EQEP_QEPCTL_PCRM (3 << 12)
111#define AM335x_EQEP_QDECCTL_QSRC (3 << 14)
112#define AM335x_EQEP_QDECCTL_XCR (1 << 11)
113#define AM335x_EQEP_QDECCTL_SWAP (1 << 10)
114#define AM335x_EQEP_QDECCTL_IGATE (1 << 9)
115#define AM335x_EQEP_QDECCTL_QAP (1 << 8)
116#define AM335x_EQEP_QDECCTL_QBP (1 << 7)
117#define AM335x_EQEP_QDECCTL_QIP (1 << 6)
118#define AM335x_EQEP_QDECCTL_QSP (1 << 5)
119#define AM335x_EQEP_CLK_EN (1 << 4)
120#define AM335x_EQEP_QEINT_UTO (1 << 11)
121#define AM335x_EQEP_QFLG_UTO (1 << 11)
122#define AM335x_EQEP_QFLG_MASK 0x0FFF
123
124/* The pin mux modes for the QEP input pins on the P8 and P9 headers */
125#define BBB_P8_11_MUX_QEP 4
126#define BBB_P8_12_MUX_QEP 4
127#define BBB_P8_15_MUX_QEP 4
128#define BBB_P8_16_MUX_QEP 4
129#define BBB_P8_31_MUX_QEP 2
130#define BBB_P8_32_MUX_QEP 2
131#define BBB_P8_33_MUX_QEP 2
132#define BBB_P8_35_MUX_QEP 2
133#define BBB_P8_39_MUX_QEP 3
134#define BBB_P8_40_MUX_QEP 3
135#define BBB_P8_41_MUX_QEP 3
136#define BBB_P8_42_MUX_QEP 3
137#define BBB_P9_25_MUX_QEP 1
138#define BBB_P9_27_MUX_QEP 1
139#define BBB_P9_41_MUX_QEP 1
140#define BBB_P9_42_MUX_QEP 1
141
142#define NANO_SEC_PER_SEC 1000000000
143/* This is the max clock rate for the EPWMSS module. See 15.1.2.2 of the TRM.
144 * If the CPU was using dynamic scaling this could potentially be wrong */
145#define SYSCLKOUT 100000000
146
153typedef enum {
154 QUADRATURE_COUNT = 0,
155 DIRECTION_COUNT,
156 UP_COUNT,
157 DOWN_COUNT
159
164typedef enum {
165 ABSOLUTE = 0,
166 RELATIVE
168
173typedef enum {
174 BBB_P8_11_2B_IN,
175 BBB_P8_12_2A_IN,
176 BBB_P8_15_2_STROBE,
177 BBB_P8_16_2_IDX,
178 BBB_P8_31_1_IDX,
179 BBB_P8_32_1_STROBE,
180 BBB_P8_33_1B_IN,
181 BBB_P8_35_1A_IN,
182 BBB_P8_39_2_IDX,
183 BBB_P8_40_2_STROBE,
184 BBB_P8_41_2A_IN,
185 BBB_P8_42_2B_IN,
186 BBB_P9_25_0_STROBE,
187 BBB_P9_27_0B_IN,
188 BBB_P9_41_0_IDX,
189 BBB_P9_42_0A_IN
191
192
213 BBB_PWMSS,
214 uint32_t position,
215 void* user
216);
217
218
244typedef struct {
245 const BBB_PWMSS pwmss_id;
246 const uint32_t mmio_base;
247 const rtems_vector_number irq;
248 bbb_eqep_timer_callback timer_callback;
249 void* user;
250 BBB_QEP_COUNT_MODE count_mode;
251 BBB_QEP_QUADRATURE_MODE quadrature_mode;
252 uint32_t invert_qa;
253 uint32_t invert_qb;
254 uint32_t invert_qi;
255 uint32_t invert_qs;
256 uint32_t swap_inputs;
257} bbb_eqep;
258
259
271
280
289
302 bbb_qep_pin pin_no,
303 BBB_PWMSS pwmss_id,
304 bool pullup_enable
305);
306
314int32_t beagle_qep_get_position(BBB_PWMSS pwmss_id);
315
326 BBB_PWMSS pwmss_id,
327 uint32_t position
328);
329
338 BBB_PWMSS pwmss_id,
340);
341
348
357
368 BBB_PWMSS pwmss_id,
370);
371
377uint32_t beagle_eqep_get_timer_period(BBB_PWMSS pwmss_id);
378
394 BBB_PWMSS pwmss_id,
395 uint64_t period,
396 bbb_eqep_timer_callback timer_callback,
397 void* user
398);
399
400#ifdef __cplusplus
401}
402#endif /* __cplusplus */
403
404#endif /* LIBBSP_ARM_BEAGLE_QEP_H */
ISR_Vector_number rtems_vector_number
This integer type represents interrupt vector numbers.
Definition: intr.h:102
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
BBB_PWMSS
The set of possible PWM subsystem module.
Definition: pwmss.h:58
rtems_status_code beagle_qep_set_quadrature_mode(BBB_PWMSS pwmss_id, BBB_QEP_QUADRATURE_MODE mode)
Sets the quadrature mode to either absolute or relative.
Definition: qep.c:356
rtems_status_code beagle_qep_pinmux_setup(bbb_qep_pin pin_no, BBB_PWMSS pwmss_id, bool pullup_enable)
Configures a given pin for use with the eQEP function of the supplied PWMSS module.
Definition: qep.c:232
uint32_t beagle_eqep_get_timer_period(BBB_PWMSS pwmss_id)
Returns the the currently configured unit timer period.
Definition: qep.c:402
BBB_QEP_QUADRATURE_MODE beagle_qep_get_quadrature_mode(BBB_PWMSS pwmss_id)
Returns the currently configured quadrature mode - either absolute, or relative.
Definition: qep.c:390
rtems_status_code beagle_qep_set_position(BBB_PWMSS pwmss_id, uint32_t position)
Sets the initial position value of the eQEP function for the specified PWMSS module.
Definition: qep.c:318
rtems_status_code beagle_qep_disable(BBB_PWMSS pwmss_id)
Disables the eQEP module of the specified PWMSS unit.
Definition: qep.c:220
rtems_status_code beagle_qep_set_count_mode(BBB_PWMSS pwmss_id, BBB_QEP_COUNT_MODE mode)
Sets the count mode for the eQEP module.
Definition: qep.c:332
BBB_QEP_COUNT_MODE beagle_qep_get_count_mode(BBB_PWMSS pwmss_id)
Gets the currently configured count mode for the eQEP module.
Definition: qep.c:346
rtems_status_code beagle_eqep_set_timer_period(BBB_PWMSS pwmss_id, uint64_t period, bbb_eqep_timer_callback timer_callback, void *user)
Sets the unit timer period for the eQEP module. 0 = off, greater than zero sets the period.
Definition: qep.c:419
BBB_QEP_QUADRATURE_MODE
The set of possible modes for Quadrature decode.
Definition: qep.h:164
rtems_status_code beagle_qep_init(BBB_PWMSS pwmss_id)
Initialises the eQEP module of the specified PWMSS unit. This configures the clocks,...
Definition: qep.c:117
void(* bbb_eqep_timer_callback)(BBB_PWMSS, uint32_t position, void *user)
This function definition is used to declare a callback function that will be called by the interrupt ...
Definition: qep.h:212
rtems_status_code beagle_qep_enable(BBB_PWMSS pwmss_id)
Enables the eQEP module of the specified PWMSS unit.
Definition: qep.c:208
int32_t beagle_qep_get_position(BBB_PWMSS pwmss_id)
Returns the current position value of the eQEP function for the specified PWMSS module.
Definition: qep.c:299
BBB_QEP_COUNT_MODE
The set of possible eQEP Position Counter Input Modes.
Definition: qep.h:153
bbb_qep_pin
The set of possible eQEP input pins.
Definition: qep.h:173
Definition: qep.h:244