Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
dshot_rpmCapture.c File Reference
#include "modules/actuators/dshot_rpmCapture.h"
#include <string.h>
+ Include dependency graph for dshot_rpmCapture.c:

Go to the source code of this file.

Macros

#define SWTICH_TO_CAPTURE_BASE_TIMOUT   28U
 
#define nullptr   NULL
 

Functions

static void startCapture (DshotRpmCapture *drcp)
 start the DMA capture More...
 
static void stopCapture (DshotRpmCapture *drcp)
 stop the DMA capture More...
 
static void initCache (DshotRpmCapture *drcp)
 build dma and timer registers cache More...
 
static uint32_t processErpsDmaBuffer (const uint16_t *capture, size_t dmaLen)
 convert DMA buffer full of pulse length into raw ERPS frame More...
 
static void buildDmaConfig (DshotRpmCapture *drcp)
 build dma configuration structure More...
 
static void dmaErrCb (DMADriver *dmad, dmaerrormask_t em)
 dma error ISR : More...
 
static void gptCb (GPTDriver *gptd)
 dma timeout ISR : More...
 
void dshotRpmCaptureStart (DshotRpmCapture *drcp, const DshotRpmCaptureConfig *cfg, stm32_tim_t *timer)
 Configures and activates the DSHOT ERPS CAPTURE driver. More...
 
void dshotRpmCaptureStop (DshotRpmCapture *drcp)
 stop the the DSHOT ERPS CAPTURE driver. More...
 
void dshotRpmCatchErps (DshotRpmCapture *drcp)
 capture the DSHOT ERPS frame(s) : one frame for each DSHOT_CHANNELS More...
 

Variables

static const float TIM_FREQ_MHZ = (STM32_SYSCLK / 1e6d)
 
static const float bit1t_us = TIM_FREQ_MHZ * 6.67d * 4 / 5
 
static const float speed_factor = DSHOT_SPEED / 150
 
static const uint32_t ERPS_BIT1_DUTY = bit1t_us / speed_factor
 
static const uint32_t TIM_PRESCALER = 1U
 
