mirror of
https://github.com/apache/nuttx.git
synced 2025-12-16 09:45:18 +08:00
arch/stm32h7: Fix nxstyle errors
arch/arm/src/stm32h7/stm32_qencoder.c:
* Fix nxstyle issues.
This commit is contained in:
committed by
Abdelatif Guettouche
parent
301ba3a5cd
commit
15480e51cf
@@ -1,4 +1,4 @@
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* arch/arm/src/stm32h7/stm32_qencoder.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
@@ -31,11 +31,11 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
@@ -61,11 +61,11 @@
|
||||
|
||||
#ifdef CONFIG_SENSORS_QENCODER
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Timers ***************************************************************************/
|
||||
/* Timers *******************************************************************/
|
||||
|
||||
#undef HAVE_32BIT_TIMERS
|
||||
#undef HAVE_16BIT_TIMERS
|
||||
@@ -101,7 +101,7 @@
|
||||
# define HAVE_MIXEDWIDTH_TIMERS 1
|
||||
#endif
|
||||
|
||||
/* Input filter *********************************************************************/
|
||||
/* Input filter *************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32H7_QENCODER_FILTER
|
||||
# if defined(CONFIG_STM32H7_QENCODER_SAMPLE_FDTS)
|
||||
@@ -163,9 +163,11 @@
|
||||
|
||||
#define STM32_GPIO_INPUT_FLOAT (GPIO_INPUT | GPIO_FLOAT)
|
||||
|
||||
/* Debug ****************************************************************************/
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
/* Non-standard debug that may be enabled just for testing the quadrature encoder */
|
||||
/* Non-standard debug that may be enabled just for testing the quadrature
|
||||
* encoder
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DEBUG_FEATURES
|
||||
# undef CONFIG_DEBUG_SENSORS
|
||||
@@ -181,9 +183,9 @@
|
||||
# define qe_dumpgpio(p,m)
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Constant configuration structure that is retained in FLASH */
|
||||
|
||||
@@ -228,16 +230,18 @@ struct stm32_lowerhalf_s
|
||||
#endif
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Helper functions */
|
||||
|
||||
static uint16_t stm32_getreg16(FAR struct stm32_lowerhalf_s *priv, int offset);
|
||||
static uint16_t stm32_getreg16(FAR struct stm32_lowerhalf_s *priv,
|
||||
int offset);
|
||||
static void stm32_putreg16(FAR struct stm32_lowerhalf_s *priv, int offset,
|
||||
uint16_t value);
|
||||
static uint32_t stm32_getreg32(FAR struct stm32_lowerhalf_s *priv, int offset);
|
||||
static uint32_t stm32_getreg32(FAR struct stm32_lowerhalf_s *priv,
|
||||
int offset);
|
||||
static void stm32_putreg32(FAR struct stm32_lowerhalf_s *priv, int offset,
|
||||
uint32_t value);
|
||||
|
||||
@@ -260,14 +264,15 @@ static int stm32_interrupt(int irq, FAR void *context, FAR void *arg);
|
||||
|
||||
static int stm32_setup(FAR struct qe_lowerhalf_s *lower);
|
||||
static int stm32_shutdown(FAR struct qe_lowerhalf_s *lower);
|
||||
static int stm32_position(FAR struct qe_lowerhalf_s *lower, FAR int32_t *pos);
|
||||
static int stm32_position(FAR struct qe_lowerhalf_s *lower,
|
||||
FAR int32_t *pos);
|
||||
static int stm32_reset(FAR struct qe_lowerhalf_s *lower);
|
||||
static int stm32_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* The lower half callback structure */
|
||||
|
||||
@@ -432,11 +437,11 @@ static struct stm32_lowerhalf_s g_tim8lower =
|
||||
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_getreg16
|
||||
*
|
||||
* Description:
|
||||
@@ -449,14 +454,14 @@ static struct stm32_lowerhalf_s g_tim8lower =
|
||||
* Returned Value:
|
||||
* The current contents of the specified register
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static uint16_t stm32_getreg16(struct stm32_lowerhalf_s *priv, int offset)
|
||||
{
|
||||
return getreg16(priv->config->base + offset);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_putreg16
|
||||
*
|
||||
* Description:
|
||||
@@ -469,7 +474,7 @@ static uint16_t stm32_getreg16(struct stm32_lowerhalf_s *priv, int offset)
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static void stm32_putreg16(FAR struct stm32_lowerhalf_s *priv, int offset,
|
||||
uint16_t value)
|
||||
@@ -477,13 +482,13 @@ static void stm32_putreg16(FAR struct stm32_lowerhalf_s *priv, int offset,
|
||||
putreg16(value, priv->config->base + offset);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_getreg32
|
||||
*
|
||||
* Description:
|
||||
* Read the value of a 32-bit timer register. This applies for the STM32 H7
|
||||
* 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5 (but works OK
|
||||
* with the 16-bit TIM1,8 as well).
|
||||
* Read the value of a 32-bit timer register. This applies for the
|
||||
* STM32 H7 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers
|
||||
* TIM2-5 (but works OK with the 16-bit TIM1,8 as well).
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - A reference to the lower half status
|
||||
@@ -492,20 +497,21 @@ static void stm32_putreg16(FAR struct stm32_lowerhalf_s *priv, int offset,
|
||||
* Returned Value:
|
||||
* The current contents of the specified register
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t stm32_getreg32(FAR struct stm32_lowerhalf_s *priv, int offset)
|
||||
static uint32_t stm32_getreg32(FAR struct stm32_lowerhalf_s *priv,
|
||||
int offset)
|
||||
{
|
||||
return getreg32(priv->config->base + offset);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_putreg32
|
||||
*
|
||||
* Description:
|
||||
* Write a value to a 32-bit timer register. This applies for the STM32 H7
|
||||
* 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5 (but works OK
|
||||
* with the 16-bit TIM1,8 as well).
|
||||
* Write a value to a 32-bit timer register. This applies for the
|
||||
* STM32 H7 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers
|
||||
* TIM2-5 (but works OK with the 16-bit TIM1,8 as well).
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - A reference to the lower half status
|
||||
@@ -514,7 +520,7 @@ static uint32_t stm32_getreg32(FAR struct stm32_lowerhalf_s *priv, int offset)
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static void stm32_putreg32(FAR struct stm32_lowerhalf_s *priv, int offset,
|
||||
uint32_t value)
|
||||
@@ -580,13 +586,13 @@ static void stm32_dumpregs(FAR struct stm32_lowerhalf_s *priv,
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_tim2lower
|
||||
*
|
||||
* Description:
|
||||
* Map a timer number to a device structure
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct stm32_lowerhalf_s *stm32_tim2lower(int tim)
|
||||
{
|
||||
@@ -621,14 +627,14 @@ static FAR struct stm32_lowerhalf_s *stm32_tim2lower(int tim)
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_interrupt
|
||||
*
|
||||
* Description:
|
||||
* Common timer interrupt handling. NOTE: Only 16-bit timers require timer
|
||||
* interrupts.
|
||||
* Common timer interrupt handling. NOTE: Only 16-bit timers require
|
||||
* timer interrupts.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_16BIT_TIMERS
|
||||
static int stm32_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
@@ -656,7 +662,7 @@ static int stm32_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
{
|
||||
priv->position -= (int32_t)0x00010000;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
priv->position += (int32_t)0x00010000;
|
||||
}
|
||||
@@ -665,7 +671,7 @@ static int stm32_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_setup
|
||||
*
|
||||
* Description:
|
||||
@@ -673,7 +679,7 @@ static int stm32_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
* should configure and initialize the device so that it is ready for use.
|
||||
* The initial position value should be zero. *
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_setup(FAR struct qe_lowerhalf_s *lower)
|
||||
{
|
||||
@@ -696,8 +702,8 @@ static int stm32_setup(FAR struct qe_lowerhalf_s *lower)
|
||||
|
||||
cr1 = stm32_getreg16(priv, STM32_GTIM_CR1_OFFSET);
|
||||
|
||||
/* Clear the direction bit (0=count up) and select the Counter Mode (0=Edge aligned)
|
||||
* (Timers 2-5 and 1-8 only)
|
||||
/* Clear the direction bit (0=count up) and select the Counter Mode
|
||||
* (0=Edge aligned) (Timers 2-5 and 1-8 only)
|
||||
*/
|
||||
|
||||
cr1 &= ~(GTIM_CR1_DIR | GTIM_CR1_CMS_MASK);
|
||||
@@ -760,6 +766,7 @@ static int stm32_setup(FAR struct qe_lowerhalf_s *lower)
|
||||
stm32_putreg32(priv, STM32_GTIM_SMCR_OFFSET, smcr);
|
||||
|
||||
/* TI1 Channel Configuration */
|
||||
|
||||
/* Disable the Channel 1: Reset the CC1E Bit */
|
||||
|
||||
ccer = stm32_getreg16(priv, STM32_GTIM_CCER_OFFSET);
|
||||
@@ -795,6 +802,7 @@ static int stm32_setup(FAR struct qe_lowerhalf_s *lower)
|
||||
stm32_putreg32(priv, STM32_GTIM_CCMR1_OFFSET, ccmr1);
|
||||
|
||||
/* TI2 Channel Configuration */
|
||||
|
||||
/* Disable the Channel 2: Reset the CC2E Bit */
|
||||
|
||||
ccer = stm32_getreg16(priv, STM32_GTIM_CCER_OFFSET);
|
||||
@@ -899,15 +907,16 @@ static int stm32_setup(FAR struct qe_lowerhalf_s *lower)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_shutdown
|
||||
*
|
||||
* Description:
|
||||
* This method is called when the driver is closed. The lower half driver
|
||||
* should stop data collection, free any resources, disable timer hardware, and
|
||||
* put the system into the lowest possible power usage state *
|
||||
* This method is called when the driver is closed. The lower half
|
||||
* driver should stop data collection, free any resources, disable timer
|
||||
* hardware, and put the system into the lowest possible power usage
|
||||
* state
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_shutdown(FAR struct qe_lowerhalf_s *lower)
|
||||
{
|
||||
@@ -1015,13 +1024,13 @@ static int stm32_shutdown(FAR struct qe_lowerhalf_s *lower)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_position
|
||||
*
|
||||
* Description:
|
||||
* Return the current position measurement.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_position(FAR struct qe_lowerhalf_s *lower, FAR int32_t *pos)
|
||||
{
|
||||
@@ -1037,8 +1046,8 @@ static int stm32_position(FAR struct qe_lowerhalf_s *lower, FAR int32_t *pos)
|
||||
|
||||
do
|
||||
{
|
||||
/* Don't let another task preempt us until we get the measurement. The timer
|
||||
* interrupt may still be processed
|
||||
/* Don't let another task preempt us until we get the measurement.
|
||||
* The timer interrupt may still be processed
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
@@ -1060,13 +1069,13 @@ static int stm32_position(FAR struct qe_lowerhalf_s *lower, FAR int32_t *pos)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_reset
|
||||
*
|
||||
* Description:
|
||||
* Reset the position measurement to zero.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_reset(FAR struct qe_lowerhalf_s *lower)
|
||||
{
|
||||
@@ -1077,8 +1086,8 @@ static int stm32_reset(FAR struct qe_lowerhalf_s *lower)
|
||||
sninfo("Resetting position to zero\n");
|
||||
DEBUGASSERT(lower && priv->inuse);
|
||||
|
||||
/* Reset the timer and the counter. Interrupts are disabled to make this atomic
|
||||
* (if possible)
|
||||
/* Reset the timer and the counter. Interrupts are disabled to make this
|
||||
* atomic (if possible)
|
||||
*/
|
||||
|
||||
flags = enter_critical_section();
|
||||
@@ -1096,15 +1105,16 @@ static int stm32_reset(FAR struct qe_lowerhalf_s *lower)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_ioctl
|
||||
*
|
||||
* Description:
|
||||
* Lower-half logic may support platform-specific ioctl commands
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, unsigned long arg)
|
||||
static int stm32_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
/* No ioctl commands supported */
|
||||
|
||||
@@ -1113,32 +1123,35 @@ static int stm32_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, unsigned long
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_qeinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize a quadrature encoder interface. This function must be called from
|
||||
* board-specific logic.
|
||||
* Initialize a quadrature encoder interface. This function must be
|
||||
* called from board-specific logic.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/qe0"
|
||||
* tim - The timer number to used. 'tim' must be an element of {1,2,3,4,5,8}
|
||||
* tim - The timer number to used. 'tim' must be an element of
|
||||
* {1,2,3,4,5,8}
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; A negated errno value is returned on failure.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_qeinitialize(FAR const char *devpath, int tim)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv;
|
||||
int ret;
|
||||
|
||||
/* Find the pre-allocated timer state structure corresponding to this timer */
|
||||
/* Find the pre-allocated timer state structure corresponding to this
|
||||
* timer
|
||||
*/
|
||||
|
||||
priv = stm32_tim2lower(tim);
|
||||
if (!priv)
|
||||
|
||||
Reference in New Issue
Block a user