Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
 
static void stopCapture (DshotRpmCapture *drcp)
 stop the DMA capture
 
static void initCache (DshotRpmCapture *drcp)
 build dma and timer registers cache
 
static uint32_t processErpsDmaBuffer (const uint16_t *capture, size_t dmaLen)
 convert DMA buffer full of pulse length into raw ERPS frame
 
static void buildDmaConfig (DshotRpmCapture *drcp)
 build dma configuration structure
 
static void dmaErrCb (DMADriver *dmad, dmaerrormask_t em)
 dma error ISR :
 
static void gptCb (GPTDriver *gptd)
 dma timeout ISR :
 
void dshotRpmCaptureStart (DshotRpmCapture *drcp, const DshotRpmCaptureConfig *cfg, stm32_tim_t *timer)
 Configures and activates the DSHOT ERPS CAPTURE driver.
 
void dshotRpmCaptureStop (DshotRpmCapture *drcp)
 stop the the DSHOT ERPS CAPTURE driver.
 
void dshotRpmCatchErps (DshotRpmCapture *drcp)
 capture the DSHOT ERPS frame(s) : one frame for each DSHOT_CHANNELS
 

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 DMA_DIR_P2M, DMA_ONESHOT, dmaErrCb(), DSHOT_CHANNELS, foo, and DMAConfig::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.

References foo.

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 foo, 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 foo, and 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 dmaGetTransactionCounter(), dmaStartTransfert(), dmaStopTransfertI(), DSHOT_CHANNELS, DSHOT_DMA_DATA_LEN, DSHOT_DMA_EXTRADATA_LEN, DSHOT_SPEED, foo, msg, processErpsDmaBuffer(), startCapture(), stopCapture(), SWTICH_TO_CAPTURE_BASE_TIMOUT, and timeoutUs.

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 foo.

◆ 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(), dmaObjectInit(), dmaStart(), DSHOT_CHANNELS, dshotRpmCaptureStop(), foo, 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, and foo.

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 foo, gptCfg, 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 foo, 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

◆ [struct]

◆ 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().