mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
Add tiva PWM lower-half driver implementation
This commit is contained in:
@@ -101,6 +101,10 @@ ifeq ($(CONFIG_TIVA_I2C),y)
|
||||
CHIP_CSRCS += tiva_i2c.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_TIVA_PWM),y)
|
||||
CHIP_CSRCS += tiva_pwm.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_TIVA_TIMER),y)
|
||||
CHIP_CSRCS += tiva_timerlib.c
|
||||
ifeq ($(CONFIG_TIVA_TIMER32_PERIODIC),y)
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/tiva/chip/tiva_pwm.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_PWM_H
|
||||
#define __ARCH_ARM_SRC_TIVA_CHIP_TIVA_PWM_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
#define TIVA_PWM_CTL_OFFSET (0x0) /* PWM Master Control */
|
||||
#define TIVA_PWM_SYNC_OFFSET (0x4) /* PWM Time Base Sync */
|
||||
#define TIVA_PWM_ENABLE_OFFSET (0x8) /* PWM Output Enable */
|
||||
#define TIVA_PWM_INVERT_OFFSET (0xc) /* PWM Output Inversion */
|
||||
#define TIVA_PWM_FAULT_OFFSET (0x10) /* PWM Output Fault */
|
||||
#define TIVA_PWM_INTEN_OFFSET (0x14) /* PWM Interrupt Enable */
|
||||
#define TIVA_PWM_RIS_OFFSET (0x18) /* PWM Raw Interrupt Status */
|
||||
#define TIVA_PWM_ISC_OFFSET (0x1c) /* PWM Interrupt Status and Clear */
|
||||
#define TIVA_PWM_STATUS_OFFSET (0x20) /* PWM Status */
|
||||
#define TIVA_PWM_FAULTVAL_OFFSET (0x24) /* PWM Fault Condition Value */
|
||||
#define TIVA_PWM_ENUPD_OFFSET (0x28) /* PWM Enable Update */
|
||||
|
||||
#define TIVA_PWMn_BASE (0x40) /* PWMn Base */
|
||||
#define TIVA_PWMn_INTERVAL (0x40) /* PWMn Interval */
|
||||
|
||||
#define TIVA_PWMn_CTL_OFFSET (0x0) /* PWMn Control */
|
||||
#define TIVA_PWMn_INTEN_OFFSET (0x4) /* PWMn Interrupt and Trigger Enable */
|
||||
#define TIVA_PWMn_RIS_OFFSET (0x8) /* PWMn Raw Interrupt Status */
|
||||
#define TIVA_PWMn_ISC_OFFSET (0xc) /* PWMn Interrupt Status and Clear */
|
||||
#define TIVA_PWMn_LOAD_OFFSET (0x10) /* PWMn Load */
|
||||
#define TIVA_PWMn_COUNT_OFFSET (0x14) /* PWMn Counter */
|
||||
#define TIVA_PWMn_CMPA_OFFSET (0x18) /* PWMn Compare A */
|
||||
#define TIVA_PWMn_CMPB_OFFSET (0x1c) /* PWMn Compare B */
|
||||
#define TIVA_PWMn_GENA_OFFSET (0x20) /* PWMn Generator A Control */
|
||||
#define TIVA_PWMn_GENB_OFFSET (0x24) /* PWMn Generator B Control */
|
||||
#define TIVA_PWMn_DBCTL_OFFSET (0x28) /* PWMn Dead-Band Control */
|
||||
#define TIVA_PWMn_DBRISE_OFFSET (0x2c) /* PWMn Dead-Band Rising-Edge-Delay */
|
||||
#define TIVA_PWMn_DBFALL_OFFSET (0x30) /* PWMn Dead-Band Falling-Edge-Delay */
|
||||
#define TIVA_PWMn_FLTSRC0_OFFSET (0x34) /* PWMn Fault Source 0 */
|
||||
#define TIVA_PWMn_FLTSRC1_OFFSET (0x38) /* PWMn Fault Source 1 */
|
||||
#define TIVA_PWMn_MINFLTPER_OFFSET (0x3c) /* PWMn Minimum Fault Period */
|
||||
|
||||
#define TIVA_PWMn_FAULT_BASE (0x800) /* PWMn Fault Base */
|
||||
#define TIVA_PWMn_FAULT_INTERVAL (0x80) /* PWMn Fault Interval */
|
||||
|
||||
#define TIVA_PWMn_FAULT_SEN_OFFSET (0x0) /* PWMn Fault Pin Logic Sense */
|
||||
#define TIVA_PWMn_FAULT_STAT0_OFFSET (0x4) /* PWMn Fault Status 0 */
|
||||
#define TIVA_PWMn_FAULT_STAT1_OFFSET (0x8) /* PWMn Fault Status 1 */
|
||||
|
||||
#define TIVA_PWM_PP (0xfc0) /* PWM Peripheral Properties */
|
||||
#define TIVA_PWM_CC (0xfc8) /* PWM Clock Configuration */
|
||||
|
||||
#define TIVA_PWMn_GENx_ACTCMPBD (10) /* (Bit) Action for Comparator B Down */
|
||||
#define TIVA_PWMn_GENx_ACTCMPBU (8) /* (Bit) Action for Comparator B Up */
|
||||
#define TIVA_PWMn_GENx_ACTCMPAD (6) /* (Bit) Action for Comparator A Down */
|
||||
#define TIVA_PWMn_GENx_ACTCMPAU (4) /* (Bit) Action for Comparator A Up */
|
||||
#define TIVA_PWMn_GENx_ACTLOAD (2) /* (Bit) Action for Counter equals LOAD */
|
||||
#define TIVA_PWMn_GENx_ACTZERO (0) /* (Bit) Action for Counter equals ZERO */
|
||||
#define GENx_INVERT (0x1) /* (Value) Invert */
|
||||
#define GENx_LOW (0x2) /* (Value) Drive Low */
|
||||
#define GENx_HIGH (0x3) /* (Value) Drive High */
|
||||
|
||||
#define TIVA_PWM_CC_USEPWM (8) /* (Bit) Use PWM Clock Divisor */
|
||||
#define TIVA_PWM_CC_PWMDIV (0) /* (Bit) PWM Clock Divider */
|
||||
#define CC_USEPWM (0x1) /* (Value) Use PWM divider as clock source */
|
||||
#define CC_PWMDIV_2 (0x0) /* (Value) Divided by 2 */
|
||||
#define CC_PWMDIV_4 (0x1) /* (Value) Divided by 4 */
|
||||
#define CC_PWMDIV_8 (0x2) /* (Value) Divided by 8 */
|
||||
#define CC_PWMDIV_16 (0x3) /* (Value) Divided by 16 */
|
||||
#define CC_PWMDIV_32 (0x4) /* (Value) Divided by 32 */
|
||||
#define CC_PWMDIV_64 (0x5) /* (Value) Divided by 64 */
|
||||
|
||||
#define TIVA_PWMn_CTL_ENABLE (0) /* (Bit) PWM Block Enable */
|
||||
#define CTL_ENABLE (1) /* (Value) Enable */
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_TIVA_CHIP_TIVA_PWM_H */
|
||||
@@ -1895,7 +1895,9 @@
|
||||
|
||||
/* PWM Power Control */
|
||||
|
||||
#define SYSCON_PCPWM_P0 (1 << 0) /* Bit 0: PWM Module 0 Power Control */
|
||||
#define SYSCON_PCPWM(n) (1 << (n)) /* Bit n: PWM module n Power Control */
|
||||
# define SYSCON_PCPWM_P0 (1 << 0) /* Bit 0: PWM Module 0 Power Control */
|
||||
# define SYSCON_PCPWM_P1 (1 << 1) /* Bit 1: PWM Module 1 Power Control */
|
||||
|
||||
/* QE Interface Power Control */
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/tiva/tiva_pwm.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_PWM_H
|
||||
#define __ARCH_ARM_SRC_TIVA_TIVA_PWM_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/drivers/pwm.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct pwm_lowerhalf_s *tiva_pwm_initialize(int channel);
|
||||
|
||||
void tm4c_pwm_register(int channel);
|
||||
int board_pwm_setup(void);
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_TIVA_TIVA_PWM_H */
|
||||
@@ -511,7 +511,7 @@ static int tiva_ioctl(struct timer_lowerhalf_s *lower, int cmd,
|
||||
{
|
||||
int ret = -ENOTTY;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
DEBUGASSERT(lower);
|
||||
tmrinfo("Entry: cmd=%d arg=%ld\n", cmd, arg);
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
@@ -45,8 +48,13 @@
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "tiva_i2c.h"
|
||||
#include "tiva_pwm.h"
|
||||
#include "tm4c1294-launchpad.h"
|
||||
|
||||
#define PWM_PATH_FMT "/dev/pwm%d"
|
||||
#define PWM_PATH_FMTLEN (10)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
@@ -55,6 +63,10 @@
|
||||
# define HAVE_TIMER
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TM4C1294_LAUNCHPAD_PWM
|
||||
# define HAVE_PWM
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -136,6 +148,82 @@ static void tm4c_i2ctool(void)
|
||||
# define tm4c_i2ctool()
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tm4c_pwm_register
|
||||
*
|
||||
* Description:
|
||||
* Register a PWM dev file with the upper_level PWM driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* channel - A number identifying the PWM channel use.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void tm4c_pwm_register(int channel)
|
||||
{
|
||||
FAR struct pwm_lowerhalf_s *dev;
|
||||
int ret;
|
||||
char pwm_path[PWM_PATH_FMTLEN];
|
||||
|
||||
dev = tiva_pwm_initialize(channel);
|
||||
if (dev == NULL)
|
||||
{
|
||||
dbg("ERROR: Failed to get PWM%d interface\n", channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(pwm_path, PWM_PATH_FMTLEN, PWM_PATH_FMT, channel);
|
||||
ret = pwm_register(pwm_path, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
dbg("ERROR: Failed to register PWM%d driver: %d\n", channel, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tm4c_pwm
|
||||
*
|
||||
* Description:
|
||||
* Register PWM drivers for the PWM tool.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_PWM
|
||||
|
||||
static void tm4c_pwm(void)
|
||||
{
|
||||
#ifdef CONFIG_TIVA_PWM0_CHAN0
|
||||
tm4c_pwm_register(0);
|
||||
#endif
|
||||
#ifdef CONFIG_TIVA_PWM0_CHAN1
|
||||
tm4c_pwm_register(1);
|
||||
#endif
|
||||
#ifdef CONFIG_TIVA_PWM0_CHAN2
|
||||
tm4c_pwm_register(2);
|
||||
#endif
|
||||
#ifdef CONFIG_TIVA_PWM0_CHAN3
|
||||
tm4c_pwm_register(3);
|
||||
#endif
|
||||
#ifdef CONFIG_TIVA_PWM0_CHAN4
|
||||
tm4c_pwm_register(4);
|
||||
#endif
|
||||
#ifdef CONFIG_TIVA_PWM0_CHAN5
|
||||
tm4c_pwm_register(5);
|
||||
#endif
|
||||
#ifdef CONFIG_TIVA_PWM0_CHAN6
|
||||
tm4c_pwm_register(6);
|
||||
#endif
|
||||
#ifdef CONFIG_TIVA_PWM0_CHAN7
|
||||
tm4c_pwm_register(7);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -158,6 +246,10 @@ int tm4c_bringup(void)
|
||||
|
||||
tm4c_i2ctool();
|
||||
|
||||
/* Register PWM drivers */
|
||||
|
||||
tm4c_pwm();
|
||||
|
||||
#ifdef HAVE_TIMER
|
||||
/* Initialize the timer driver */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user