struct {
uint32_t active
 
uint32_t dier
 
activeDier [4]
 
static const TimICConfig timicCfgSkel
 
static const GPTConfig gptCfg
 

Macro Definition Documentation

◆ nullptr

#define nullptr   NULL

Definition at line 49 of file dshot_rpmCapture.c.

◆ SWTICH_TO_CAPTURE_BASE_TIMOUT

#define SWTICH_TO_CAPTURE_BASE_TIMOUT   28U

Definition at line 31 of file dshot_rpmCapture.c.

Function Documentation

◆ buildDmaConfig()

static void buildDmaConfig ( DshotRpmCapture drcp)
static

build dma configuration structure

Parameters
[in]drcppointer to the DshotRpmCapture object

Definition at line 250 of file dshot_rpmCapture.c.

References DMAConfig::channel, DshotDmaStreamChan::channel, DshotRpmCapture::config, DMA_DIR_P2M, DMA_ONESHOT, DshotRpmCaptureConfig::dma_streams, DshotRpmCapture::dmaCfgs, dmaErrCb(), DSHOT_CHANNELS, DMAConfig::stream, and DshotDmaStreamChan::stream.

Referenced by initCache().

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

◆ dmaErrCb()

static void dmaErrCb ( DMADriver dmad,
dmaerrormask_t  em 
)
static

dma error ISR :

Parameters
[in]drcppointer to the DMADriver
[in]emerror mask
Note
does nothing if DSHOT_STATISTICS == FALSE

Definition at line 397 of file dshot_rpmCapture.c.

Referenced by buildDmaConfig().

+ Here is the caller graph for this function:

◆ dshotRpmCaptureStart()

void dshotRpmCaptureStart ( DshotRpmCapture drcp,
const DshotRpmCaptureConfig cfg,
stm32_tim_t *  timer 
)

Configures and activates the DSHOT ERPS CAPTURE driver.

Parameters
[in]drcppointer to the DshotRpmCapture object
[in]cfgpointer to the DshotRpmCaptureConfig object.
[in]timerpointer to the underlying timer (same one used to output control frame) @api

Definition at line 108 of file dshot_rpmCapture.c.

References DshotRpmCapture::config, DshotRpmCapture::icCfg, initCache(), TimICConfig::timer, and timicCfgSkel.

Referenced by dshotStart().

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

◆ dshotRpmCaptureStop()

void dshotRpmCaptureStop ( DshotRpmCapture drcp)

stop the the DSHOT ERPS CAPTURE driver.

Parameters
[in]drcppointer to the DshotRpmCapture object @api

Definition at line 124 of file dshot_rpmCapture.c.

References stopCapture().

Referenced by initCache().

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

◆ dshotRpmCatchErps()

void dshotRpmCatchErps ( DshotRpmCapture drcp)

capture the DSHOT ERPS frame(s) : one frame for each DSHOT_CHANNELS

Parameters
[in]drcppointer to the DshotRpmCapture object
Note
synchronous API, when it returns, the erpm data is available @api

Definition at line 149 of file dshot_rpmCapture.c.

References DshotRpmCaptureOneChannelDmaBuffer::buf, TimICDriver::config, DshotRpmCapture::config, DshotRpmCaptureDmaBuffer::dma_buf, DshotRpmCaptureConfig::dma_capture, DshotRpmCapture::dmads, dmaGetTransactionCounter(), dmaStartTransfert(), dmaStopTransfertI(), DSHOT_CHANNELS, DSHOT_DMA_DATA_LEN, DSHOT_DMA_EXTRADATA_LEN, DSHOT_SPEED, DshotRpmCaptureConfig::gptd, DshotRpmCapture::icd, msg, processErpsDmaBuffer(), DshotRpmCapture::rpms, startCapture(), stopCapture(), SWTICH_TO_CAPTURE_BASE_TIMOUT, timeoutUs, and TimICConfig::timer.

Referenced by dshotSendFrame().

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

◆ gptCb()

static void gptCb ( GPTDriver *  gptd)
static

dma timeout ISR :

Parameters
[in]gptdpointer to the GPTDriver that trigger the timeout
Note
does nothing if DSHOT_STATISTICS == FALSE

Definition at line 414 of file dshot_rpmCapture.c.

References DshotRpmCapture::dmads.

◆ initCache()

static void initCache ( DshotRpmCapture drcp)
static

build dma and timer registers cache

Parameters
[in]drcppointer to the DshotRpmCapture object

Definition at line 297 of file dshot_rpmCapture.c.

References buildDmaConfig(), DshotRpmCapture::cache, DshotRpmCapture::config, DshotRpmCapture::dmaCfgs, DshotRpmCapture::dmads, dmaObjectInit(), dmaStart(), DSHOT_CHANNELS, dshotRpmCaptureStop(), DshotRpmCaptureConfig::gptd, DshotRpmCapture::icCfg, DshotRpmCapture::icd, TimICConfig::timer, timerDmaCache_cache(), timIcObjectInit(), and timIcStart().

Referenced by dshotRpmCaptureStart().

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

◆ processErpsDmaBuffer()

static uint32_t processErpsDmaBuffer ( const uint16_t capture,
size_t  dmaLen 
)
static

convert DMA buffer full of pulse length into raw ERPS frame

Parameters
[in]drcppointer to the DshotRpmCapture object

Definition at line 347 of file dshot_rpmCapture.c.

References ERPS_BIT1_DUTY.

Referenced by dshotRpmCatchErps().

+ Here is the caller graph for this function:

◆ startCapture()

static void startCapture ( DshotRpmCapture drcp)
static

start the DMA capture

Parameters
[in]drcppointer to the DshotRpmCapture object

Definition at line 320 of file dshot_rpmCapture.c.

References DshotRpmCapture::cache, DshotRpmCapture::config, DshotRpmCapture::dmads, gptCfg, DshotRpmCaptureConfig::gptd, DshotRpmCapture::icCfg, DshotRpmCapture::icd, TimICConfig::timer, timerDmaCache_restore(), and timIcStartCapture().

Referenced by dshotRpmCatchErps().

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

◆ stopCapture()

static void stopCapture ( DshotRpmCapture drcp)
static

stop the DMA capture

Parameters
[in]drcppointer to the DshotRpmCapture object

Definition at line 333 of file dshot_rpmCapture.c.

References DshotRpmCapture::config, DshotRpmCaptureConfig::gptd, DshotRpmCapture::icd, timIcRccDisable(), and timIcStopCapture().

Referenced by dshotRpmCaptureStop(), and dshotRpmCatchErps().

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

Variable Documentation

◆ 

const { ... } activeDier[4]
Initial value:
= {
TIM_DIER_CC1DE | TIM_DIER_TDE},
TIM_DIER_CC1DE | TIM_DIER_CC2DE | TIM_DIER_TDE},
TIM_DIER_CC1DE | TIM_DIER_CC2DE | TIM_DIER_CC3DE | TIM_DIER_TDE},
TIM_DIER_CC1DE | TIM_DIER_CC2DE | TIM_DIER_CC3DE | TIM_DIER_CC4DE | TIM_DIER_TDE}
}
@ CH1_BOTH_EDGES
@ CH3_BOTH_EDGES
@ CH4_BOTH_EDGES
@ CH2_BOTH_EDGES

◆ bit1t_us

const float bit1t_us = TIM_FREQ_MHZ * 6.67d * 4 / 5
static

Definition at line 17 of file dshot_rpmCapture.c.

◆ ERPS_BIT1_DUTY

const uint32_t ERPS_BIT1_DUTY = bit1t_us / speed_factor
static

Definition at line 20 of file dshot_rpmCapture.c.

Referenced by processErpsDmaBuffer().

◆ gptCfg

const GPTConfig gptCfg
static
Initial value:
= {
.frequency = 1000U * 1000U,
.callback = &gptCb,
.cr2 = 0,
.dier = 0
}
static void gptCb(GPTDriver *gptd)
dma timeout ISR :

Definition at line 92 of file dshot_rpmCapture.c.

Referenced by startCapture().

◆ speed_factor

const float speed_factor = DSHOT_SPEED / 150
static

Definition at line 18 of file dshot_rpmCapture.c.

◆ TIM_FREQ_MHZ

const float TIM_FREQ_MHZ = (STM32_SYSCLK / 1e6d)
static

Definition at line 15 of file dshot_rpmCapture.c.

◆ TIM_PRESCALER

const uint32_t TIM_PRESCALER = 1U
static

Definition at line 21 of file dshot_rpmCapture.c.

◆ timicCfgSkel

const TimICConfig timicCfgSkel
static
Initial value:
= {
.timer = NULL,
.capture_cb = NULL,
.overflow_cb = NULL,
.active = activeDier[DSHOT_CHANNELS-1].active,
.dier = activeDier[DSHOT_CHANNELS-1].dier,
.dcr = 0,
.prescaler = TIM_PRESCALER,
.arr = 0xffffffff
}
static const uint32_t TIM_PRESCALER
static const struct @5 activeDier[4]
#define DSHOT_CHANNELS
@ TIMIC_INPUT_CAPTURE

Definition at line 68 of file dshot_rpmCapture.c.

Referenced by dshotRpmCaptureStart().