PX4 Firmware
PX4 Autopilot Software http://px4.io
pwm_input.cpp File Reference

PWM input driver based on earlier driver from Evan Slatyer, which in turn was based on drv_hrt.c. More...

#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/time.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <sys/types.h>
#include <stdbool.h>
#include <assert.h>
#include <debug.h>
#include <time.h>
#include <queue.h>
#include <errno.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <board_config.h>
#include <drivers/drv_pwm_input.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_range_finder.h>
#include "chip.h"
#include "up_internal.h"
#include "up_arch.h"
#include "stm32_gpio.h"
#include "stm32_tim.h"
#include <systemlib/err.h>
#include <uORB/uORB.h>
#include <uORB/topics/pwm_input.h>
#include <drivers/drv_device.h>
#include <drivers/device/device.h>
#include <drivers/device/ringbuffer.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "timer_registers.h"
Include dependency graph for pwm_input.cpp:

Go to the source code of this file.

Classes

class  PWMIN
 

Macros

#define GPIO_VDD_RANGEFINDER_EN   GPIO_GPIO5_OUTPUT
 
#define INPUT_TIMER   PWMIN_TIMER
 
#define PWMIN_TIMER_BASE   TIMER_BASE
 
#define PWMIN_TIMER_CLOCK   TIMER_CLOCK
 
#define PWMIN_TIMER_POWER_REG   TIMER_CLOCK_POWER_REG
 
#define PWMIN_TIMER_POWER_BIT   TIMER_CLOCK_POWER_BIT
 
#define PWMIN_TIMER_VECTOR   TIMER_IRQ_REG
 
#define REG(_reg)   (*(volatile uint32_t *)(PWMIN_TIMER_BASE + _reg))
 
#define rCR1   REG(STM32_GTIM_CR1_OFFSET)
 
#define rCR2   REG(STM32_GTIM_CR2_OFFSET)
 
#define rSMCR   REG(STM32_GTIM_SMCR_OFFSET)
 
#define rDIER   REG(STM32_GTIM_DIER_OFFSET)
 
#define rSR   REG(STM32_GTIM_SR_OFFSET)
 
#define rEGR   REG(STM32_GTIM_EGR_OFFSET)
 
#define rCCMR1   REG(STM32_GTIM_CCMR1_OFFSET)
 
#define rCCMR2   REG(STM32_GTIM_CCMR2_OFFSET)
 
#define rCCER   REG(STM32_GTIM_CCER_OFFSET)
 
#define rCNT   REG(STM32_GTIM_CNT_OFFSET)
 
#define rPSC   REG(STM32_GTIM_PSC_OFFSET)
 
#define rARR   REG(STM32_GTIM_ARR_OFFSET)
 
#define rCCR1   REG(STM32_GTIM_CCR1_OFFSET)
 
#define rCCR2   REG(STM32_GTIM_CCR2_OFFSET)
 
#define rCCR3   REG(STM32_GTIM_CCR3_OFFSET)
 
#define rCCR4   REG(STM32_GTIM_CCR4_OFFSET)
 
#define rDCR   REG(STM32_GTIM_DCR_OFFSET)
 
#define rDMAR   REG(STM32_GTIM_DMAR_OFFSET)
 
#define TIMEOUT_POLL   300000 /* reset after no response over this time in microseconds [0.3s] */
 
#define TIMEOUT_READ   200000 /* don't reset if the last read is back more than this time in microseconds [0.2s] */
 

Functions

static int pwmin_tim_isr (int irq, void *context, void *arg)
 
static void pwmin_start ()
 
static void pwmin_info (void)
 
static void pwmin_test (void)
 
static void pwmin_reset (void)
 
static void pwmin_usage (void)
 
int pwm_input_main (int argc, char *argv[])
 

Variables

static PWMINg_dev
 

Detailed Description

PWM input driver based on earlier driver from Evan Slatyer, which in turn was based on drv_hrt.c.

Author
: Andrew Tridgell
: Ban Siesta bansi.nosp@m.esta.nosp@m.@gmai.nosp@m.l.co.nosp@m.m

Definition in file pwm_input.cpp.

Macro Definition Documentation

◆ GPIO_VDD_RANGEFINDER_EN

#define GPIO_VDD_RANGEFINDER_EN   GPIO_GPIO5_OUTPUT

Definition at line 87 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init(), PWMIN::_turn_off(), and PWMIN::_turn_on().

◆ INPUT_TIMER

#define INPUT_TIMER   PWMIN_TIMER

Definition at line 98 of file pwm_input.cpp.

◆ PWMIN_TIMER_BASE

#define PWMIN_TIMER_BASE   TIMER_BASE

Definition at line 100 of file pwm_input.cpp.

◆ PWMIN_TIMER_CLOCK

#define PWMIN_TIMER_CLOCK   TIMER_CLOCK

Definition at line 101 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ PWMIN_TIMER_POWER_BIT

#define PWMIN_TIMER_POWER_BIT   TIMER_CLOCK_POWER_BIT

Definition at line 103 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ PWMIN_TIMER_POWER_REG

#define PWMIN_TIMER_POWER_REG   TIMER_CLOCK_POWER_REG

Definition at line 102 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ PWMIN_TIMER_VECTOR

#define PWMIN_TIMER_VECTOR   TIMER_IRQ_REG

