mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Add QEI lower-half driver impl. for Tiva series chip
This commit is contained in:
@@ -105,6 +105,10 @@ ifeq ($(CONFIG_TIVA_PWM),y)
|
||||
CHIP_CSRCS += tiva_pwm.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_TIVA_QEI),y)
|
||||
CHIP_CSRCS += tiva_qencoder.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_TIVA_TIMER),y)
|
||||
CHIP_CSRCS += tiva_timerlib.c
|
||||
ifeq ($(CONFIG_TIVA_TIMER32_PERIODIC),y)
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/tiva/chip/tiva_qencoder.h
|
||||
*
|
||||
* Copyright (C) 2016 Young Mu. All rights reserved.
|
||||
* Author: Young Mu <young.mu@aliyun.com>
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* 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 __ARCH_ARM_SRC_TIVA_CHIP_TIVA_QENCODER_H
|
||||
#define __ARCH_ARM_SRC_TIVA_CHIP_TIVA_QENCODER_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
#define TIVA_QEI_CTL_OFFSET (0x0) /* QEI Control */
|
||||
#define TIVA_QEI_STAT_OFFSET (0x4) /* QEI Status */
|
||||
#define TIVA_QEI_POS_OFFSET (0x8) /* QEI Position */
|
||||
#define TIVA_QEI_MAXPOS_OFFSET (0xc) /* QEI Maximum Position */
|
||||
#define TIVA_QEI_LOAD_OFFSET (0x10) /* QEI Timer Load */
|
||||
#define TIVA_QEI_TIME_OFFSET (0x14) /* QEI Timer */
|
||||
#define TIVA_QEI_COUNT_OFFSET (0x18) /* QEI Velocity Counter */
|
||||
#define TIVA_QEI_SPEED_OFFSET (0x1c) /* QEI Velocity */
|
||||
#define TIVA_QEI_INTEN_OFFSET (0x20) /* QEI Interrupt Enable */
|
||||
#define TIVA_QEI_RIS_OFFSET (0x24) /* QEI Raw Interrupt Status */
|
||||
#define TIVA_QEI_ISC_OFFSET (0x28) /* QEI Interrupt Status and Clear */
|
||||
|
||||
#define TIVA_QEI_CTL_FILTCNT (16) /* (Bit) Input Filter Prescale Count */
|
||||
#define TIVA_QEI_CTL_FILTEN (13) /* (Bit) Enable Input Filter */
|
||||
#define TIVA_QEI_CTL_STALLEN (12) /* (Bit) Stall QEI */
|
||||
#define TIVA_QEI_CTL_INVI (11) /* (Bit) Invert Index Pulse */
|
||||
#define TIVA_QEI_CTL_INVB (10) /* (Bit) Invert PhB */
|
||||
#define TIVA_QEI_CTL_INVA (9) /* (Bit) Invert PhA */
|
||||
#define TIVA_QEI_CTL_SIGMODE (2) /* (Bit) Signal Mode */
|
||||
#define TIVA_QEI_CTL_SWAP (1) /* (Bit) Swap Signals */
|
||||
|
||||
#define TIVA_QEI_CTL_VELDIV (6) /* (Bit) Predivide Velocity */
|
||||
#define VELDIV_1 (0x0) /* (Value) Divided by 1 */
|
||||
#define VELDIV_2 (0x1) /* (Value) Divided by 2 */
|
||||
#define VELDIV_4 (0x2) /* (Value) Divided by 4 */
|
||||
#define VELDIV_8 (0x3) /* (Value) Divided by 8 */
|
||||
#define VELDIV_16 (0x4) /* (Value) Divided by 16 */
|
||||
#define VELDIV_32 (0x5) /* (Value) Divided by 32 */
|
||||
#define VELDIV_64 (0x6) /* (Value) Divided by 64 */
|
||||
#define VELDIV_128 (0x7) /* (Value) Divided by 128 */
|
||||
|
||||
#define TIVA_QEI_CTL_VELEN (5) /* (Bit) Capture Velocity */
|
||||
#define VELEN_DISABLE (0) /* (value) Disable Velocity Capture */
|
||||
#define VELEN_ENABLE (1) /* (value) Enable Velocity Capture */
|
||||
|
||||
#define TIVA_QEI_CTL_RESMODE (4) /* (Bit) Reset Mode */
|
||||
#define RESMODE_BY_MAXPOS (0) /* (Value) Reset by MAXPOS */
|
||||
#define RESMODE_BY_INDEX_PULSE (1) /* (Value) Reset by Index Pulse */
|
||||
|
||||
#define TIVA_QEI_CTL_CAPMODE (3) /* (Bit) Capture Mode */
|
||||
#define CAPMODE_ONLY_PHA (0) /* (Value) Count PhA both edges */
|
||||
#define CAPMODE_PHA_AND_PHB (1) /* (Value) Count PhA and PhB both edges */
|
||||
|
||||
#define TIVA_QEI_CTL_ENABLE (0) /* (Bit) Enable QEI */
|
||||
#define QEI_DISABLE (0) /* (Value) Disable QEI */
|
||||
#define QEI_ENABLE (1) /* (Value) Enable QEI */
|
||||
|
||||
#define TIVA_QEI_STAT_DIRECTION (1) /* (Bit) Direction of Rotation */
|
||||
#define DIRECTION_FORWARD (0) /* (Value) Forward */
|
||||
#define DIRECTION_BACKWARD (1) /* (Value) Backward */
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_TIVA_CHIP_TIVA_QENCODER_H */
|
||||
@@ -1901,7 +1901,9 @@
|
||||
|
||||
/* QE Interface Power Control */
|
||||
|
||||
#define SYSCON_PCQEI_P0 (1 << 0) /* Bit 0: QEI Module 0 Power Control */
|
||||
#define SYSCON_PCQEI(n) (1 << (n)) /* Bit n: QEI module n Power Control */
|
||||
# define SYSCON_PCQEI_P0 (1 << 0) /* Bit 0: QEI Module 0 Power Control */
|
||||
# define SYSCON_PCQEI_P1 (1 << 1) /* Bit 1: QEI Module 1 Power Control */
|
||||
|
||||
/* EEPROM Power Control */
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,58 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/tiva/tiva_qencoder.h
|
||||
*
|
||||
* Copyright (C) 2016 Young Mu. All rights reserved.
|
||||
* Author: Young Mu <young.mu@aliyun.com>
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* 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 __ARCH_ARM_SRC_TIVA_TIVA_QENCODER_H
|
||||
#define __ARCH_ARM_SRC_TIVA_TIVA_QENCODER_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/sensors/qencoder.h>
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
#define QEIOC_DIRECTION _QEIOC(QEIOC_USER)
|
||||
#define QEIOC_VELOCITY _QEIOC(QEIOC_USER+1)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct qe_lowerhalf_s *tiva_qei_initialize(int id);
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_TIVA_TIVA_QENCODER_H */
|
||||
@@ -50,6 +50,7 @@
|
||||
|
||||
#include "tiva_i2c.h"
|
||||
#include "tiva_pwm.h"
|
||||
#include "tiva_qencoder.h"
|
||||
#include "tm4c1294-launchpad.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -64,9 +65,16 @@
|
||||
# define HAVE_PWM
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TM4C1294_LAUNCHPAD_QEI
|
||||
# define HAVE_QEI
|
||||
#endif
|
||||
|
||||
#define PWM_PATH_FMT "/dev/pwm%d"
|
||||
#define PWM_PATH_FMTLEN (10)
|
||||
|
||||
#define QEI_PATH_FMT "/dev/qei%d"
|
||||
#define QEI_PATH_FMTLEN (10)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -172,7 +180,7 @@ void tm4c_pwm_register(int channel)
|
||||
dev = tiva_pwm_initialize(channel);
|
||||
if (dev == NULL)
|
||||
{
|
||||
pwmerr("ERROR: Failed to get PWM%d interface\n", channel);
|
||||
_err("ERROR: Failed to get PWM%d interface\n", channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -180,7 +188,7 @@ void tm4c_pwm_register(int channel)
|
||||
ret = pwm_register(pwm_path, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
pwmerr("ERROR: Failed to register PWM%d driver: %d\n",
|
||||
_err("ERROR: Failed to register PWM%d driver: %d\n",
|
||||
channel, ret);
|
||||
}
|
||||
}
|
||||
@@ -225,6 +233,62 @@ static void tm4c_pwm(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tm4c_qei_register
|
||||
*
|
||||
* Description:
|
||||
* Register a QEI dev file with the upper_level QEI driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* id - A number identifying the QEI.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void tm4c_qei_register(int id)
|
||||
{
|
||||
FAR struct qe_lowerhalf_s *dev;
|
||||
int ret;
|
||||
char qe_path[QEI_PATH_FMTLEN];
|
||||
|
||||
dev = tiva_qei_initialize(id);
|
||||
if (dev == NULL)
|
||||
{
|
||||
_err("ERROR: Failed to get QEI %d\n", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(qe_path, QEI_PATH_FMTLEN, QEI_PATH_FMT, id);
|
||||
ret = qe_register(qe_path, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
_err("ERROR: Failed to register QEI %d driver: %d\n", id, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tm4c_qei
|
||||
*
|
||||
* Description:
|
||||
* Register QEI drivers for the QEI tool.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_QEI
|
||||
static void tm4c_qei(void)
|
||||
{
|
||||
#ifdef CONFIG_TIVA_QEI0
|
||||
tm4c_qei_register(0);
|
||||
#endif
|
||||
#ifdef CONFIG_TIVA_QEI1
|
||||
tm4c_qei_register(1);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -253,6 +317,12 @@ int tm4c_bringup(void)
|
||||
tm4c_pwm();
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QEI
|
||||
/* Register QEI drivers */
|
||||
|
||||
tm4c_qei();
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TIMER
|
||||
/* Initialize the timer driver */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user