Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
dshot_rpmCapture.h File Reference
#include <ch.h>
#include <hal.h>
#include "mcu_periph/input_capture_arch.h"
#include "mcu_periph/hal_stm32_dma.h"
#include "mcu_periph/timerDmaCache.h"
#include "modules/actuators/esc_dshot_config.h"
+ Include dependency graph for dshot_rpmCapture.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  DshotDmaStreamChan
 structure defining dma channel More...
 
struct  DshotRpmCaptureOneChannelDmaBuffer
 DMA capture if (errFrame > 2000) { chSysHalt("p *dshotd.config.dma_capt_cfg.dma_capture"); } buffer. More...
 
struct  DshotRpmCaptureDmaBuffer
 
struct  DshotRpmCaptureConfig
 : DSHOT Rpm Capture Driver configuration structure. More...
 
struct  DshotRpmCapture
 

Macros

#define DSHOT_DMA_DATA_LEN   16U
 
#define DSHOT_DMA_EXTRADATA_LEN   2U
 
#define DSHOT_CONCAT_CAPTURE_NX(pre, tim, stream, channel)   pre ## tim ## stream , pre ## tim ## channel
 macro helper to design DMA stream More...
 
#define DSHOTS_1STREAM(tim)   DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL)
 
#define DSHOTS_2STREAMS(tim)
 
#define DSHOTS_3STREAMS(tim)
 
#define DSHOTS_4STREAMS(tim)
 
#define STM32_SYSCLK   STM32_SYS_CK
 

Functions

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...
 
static uint32_t dshotRpmGetFrame (const DshotRpmCapture *drcp, uint8_t index)
 return last collected erps frame More...
 

Data Structure Documentation

◆ DshotDmaStreamChan

struct DshotDmaStreamChan

structure defining dma channel

Note
does not apply for DMAMUX MCU

Definition at line 79 of file dshot_rpmCapture.h.

Data Fields
uint8_t channel
uint32_t stream

◆ DshotRpmCaptureOneChannelDmaBuffer

struct DshotRpmCaptureOneChannelDmaBuffer

DMA capture if (errFrame > 2000) { chSysHalt("p *dshotd.config.dma_capt_cfg.dma_capture"); } buffer.

Definition at line 95 of file dshot_rpmCapture.h.

Data Fields
uint16_t buf[DSHOT_DMA_DATA_LEN+DSHOT_DMA_EXTRADATA_LEN]

◆ DshotRpmCaptureDmaBuffer

struct DshotRpmCaptureDmaBuffer

Definition at line 99 of file dshot_rpmCapture.h.

+ Collaboration diagram for DshotRpmCaptureDmaBuffer:
Data Fields
DshotRpmCaptureOneChannelDmaBuffer dma_buf[DSHOT_CHANNELS]

◆ DshotRpmCaptureConfig

struct DshotRpmCaptureConfig

: DSHOT Rpm Capture Driver configuration structure.

Definition at line 106 of file dshot_rpmCapture.h.

+ Collaboration diagram for DshotRpmCaptureConfig:
Data Fields
DshotRpmCaptureDmaBuffer * dma_capture : pointer to the input capture DMA buffer
Note
: dma_capture must point to DMA compatible memory DCACHE disabled section for F7
DshotDmaStreamChan dma_streams[DSHOT_CHANNELS] : array of DMA stream for each capture channel
GPTDriver * gptd : GPT Driver to manage microseconds timeout
Note
: timeout is too narrow to be managed by RTOS

◆ DshotRpmCapture

struct DshotRpmCapture

Definition at line 131 of file dshot_rpmCapture.h.

+ Collaboration diagram for DshotRpmCapture:
Data Fields
TimerDmaCache cache : cache for timer and dma configuration
Note
: cached configuration are restored via memcpy which is faster than field by field setting
const DshotRpmCaptureConfig * config : pointer to configuration structure
Note
: must be valid for the object life
DMAConfig dmaCfgs[DSHOT_CHANNELS] : dma input capture configuration
DMADriver dmads[DSHOT_CHANNELS] : dma input capture drivers
uint32_t erps[DSHOT_CHANNELS] : array of erps frames
TimICConfig icCfg : input capture timer configuration
TimICDriver icd : input capture timer driver
uint32_t rpms[DSHOT_CHANNELS] : array of rpms

Macro Definition Documentation

◆ DSHOT_CONCAT_CAPTURE_NX

#define DSHOT_CONCAT_CAPTURE_NX (   pre,
  tim,
  stream,
  channel 
)    pre ## tim ## stream , pre ## tim ## channel

macro helper to design DMA stream

Note
does not apply for DMAMUX MCU

Definition at line 23 of file dshot_rpmCapture.h.

◆ DSHOT_DMA_DATA_LEN

#define DSHOT_DMA_DATA_LEN   16U

Definition at line 14 of file dshot_rpmCapture.h.

◆ DSHOT_DMA_EXTRADATA_LEN

#define DSHOT_DMA_EXTRADATA_LEN   2U

Definition at line 15 of file dshot_rpmCapture.h.

◆ DSHOTS_1STREAM

#define DSHOTS_1STREAM (   tim)    DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL)

Definition at line 24 of file dshot_rpmCapture.h.

◆ DSHOTS_2STREAMS

#define DSHOTS_2STREAMS (   tim)
Value:
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL), \
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH2_DMA_STREAM, _CH2_DMA_CHANNEL)
#define DSHOT_CONCAT_CAPTURE_NX(pre, tim, stream, channel)
macro helper to design DMA stream

Definition at line 25 of file dshot_rpmCapture.h.

◆ DSHOTS_3STREAMS

#define DSHOTS_3STREAMS (   tim)
Value:
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL), \
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH2_DMA_STREAM, _CH2_DMA_CHANNEL), \
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH3_DMA_STREAM, _CH3_DMA_CHANNEL)

Definition at line 27 of file dshot_rpmCapture.h.

◆ DSHOTS_4STREAMS

#define DSHOTS_4STREAMS (   tim)
Value:
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL), \
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH2_DMA_STREAM, _CH2_DMA_CHANNEL), \
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH3_DMA_STREAM, _CH3_DMA_CHANNEL), \
DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH4_DMA_STREAM, _CH4_DMA_CHANNEL)

Definition at line 30 of file dshot_rpmCapture.h.

◆ STM32_SYSCLK

#define STM32_SYSCLK   STM32_SYS_CK

Definition at line 71 of file dshot_rpmCapture.h.

Function Documentation

◆ 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:

◆ dshotRpmGetFrame()

static uint32_t dshotRpmGetFrame ( const DshotRpmCapture drcp,
uint8_t  index 
)
inlinestatic

return last collected erps frame

Parameters
[in]drcppointer to the DshotRpmCapture object
[in]indexindex of the channel [1 .. 4] @api

Definition at line 197 of file dshot_rpmCapture.h.

References DshotRpmCapture::rpms.