Definition at line 104 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rARR

#define rARR   REG(STM32_GTIM_ARR_OFFSET)

Definition at line 129 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rCCER

#define rCCER   REG(STM32_GTIM_CCER_OFFSET)

Definition at line 126 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rCCMR1

#define rCCMR1   REG(STM32_GTIM_CCMR1_OFFSET)

Definition at line 124 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rCCMR2

#define rCCMR2   REG(STM32_GTIM_CCMR2_OFFSET)

Definition at line 125 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rCCR1

#define rCCR1   REG(STM32_GTIM_CCR1_OFFSET)

Definition at line 130 of file pwm_input.cpp.

◆ rCCR2

#define rCCR2   REG(STM32_GTIM_CCR2_OFFSET)

Definition at line 131 of file pwm_input.cpp.

◆ rCCR3

#define rCCR3   REG(STM32_GTIM_CCR3_OFFSET)

Definition at line 132 of file pwm_input.cpp.

◆ rCCR4

#define rCCR4   REG(STM32_GTIM_CCR4_OFFSET)

Definition at line 133 of file pwm_input.cpp.

◆ rCNT

#define rCNT   REG(STM32_GTIM_CNT_OFFSET)

Definition at line 127 of file pwm_input.cpp.

◆ rCR1

#define rCR1   REG(STM32_GTIM_CR1_OFFSET)

Definition at line 118 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rCR2

#define rCR2   REG(STM32_GTIM_CR2_OFFSET)

Definition at line 119 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rDCR

#define rDCR   REG(STM32_GTIM_DCR_OFFSET)

Definition at line 134 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rDIER

#define rDIER   REG(STM32_GTIM_DIER_OFFSET)

Definition at line 121 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rDMAR

#define rDMAR   REG(STM32_GTIM_DMAR_OFFSET)

Definition at line 135 of file pwm_input.cpp.

◆ REG

#define REG (   _reg)    (*(volatile uint32_t *)(PWMIN_TIMER_BASE + _reg))

Definition at line 116 of file pwm_input.cpp.

◆ rEGR

#define rEGR   REG(STM32_GTIM_EGR_OFFSET)

Definition at line 123 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rPSC

#define rPSC   REG(STM32_GTIM_PSC_OFFSET)

Definition at line 128 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rSMCR

#define rSMCR   REG(STM32_GTIM_SMCR_OFFSET)

Definition at line 120 of file pwm_input.cpp.

Referenced by PWMIN::_timer_init().

◆ rSR

#define rSR   REG(STM32_GTIM_SR_OFFSET)

Definition at line 122 of file pwm_input.cpp.

Referenced by pwmin_tim_isr().

◆ TIMEOUT_POLL

#define TIMEOUT_POLL   300000 /* reset after no response over this time in microseconds [0.3s] */

Definition at line 170 of file pwm_input.cpp.

Referenced by PWMIN::_freeze_test(), and PWMIN::init().

◆ TIMEOUT_READ

#define TIMEOUT_READ   200000 /* don't reset if the last read is back more than this time in microseconds [0.2s] */

Definition at line 171 of file pwm_input.cpp.

Referenced by PWMIN::_freeze_test().

Function Documentation

◆ pwm_input_main()

int pwm_input_main ( int  argc,
char *  argv[] 
)

Definition at line 585 of file pwm_input.cpp.

References pwmin_info(), pwmin_reset(), pwmin_start(), pwmin_test(), and pwmin_usage().

Here is the call graph for this function:

◆ pwmin_info()

static void pwmin_info ( void  )
static

Definition at line 566 of file pwm_input.cpp.

References PWMIN::print_info().

Referenced by pwm_input_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pwmin_reset()

static void pwmin_reset ( void  )
static

Definition at line 546 of file pwm_input.cpp.

References cdev::CDev::close(), errx, fd, PWMIN::hard_reset(), PWMIN::ioctl(), OK, PWMIN::open(), PWMIN0_DEVICE_PATH, and SENSORIOCRESET.

Referenced by pwm_input_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pwmin_start()

static void pwmin_start ( )
static

Definition at line 490 of file pwm_input.cpp.

References errx, PWMIN::init(), OK, and PWMIN::PWMIN().

Referenced by pwm_input_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pwmin_test()

static void pwmin_test ( void  )
static

Definition at line 512 of file pwm_input.cpp.

References cdev::CDev::close(), pwm_input_s::error_count, errx, fd, hrt_absolute_time(), PWMIN::open(), pwm_input_s::period, pwm_input_s::pulse_width, PWMIN0_DEVICE_PATH, and PWMIN::read().

Referenced by pwm_input_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pwmin_tim_isr()

static int pwmin_tim_isr ( int  irq,
void *  context,
void *  arg 
)
static

Definition at line 471 of file pwm_input.cpp.

References OK, pwm_input_s::period, PWMIN::publish(), pwm_input_s::pulse_width, rSR, and status.

Referenced by PWMIN::_timer_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pwmin_usage()

static void pwmin_usage ( void  )
static

Definition at line 577 of file pwm_input.cpp.

Referenced by pwm_input_main().

Here is the caller graph for this function:

Variable Documentation

◆ g_dev

PWMIN* g_dev
static

Definition at line 216 of file pwm_input.cpp.