[PATCH v3 0/1] Resubmission of patch previously submitted Sept 2020

2021-02-21 Thread James Fitzsimons
This patch adds driver support for the eQEP (enhanced Quadrature Encoder Pulse)
module within each of the PWMSS units in the AM335x. The eQEP module is used for
hardware decoding of rotrary encoders, motor encoders etc.

Because the PWMSS module includes several components some of the existing code 
in
the pwm driver could be reused. To make this common I have added a pwmss.h 
header
and moved some of the pwmss specific defines and enum to this file. The pwmss.c
file contains a refactored (simplified) version of the clock configuration
method that was previously in the pwm.c file. The pwmss_module_clk_config will
now be shared by both the pwm and eqep drivers (and eventually the ecap driver 
if
that is ever added).

The approach taken with the qep.h header was to move some of the qep specific
defines from the am335x.h header to this file. They are specific to the qep
function and would likely never be referenced by anything other than this 
driver.
Doing this keeps these definitions with the driver code and reduces clutter in
am335x.h header.

The driver supports two primary modes of operation. A polled mode (which is the
default mode), and an interrupt event driven mode.

This patch includes the following revisions after feedback from Chris Johns:
 - improved documentation
 - addition of void* user argument to interrupt callback
 - addition of position value arg to interrupt callback

James Fitzsimons (1):
  Adding QEP driver support to BeagleBoneBlack BSP

 bsps/arm/beagle/headers.am  |   2 +
 bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
 bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
 bsps/arm/beagle/include/bsp/qep.h   | 382 
 bsps/arm/beagle/pwm/pwm.c   |  60 +---
 bsps/arm/beagle/pwmss/pwmss.c   |  64 
 bsps/arm/beagle/qep/qep.c   | 445 
 c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
 spec/build/bsps/arm/beagle/obj.yml  |   5 +-
 9 files changed, 959 insertions(+), 70 deletions(-)
 create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
 create mode 100644 bsps/arm/beagle/include/bsp/qep.h
 create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
 create mode 100644 bsps/arm/beagle/qep/qep.c

-- 
2.25.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v3 1/1] Adding QEP driver support to BeagleBoneBlack BSP

2021-02-21 Thread James Fitzsimons
---
 bsps/arm/beagle/headers.am  |   2 +
 bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
 bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
 bsps/arm/beagle/include/bsp/qep.h   | 382 
 bsps/arm/beagle/pwm/pwm.c   |  60 +---
 bsps/arm/beagle/pwmss/pwmss.c   |  64 
 bsps/arm/beagle/qep/qep.c   | 445 
 c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
 spec/build/bsps/arm/beagle/obj.yml  |   5 +-
 9 files changed, 959 insertions(+), 70 deletions(-)
 create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
 create mode 100644 bsps/arm/beagle/include/bsp/qep.h
 create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
 create mode 100644 bsps/arm/beagle/qep/qep.c

