<div dir="ltr"><div>Hi Chris,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 22 Aug 2020 at 20:41, Chris Johns <<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 21/8/20 8:01 pm, James Fitzsimons wrote:<br>...<br>
> +<br>
> +<br>
> +typedef void (*bbb_eqep_timer_callback)(BBB_PWMSS);<br>
<br>
What is BBB_PWMSS used for as an argument?<br></blockquote><div><br></div><div>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.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Could a `void* user` be passed back? It helps if the interrupt provides a user<br>
specific data pointer.<br></blockquote><div><br></div><div>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?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +<br>
> +<br>
> +/**<br>
> + * @brief This structure represents an eQEP module instance.<br>
> + *<br>
> + * The members are closely modelled on the FDT structure. *<br>
> + */<br>
> +typedef struct {<br>
> + const BBB_PWMSS pwmss_id;<br>
> + const uint32_t mmio_base;<br>
> + const rtems_vector_number irq;<br>
> + bbb_eqep_timer_callback timer_callback;<br>
<br>
Is this part of the FDT? I think some extra documentation here would be good to<br>
have.<br></blockquote><div><br></div><div>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. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Can we have a `void* user;`?<br></blockquote><div><br></div><div>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?</div><div> </div><div>Many thanks for your review and comments!</div><div><br></div><div>Cheers,</div><div>James </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Thanks<br>
Chris<br>
<br>
> + BBB_QEP_COUNT_MODE count_mode;<br>
> + BBB_QEP_QUADRATURE_MODE quadrature_mode;<br>
> + uint32_t invert_qa;<br>
> + uint32_t invert_qb;<br>
> + uint32_t invert_qi;<br>
> + uint32_t invert_qs;<br>
> + uint32_t swap_inputs;<br>
> +} bbb_eqep;<br>
> +<br>
> +<br>
> +/**<br>
> + * @brief Initialises the eQEP module of the specified PWMSS unit. This<br>
> + * configures the clocks, sets up the interrupt handler and unit timer,<br>
> + * The module is configured in Quadrature decode mode using<br>
> + * absolute position by default.<br>
> + *<br>
> + * @param pwmss_id The PWMSS module to configure the eQEP for.<br>
> + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is<br>
> + * supplied.<br>
> + */<br>
> +rtems_status_code beagle_qep_init(BBB_PWMSS pwmss_id);<br>
> +<br>
> +/**<br>
> + * @brief Enables the eQEP module of the specified PWMSS unit.<br>
> + *<br>
> + * @param pwmss_id The PWMSS module which will have the eQEP function enabled.<br>
> + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is<br>
> + * supplied.<br>
> + */<br>
> +rtems_status_code beagle_qep_enable(BBB_PWMSS pwmss_id);<br>
> +<br>
> +/**<br>
> + * @brief Disables the eQEP module of the specified PWMSS unit.<br>
> + *<br>
> + * @param pwmss_id The PWMSS module which will have the eQEP function disabled.<br>
> + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is<br>
> + * supplied.<br>
> + */<br>
> +rtems_status_code beagle_qep_disable(BBB_PWMSS pwmss_id);<br>
> +<br>
> +/**<br>
> + * @brief Configures a given pin for use with the eQEP function of the supplied<br>
> + * PWMSS module.<br>
> + *<br>
> + * @param pin_no The P9 or P8 header pin to be configured for the eQEP function.<br>
> + * @param pwmss_id The PWMSS module which will have the eQEP function enabled.<br>
> + * @param pullup_enable If true then the internal pull up resistor on the<br>
> + * specified pin will be enabled, if false the pull down will be enabled.<br>
> + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is<br>
> + * supplied.<br>
> + */<br>
> +rtems_status_code beagle_qep_pinmux_setup(<br>
> + bbb_qep_pin pin_no,<br>
> + BBB_PWMSS pwmss_id,<br>
> + bool pullup_enable<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Returns the current position value of the eQEP function for the<br>
> + * specified PWMSS module.<br>
> + *<br>
> + * @param pwmss_id Identifies which PWMSS module to return the eQEP position for<br>
> + * @return int32_t The current position value.<br>
> + */<br>
> +int32_t beagle_qep_get_position(BBB_PWMSS pwmss_id);<br>
> +<br>
> +/**<br>
> + * @brief Sets the initial position value of the eQEP function for the<br>
> + * specified PWMSS module.<br>
> + *<br>
> + * @param pwmss_id Identifies which PWMSS module to set the eQEP position for<br>
> + * @param position The value to initialise the position register with.<br>
> + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is<br>
> + * supplied.<br>
> + */<br>
> +rtems_status_code beagle_qep_set_position(<br>
> + BBB_PWMSS pwmss_id,<br>
> + uint32_t position<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Sets the count mode for the eQEP module.<br>
> + * @param pwmss_id Identifies which PWMSS module to set the eQEP count mode for.<br>
> + * @param mode One of the above modes to configure the eQEP module for.<br>
> + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is<br>
> + * supplied.<br>
> + */<br>
> +rtems_status_code beagle_qep_set_count_mode(<br>
> + BBB_PWMSS pwmss_id,<br>
> + BBB_QEP_COUNT_MODE mode<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets the currently configured count mode for the eQEP module.<br>
> + * @param pwmss_id Identifies which PWMSS module to set the eQEP count mode for.<br>
> + * @return An enum value representing the current count mode.<br>
> + */<br>
> +BBB_QEP_COUNT_MODE beagle_qep_get_count_mode(BBB_PWMSS pwmss_id);<br>
> +<br>
> +/**<br>
> + * @brief Returns the currently configured quadrature mode - either absolute,<br>
> + * or relative.<br>
> + * @param pwmss_id Identifies which PWMSS module to get the eQEP quadrature<br>
> + * mode for.<br>
> + * @return BBB_QEP_QUADRATURE_MODE The currently configured quadrature mode.<br>
> + */<br>
> +BBB_QEP_QUADRATURE_MODE beagle_qep_get_quadrature_mode(BBB_PWMSS pwmss_id);<br>
> +<br>
> +/**<br>
> + * @brief Sets the quadrature mode to either absolute or relative.<br>
> + * @param pwmss_id Identifies which PWMSS module to set the eQEP quadrature<br>
> + * mode for.<br>
> + * @param mode BBB_QEP_QUADRATURE_MODE Set the mode of the eQEP to either<br>
> + * absolute or relative.<br>
> + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is<br>
> + * supplied.<br>
> + */<br>
> +rtems_status_code beagle_qep_set_quadrature_mode(<br>
> + BBB_PWMSS pwmss_id,<br>
> + BBB_QEP_QUADRATURE_MODE mode<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Returns the the currently configured unit timer period.<br>
> + * @param pwmss_id Identifies which PWMSS module to get the eQEP timer value for<br>
> + * @return uint32_t The current unit timer value in nanoseconds<br>
> + */<br>
> +uint32_t beagle_eqep_get_timer_period(BBB_PWMSS pwmss_id);<br>
> +<br>
> +/**<br>
> + * @brief Sets the unit timer period for the eQEP module.<br>
> + * 0 = off, greater than zero sets the period.<br>
> + * @param pwmss_id Identifies which PWMSS module to set the eQEP unit timer for.<br>
> + * @param period The value in nanoseconds to set the unit timer period to.<br>
> + * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_ID if an invalid pwmss_id is<br>
> + * supplied.<br>
> + */<br>
> +rtems_status_code beagle_eqep_set_timer_period(<br>
> + BBB_PWMSS pwmss_id,<br>
> + uint64_t period,<br>
> + bbb_eqep_timer_callback timer_callback<br>
> +);<br>
> +<br>
> +#ifdef __cplusplus<br>
> +}<br>
> +#endif /* __cplusplus */<br>
> +<br>
> +#endif /* LIBBSP_ARM_BEAGLE_QEP_H */<br>
> diff --git a/bsps/arm/beagle/pwm/pwm.c b/bsps/arm/beagle/pwm/pwm.c<br>
> index 0bc5d125bf..4bd09293e8 100644<br>
> --- a/bsps/arm/beagle/pwm/pwm.c<br>
> +++ b/bsps/arm/beagle/pwm/pwm.c<br>
> @@ -23,6 +23,7 @@<br>
> #include <bsp/gpio.h><br>
> #include <bsp/bbb-gpio.h><br>
> #include <bsp.h><br>
> +#include <bsp/pwmss.h><br>
> #include <bsp/bbb-pwm.h><br>
> #include <bsp/beagleboneblack.h><br>
> <br>
> @@ -38,7 +39,7 @@<br>
> * @param pwm_id It is the instance number of EPWM of pwm sub system.<br>
> * <br>
> * @return Base Address of respective pwm instant.<br>
> -*/<br>
> + */<br>
> static uint32_t select_pwm(BBB_PWMSS pwm_id)<br>
> {<br>
> uint32_t baseAddr=0;<br>
> @@ -102,9 +103,9 @@ bool beagle_pwm_pinmux_setup(bbb_pwm_pin_t pin_no, BBB_PWMSS pwm_id)<br>
> } else if (pin_no == BBB_P8_36_1A) {<br>
> REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_LCD_DATA(10)) = BBB_MUXMODE(BBB_P8_36_MUX_PWM);<br>
> } else if (pin_no == BBB_P9_14_1A) {<br>
> - REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(2)) = BBB_MUXMODE(BBB_P9_14_MUX_PWM);<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_GPMC_A2) = BBB_MUXMODE(BBB_P9_14_MUX_PWM);<br>
> } else if (pin_no == BBB_P9_16_1B) {<br>
> - REG(AM335X_PADCONF_BASE + BBB_CONTROL_CONF_GPMC_AD(3)) = BBB_MUXMODE(BBB_P9_16_MUX_PWM);<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_GPMC_A3) = BBB_MUXMODE(BBB_P9_16_MUX_PWM);<br>
> } else { <br>
> is_valid = false;<br>
> }<br>
> @@ -181,63 +182,6 @@ static bool pwm_clock_enable(BBB_PWMSS pwm_id)<br>
> return status;<br>
> }<br>
> <br>
> -/**<br>
> - * @brief This function configures the L3 and L4_PER system clocks.<br>
> - * It also configures the system clocks for the specified ePWMSS<br>
> - * instance.<br>
> - *<br>
> - * @param pwmss_id The instance number of ePWMSS whose system clocks<br>
> - * have to be configured.<br>
> - *<br>
> - * 'pwmss_id' can take one of the following values:<br>
> - * (0 <= pwmss_id <= 2)<br>
> - *<br>
> - * @return True if successful<br>
> - * False if Unsuccessful <br>
> - */<br>
> -static bool pwmss_module_clk_config(BBB_PWMSS pwmss_id)<br>
> -{<br>
> - bool is_valid = true;<br>
> - <br>
> - if(pwmss_id == BBB_PWMSS0) {<br>
> - const uint32_t is_functional = AM335X_CM_PER_EPWMSS0_CLKCTRL_IDLEST_FUNC <<<br>
> - AM335X_CM_PER_EPWMSS0_CLKCTRL_IDLEST_SHIFT;<br>
> - const uint32_t clkctrl = AM335X_CM_PER_ADDR + AM335X_CM_PER_EPWMSS0_CLKCTRL;<br>
> - const uint32_t idle_bits = AM335X_CM_PER_EPWMSS0_CLKCTRL_IDLEST;<br>
> - const uint32_t is_enable = AM335X_CM_PER_EPWMSS0_CLKCTRL_MODULEMODE_ENABLE;<br>
> - const uint32_t module_mode = AM335X_CM_PER_EPWMSS0_CLKCTRL_MODULEMODE;<br>
> - <br>
> - REG(clkctrl) |= is_enable;<br>
> - while((REG(clkctrl) & module_mode) != is_enable);<br>
> - while((REG(clkctrl) & idle_bits) != is_functional);<br>
> - }<br>
> - else if(pwmss_id == BBB_PWMSS1) {<br>
> - const uint32_t is_functional = AM335X_CM_PER_EPWMSS1_CLKCTRL_IDLEST_FUNC <<<br>
> - AM335X_CM_PER_EPWMSS1_CLKCTRL_IDLEST_SHIFT;<br>
> - const uint32_t clkctrl = AM335X_CM_PER_ADDR + AM335X_CM_PER_EPWMSS1_CLKCTRL;<br>
> - const uint32_t idle_bits = AM335X_CM_PER_EPWMSS1_CLKCTRL_IDLEST;<br>
> - const uint32_t is_enable = AM335X_CM_PER_EPWMSS1_CLKCTRL_MODULEMODE_ENABLE;<br>
> - const uint32_t module_mode = AM335X_CM_PER_EPWMSS1_CLKCTRL_MODULEMODE;<br>
> -<br>
> - REG(clkctrl) |= is_enable;<br>
> - while((REG(clkctrl) & module_mode) != is_enable);<br>
> - while((REG(clkctrl) & idle_bits) != is_functional);<br>
> - } else if(pwmss_id == BBB_PWMSS2) {<br>
> - const uint32_t is_functional = AM335X_CM_PER_EPWMSS2_CLKCTRL_IDLEST_FUNC <<<br>
> - AM335X_CM_PER_EPWMSS2_CLKCTRL_IDLEST_SHIFT;<br>
> - const uint32_t clkctrl = AM335X_CM_PER_ADDR + AM335X_CM_PER_EPWMSS2_CLKCTRL;<br>
> - const uint32_t idle_bits = AM335X_CM_PER_EPWMSS2_CLKCTRL_IDLEST;<br>
> - const uint32_t is_enable = AM335X_CM_PER_EPWMSS2_CLKCTRL_MODULEMODE_ENABLE;<br>
> - const uint32_t module_mode = AM335X_CM_PER_EPWMSS2_CLKCTRL_MODULEMODE;<br>
> -<br>
> - REG(clkctrl) |= is_enable;<br>
> - while((REG(clkctrl) & module_mode) != is_enable);<br>
> - while((REG(clkctrl) & idle_bits) != is_functional);<br>
> - } else <br>
> - is_valid = false;<br>
> - return is_valid;<br>
> -}<br>
> -<br>
> bool beagle_pwm_init(BBB_PWMSS pwmss_id)<br>
> {<br>
> const bool id_is_valid = pwmss_id < BBB_PWMSS_COUNT;<br>
> diff --git a/bsps/arm/beagle/pwmss/pwmss.c b/bsps/arm/beagle/pwmss/pwmss.c<br>
> new file mode 100644<br>
> index 0000000000..c4d36d8ae1<br>
> --- /dev/null<br>
> +++ b/bsps/arm/beagle/pwmss/pwmss.c<br>
> @@ -0,0 +1,64 @@<br>
> +/**<br>
> + * @file<br>
> + *<br>
> + * @ingroup arm_beagle<br>
> + *<br>
> + * @brief Support for eQEP for the BeagleBone Black.<br>
> + */<br>
> +<br>
> +/**<br>
> + * Copyright (c) 2020 James Fitzsimons <<a href="mailto:james.fitzsimons@gmail.com" target="_blank">james.fitzsimons@gmail.com</a>><br>
> + *<br>
> + * The license and distribution terms for this file may be<br>
> + * found in the file LICENSE in this distribution or at<br>
> + * <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/LICENSE</a>.<br>
> + */<br>
> +<br>
> +#include <libcpu/am335x.h><br>
> +#include <stdio.h><br>
> +#include <bsp.h><br>
> +#include <bsp/pwmss.h><br>
> +#include <bsp/beagleboneblack.h><br>
> +<br>
> +<br>
> +/**<br>
> + * @brief This function configures the L3 and L4_PER system clocks.<br>
> + * It also configures the system clocks for the specified ePWMSS<br>
> + * instance.<br>
> + *<br>
> + * @param pwmss_id The instance number of ePWMSS whose system clocks<br>
> + * have to be configured.<br>
> + *<br>
> + * 'pwmss_id' can take one of the following values:<br>
> + * (0 <= pwmss_id <= 2)<br>
> + *<br>
> + * @return True if successful<br>
> + * False if Unsuccessful<br>
> + */<br>
> +rtems_status_code pwmss_module_clk_config(BBB_PWMSS pwmss_id)<br>
> +{<br>
> + uint32_t clkctrl;<br>
> +<br>
> + /* calculate the address of the clock control register for the PWMSS<br>
> + * module we are configuring */<br>
> + if(pwmss_id == BBB_PWMSS0) {<br>
> + clkctrl = AM335X_CM_PER_ADDR + AM335X_CM_PER_EPWMSS0_CLKCTRL;<br>
> + } else if(pwmss_id == BBB_PWMSS1) {<br>
> + clkctrl = AM335X_CM_PER_ADDR + AM335X_CM_PER_EPWMSS1_CLKCTRL;<br>
> + } else if(pwmss_id == BBB_PWMSS2) {<br>
> + clkctrl = AM335X_CM_PER_ADDR + AM335X_CM_PER_EPWMSS2_CLKCTRL;<br>
> + }<br>
> +<br>
> + /* when the module is functional the IDLEST bits (16 -17) of the<br>
> + * CM_PER_EPWMSSx_CLKCTRL register will be 0x0. */<br>
> + const uint32_t is_functional = 0x0;<br>
> + const uint32_t idle_bits = AM335X_CM_PER_EPWMSSx_CLKCTRL_IDLEST;<br>
> + const uint32_t is_enable = AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE_ENABLE;<br>
> + const uint32_t module_mode = AM335X_CM_PER_EPWMSSx_CLKCTRL_MODULEMODE;<br>
> +<br>
> + REG(clkctrl) |= is_enable;<br>
> + while((REG(clkctrl) & module_mode) != is_enable);<br>
> + while((REG(clkctrl) & idle_bits) != is_functional);<br>
> +<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> diff --git a/bsps/arm/beagle/qep/qep.c b/bsps/arm/beagle/qep/qep.c<br>
> new file mode 100644<br>
> index 0000000000..d0fc9fc6ba<br>
> --- /dev/null<br>
> +++ b/bsps/arm/beagle/qep/qep.c<br>
> @@ -0,0 +1,435 @@<br>
> +/**<br>
> + * @file<br>
> + *<br>
> + * @ingroup arm_beagle<br>
> + *<br>
> + * @brief Support for eQEP for the BeagleBone Black.<br>
> + */<br>
> +<br>
> +/**<br>
> + * Copyright (c) 2020 James Fitzsimons <<a href="mailto:james.fitzsimons@gmail.com" target="_blank">james.fitzsimons@gmail.com</a>><br>
> + *<br>
> + * The license and distribution terms for this file may be<br>
> + * found in the file LICENSE in this distribution or at<br>
> + * <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/LICENSE</a>.<br>
> + */<br>
> +<br>
> +#include <libcpu/am335x.h><br>
> +#include <stdio.h><br>
> +#include <stdlib.h><br>
> +#include <bsp/gpio.h><br>
> +#include <bsp/bbb-gpio.h><br>
> +#include <bsp.h><br>
> +#include <bsp/pwmss.h><br>
> +#include <bsp/qep.h><br>
> +#include <bsp/beagleboneblack.h><br>
> +<br>
> +<br>
> +/**<br>
> + * @brief Represents all the PWMSS QEP modules and their default values.<br>
> + */<br>
> +static bbb_eqep bbb_eqep_table[ BBB_PWMSS_COUNT ] =<br>
> +{<br>
> + {<br>
> + .pwmss_id = BBB_PWMSS0,<br>
> + .mmio_base = AM335X_EQEP_0_REGS,<br>
> + .irq = AM335X_INT_eQEP0INT,<br>
> + .timer_callback = NULL,<br>
> + .count_mode = QUADRATURE_COUNT,<br>
> + .quadrature_mode = ABSOLUTE,<br>
> + .invert_qa = 0,<br>
> + .invert_qb = 0,<br>
> + .invert_qi = 0,<br>
> + .invert_qs = 0,<br>
> + .swap_inputs = 0<br>
> + },<br>
> + {<br>
> + .pwmss_id = BBB_PWMSS1,<br>
> + .mmio_base = AM335X_EQEP_1_REGS,<br>
> + .irq = AM335X_INT_eQEP1INT,<br>
> + .timer_callback = NULL,<br>
> + .count_mode = QUADRATURE_COUNT,<br>
> + .quadrature_mode = ABSOLUTE,<br>
> + .invert_qa = 0,<br>
> + .invert_qb = 0,<br>
> + .invert_qi = 0,<br>
> + .invert_qs = 0,<br>
> + .swap_inputs = 0<br>
> + },<br>
> + {<br>
> + .pwmss_id = BBB_PWMSS2,<br>
> + .mmio_base = AM335X_EQEP_2_REGS,<br>
> + .irq = AM335X_INT_eQEP2INT,<br>
> + .timer_callback = NULL,<br>
> + .count_mode = QUADRATURE_COUNT,<br>
> + .quadrature_mode = ABSOLUTE,<br>
> + .invert_qa = 0,<br>
> + .invert_qb = 0,<br>
> + .invert_qi = 0,<br>
> + .invert_qs = 0,<br>
> + .swap_inputs = 0<br>
> + }<br>
> +};<br>
> +<br>
> +/* eQEP Interrupt handler */<br>
> +static void beagle_eqep_irq_handler(void *arg)<br>
> +{<br>
> + uint16_t flags;<br>
> + bbb_eqep* eqep = arg;<br>
> +<br>
> + /* Use the interrupt register (QFLG) mask to determine what caused the<br>
> + * interrupt. */<br>
> + flags = REG16(eqep->mmio_base + AM335x_EQEP_QFLG) & AM335x_EQEP_QFLG_MASK;<br>
> + /* Check the interrupt source to see if it was a unit timer overflow */<br>
> + if (flags & AM335x_EQEP_QFLG_UTO && eqep->timer_callback != NULL) {<br>
> + /* Handle the unit timer overflow interrupt */<br>
> + eqep->timer_callback(eqep->pwmss_id);<br>
> + }<br>
> +<br>
> + /* Clear interrupt flags (write back triggered flags to the clear register) */<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QCLR) = flags;<br>
> +}<br>
> +<br>
> +rtems_status_code beagle_qep_init(BBB_PWMSS pwmss_id)<br>
> +{<br>
> + rtems_status_code sc;<br>
> + uint16_t qdecctl;<br>
> +<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> +<br>
> + sc = pwmss_module_clk_config(eqep->pwmss_id);<br>
> + if (sc != RTEMS_SUCCESSFUL) {<br>
> + /* failed to successfully configure the PWMSS module clocks */<br>
> + return sc;<br>
> + }<br>
> +<br>
> + /* This enables clock for EQEP module in PWMSS subsystem. */<br>
> + REG(eqep->mmio_base + AM335X_PWMSS_CLKCONFIG) |= AM335x_EQEP_CLK_EN;<br>
> +<br>
> + /* Setup interrupt handler */<br>
> + sc = rtems_interrupt_handler_install(<br>
> + eqep->irq,<br>
> + NULL,<br>
> + RTEMS_INTERRUPT_UNIQUE,<br>
> + (rtems_interrupt_handler)beagle_eqep_irq_handler,<br>
> + (void*)eqep<br>
> + );<br>
> +<br>
> + /* The QDECCTL register configures the QEP Decoder module. We use it to set */<br>
> + /* the count mode, input inversion, channel swaps, unit timer interrupt etc. */<br>
> + qdecctl = 0;<br>
> + if (eqep->count_mode <= 3) {<br>
> + qdecctl |= eqep->count_mode << 14;<br>
> +<br>
> + /* If the count mode is UP_COUNT or DOWN_COUNT then only count on<br>
> + * the rising edge. QUADRATURE_COUNT and DIRECTION_COUNT count on<br>
> + * both edges. */<br>
> + if (eqep->count_mode >= 2) {<br>
> + qdecctl |= AM335x_EQEP_QDECCTL_XCR;<br>
> + }<br>
> + }<br>
> +<br>
> + /* Should we swap the cha and chb inputs */<br>
> + if (eqep->swap_inputs == 1) {<br>
> + qdecctl |= AM335x_EQEP_QDECCTL_SWAP;<br>
> + }<br>
> + /* Should we invert the qa input */<br>
> + if (eqep->invert_qa == 1) {<br>
> + qdecctl |= AM335x_EQEP_QDECCTL_QAP;<br>
> + }<br>
> + /* Should we invert the qb input */<br>
> + if (eqep->invert_qb == 1) {<br>
> + qdecctl |= AM335x_EQEP_QDECCTL_QBP;<br>
> + }<br>
> + /* Should we invert the index input */<br>
> + if (eqep->invert_qi == 1) {<br>
> + qdecctl |= AM335x_EQEP_QDECCTL_QIP;<br>
> +<br>
> + }<br>
> + /* Should we invert the strobe input */<br>
> + if (eqep->invert_qs == 1) {<br>
> + qdecctl |= AM335x_EQEP_QDECCTL_QSP;<br>
> + }<br>
> +<br>
> + /* Write the configured decoder control settings to the QDECCTL register */<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QDECCTL) = qdecctl;<br>
> + /* Set the position counter initialisation register */<br>
> + REG(eqep->mmio_base + AM335x_EQEP_QPOSINIT) = 0;<br>
> + /* initialise the maximum position counter value */<br>
> + REG(eqep->mmio_base + AM335x_EQEP_QPOSMAX) = ~0;<br>
> + /* initialise the position counter register */<br>
> + REG(eqep->mmio_base + AM335x_EQEP_QPOSCNT) = 0;<br>
> + /* Enable Unit Time Period interrupt. */<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QEINT) |= AM335x_EQEP_QEINT_UTO;<br>
> +<br>
> + /* The following bitmasks enable the eQEP module with:<br>
> + * - the unit timer disabled<br>
> + * - will latch the value in QPOSLAT to QPOSCNT upon unit timer overflow<br>
> + * - will latch QPOSILAT on index signal.<br>
> + * - Software initialisation of position counter (will be set to 0 because<br>
> + * QPOSINIT = 0).<br>
> + */<br>
> + uint32_t value = AM335x_EQEP_QEPCTL_QCLM | AM335x_EQEP_QEPCTL_IEL |<br>
> + AM335x_EQEP_QEPCTL_PHEN | AM335x_EQEP_QEPCTL_SWI;<br>
> +<br>
> + /* set the enable bit of the control register */<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QEPCTL) = value;<br>
> +<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> +<br>
> +rtems_status_code beagle_qep_enable(BBB_PWMSS pwmss_id)<br>
> +{<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + const bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> + /* set the enable bit of the control register */<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QEPCTL) |= AM335x_EQEP_QEPCTL_PHEN;<br>
> +<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> +<br>
> +rtems_status_code beagle_qep_disable(BBB_PWMSS pwmss_id)<br>
> +{<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + const bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> + /* clear the enable bit of the control register */<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QEPCTL) &= ~AM335x_EQEP_QEPCTL_PHEN;<br>
> +<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> +<br>
> +rtems_status_code beagle_qep_pinmux_setup(<br>
> + bbb_qep_pin pin_no,<br>
> + BBB_PWMSS pwmss_id,<br>
> + bool pullup_enable<br>
> +)<br>
> +{<br>
> + rtems_status_code result = RTEMS_SUCCESSFUL;<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + /* enable internal pull up / pull down resistor in pull up mode, and set the<br>
> + * pin as an input. */<br>
> + uint32_t pin_mode = BBB_RXACTIVE;<br>
> + if ( pullup_enable ) {<br>
> + pin_mode |= BBB_PU_EN;<br>
> + }<br>
> + // The offsets from AM335X_PADCONF_BASE (44e10000) are named after the mode0 mux for that pin.<br>
> + if(pwmss_id == BBB_PWMSS0) {<br>
> + if (pin_no == BBB_P9_25_0_STROBE) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_MCASP0_AHCLKX) = pin_mode | BBB_MUXMODE(BBB_P9_25_MUX_QEP);<br>
> + } else if (pin_no == BBB_P9_27_0B_IN) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_MCASP0_FSR) = pin_mode | BBB_MUXMODE(BBB_P9_27_MUX_QEP);<br>
> + } else if (pin_no == BBB_P9_41_0_IDX) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_MCASP0_AXR1) = pin_mode | BBB_MUXMODE(BBB_P9_41_MUX_QEP);<br>
> + } else if (pin_no == BBB_P9_42_0A_IN) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_MCASP0_ACLKR) = pin_mode | BBB_MUXMODE(BBB_P9_42_MUX_QEP);<br>
> + } else {<br>
> + result = RTEMS_INTERNAL_ERROR;<br>
> + }<br>
> + } else if (pwmss_id == BBB_PWMSS1) {<br>
> + if (pin_no == BBB_P8_31_1_IDX) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_LCD_DATA14) = pin_mode | BBB_MUXMODE(BBB_P8_31_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_32_1_STROBE) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_LCD_DATA15) = pin_mode | BBB_MUXMODE(BBB_P8_32_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_33_1B_IN) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_LCD_DATA13) = pin_mode | BBB_MUXMODE(BBB_P8_33_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_35_1A_IN) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_LCD_DATA12) = pin_mode | BBB_MUXMODE(BBB_P8_35_MUX_QEP);<br>
> + } else {<br>
> + result = RTEMS_INTERNAL_ERROR;<br>
> + }<br>
> + } else if (pwmss_id == BBB_PWMSS2) {<br>
> + if (pin_no == BBB_P8_11_2B_IN) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_GPMC_AD13) = pin_mode | BBB_MUXMODE(BBB_P8_11_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_12_2A_IN) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_GPMC_AD12) = pin_mode | BBB_MUXMODE(BBB_P8_12_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_15_2_STROBE) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_GPMC_AD15) = pin_mode | BBB_MUXMODE(BBB_P8_15_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_16_2_IDX) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_GPMC_AD14) = pin_mode | BBB_MUXMODE(BBB_P8_16_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_39_2_IDX) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_LCD_DATA6) = pin_mode | BBB_MUXMODE(BBB_P8_39_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_40_2_STROBE) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_LCD_DATA7) = pin_mode | BBB_MUXMODE(BBB_P8_40_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_41_2A_IN) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_LCD_DATA4) = pin_mode | BBB_MUXMODE(BBB_P8_41_MUX_QEP);<br>
> + } else if (pin_no == BBB_P8_42_2B_IN) {<br>
> + REG(AM335X_PADCONF_BASE + AM335X_CONF_LCD_DATA5) = pin_mode | BBB_MUXMODE(BBB_P8_42_MUX_QEP);<br>
> + } else {<br>
> + result = RTEMS_INTERNAL_ERROR;<br>
> + }<br>
> + } else {<br>
> + result = RTEMS_INTERNAL_ERROR;<br>
> + }<br>
> + return result;<br>
> +}<br>
> +<br>
> +int32_t beagle_qep_get_position(BBB_PWMSS pwmss_id)<br>
> +{<br>
> + int32_t position = 0;<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return -1;<br>
> + }<br>
> + const bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> +<br>
> + if (eqep->quadrature_mode == ABSOLUTE) {<br>
> + /* return the current value of the QPOSCNT register */<br>
> + position = REG(eqep->mmio_base + AM335x_EQEP_QPOSCNT);<br>
> + } else if (eqep->quadrature_mode == RELATIVE) {<br>
> + /* return the latched value from the last unit timer interrupt */<br>
> + position = REG(eqep->mmio_base + AM335x_EQEP_QPOSLAT);<br>
> + }<br>
> +<br>
> + return position;<br>
> +}<br>
> +<br>
> +rtems_status_code beagle_qep_set_position(BBB_PWMSS pwmss_id, uint32_t position)<br>
> +{<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + const bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> + /* setting the position only really makes sense in ABSOLUTE mode. */<br>
> + if (eqep->quadrature_mode == ABSOLUTE) {<br>
> + REG(eqep->mmio_base + AM335x_EQEP_QPOSCNT) = position;<br>
> + }<br>
> +<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> +<br>
> +rtems_status_code beagle_qep_set_count_mode(<br>
> + BBB_PWMSS pwmss_id,<br>
> + BBB_QEP_COUNT_MODE mode<br>
> +)<br>
> +{<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> + eqep->count_mode = mode;<br>
> +<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> +<br>
> +BBB_QEP_COUNT_MODE beagle_qep_get_count_mode(BBB_PWMSS pwmss_id)<br>
> +{<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + const bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> +<br>
> + return eqep->count_mode;<br>
> +}<br>
> +<br>
> +rtems_status_code beagle_qep_set_quadrature_mode(<br>
> + BBB_PWMSS pwmss_id,<br>
> + BBB_QEP_QUADRATURE_MODE mode<br>
> +)<br>
> +{<br>
> + uint16_t qepctl;<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> +<br>
> + qepctl = REG16(eqep->mmio_base + AM335x_EQEP_QEPCTL);<br>
> +<br>
> + if (mode == ABSOLUTE) {<br>
> + /*<br>
> + * Disable the unit timer position reset<br>
> + */<br>
> + qepctl &= ~AM335x_EQEP_QEPCTL_PCRM;<br>
> +<br>
> + eqep->quadrature_mode = ABSOLUTE;<br>
> + } else if (mode == RELATIVE) {<br>
> + /*<br>
> + * enable the unit timer position reset<br>
> + */<br>
> + qepctl |= AM335x_EQEP_QEPCTL_PCRM;<br>
> +<br>
> + eqep->quadrature_mode = RELATIVE;<br>
> + }<br>
> +<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QEPCTL) = qepctl;<br>
> +<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> +<br>
> +BBB_QEP_QUADRATURE_MODE beagle_qep_get_quadrature_mode(BBB_PWMSS pwmss_id)<br>
> +{<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return -1;<br>
> + }<br>
> + const bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> +<br>
> + return eqep->quadrature_mode;<br>
> +}<br>
> +<br>
> +<br>
> +/* Function to read the period of the unit time event timer */<br>
> +uint32_t beagle_eqep_get_timer_period(BBB_PWMSS pwmss_id)<br>
> +{<br>
> + uint64_t period;<br>
> + uint32_t timer_period;<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return -1;<br>
> + }<br>
> + const bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> +<br>
> + /* Convert from counts per interrupt back into period_ns */<br>
> + period = REG(eqep->mmio_base + AM335x_EQEP_QUPRD);<br>
> + period = period * NANO_SEC_PER_SEC;<br>
> + timer_period = (uint32_t)(period / SYSCLKOUT);<br>
> +<br>
> + return timer_period;<br>
> +}<br>
> +<br>
> +rtems_status_code beagle_eqep_set_timer_period(<br>
> + BBB_PWMSS pwmss_id,<br>
> + uint64_t period,<br>
> + bbb_eqep_timer_callback timer_callback<br>
> +)<br>
> +{<br>
> + uint16_t qepctl;<br>
> + uint64_t tmp_period;<br>
> + uint32_t timer_period;<br>
> + if ( pwmss_id >= BBB_PWMSS_COUNT ) {<br>
> + return RTEMS_INVALID_ID;<br>
> + }<br>
> + bbb_eqep* eqep = &bbb_eqep_table[pwmss_id];<br>
> +<br>
> + /* Disable the unit timer before modifying its period register */<br>
> + qepctl = readw(eqep->mmio_base + AM335x_EQEP_QEPCTL);<br>
> + qepctl &= ~(AM335x_EQEP_QEPCTL_UTE | AM335x_EQEP_QEPCTL_QCLM);<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QEPCTL) = qepctl;<br>
> +<br>
> + /* Zero the unit timer counter register */<br>
> + REG(eqep->mmio_base + AM335x_EQEP_QUTMR) = 0;<br>
> +<br>
> + /* If the timer is enabled (a non-zero period has been passed) */<br>
> + if (period) {<br>
> + /* update the period */<br>
> + tmp_period = period * SYSCLKOUT;<br>
> + timer_period = (uint32_t)(tmp_period / NANO_SEC_PER_SEC);<br>
> + REG(eqep->mmio_base + AM335x_EQEP_QUPRD) = timer_period;<br>
> +<br>
> + /* Enable unit timer, and latch QPOSLAT to QPOSCNT on timer expiration */<br>
> + qepctl |= AM335x_EQEP_QEPCTL_UTE | AM335x_EQEP_QEPCTL_QCLM;<br>
> + REG16(eqep->mmio_base + AM335x_EQEP_QEPCTL) = qepctl;<br>
> +<br>
> + /* attach the unit timer interrupt handler if one has been supplied */<br>
> + if (timer_callback != NULL) {<br>
> + eqep->timer_callback = timer_callback;<br>
> + }<br>
> + }<br>
> +<br>
> + return RTEMS_SUCCESSFUL;<br>
> +}<br>
> diff --git a/c/src/lib/libbsp/arm/beagle/Makefile.am b/c/src/lib/libbsp/arm/beagle/Makefile.am<br>
> index e37472373c..c9492f41a1 100644<br>
> --- a/c/src/lib/libbsp/arm/beagle/Makefile.am<br>
> +++ b/c/src/lib/libbsp/arm/beagle/Makefile.am<br>
> @@ -76,9 +76,15 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/beagle/spi/spi.c<br>
> # GPIO<br>
> librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/beagle/gpio/bbb-gpio.c<br>
> <br>
> +#pwmss shared<br>
> +librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/beagle/pwmss/pwmss.c<br>
> +<br>
> #pwm<br>
> librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/beagle/pwm/pwm.c<br>
> <br>
> +#qep<br>
> +librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/beagle/qep/qep.c<br>
> +<br>
> #RTC<br>
> librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/beagle/rtc/rtc.c<br>
> librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/rtc/rtc-support.c<br>
> <br>
</blockquote></div></div>