Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
dshot_rpmCapture.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ch.h>
4 #include <hal.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #define DSHOT_DMA_DATA_LEN 16U
15 #define DSHOT_DMA_EXTRADATA_LEN 2U
16 
17 
18 #if STM32_DMA_SUPPORTS_DMAMUX == false
23 #define DSHOT_CONCAT_CAPTURE_NX(pre, tim, stream, channel) pre ## tim ## stream , pre ## tim ## channel
24 #define DSHOTS_1STREAM(tim) DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL)
25 #define DSHOTS_2STREAMS(tim) DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL), \
26  DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH2_DMA_STREAM, _CH2_DMA_CHANNEL)
27 #define DSHOTS_3STREAMS(tim) DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL), \
28  DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH2_DMA_STREAM, _CH2_DMA_CHANNEL), \
29  DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH3_DMA_STREAM, _CH3_DMA_CHANNEL)
30 #define DSHOTS_4STREAMS(tim) DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH1_DMA_STREAM, _CH1_DMA_CHANNEL), \
31  DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH2_DMA_STREAM, _CH2_DMA_CHANNEL), \
32  DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH3_DMA_STREAM, _CH3_DMA_CHANNEL), \
33  DSHOT_CONCAT_CAPTURE_NX(STM32_TIM, tim, _CH4_DMA_STREAM, _CH4_DMA_CHANNEL)
34 
35 #else // STM32_DMA_SUPPORTS_DMAMUX == true
41 #define DSHOT_CONCAT_CAPTURE_NX(pre, tim, event) {STM32_DMA_STREAM_ID_ANY , pre ## tim ## event}
42 #define DSHOTS_1STREAM(tim) DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH1)
43 #define DSHOTS_2STREAMS(tim) DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH1), \
44  DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH2)
45 #define DSHOTS_3STREAMS(tim) DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH1), \
46  DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH2), \
47  DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH3)
48 #define DSHOTS_4STREAMS(tim) DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH1), \
49  DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH2), \
50  DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH3), \
51  DSHOT_CONCAT_CAPTURE_NX(STM32_DMAMUX1_TIM, tim, _CH4)
52 #endif // STM32_DMA_SUPPORTS_DMAMUX == false
53 
54 #if DSHOT_CHANNELS == 1
55 #define DSHOTS_CAPTURE_STREAMS(tim) DSHOTS_1STREAM(tim)
56 #elif DSHOT_CHANNELS == 2
57 #define DSHOTS_CAPTURE_STREAMS(tim) DSHOTS_2STREAMS(tim)
58 #elif DSHOT_CHANNELS == 3
59 #define DSHOTS_CAPTURE_STREAMS(tim) DSHOTS_3STREAMS(tim)
60 #elif DSHOT_CHANNELS == 4
61 #define DSHOTS_CAPTURE_STREAMS(tim) DSHOTS_4STREAMS(tim)
62 #else // DSHOT_CHANNELS = X
63 #error DSHOT_CHANNELS must be 1 to 4
64 #endif // DSHOT_CHANNELS = X
65 
66 
67 #if !defined STM32_SYSCLK && !defined STM32_SYS_CK
68 #error neither STM32_SYSCLK or STM32_SYS_CK defined
69 #endif
70 #if !defined STM32_SYSCLK
71 #define STM32_SYSCLK STM32_SYS_CK
72 #endif
73 
74 
79 typedef struct {
81 #if STM32_DMA_SUPPORTS_DMAMUX
82  uint8_t dmamux;
83 #else
85 #endif
87 
88 
95 typedef struct {
96  __attribute__((aligned(32)))
99 typedef struct {
102 
106 typedef struct {
111  GPTDriver *gptd;
122 #if __DCACHE_PRESENT
126  bool dcache_memory_in_use;
127 #endif
129 
130 
131 typedef struct
132 {
168 #ifdef DSHOT_STATISTICS
172  uint64_t accumDecodeTime;
176  uint32_t nbDecode;
177 #endif
179 
180 
181 
183  stm32_tim_t *timer);
186 #if DSHOT_STATISTICS
187 void dshotRpmTrace(DshotRpmCapture *drcp, uint8_t index);
188 uint32_t dshotRpmGetDmaErr(void) ;
189 #endif
197 static inline uint32_t dshotRpmGetFrame(const DshotRpmCapture *drcp, uint8_t index) {
198  return drcp->rpms[index];
199 }
200 #if DSHOT_STATISTICS
208 static inline uint32_t dshotRpmGetAverageDecodeTimeNs(DshotRpmCapture *drcp) {
209  return (drcp->accumDecodeTime * 1e9f) / STM32_SYSCLK / drcp->nbDecode;
210 }
211 #endif
212 
213 
214 #ifdef __cplusplus
215 }
216 #endif
TimICDriver icd
: input capture timer driver
#define DSHOT_DMA_EXTRADATA_LEN
TimICConfig icCfg
: input capture timer configuration
void dshotRpmCaptureStart(DshotRpmCapture *drcp, const DshotRpmCaptureConfig *cfg, stm32_tim_t *timer)
Configures and activates the DSHOT ERPS CAPTURE driver.
const DshotRpmCaptureConfig * config
: pointer to configuration structure
TimerDmaCache cache
: cache for timer and dma configuration
uint32_t rpms[DSHOT_CHANNELS]
: array of rpms
#define STM32_SYSCLK
DshotRpmCaptureDmaBuffer * dma_capture
: pointer to the input capture DMA buffer
static uint32_t dshotRpmGetFrame(const DshotRpmCapture *drcp, uint8_t index)
return last collected erps frame
#define DSHOT_DMA_DATA_LEN
void dshotRpmCatchErps(DshotRpmCapture *drcp)
capture the DSHOT ERPS frame(s) : one frame for each DSHOT_CHANNELS
void dshotRpmCaptureStop(DshotRpmCapture *drcp)
stop the the DSHOT ERPS CAPTURE driver.
GPTDriver * gptd
: GPT Driver to manage microseconds timeout
structure defining dma channel
: DSHOT Rpm Capture Driver configuration structure.
DMA capture if (errFrame > 2000) { chSysHalt("p *dshotd.config.dma_capt_cfg.dma_capture"); } buffer.
#define DSHOT_CHANNELS
STM32 DMA subsystem driver header.
DMA stream configuration structure.
Structure representing a DMA driver.
TimIC Driver configuration structure.
Structure representing a TimIC driver.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned long long uint64_t
Definition: vl53l1_types.h:72
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98