boards/fmu-v5x: allocating PPS pin

- start pps_capture before pwm_out
This commit is contained in:
Igor Mišić 2021-11-18 12:55:41 +01:00 committed by Beat Küng
parent 60a212f717
commit 298a8c4637
11 changed files with 40 additions and 14 deletions

View File

@ -477,6 +477,9 @@ else
rc_input start $RC_INPUT_ARGS
fi
# PPS capture driver (before pwm_out)
pps_capture start
# Camera capture driver (before pwm_out)
if param greater -s CAM_CAP_FBACK 0
then

View File

@ -62,7 +62,8 @@ typedef enum io_timer_channel_mode_t {
IOTimerChanMode_Trigger = 5,
IOTimerChanMode_Dshot = 6,
IOTimerChanMode_LED = 7,
IOTimerChanMode_Other = 8,
IOTimerChanMode_PPS = 8,
IOTimerChanMode_Other = 9,
IOTimerChanModeSize
} io_timer_channel_mode_t;

View File

@ -149,8 +149,8 @@ static int io_timer_handler7(int irq, void *context, void *arg);
#define rFCTRL20(_tim) REG(_tim, 0, IMXRT_FLEXPWM_FCTRL20_OFFSET) /* Fault Control 2 Register */
// NotUsed PWMOut PWMIn Capture OneShot Trigger Dshot LED Other
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT16_MAX, 0, 0, 0, 0, 0, 0, 0, 0 };
// NotUsed PWMOut PWMIn Capture OneShot Trigger Dshot LED PPS Other
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT16_MAX, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
typedef uint8_t io_timer_allocation_t; /* big enough to hold MAX_IO_TIMERS */

View File

@ -66,7 +66,8 @@ typedef enum io_timer_channel_mode_t {
IOTimerChanMode_Trigger = 5,
IOTimerChanMode_Dshot = 6,
IOTimerChanMode_LED = 7,
IOTimerChanMode_Other = 8,
IOTimerChanMode_PPS = 8,
IOTimerChanMode_Other = 9,
IOTimerChanModeSize
} io_timer_channel_mode_t;

View File

@ -152,8 +152,8 @@ static int io_timer_handler7(int irq, void *context, void *arg);
#define CnSC_PWMIN_INIT 0 // TBD
// NotUsed PWMOut PWMIn Capture OneShot Trigger Dshot LED Other
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT16_MAX, 0, 0, 0, 0, 0, 0, 0, 0 };
// NotUsed PWMOut PWMIn Capture OneShot Trigger Dshot LED PPS Other
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT16_MAX, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
typedef uint8_t io_timer_allocation_t; /* big enough to hold MAX_IO_TIMERS */

View File

@ -62,7 +62,8 @@ typedef enum io_timer_channel_mode_t {
IOTimerChanMode_Trigger = 5,
IOTimerChanMode_Dshot = 6,
IOTimerChanMode_LED = 7,
IOTimerChanMode_Other = 8,
IOTimerChanMode_PPS = 8,
IOTimerChanMode_Other = 9,
IOTimerChanModeSize
} io_timer_channel_mode_t;

View File

@ -150,8 +150,8 @@ static int io_timer_handler7(int irq, void *context, void *arg);
#define CnSC_PWMIN_INIT 0 // TBD
// NotUsed PWMOut PWMIn Capture OneShot Trigger Dshot LED Other
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT16_MAX, 0, 0, 0, 0, 0, 0, 0, 0 };
// NotUsed PWMOut PWMIn Capture OneShot Trigger Dshot LED PPS Other
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT16_MAX, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
typedef uint8_t io_timer_allocation_t; /* big enough to hold MAX_IO_TIMERS */

View File

@ -75,7 +75,8 @@ typedef enum io_timer_channel_mode_t {
IOTimerChanMode_Trigger = 5,
IOTimerChanMode_Dshot = 6,
IOTimerChanMode_LED = 7,
IOTimerChanMode_Other = 8,
IOTimerChanMode_PPS = 8,
IOTimerChanMode_Other = 9,
IOTimerChanModeSize
} io_timer_channel_mode_t;

View File

@ -149,8 +149,8 @@ static int io_timer_handler7(int irq, void *context, void *arg);
/* The transfer is done to 4 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
#define TIM_DMABURSTLENGTH_4TRANSFERS 0x00000300U
// NotUsed PWMOut PWMIn Capture OneShot Trigger Dshot LED Other
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT16_MAX, 0, 0, 0, 0, 0, 0, 0, 0 };
// NotUsed PWMOut PWMIn Capture OneShot Trigger Dshot LED PPS Other
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT16_MAX, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
typedef uint8_t io_timer_allocation_t; /* big enough to hold MAX_IO_TIMERS */

View File

@ -40,6 +40,7 @@
#include "PPSCapture.hpp"
#include "board_config.h"
#include <px4_arch/io_timer.h>
PPSCapture::PPSCapture() :
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default)
@ -48,19 +49,36 @@ PPSCapture::PPSCapture() :
PPSCapture::~PPSCapture()
{
px4_arch_gpiosetevent(BOARD_CAPTURE_GPIO, false, false, false, nullptr, nullptr);
#if defined(PPS_CAPTURE_CHANNEL)
io_timer_unallocate_channel(PPS_CAPTURE_CHANNEL);
px4_arch_gpiosetevent(_pps_capture_gpio, false, false, false, nullptr, nullptr);
#endif
}
bool PPSCapture::init()
{
bool success = false;
int ret_val = px4_arch_gpiosetevent(BOARD_CAPTURE_GPIO, true, false, true, &PPSCapture::gpio_interrupt_callback, this);
#if defined(PPS_CAPTURE_CHANNEL)
int ret = io_timer_allocate_channel(PPS_CAPTURE_CHANNEL, IOTimerChanMode_PPS);
if (ret != PX4_OK) {
PX4_ERR("gpio alloc failed (%i) for PPS at channel (%d)", ret, PPS_CAPTURE_CHANNEL);
return false;
}
_pps_capture_gpio = PX4_MAKE_GPIO_EXTI(io_timer_channel_get_as_pwm_input(PPS_CAPTURE_CHANNEL));
int ret_val = px4_arch_gpiosetevent(_pps_capture_gpio, true, false, true, &PPSCapture::gpio_interrupt_callback, this);
if (ret_val == PX4_OK) {
success = true;
}
#else
#error Driver requires PPS_CAPTURE_CHANNEL to be enabled
#endif
return success;
}

View File

@ -67,6 +67,7 @@ public:
private:
void Run() override;
uint32_t _pps_capture_gpio{0};
uORB::Publication<pps_capture_s> _pps_capture_pub{ORB_ID(pps_capture)};
static constexpr unsigned USEC_IN_1_SEC{1000000}; // microseconds in 1 second