diff --git a/bsps/arm/beagle/headers.am b/bsps/arm/beagle/headers.am
index 4dc35f2e2a..e4a746b2e1 100644
--- a/bsps/arm/beagle/headers.am
+++ b/bsps/arm/beagle/headers.am
@@ -13,3 +13,5 @@ include_bsp_HEADERS += 
../../../../../../bsps/arm/beagle/include/bsp/beagleboneb
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/i2c.h
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/irq.h
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/spi.h
+include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/qep.h
+include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/pwmss.h
diff --git a/bsps/arm/beagle/include/bsp/bbb-pwm.h 
b/bsps/arm/beagle/include/bsp/bbb-pwm.h
index cf5d6fe552..6fdba486be 100644
--- a/bsps/arm/beagle/include/bsp/bbb-pwm.h
+++ b/bsps/arm/beagle/include/bsp/bbb-pwm.h
@@ -31,17 +31,6 @@ extern "C" {
 #define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
 #define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))
 
-/**
- * @brief The set of possible PWM subsystem module
- *
- * Enumerated type to define various instance of pwm module.
- */
-typedef enum{
-  BBB_PWMSS0 = 0,
-  BBB_PWMSS1,
-  BBB_PWMSS2,
-  BBB_PWMSS_COUNT
-}BBB_PWMSS;
 
 typedef enum{
   BBB_P8_13_2B = 3,
diff --git a/bsps/arm/beagle/include/bsp/pwmss.h 
b/bsps/arm/beagle/include/bsp/pwmss.h
new file mode 100644
index 00..3a9dcbb70a
--- /dev/null
+++ b/bsps/arm/beagle/include/bsp/pwmss.h
@@ -0,0 +1,54 @@
+/**
+ * @file
+ *
+ * @ingroup arm_beagle
+ *
+ * @brief Shared PWMSS module functions used by PWM, eQEP and eCAP (when 
added).
+ */
+
+/**
+ * Copyright (c) 2020 James Fitzsimons 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *.
+ */
+
+#ifndef LIBBSP_ARM_BEAGLE_PWMSS_H
+#define LIBBSP_ARM_BEAGLE_PWMSS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* The following definitions are bitmasks for the clk control registers for
+ * the PWMSS module clocks. All three modules have the same clock control
+ * hence the EPMSSx to signify these values are consistent across all
+ * EPWMSS instances. */
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE_ENABLE   (0x2u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE   (0x0003u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST_FUNC  (0x0u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST_SHIFT (0x0010u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST   (0x0003u)
+
+/**
+ * @brief The set of possible PWM subsystem module
+ *
+ * Enumerated type to define various instance of pwm module.
+ */
+typedef enum {
+  BBB_PWMSS0 = 0,
+  BBB_PWMSS1,
+  BBB_PWMSS2,
+  BBB_PWMSS_COUNT
+} BBB_PWMSS;
+
+
+rtems_status_code pwmss_module_clk_config(BBB_PWMSS pwmss_id);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LIBBSP_ARM_BEAGLE_PWMSS_H */
diff --git a/bsps/arm/beagle/include/bsp/qep.h 
b/bsps/arm/beagle/include/bsp/qep.h
new file mode 100644
index 00..fc086e3c80
--- /dev/null
+++ b/bsps/arm/beagle/include/bsp/qep.h
@@ -0,0 +1,382 @@
+/**
+ * @file
+ *
+ * @ingroup arm_beagle
+ *
+ * @brief eQEP (enhanced Quadrature Encoder Pulse) support API.
+ */
+
+/**
+ * Copyright (c) 2020 James Fitzsimons 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *
+ * For details of the Enhanced Quadrature Encoder Pulse (eQEP) Module refer to
+ * page 2511 of the TI Technical Reference Manual
+ * (https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf)
+ *
+ * This driver supports using the QEP modules in Quadrature-clock Mode.
+ * Direction-count Mode is not currently supported. Similarly the QEPI: Index
+ * or Zero Marker and QEPS: Strobe Input pins are not currently supported.
+ *
+ * The mode can be any one of:
+ *  - Quadrature-count mode - For encoders that generate pulses 90 degrees
+ *  out of phase for determining direction and speed.
+ *  - Direction-count mode - for position encoders that provide direction and
+ *  clock outputs, instead of quadrature outputs.
+ *  - UP-coun

Re: [PATCH v3 0/1] Resubmission of patch previously submitted Sept 2020

2021-02-22 Thread James Fitzsimons
Thanks Christian,

That's much appreciated.

Cheers,
James

On Tue, 23 Feb 2021 at 08:01, Christian Mauderer  wrote:

> Hello James,
>
> thanks for the patch and sorry that it get lost on the first submission.
>
> The patch compiles fine and it doesn't seem to change interfaces a lot.
> So I would say it is OK. I'll give it two or three more days of review
> before pushing it.
>
> Please remind me again in a week in case I forget to push it.
>
> Best regards
>
> Christian
>
> On 21/02/2021 10:29, James Fitzsimons wrote:
> > This patch adds driver support for the eQEP (enhanced Quadrature Encoder
> Pulse)
> > module within each of the PWMSS units in the AM335x. The eQEP module is
> used for
> > hardware decoding of rotrary encoders, motor encoders etc.
> >
> > Because the PWMSS module includes several components some of the
> existing code in
> > the pwm driver could be reused. To make this common I have added a
> pwmss.h header
> > and moved some of the pwmss specific defines and enum to this file. The
> pwmss.c
> > file contains a refactored (simplified) version of the clock
> configuration
> > method that was previously in the pwm.c file. The
> pwmss_module_clk_config will
> > now be shared by both the pwm and eqep drivers (and eventually the ecap
> driver if
> > that is ever added).
> >
> > The approach taken with the qep.h header was to move some of the qep
> specific
> > defines from the am335x.h header to this file. They are specific to the
> qep
> > function and would likely never be referenced by anything other than
> this driver.
> > Doing this keeps these definitions with the driver code and reduces
> clutter in
> > am335x.h header.
> >
> > The driver supports two primary modes of operation. A polled mode (which
> is the
> > default mode), and an interrupt event driven mode.
> >
> > This patch includes the following revisions after feedback from Chris
> Johns:
> >   - improved documentation
> >   - addition of void* user argument to interrupt callback
> >   - addition of position value arg to interrupt callback
> >
> > James Fitzsimons (1):
> >Adding QEP driver support to BeagleBoneBlack BSP
> >
> >   bsps/arm/beagle/headers.am  |   2 +
> >   bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
> >   bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
> >   bsps/arm/beagle/include/bsp/qep.h   | 382 
> >   bsps/arm/beagle/pwm/pwm.c   |  60 +---
> >   bsps/arm/beagle/pwmss/pwmss.c   |  64 
> >   bsps/arm/beagle/qep/qep.c   | 445 
> >   c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
> >   spec/build/bsps/arm/beagle/obj.yml  |   5 +-
> >   9 files changed, 959 insertions(+), 70 deletions(-)
> >   create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
> >   create mode 100644 bsps/arm/beagle/include/bsp/qep.h
> >   create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
> >   create mode 100644 bsps/arm/beagle/qep/qep.c
> >
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH v4 1/2] bsps/beagle: Adding QEP driver support to BeagleBoneBlack BSP

2021-02-23 Thread James Fitzsimons
---
 bsps/arm/beagle/headers.am  |   2 +
 bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
 bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
 bsps/arm/beagle/include/bsp/qep.h   | 382 
 bsps/arm/beagle/pwm/pwm.c   |  60 +---
 bsps/arm/beagle/pwmss/pwmss.c   |  64 
 bsps/arm/beagle/qep/qep.c   | 445 
 c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
 spec/build/bsps/arm/beagle/obj.yml  |   5 +-
 9 files changed, 959 insertions(+), 70 deletions(-)
 create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
 create mode 100644 bsps/arm/beagle/include/bsp/qep.h
 create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
 create mode 100644 bsps/arm/beagle/qep/qep.c

diff --git a/bsps/arm/beagle/headers.am b/bsps/arm/beagle/headers.am
index 4dc35f2e2a..e4a746b2e1 100644
--- a/bsps/arm/beagle/headers.am
+++ b/bsps/arm/beagle/headers.am
@@ -13,3 +13,5 @@ include_bsp_HEADERS += 
../../../../../../bsps/arm/beagle/include/bsp/beagleboneb
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/i2c.h
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/irq.h
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/spi.h
+include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/qep.h
+include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/pwmss.h
diff --git a/bsps/arm/beagle/include/bsp/bbb-pwm.h 
b/bsps/arm/beagle/include/bsp/bbb-pwm.h
index cf5d6fe552..6fdba486be 100644
--- a/bsps/arm/beagle/include/bsp/bbb-pwm.h
+++ b/bsps/arm/beagle/include/bsp/bbb-pwm.h
@@ -31,17 +31,6 @@ extern "C" {
 #define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
 #define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))
 
-/**
- * @brief The set of possible PWM subsystem module
- *
- * Enumerated type to define various instance of pwm module.
- */
-typedef enum{
-  BBB_PWMSS0 = 0,
-  BBB_PWMSS1,
-  BBB_PWMSS2,
-  BBB_PWMSS_COUNT
-}BBB_PWMSS;
 
 typedef enum{
   BBB_P8_13_2B = 3,
diff --git a/bsps/arm/beagle/include/bsp/pwmss.h 
b/bsps/arm/beagle/include/bsp/pwmss.h
new file mode 100644
index 00..3a9dcbb70a
--- /dev/null
+++ b/bsps/arm/beagle/include/bsp/pwmss.h
@@ -0,0 +1,54 @@
+/**
+ * @file
+ *
+ * @ingroup arm_beagle
+ *
+ * @brief Shared PWMSS module functions used by PWM, eQEP and eCAP (when 
added).
+ */
+
+/**
+ * Copyright (c) 2020 James Fitzsimons 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *.
+ */
+
+#ifndef LIBBSP_ARM_BEAGLE_PWMSS_H
+#define LIBBSP_ARM_BEAGLE_PWMSS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* The following definitions are bitmasks for the clk control registers for
+ * the PWMSS module clocks. All three modules have the same clock control
+ * hence the EPMSSx to signify these values are consistent across all
+ * EPWMSS instances. */
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE_ENABLE   (0x2u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE   (0x0003u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST_FUNC  (0x0u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST_SHIFT (0x0010u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST   (0x0003u)
+
+/**
+ * @brief The set of possible PWM subsystem module
+ *
+ * Enumerated type to define various instance of pwm module.
+ */
+typedef enum {
+  BBB_PWMSS0 = 0,
+  BBB_PWMSS1,
+  BBB_PWMSS2,
+  BBB_PWMSS_COUNT
+} BBB_PWMSS;
+
+
+rtems_status_code pwmss_module_clk_config(BBB_PWMSS pwmss_id);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LIBBSP_ARM_BEAGLE_PWMSS_H */
diff --git a/bsps/arm/beagle/include/bsp/qep.h 
b/bsps/arm/beagle/include/bsp/qep.h
new file mode 100644
index 00..fc086e3c80
--- /dev/null
+++ b/bsps/arm/beagle/include/bsp/qep.h
@@ -0,0 +1,382 @@
+/**
+ * @file
+ *
+ * @ingroup arm_beagle
+ *
+ * @brief eQEP (enhanced Quadrature Encoder Pulse) support API.
+ */
+
+/**
+ * Copyright (c) 2020 James Fitzsimons 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *
+ * For details of the Enhanced Quadrature Encoder Pulse (eQEP) Module refer to
+ * page 2511 of the TI Technical Reference Manual
+ * (https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf)
+ *
+ * This driver supports using the QEP modules in Quadrature-clock Mode.
+ * Direction-count Mode is not currently supported. Similarly the QEPI: Index
+ * or Zero Marker and QEPS: Strobe Input pins are not currently supported.
+ *
+ * The mode can be any one of:
+ *  - Quadrature-count mode - For encoders that generate pulses 90 degrees
+ *  out of phase for determining direction and speed.
+ *  - Direction-count mode - for position encoders that provide direction and
+ *  clock outputs, instead of quadrature outputs.
+ *  - UP-coun

[PATCH v4 2/2] bsps/beagle: Updating licences to latest BSD 2 clause

2021-02-23 Thread James Fitzsimons
---
 bsps/arm/beagle/include/bsp/bbb-pwm.h | 28 +++
 bsps/arm/beagle/include/bsp/pwmss.h   | 30 -
 bsps/arm/beagle/include/bsp/qep.h | 32 ++-
 bsps/arm/beagle/pwm/pwm.c | 27 ++
 bsps/arm/beagle/pwmss/pwmss.c | 29 +++-
 bsps/arm/beagle/qep/qep.c | 29 +++-
 6 files changed, 146 insertions(+), 29 deletions(-)

diff --git a/bsps/arm/beagle/include/bsp/bbb-pwm.h 
b/bsps/arm/beagle/include/bsp/bbb-pwm.h
index 6fdba486be..34f610f86d 100644
--- a/bsps/arm/beagle/include/bsp/bbb-pwm.h
+++ b/bsps/arm/beagle/include/bsp/bbb-pwm.h
@@ -6,14 +6,34 @@
  * @brief BeagleBone Black PWM support definitions.
  */
 
-/**
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c) 2016 Punit Vara 
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * 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.
  */
 
+
 /** Some constants are taken from 
  * 
https://github.com/VegetableAvenger/BBBIOlib/blob/master/BBBio_lib/BBBiolib_PWMSS.h
  */
diff --git a/bsps/arm/beagle/include/bsp/pwmss.h 
b/bsps/arm/beagle/include/bsp/pwmss.h
index 3a9dcbb70a..c1449ec600 100644
--- a/bsps/arm/beagle/include/bsp/pwmss.h
+++ b/bsps/arm/beagle/include/bsp/pwmss.h
@@ -6,13 +6,31 @@
  * @brief Shared PWMSS module functions used by PWM, eQEP and eCAP (when 
added).
  */
 
-/**
- * Copyright (c) 2020 James Fitzsimons 
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020, 2021 James Fitzsimons 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. 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.
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- *.
+ * 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 LIBBSP_ARM_BEAGLE_PWMSS_H
diff --git a/bsps/arm/beagle/include/bsp/qep.h 
b/bsps/arm/beagle/include/bsp/qep.h
index fc086e3c80..736224503e 100644
--- a/bsps/arm/beagle/include/bsp/qep.h
+++ b/bsps/arm/beagle/include/bsp/qep.h
@@ -6,12 +6,34 @@
  * @brief eQEP (enhanced Quadrature Encoder Pulse) support API.
  */
 
-/**
- * Copyright (c) 2020 James Fitzsimons 
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020, 2021 James Fitzsimons 
+ *
+ * Redistribution and use in source and binary forms, with or with

Re: [PATCH v3 0/1] Resubmission of patch previously submitted Sept 2020

2021-02-23 Thread James Fitzsimons
Hi Chris,

I've just submitted v4 with those licences updated. I hope I've done it
correctly.

Cheers,
James

On Tue, 23 Feb 2021 at 10:23, Chris Johns  wrote:

> Hi James,
>
> Thanks for the patch. It is close. Could I ask if all the source files
> from you
> please be updated to the latest template with the 2-clause BSD license? It
> will
> say us having to include them in the sweep when we get to that task. I see
> a mix
> in the files provided.
>
> Thanks
> Chris
>
> On 21/2/21 8:29 pm, James Fitzsimons wrote:
> > This patch adds driver support for the eQEP (enhanced Quadrature Encoder
> Pulse)
> > module within each of the PWMSS units in the AM335x. The eQEP module is
> used for
> > hardware decoding of rotrary encoders, motor encoders etc.
> >
> > Because the PWMSS module includes several components some of the
> existing code in
> > the pwm driver could be reused. To make this common I have added a
> pwmss.h header
> > and moved some of the pwmss specific defines and enum to this file. The
> pwmss.c
> > file contains a refactored (simplified) version of the clock
> configuration
> > method that was previously in the pwm.c file. The
> pwmss_module_clk_config will
> > now be shared by both the pwm and eqep drivers (and eventually the ecap
> driver if
> > that is ever added).
> >
> > The approach taken with the qep.h header was to move some of the qep
> specific
> > defines from the am335x.h header to this file. They are specific to the
> qep
> > function and would likely never be referenced by anything other than
> this driver.
> > Doing this keeps these definitions with the driver code and reduces
> clutter in
> > am335x.h header.
> >
> > The driver supports two primary modes of operation. A polled mode (which
> is the
> > default mode), and an interrupt event driven mode.
> >
> > This patch includes the following revisions after feedback from Chris
> Johns:
> >  - improved documentation
> >  - addition of void* user argument to interrupt callback
> >  - addition of position value arg to interrupt callback
> >
> > James Fitzsimons (1):
> >   Adding QEP driver support to BeagleBoneBlack BSP
> >
> >  bsps/arm/beagle/headers.am  |   2 +
> >  bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
> >  bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
> >  bsps/arm/beagle/include/bsp/qep.h   | 382 
> >  bsps/arm/beagle/pwm/pwm.c   |  60 +---
> >  bsps/arm/beagle/pwmss/pwmss.c   |  64 
> >  bsps/arm/beagle/qep/qep.c   | 445 
> >  c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
> >  spec/build/bsps/arm/beagle/obj.yml  |   5 +-
> >  9 files changed, 959 insertions(+), 70 deletions(-)
> >  create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
> >  create mode 100644 bsps/arm/beagle/include/bsp/qep.h
> >  create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
> >  create mode 100644 bsps/arm/beagle/qep/qep.c
> >
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH] Fix for Beaglebone BSP PWM bug

2020-07-05 Thread James Fitzsimons
---
Fixed incorrect register offset values for EHRPWM1A on P9_14
 and EHRPWM1B on P9_16

 bsps/arm/beagle/pwm/pwm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bsps/arm/beagle/pwm/pwm.c b/bsps/arm/beagle/pwm/pwm.c
index 0bc5d125bf..9a346995aa 100644
--- a/bsps/arm/beagle/pwm/pwm.c
+++ b/bsps/arm/beagle/pwm/pwm.c
@@ -102,9 +102,9 @@ bool beagle_pwm_pinmux_setup(bbb_pwm_pin_t pin_no, 
BBB_PWMSS pwm_id)
} else if (pin_no == BBB_P8_36_1A) {
  REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_LCD_DATA(10)) = 
BBB_MUXMODE(BBB_P8_36_MUX_PWM);
} else if (pin_no == BBB_P9_14_1A) {
- REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(2)) = 
BBB_MUXMODE(BBB_P9_14_MUX_PWM);
+ REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(18)) = 
BBB_MUXMODE(BBB_P9_14_MUX_PWM);
} else if (pin_no == BBB_P9_16_1B) {
- REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(3)) = 
BBB_MUXMODE(BBB_P9_16_MUX_PWM);
+ REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(19)) = 
BBB_MUXMODE(BBB_P9_16_MUX_PWM);
} else { 
  is_valid = false;
 }
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] Fix for Beaglebone BSP PWM bug

2020-07-05 Thread James Fitzsimons
Hi all,

I hope that patch is ok, that was my first time using git send-email.

This patch fixes a bug in the Beaglebone BSP where the register offsets for
the PWM outputs on header pins P9_14 and P9_16 are incorrectly calculated.

I'm about to start work on adding the QEP driver to the beaglebone BSP. Is
this list where should I ask questions on BSP changes (coding style, API
design etc), or should I do that on the users list?

Many thanks,
James Fitzsimons

On Sun, 5 Jul 2020 at 22:41, James Fitzsimons 
wrote:

> ---
> Fixed incorrect register offset values for EHRPWM1A on P9_14
>  and EHRPWM1B on P9_16
>
>  bsps/arm/beagle/pwm/pwm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/bsps/arm/beagle/pwm/pwm.c b/bsps/arm/beagle/pwm/pwm.c
> index 0bc5d125bf..9a346995aa 100644
> --- a/bsps/arm/beagle/pwm/pwm.c
> +++ b/bsps/arm/beagle/pwm/pwm.c
> @@ -102,9 +102,9 @@ bool beagle_pwm_pinmux_setup(bbb_pwm_pin_t pin_no,
> BBB_PWMSS pwm_id)
> } else if (pin_no == BBB_P8_36_1A) {
>   REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_LCD_DATA(10)) =
> BBB_MUXMODE(BBB_P8_36_MUX_PWM);
> } else if (pin_no == BBB_P9_14_1A) {
> - REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(2)) =
> BBB_MUXMODE(BBB_P9_14_MUX_PWM);
> + REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(18)) =
> BBB_MUXMODE(BBB_P9_14_MUX_PWM);
> } else if (pin_no == BBB_P9_16_1B) {
> - REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(3)) =
> BBB_MUXMODE(BBB_P9_16_MUX_PWM);
> + REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(19)) =
> BBB_MUXMODE(BBB_P9_16_MUX_PWM);
> } else {
>   is_valid = false;
>  }
> --
> 2.17.1
>
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH] Changing pwm pinmux to use better register definitions

2020-07-13 Thread James Fitzsimons
---
 bsps/arm/beagle/pwm/pwm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bsps/arm/beagle/pwm/pwm.c b/bsps/arm/beagle/pwm/pwm.c
index 9a346995aa..81ace1254e 100644
--- a/bsps/arm/beagle/pwm/pwm.c
+++ b/bsps/arm/beagle/pwm/pwm.c
@@ -102,9 +102,9 @@ bool beagle_pwm_pinmux_setup(bbb_pwm_pin_t pin_no, 
BBB_PWMSS pwm_id)
} else if (pin_no == BBB_P8_36_1A) {
  REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_LCD_DATA(10)) = 
BBB_MUXMODE(BBB_P8_36_MUX_PWM);
} else if (pin_no == BBB_P9_14_1A) {
- REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(18)) = 
BBB_MUXMODE(BBB_P9_14_MUX_PWM);
+ REG(AM335X_PADCONF_BASE + AM335X_CONF_GPMC_A2) = 
BBB_MUXMODE(BBB_P9_14_MUX_PWM);
} else if (pin_no == BBB_P9_16_1B) {
- REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(19)) = 
BBB_MUXMODE(BBB_P9_16_MUX_PWM);
+ REG(AM335X_PADCONF_BASE + AM335X_CONF_GPMC_A3) = 
BBB_MUXMODE(BBB_P9_16_MUX_PWM);
} else { 
  is_valid = false;
 }
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] Fix for Beaglebone BSP PWM bug

2020-07-13 Thread James Fitzsimons
Hi Christian and Chris,

On Sun, 12 Jul 2020 at 06:27, Christian Mauderer  wrote:

> Hello Fitzsimons,
>
> sorry for the late review and thanks Chris for poking me.
>
> I have some troubles understanding the patch and the current code:
>
> == Regarding your patch:
>
> There is no pin GPMC_AD(18) or GPMC_AD(19). That offset will lead you to
> the pins GPMC_A8 and GPMC_A9. The correct macros to use would be
> AM335X_CONF_GPMC_A8 and AM335X_CONF_GPMC_A9. But that's only a style topic.
>
> What's a bit odd is that GPMC_A8 seems to be connected to the LED USR3
> on the BBB. Reasonable output for a PWM. But GPMC_A9 is a HDMI_INT,
> which seems a bit odd


This is my fault for not really understanding the RTEMS header structure
for the beaglebone bsp properly prior to now. I've dug into it a lot more
over the last week or so while I've been working on implementing the eQEP
driver and now have a much better understanding of how all the register
definitions work.

To be honest I found the following two macro definitions a bit unnecessary
but thought I was doing the right thing by following the established
pattern,
/**
 * @brief  BeagleBone Black PWM Macros.
 */
#define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
#define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))


>
== Regarding the old pins
>
> The old pins on the other hand (GPMC_AD2 and AD3) are connected to
> MMC1_DAT2 and 3 which is on P8 pin 5 and 6. That sounds a lot more
> reasonable. But the pins are definitively not what the pin_no suggests.
>
> == What (maybe) should be the correct one
>
> P9_14 and P9_16 are EHRPWM1A and EHRPWM1B on the beagle schematic. These
> are GPMC_AD8 and GPMC_AD9. These pins have a PWM function as an
> alternative function. So I would expect that you have to use these.
>
> It's really hard to find a documentation from TI for the pinmux but I
> found a list:
>
>
> https://git.ti.com/cgit/sitara-dss-files/am335x-dss-files/tree/padconf/am335x-pinmux.data


A much better and easier to understand resource are the following two
documents from Derek Molloy's Exploring Beaglebone website:

http://exploringbeaglebone.com/wp-content/uploads/2019/01/533160-c06f008.png
http://exploringbeaglebone.com/wp-content/uploads/2019/01/533160-c06f009.png


As you can see from the P9 header sheet, the Address we want for EHRPWM1A
on pin P9_14 is 0x848, and EHRPWM1B on pin P9_16 is 0x84c.

It seems like all the register definitions in the am335x.h header in RTEMS
are using the pin mode 1 name as the #define. So, for  EHRPWM1A  on pin
P9_14 I should have used AM335X_CONF_GPMC_A2, and for  EHRPWM1B on pin
P9_16 I should have used AM335X_CONF_GPMC_A3.
I have just made this change and tested it and it works as expected. I'll
submit an updated patch for your review.

Can you please double check the registers used in your patch
>

BTW - the previous patch did actually calculate the correct register offset
- I confirmed this both by printing the register value in a debug statement
and by physically measuring a PWM output signal on the pins.

Cheers,
James


> Best regards
>
> Christian
>
>
> On 05/07/2020 12:39, James Fitzsimons wrote:
> > ---
> > Fixed incorrect register offset values for EHRPWM1A on P9_14
> >  and EHRPWM1B on P9_16
> >
> >  bsps/arm/beagle/pwm/pwm.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/bsps/arm/beagle/pwm/pwm.c b/bsps/arm/beagle/pwm/pwm.c
> > index 0bc5d125bf..9a346995aa 100644
> > --- a/bsps/arm/beagle/pwm/pwm.c
> > +++ b/bsps/arm/beagle/pwm/pwm.c
> > @@ -102,9 +102,9 @@ bool beagle_pwm_pinmux_setup(bbb_pwm_pin_t pin_no,
> BBB_PWMSS pwm_id)
> >   } else if (pin_no == BBB_P8_36_1A) {
> > REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_LCD_DATA(10)) =
> BBB_MUXMODE(BBB_P8_36_MUX_PWM);
> >   } else if (pin_no == BBB_P9_14_1A) {
> > -   REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(2)) =
> BBB_MUXMODE(BBB_P9_14_MUX_PWM);
> > +   REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(18)) =
> BBB_MUXMODE(BBB_P9_14_MUX_PWM);
> >   } else if (pin_no == BBB_P9_16_1B) {
> > -   REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(3)) =
> BBB_MUXMODE(BBB_P9_16_MUX_PWM);
> > +   REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(19)) =
> BBB_MUXMODE(BBB_P9_16_MUX_PWM);
> >   } else {
> > is_valid = false;
> >  }
> >
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] Fix for Beaglebone BSP PWM bug

2020-07-13 Thread James Fitzsimons
Hi Christian,

Thanks very much for that, much appreciated.

Cheers,
James

On Tue, 14 Jul 2020, 03:52 Christian Mauderer,  wrote:

>
>
> On 13/07/2020 11:55, James Fitzsimons wrote:
> > Hi Christian and Chris,
> >
> > On Sun, 12 Jul 2020 at 06:27, Christian Mauderer  > <mailto:o...@c-mauderer.de>> wrote:
> >
> > Hello Fitzsimons,
> >
> > sorry for the late review and thanks Chris for poking me.
> >
> > I have some troubles understanding the patch and the current code:
> >
> > == Regarding your patch:
> >
> > There is no pin GPMC_AD(18) or GPMC_AD(19). That offset will lead
> you to
> > the pins GPMC_A8 and GPMC_A9. The correct macros to use would be
> > AM335X_CONF_GPMC_A8 and AM335X_CONF_GPMC_A9. But that's only a style
> > topic.
> >
> > What's a bit odd is that GPMC_A8 seems to be connected to the LED
> USR3
> > on the BBB. Reasonable output for a PWM. But GPMC_A9 is a HDMI_INT,
> > which seems a bit odd
> >
> >
> > This is my fault for not really understanding the RTEMS header structure
> > for the beaglebone bsp properly prior to now. I've dug into it a lot
> > more over the last week or so while I've been working on implementing
> > the eQEP driver and now have a much better understanding of how all the
> > register definitions work.
> >
> > To be honest I found the following two macro definitions a bit
> > unnecessary but thought I was doing the right thing by following the
> > established pattern,
> > /**
> >  * @brief  BeagleBone Black PWM Macros.
> >  */
> > #define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
> > #define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))
> >
>
> The BBB headers have grown a bit. It's a cheap platform and therefore it
> has been used during quite some GSoC and entry level projects. With that
> the files have been written by much more authors then most other BSPs.
> The headers most likely would need some clean up to get a consistent
> structure.
>
> >
> >
> > == Regarding the old pins
> >
> > The old pins on the other hand (GPMC_AD2 and AD3) are connected to
> > MMC1_DAT2 and 3 which is on P8 pin 5 and 6. That sounds a lot more
> > reasonable. But the pins are definitively not what the pin_no
> suggests.
> >
> > == What (maybe) should be the correct one
> >
> > P9_14 and P9_16 are EHRPWM1A and EHRPWM1B on the beagle schematic.
> These
> > are GPMC_AD8 and GPMC_AD9. These pins have a PWM function as an
> > alternative function. So I would expect that you have to use these.
> >
> > It's really hard to find a documentation from TI for the pinmux but I
> > found a list:
> >
> >
> https://git.ti.com/cgit/sitara-dss-files/am335x-dss-files/tree/padconf/am335x-pinmux.data
> >
> >
> > A much better and easier to understand resource are the following two
> > documents from Derek Molloy's Exploring Beaglebone website:
> >
> >
> http://exploringbeaglebone.com/wp-content/uploads/2019/01/533160-c06f008.png
> >
> http://exploringbeaglebone.com/wp-content/uploads/2019/01/533160-c06f009.png
>
> >
> > As you can see from the P9 header sheet, the Address we want for
> > EHRPWM1A  on pin P9_14 is 0x848, and EHRPWM1B on pin P9_16 is 0x84c.
> >
> > It seems like all the register definitions in the am335x.h header in
> > RTEMS are using the pin mode 1 name as the #define. So, for  EHRPWM1A
> > on pin P9_14 I should have used AM335X_CONF_GPMC_A2, and for  EHRPWM1B
> > on pin P9_16 I should have used AM335X_CONF_GPMC_A3.
> > I have just made this change and tested it and it works as expected.
> > I'll submit an updated patch for your review.
> >
> > Can you please double check the registers used in your patch
> >
> >
> > BTW - the previous patch did actually calculate the correct register
> > offset - I confirmed this both by printing the register value in a debug
> > statement and by physically measuring a PWM output signal on the pins.
>
> You are right. I'm not sure where I got my offset wrong. Of course it
> should be GPMC_A2 and GPMC_A3.
>
> Your new patch is on top of the first one (replaces ...AD(18) with
> ...A2). I'll squash both patches into one and push that one.
>
> Best regards
>
> Christian
>
> >
> > Cheers,
> > James
> >
> >
> > Best regards
> >
> > Christian
> >
> >
> > On 05/0

Beaglebone QEP driver design question

2020-07-21 Thread James Fitzsimons
Hi all,

I have a very basic version of the QEP driver for the Beaglebone black
working now.

I will tidy up my code and submit a patch in the next few days. For first
patches that are likely to require a bit of discussion etc, is the best
idea to still submit them to this list per the normal process, or is there
an alternative approach that would be better? (The patch adds several files
and modifies several existing ones).

Secondly, I have an RTEMS style question. The driver would work best if I
had a small struct that contained a few properties about the driver
configuration. One such property is difficult to intuit from the state of
the registers and so would be better in a separate data structure. This
would mean that the code might look something like this:

typedef struct {
  BBB_PWMSS pwmss_id;
  BBB_QEP_COUNT_MODE mode;
} bbb_eqep_t;

rtems_status_code beagle_qep_init(bbb_eqep_t* eqep);

int32_t beagle_qep_get_position(bbb_eqep_t* eqep);

Is that in keeping with the RTEMS approach? Looking at some of the other
BSPs I see similar approaches for other drivers that need to track state
for multiple instances of hardware.

Your advice is appreciated.

Cheers,
James Fitzsimons
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH 1/1] Adding QEP driver to Beaglebone bsp

2020-08-21 Thread James Fitzsimons
---
 bsps/arm/beagle/headers.am  |   2 +
 bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
 bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
 bsps/arm/beagle/include/bsp/qep.h   | 331 ++
 bsps/arm/beagle/pwm/pwm.c   |  64 +---
 bsps/arm/beagle/pwmss/pwmss.c   |  64 
 bsps/arm/beagle/qep/qep.c   | 435 
 c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
 8 files changed, 896 insertions(+), 71 deletions(-)
 create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
 create mode 100644 bsps/arm/beagle/include/bsp/qep.h
 create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
 create mode 100644 bsps/arm/beagle/qep/qep.c

diff --git a/bsps/arm/beagle/headers.am b/bsps/arm/beagle/headers.am
index 4dc35f2e2a..e4a746b2e1 100644
--- a/bsps/arm/beagle/headers.am
+++ b/bsps/arm/beagle/headers.am
@@ -13,3 +13,5 @@ include_bsp_HEADERS += 
../../../../../../bsps/arm/beagle/include/bsp/beagleboneb
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/i2c.h
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/irq.h
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/spi.h
+include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/qep.h
+include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/pwmss.h
diff --git a/bsps/arm/beagle/include/bsp/bbb-pwm.h 
b/bsps/arm/beagle/include/bsp/bbb-pwm.h
index cf5d6fe552..6fdba486be 100644
--- a/bsps/arm/beagle/include/bsp/bbb-pwm.h
+++ b/bsps/arm/beagle/include/bsp/bbb-pwm.h
@@ -31,17 +31,6 @@ extern "C" {
 #define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
 #define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))
 
-/**
- * @brief The set of possible PWM subsystem module
- *
- * Enumerated type to define various instance of pwm module.
- */
-typedef enum{
-  BBB_PWMSS0 = 0,
-  BBB_PWMSS1,
-  BBB_PWMSS2,
-  BBB_PWMSS_COUNT
-}BBB_PWMSS;
 
 typedef enum{
   BBB_P8_13_2B = 3,
diff --git a/bsps/arm/beagle/include/bsp/pwmss.h 
b/bsps/arm/beagle/include/bsp/pwmss.h
new file mode 100644
index 00..3a9dcbb70a
--- /dev/null
+++ b/bsps/arm/beagle/include/bsp/pwmss.h
@@ -0,0 +1,54 @@
+/**
+ * @file
+ *
+ * @ingroup arm_beagle
+ *
+ * @brief Shared PWMSS module functions used by PWM, eQEP and eCAP (when 
added).
+ */
+
+/**
+ * Copyright (c) 2020 James Fitzsimons 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *.
+ */
+
+#ifndef LIBBSP_ARM_BEAGLE_PWMSS_H
+#define LIBBSP_ARM_BEAGLE_PWMSS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* The following definitions are bitmasks for the clk control registers for
+ * the PWMSS module clocks. All three modules have the same clock control
+ * hence the EPMSSx to signify these values are consistent across all
+ * EPWMSS instances. */
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE_ENABLE   (0x2u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE   (0x0003u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST_FUNC  (0x0u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST_SHIFT (0x0010u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST   (0x0003u)
+
+/**
+ * @brief The set of possible PWM subsystem module
+ *
+ * Enumerated type to define various instance of pwm module.
+ */
+typedef enum {
+  BBB_PWMSS0 = 0,
+  BBB_PWMSS1,
+  BBB_PWMSS2,
+  BBB_PWMSS_COUNT
+} BBB_PWMSS;
+
+
+rtems_status_code pwmss_module_clk_config(BBB_PWMSS pwmss_id);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LIBBSP_ARM_BEAGLE_PWMSS_H */
diff --git a/bsps/arm/beagle/include/bsp/qep.h 
b/bsps/arm/beagle/include/bsp/qep.h
new file mode 100644
index 00..671d9cca6c
--- /dev/null
+++ b/bsps/arm/beagle/include/bsp/qep.h
@@ -0,0 +1,331 @@
+/**
+ * @file
+ *
+ * @ingroup arm_beagle
+ *
+ * @brief eQEP (enhanced Quadrature Encoder Pulse) support API.
+ */
+
+/**
+ * Copyright (c) 2020 James Fitzsimons 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *
+ * For details of the Enhanced Quadrature Encoder Pulse (eQEP) Module refer to
+ * page 2511 of the TI Technical Reference Manual
+ * (https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf)
+ *
+ * This driver supports using the QEP modules in Quadrature-clock Mode.
+ * Direction-count Mode is not currently supported. Similarly the QEPI: Index
+ * or Zero Marker and QEPS: Strobe Input pins are not currently supported.
+ *
+ * The mode can be any one of:
+ *  - Quadrature-count mode - For encoders that generate pulses 90 degrees
+ *  out of phase for determining direction and speed.
+ *  - Direction-count mode - for position encoders that provide direction and
+ *  clock outputs, instead of quadrature outputs.
+ *  - UP-count mode - The counter direction signal is hard-wired for u

[PATCH 0/1] Adds QEP driver to Beaglebone BSP

2020-08-21 Thread James Fitzsimons
This patch adds driver support for the eQEP (enhanced Quadrature Encoder Pulse) 
module within each of the PWMSS units in the AM335x. The eQEP module is used 
for 
hardware decoding of rotrary encoders, motor encoders etc. 

Because the PWMSS module includes several components some of the existing code 
in
the pwm driver could be reused. To make this common I have added a pwmss.h 
header
and moved some of the pwmss specific defines and enum to this file. The pwmss.c
file contains a refactored (simplified) version of the clock configuration
method that was previously in the pwm.c file. The pwmss_module_clk_config will
now be shared by both the pwm and eqep drivers (and eventually the ecap driver 
if
that is ever added).

The approach taken with the qep.h header was to move some of the qep specific 
defines from the am335x.h header to this file. They are specific to the qep 
function and would likely never be referenced by anything other than this 
driver.
Doing this keeps these definitions with the driver code and reduces clutter in 
am335x.h header.

The driver supports two primary modes of operation. A polled mode (which is the
default mode), and an interrupt event driven mode.

The one area of the patch that I am least happy with and could do with some 
advice on 
is the callback approach I have used for the interrupt event driven model. Here 
a 
unit timer is configured with a set time period (in nanoseconds) and on expiry 
the unit
timer raises an interrupt. The interrupt handler calls an optional callback 
function that
the user can supply when setting the unit timer period via the 
beagle_eqep_set_timer_period. Although this works ok, I realise that calling a 
user 
function from a OS level interrupt is not desirable. Better suggestions for 
this would be
gratefully received.

I will send a follow up email including some sample test programs with their 
associated 
output.

Regards,
James

James Fitzsimons (1):
  Adding QEP driver to Beaglebone bsp

 bsps/arm/beagle/headers.am  |   2 +
 bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
 bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
 bsps/arm/beagle/include/bsp/qep.h   | 331 ++
 bsps/arm/beagle/pwm/pwm.c   |  64 +---
 bsps/arm/beagle/pwmss/pwmss.c   |  64 
 bsps/arm/beagle/qep/qep.c   | 435 
 c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
 8 files changed, 896 insertions(+), 71 deletions(-)
 create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
 create mode 100644 bsps/arm/beagle/include/bsp/qep.h
 create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
 create mode 100644 bsps/arm/beagle/qep/qep.c

-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


QEP driver patch example programs and output

2020-08-21 Thread James Fitzsimons
Hi all,

Further to the patch I have just submitted I thought it would be useful for
any reviewers to have the following example programs and output as a
reference when reviewing the patch.

Thanks in advance for your review and feedback.

Regards,
James Fitzsimons
U-Boot SPL 2019.04-2-g07d5700e21 (Mar 06 2020 - 11:24:55 -0600)
Trying to boot from MMC2
Loading Environment from EXT4... 
** Unable to use mmc 0:1 for loading the env **


U-Boot 2019.04-2-g07d5700e21 (Mar 06 2020 - 11:24:55 -0600), Build: 
jenkins-github_Bootloader-Builder-137

CPU  : AM335X-GP rev 2.1
I2C:   ready
DRAM:  512 MiB
No match for driver 'omap_hsmmc'
No match for driver 'omap_hsmmc'
Some drivers were not found
Reset Source: Power-on reset has occurred.
RTC 32KCLK Source: External.
MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from EXT4... 
** Unable to use mmc 0:1 for loading the env **
Board: BeagleBone Black
 not set. Validating first E-fuse MAC
BeagleBone Black:
Model: BeagleBoard.org BeagleBone Black Wireless:
BeagleBone: cape eeprom: i2c_probe: 0x54:
BeagleBone: cape eeprom: i2c_probe: 0x55:
BeagleBone: cape eeprom: i2c_probe: 0x56:
BeagleBone: cape eeprom: i2c_probe: 0x57:
Net:   eth0: MII MODE
Could not get PHY for cpsw: addr 0
cpsw, usb_ether
Press SPACE to abort autoboot in 0 seconds
board_name=[BBBW] ...
switch to partitions #0, OK
mmc0 is current device
SD/MMC found on device 0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
53130 bytes read in 6 ms (8.4 MiB/s)
gpio: pin 56 (gpio 56) value is 0
gpio: pin 55 (gpio 55) value is 0
gpio: pin 54 (gpio 54) value is 0
gpio: pin 53 (gpio 53) value is 1
switch to partitions #0, OK
mmc0 is current device
gpio: pin 54 (gpio 54) value is 1
Checking for: /uEnv.txt ...
282 bytes read in 2 ms (137.7 KiB/s)
gpio: pin 55 (gpio 55) value is 1
Loaded environment from /uEnv.txt
Importing environment from mmc ...
Checking if uenvcmd is set ...
gpio: pin 56 (gpio 56) value is 1
Running uenvcmd ...
86538 bytes read in 8 ms (10.3 MiB/s)
53130 bytes read in 6 ms (8.4 MiB/s)
373 bytes read in 2 ms (181.6 KiB/s)
## Booting kernel from Legacy Image at 8080 ...
   Image Name:   RTEMS
   Created:  2020-08-21   9:28:55 UTC
   Image Type:   ARM Linux Kernel Image (gzip compressed)
   Data Size:86474 Bytes = 84.4 KiB
   Load Address: 8000
   Entry Point:  8000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 8800
   Booting using the fdt blob at 0x8800
   Uncompressing Kernel Image ... OK
   Loading Device Tree to 8ffef000, end 8fff ... OK

Starting kernel ...


RTEMS Beagleboard: am335x-based
ARM Debug: 0x4b141000
Initialising QEP
Setting Quadrature mode to relative
Setting unit timer to 1s
Completed initialising QEP
clock is running true
Enabling PWM  output
Value of qep position is -4936
Value of qep position is -5382
Value of qep position is -5400
Value of qep position is -5403
Value of qep position is -5406
Value of qep position is -5413
Value of qep position is -5418
Value of qep position is -5421
Value of qep position is -5421
Value of qep position is -5422
Value of qep position is -5422
Value of qep position is -5431
Value of qep position is -5435
Value of qep position is -5434
Value of qep position is -5438
Value of qep position is -5437
Value of qep position is -5440
Value of qep position is -5444
Value of qep position is -5444
PWM disabled. Test finished.

*** FATAL ***
fatal source: 0 (INTERNAL_ERROR_CORE)
fatal code: 5 (INTERNAL_ERROR_THREAD_EXITTED)
/*
 * Copyright (c) 2020 
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 


static void
Init(rtems_task_argument arg)
{
rtems_status_code sc;
bool success;
int32_t position = 0;

/*Initialize GPIO pins in BBB*/
rtems_gpio_initialize();

sc = rtems_gp

Re: [PATCH 1/1] Adding QEP driver to Beaglebone bsp

2020-08-23 Thread James Fitzsimons
Hi Chris,

On Sat, 22 Aug 2020 at 20:41, Chris Johns  wrote:

> On 21/8/20 8:01 pm, James Fitzsimons wrote:
> ...
> > +
> > +
> > +typedef void (*bbb_eqep_timer_callback)(BBB_PWMSS);
>
> What is BBB_PWMSS used for as an argument?
>

The BBB_PWMSS argument is provided to the user call back function so that
the user knows which QEP module raised the interrupt. It is quite likely
that a user would have multiple QEP modules configured. Thinking about this
now, the call back could also have the count provided as an argument so the
user doesn't need to call the "int32_t beagle_qep_get_position(BBB_PWMSS
pwmss_id);" function from their call back handler.

>
> Could a `void* user` be passed back? It helps if the interrupt provides a
> user
> specific data pointer.
>

I'm sorry I don't understand what you mean here. Do you mean the argument
to the call back should be "void* user" which presumably would be a pointer
to an arbitrary data structure?


> > +
> > +
> > +/**
> > + * @brief This structure represents an eQEP module instance.
> > + *
> > + * The members are closely modelled on the FDT structure. *
> > + */
> > +typedef struct {
> > +  const BBB_PWMSS pwmss_id;
> > +  const uint32_t mmio_base;
> > +  const rtems_vector_number irq;
> > +  bbb_eqep_timer_callback timer_callback;
>
> Is this part of the FDT? I think some extra documentation here would be
> good to
> have.
>

Good catch - that comment needs updating. When I first added the bbb_eqep
structure it did closely resemble the structure used in the FDT
configuration (at least for Linux). However, I then added additional
members such as the rtems_vector_number and the bbb_eqep_timer_callback
which have no relationship to the FDT. I can update the comment to more
accurately reflect the current state.

>
> Can we have a `void* user;`?
>

Are you suggesting replacing "bbb_eqep_timer_callback timer_callback;" with
"void* user;"? If so yes I can do that. Is there a convention for passing
arguments to that function from the interrupt handler?

Many thanks for your review and comments!

Cheers,
James

>
> Thanks
> Chris
>
> > +  BBB_QEP_COUNT_MODE count_mode;
> > +  BBB_QEP_QUADRATURE_MODE quadrature_mode;
> > +  uint32_t invert_qa;
> > +  uint32_t invert_qb;
> > +  uint32_t invert_qi;
> > +  uint32_t invert_qs;
> > +  uint32_t swap_inputs;
> > +} bbb_eqep;
> > +
> > +
> > +/**
> > + * @brief Initialises the eQEP module of the specified PWMSS unit. This
> > + * configures the clocks, sets up the interrupt handler and unit timer,
> > + * The module is configured in Quadrature decode mode using
> > + * absolute position by default.
> > + *
> > + * @param pwmss_id The PWMSS module to configure the eQEP for.
> > + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid
> pwmss_id is
> > + * supplied.
> > + */
> > +rtems_status_code beagle_qep_init(BBB_PWMSS pwmss_id);
> > +
> > +/**
> > + * @brief Enables the eQEP module of the specified PWMSS unit.
> > + *
> > + * @param pwmss_id The PWMSS module which will have the eQEP function
> enabled.
> > + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid
> pwmss_id is
> > + * supplied.
> > + */
> > +rtems_status_code beagle_qep_enable(BBB_PWMSS pwmss_id);
> > +
> > +/**
> > + * @brief Disables the eQEP module of the specified PWMSS unit.
> > + *
> > + * @param pwmss_id The PWMSS module which will have the eQEP function
> disabled.
> > + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid
> pwmss_id is
> > + * supplied.
> > + */
> > +rtems_status_code beagle_qep_disable(BBB_PWMSS pwmss_id);
> > +
> > +/**
> > + * @brief Configures a given pin for use with the eQEP function of the
> supplied
> > + * PWMSS module.
> > + *
> > + * @param pin_no The P9 or P8 header pin to be configured for the eQEP
> function.
> > + * @param pwmss_id The PWMSS module which will have the eQEP function
> enabled.
> > + * @param pullup_enable If true then the internal pull up resistor on
> the
> > + * specified pin will be enabled, if false the pull down will be
> enabled.
> > + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid
> pwmss_id is
> > + * supplied.
> > + */
> > +rtems_status_code beagle_qep_pinmux_setup(
> > +  bbb_qep_pin pin_no,
> > +  BBB_PWMSS pwmss_id,
> > +  bool pullup_enable
> > +);
> > +
> > +/**
> > + * @brief Returns the current position value of the eQEP function for
> the
> >

[PATCH v2 2/2] bsp: improved documentation in Beaglebone qep driver

2020-08-25 Thread James Fitzsimons
---
 bsps/arm/beagle/include/bsp/qep.h | 59 ---
 bsps/arm/beagle/qep/qep.c | 14 ++--
 2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/bsps/arm/beagle/include/bsp/qep.h 
b/bsps/arm/beagle/include/bsp/qep.h
index 671d9cca6c..fc086e3c80 100644
--- a/bsps/arm/beagle/include/bsp/qep.h
+++ b/bsps/arm/beagle/include/bsp/qep.h
@@ -168,19 +168,63 @@ typedef enum {
 } bbb_qep_pin;
 
 
-typedef void (*bbb_eqep_timer_callback)(BBB_PWMSS);
+/**
+ * @brief This function definition is used to declare a callback function that
+ * will be called by the interrupt handler of the QEP driver. In order for the
+ * interrupt event to trigger the driver must be configured in RELATIVE mode
+ * (using the beagle_qep_get_quadrature_mode function), and the unit timer must
+ * have been configured (using the beagle_eqep_set_timer_period function).
+ *
+ * @param BBB_PWMSS This argument is provided to the user call back function so
+ * that the user can tell which QEP module raised the interrupt.
+ *
+ * @param position The value of the position counter that was latched when the
+ * unit timer raised this interrupt. This is the value that would be returned
+ * by calling "beagle_qep_get_position".
+ *
+ * @param user This a pointer to a user provided data structure. The user sets
+ * this pointer value when configuring the unit timer callback via the
+ * beagle_eqep_set_timer_period function and it is returned here as an 
argument.
+ * The driver does not touch this value.
+ */
+typedef void (*bbb_eqep_timer_callback)(
+  BBB_PWMSS,
+  uint32_t position,
+  void* user
+);
 
 
 /**
- * @brief This structure represents an eQEP module instance.
+ * @brief This structure represents an eQEP module instance. The members
+ * represent the configuration of a specific eQEP module. There are three
+ * eQEP modules in the AM335x, one associated with each PWMSS unit.
+ * @var bbb_eqep::pwmss_id The PWMSS unit this eQEP module belongs to.
+ * @var bbb_eqep::mmio_base The base address for this eQEP modules registers
+ * @var bbb_eqep::irq The IRQ vector for this eQEP module
+ * @var bbb_eqep::timer_callback An optional user provided callback function
+ * when the driver is configured in RELATIVE mode using the unit timer
+ * @var bbb_eqep::user An optional pointer to user provided data that will be
+ * handed to the callback function as an argument.
+ * @var bbb_eqep::count_mode The count mode for this eQEP module. Defaults to
+ * QUADRATURE.
+ * @var bbb_eqep::quadrature_mode The mode for QUADRATURE operation. Defaults
+ * to ABSOLUTE - will count up to overflow or until the user resets the
+ * position. Can be set to RELATIVE which will trigger a call back of the unit
+ * timer if configured.
+ * @var bbb_eqep::invert_qa 1 to invert the A channel input, 0 to leave as is.
+ * @var bbb_eqep::invert_qb 1 to invert the B channel input, 0 to leave as is.
+ * @var bbb_eqep::invert_qi 1 to invert the INDEX input, 0 to leave as is.
+ * @var bbb_eqep::invert_qs 1 to invert the STROBE input, 0 to leave as is.
+ * @var bbb_eqep::swap_inputs 1 to swap the A and B channel inputs, 0 to leave
+ * as is.
  *
- * The members are closely modelled on the FDT structure. *
  */
 typedef struct {
   const BBB_PWMSS pwmss_id;
   const uint32_t mmio_base;
   const rtems_vector_number irq;
   bbb_eqep_timer_callback timer_callback;
+  void* user;
   BBB_QEP_COUNT_MODE count_mode;
   BBB_QEP_QUADRATURE_MODE quadrature_mode;
   uint32_t invert_qa;
@@ -315,13 +359,20 @@ uint32_t beagle_eqep_get_timer_period(BBB_PWMSS pwmss_id);
  * 0 = off, greater than zero sets the period.
  * @param pwmss_id Identifies which PWMSS module to set the eQEP unit timer 
for.
  * @param period The value in nanoseconds to set the unit timer period to.
+ * @param timer_callback This is the user provided callback function that will
+ * be called by the interrupt event handler on expiry of the unit timer. The
+ * user can provide NULL if they don't require a call back.
+ * @param user This is a pointer to a user provided data structure that will be
+ * handed back as an argument to the timer callback. The driver does not touch
+ * this value.
  * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is
  * supplied.
  */
 rtems_status_code beagle_eqep_set_timer_period(
 BBB_PWMSS pwmss_id,
 uint64_t period,
-bbb_eqep_timer_callback timer_callback
+bbb_eqep_timer_callback timer_callback,
+void* user
 );
 
 #ifdef __cplusplus
diff --git a/bsps/arm/beagle/qep/qep.c b/bsps/arm/beagle/qep/qep.c
index d0fc9fc6ba..34eb453258 100644
--- a/bsps/arm/beagle/qep/qep.c
+++ b/bsps/arm/beagle/qep/qep.c
@@ -35,6 +35,7 @@ static bbb_eqep bbb_eqep_table[ BBB_PWMSS_COUNT ] =
   .mmio_base = AM335X_EQEP_0_REGS,
   .irq = AM335X_INT_eQEP0INT,
   .timer_callback = NULL,
+  .user = NULL,
   .count_mode = QUADRATURE_COUNT,
   .quadrature_mode = ABSOLUTE,
   .invert_qa = 0,
@@ -48,6 +49,7 @@ static bbb_eqep bbb_eqep_table[ BBB_PWM

[PATCH v2 0/2] Adds QEP driver to Beaglebone BSP

2020-08-25 Thread James Fitzsimons
This second version of the patch  includes:
 - improved documentation
 - addition of void* user argument to interrupt callback
 - addition of position value arg to interrupt callback

James Fitzsimons (2):
  Adding QEP driver to Beaglebone bsp
  bsp: improved documentation in Beaglebone qep driver

 bsps/arm/beagle/headers.am  |   2 +
 bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
 bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
 bsps/arm/beagle/include/bsp/qep.h   | 382 
 bsps/arm/beagle/pwm/pwm.c   |  64 +---
 bsps/arm/beagle/pwmss/pwmss.c   |  64 
 bsps/arm/beagle/qep/qep.c   | 445 
 c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
 8 files changed, 957 insertions(+), 71 deletions(-)
 create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
 create mode 100644 bsps/arm/beagle/include/bsp/qep.h
 create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
 create mode 100644 bsps/arm/beagle/qep/qep.c

-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2 1/2] Adding QEP driver to Beaglebone bsp

2020-08-25 Thread James Fitzsimons
---
 bsps/arm/beagle/headers.am  |   2 +
 bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
 bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
 bsps/arm/beagle/include/bsp/qep.h   | 331 ++
 bsps/arm/beagle/pwm/pwm.c   |  64 +---
 bsps/arm/beagle/pwmss/pwmss.c   |  64 
 bsps/arm/beagle/qep/qep.c   | 435 
 c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
 8 files changed, 896 insertions(+), 71 deletions(-)
 create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
 create mode 100644 bsps/arm/beagle/include/bsp/qep.h
 create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
 create mode 100644 bsps/arm/beagle/qep/qep.c

diff --git a/bsps/arm/beagle/headers.am b/bsps/arm/beagle/headers.am
index 4dc35f2e2a..e4a746b2e1 100644
--- a/bsps/arm/beagle/headers.am
+++ b/bsps/arm/beagle/headers.am
@@ -13,3 +13,5 @@ include_bsp_HEADERS += 
../../../../../../bsps/arm/beagle/include/bsp/beagleboneb
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/i2c.h
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/irq.h
 include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/spi.h
+include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/qep.h
+include_bsp_HEADERS += ../../../../../../bsps/arm/beagle/include/bsp/pwmss.h
diff --git a/bsps/arm/beagle/include/bsp/bbb-pwm.h 
b/bsps/arm/beagle/include/bsp/bbb-pwm.h
index cf5d6fe552..6fdba486be 100644
--- a/bsps/arm/beagle/include/bsp/bbb-pwm.h
+++ b/bsps/arm/beagle/include/bsp/bbb-pwm.h
@@ -31,17 +31,6 @@ extern "C" {
 #define BBB_CONTROL_CONF_GPMC_AD(n)   (0x800 + (n * 4))
 #define BBB_CONTROL_CONF_LCD_DATA(n)   (0x8a0 + (n * 4))
 
-/**
- * @brief The set of possible PWM subsystem module
- *
- * Enumerated type to define various instance of pwm module.
- */
-typedef enum{
-  BBB_PWMSS0 = 0,
-  BBB_PWMSS1,
-  BBB_PWMSS2,
-  BBB_PWMSS_COUNT
-}BBB_PWMSS;
 
 typedef enum{
   BBB_P8_13_2B = 3,
diff --git a/bsps/arm/beagle/include/bsp/pwmss.h 
b/bsps/arm/beagle/include/bsp/pwmss.h
new file mode 100644
index 00..3a9dcbb70a
--- /dev/null
+++ b/bsps/arm/beagle/include/bsp/pwmss.h
@@ -0,0 +1,54 @@
+/**
+ * @file
+ *
+ * @ingroup arm_beagle
+ *
+ * @brief Shared PWMSS module functions used by PWM, eQEP and eCAP (when 
added).
+ */
+
+/**
+ * Copyright (c) 2020 James Fitzsimons 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *.
+ */
+
+#ifndef LIBBSP_ARM_BEAGLE_PWMSS_H
+#define LIBBSP_ARM_BEAGLE_PWMSS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* The following definitions are bitmasks for the clk control registers for
+ * the PWMSS module clocks. All three modules have the same clock control
+ * hence the EPMSSx to signify these values are consistent across all
+ * EPWMSS instances. */
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE_ENABLE   (0x2u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE   (0x0003u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST_FUNC  (0x0u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST_SHIFT (0x0010u)
+#define AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST   (0x0003u)
+
+/**
+ * @brief The set of possible PWM subsystem module
+ *
+ * Enumerated type to define various instance of pwm module.
+ */
+typedef enum {
+  BBB_PWMSS0 = 0,
+  BBB_PWMSS1,
+  BBB_PWMSS2,
+  BBB_PWMSS_COUNT
+} BBB_PWMSS;
+
+
+rtems_status_code pwmss_module_clk_config(BBB_PWMSS pwmss_id);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LIBBSP_ARM_BEAGLE_PWMSS_H */
diff --git a/bsps/arm/beagle/include/bsp/qep.h 
b/bsps/arm/beagle/include/bsp/qep.h
new file mode 100644
index 00..671d9cca6c
--- /dev/null
+++ b/bsps/arm/beagle/include/bsp/qep.h
@@ -0,0 +1,331 @@
+/**
+ * @file
+ *
+ * @ingroup arm_beagle
+ *
+ * @brief eQEP (enhanced Quadrature Encoder Pulse) support API.
+ */
+
+/**
+ * Copyright (c) 2020 James Fitzsimons 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *
+ * For details of the Enhanced Quadrature Encoder Pulse (eQEP) Module refer to
+ * page 2511 of the TI Technical Reference Manual
+ * (https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf)
+ *
+ * This driver supports using the QEP modules in Quadrature-clock Mode.
+ * Direction-count Mode is not currently supported. Similarly the QEPI: Index
+ * or Zero Marker and QEPS: Strobe Input pins are not currently supported.
+ *
+ * The mode can be any one of:
+ *  - Quadrature-count mode - For encoders that generate pulses 90 degrees
+ *  out of phase for determining direction and speed.
+ *  - Direction-count mode - for position encoders that provide direction and
+ *  clock outputs, instead of quadrature outputs.
+ *  - UP-count mode - The counter direction signal is hard-wired for u

Re: [PATCH v2 0/2] Adds QEP driver to Beaglebone BSP

2020-09-03 Thread James Fitzsimons
Hi all,

I realise people have been busy with the recent release etc so I hadn't
followed this up. Are the changes I made in this new version sufficient or
is there still work to do on this driver?

Cheers
James

On Tue, 25 Aug 2020, 21:57 James Fitzsimons, 
wrote:

> This second version of the patch  includes:
>  - improved documentation
>  - addition of void* user argument to interrupt callback
>  - addition of position value arg to interrupt callback
>
> James Fitzsimons (2):
>   Adding QEP driver to Beaglebone bsp
>   bsp: improved documentation in Beaglebone qep driver
>
>  bsps/arm/beagle/headers.am  |   2 +
>  bsps/arm/beagle/include/bsp/bbb-pwm.h   |  11 -
>  bsps/arm/beagle/include/bsp/pwmss.h |  54 +++
>  bsps/arm/beagle/include/bsp/qep.h   | 382 
>  bsps/arm/beagle/pwm/pwm.c   |  64 +---
>  bsps/arm/beagle/pwmss/pwmss.c   |  64 
>  bsps/arm/beagle/qep/qep.c   | 445 
>  c/src/lib/libbsp/arm/beagle/Makefile.am |   6 +
>  8 files changed, 957 insertions(+), 71 deletions(-)
>  create mode 100644 bsps/arm/beagle/include/bsp/pwmss.h
>  create mode 100644 bsps/arm/beagle/include/bsp/qep.h
>  create mode 100644 bsps/arm/beagle/pwmss/pwmss.c
>  create mode 100644 bsps/arm/beagle/qep/qep.c
>
> --
> 2.17.1
>
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel