dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PiOS DMA-driven DShot driver

Generates DShot signal by updating timer CC registers via DMA bursts. More...

Data Structures

struct  pios_dmashot_timer_cfg
 Configuration struct to assign a DMA channel and stream to a timer, and optionally specify a master timer to update single timer registers of timers without DMA channel. More...
 
struct  pios_dmashot_cfg
 Configuration struct holding all timer configurations. More...
 
union  dma_buffer
 
struct  servo_timer
 

Macros

#define DMASHOT_150   150000
 
#define DMASHOT_300   300000
 
#define DMASHOT_600   600000
 
#define DMASHOT_1200   1200000
 
#define MAX_TIMERS   8
 
#define DMASHOT_MESSAGE_WIDTH   16
 
#define DMASHOT_MESSAGE_PAUSE   1
 
#define DMASHOT_STM32_BUFFER   (DMASHOT_MESSAGE_PAUSE + DMASHOT_MESSAGE_WIDTH + DMASHOT_MESSAGE_PAUSE)
 
#define DSHOT_DUTY_CYCLE_0   36
 
#define DSHOT_DUTY_CYCLE_1   74
 
#define TIMC_TO_INDEX(c)   ((c)>>2)
 

Functions

void PIOS_DMAShot_Init (const struct pios_dmashot_cfg *config)
 Initializes the DMAShot driver by loading the configuration. More...
 
void PIOS_DMAShot_Prepare ()
 Makes sure the DMAShot driver has allocated all internal structs. More...
 
bool PIOS_DMAShot_IsConfigured ()
 Checks whether DMAShot has been configured. More...
 
bool PIOS_DMAShot_IsReady ()
 Checks whether DMAShot is ready for use (i.e. at least one DMA configured timer). More...
 
bool PIOS_DMAShot_RegisterTimer (TIM_TypeDef *timer, uint32_t clockrate, uint32_t dshot_freq)
 Tells the DMAShot driver about a timer that needs to be set up. More...
 
bool PIOS_DMAShot_RegisterServo (const struct pios_tim_channel *servo_channel)
 Tells the DMAShot driver about a servo that needs to be set up. More...
 
void PIOS_DMAShot_InitializeGPIOs ()
 Initializes the GPIO on the registered servos for DMAShot operation. More...
 
void PIOS_DMAShot_InitializeTimers (TIM_OCInitTypeDef *ocinit)
 Initializes and configures the registered timers for DMAShot operation. More...
 
void PIOS_DMAShot_InitializeDMAs ()
 Initializes and configures the known DMA channels for DMAShot operation. More...
 
void PIOS_DMAShot_Validate ()
 Validates any timer and servo registrations. More...
 
void PIOS_DMAShot_WriteValue (const struct pios_tim_channel *servo_channel, uint16_t throttle)
 Sets the throttle value of a specific servo. More...
 
void PIOS_DMAShot_TriggerUpdate ()
 Triggers the configured DMA channels to fire and send throttle values to the timer DMAR and optional CCRx registers. More...
 
static bool PIOS_DMAShot_HalfWord (struct servo_timer *s_timer)
 
static int PIOS_DMAShot_GetNumChannels (struct servo_timer *timer)
 
static struct servo_timerPIOS_DMAShot_GetServoTimer (const struct pios_tim_channel *servo_channel)
 
static void PIOS_DMAShot_TimerSetup (struct servo_timer *s_timer, uint32_t sysclock, uint32_t dshot_freq, TIM_OCInitTypeDef *ocinit, bool master)
 
static void PIOS_DMAShot_DMASetup (struct servo_timer *s_timer)
 
static uint32_t PIOS_DMAShot_AllocateBuffer (uint16_t size)
 

Variables

TIM_TypeDef * pios_dmashot_timer_cfg::timer
 
DMA_Stream_TypeDef * pios_dmashot_timer_cfg::stream
 
uint32_t pios_dmashot_timer_cfg::channel
 
uint32_t pios_dmashot_timer_cfg::tcif
 
TIM_TypeDef * pios_dmashot_timer_cfg::master_timer
 
uint16_t pios_dmashot_timer_cfg::master_config
 
const struct
pios_dmashot_timer_cfg
pios_dmashot_cfg::timer_cfg
 
uint8_t pios_dmashot_cfg::num_timers
 
uint32_t dma_buffer::ptr
 
uint32_t * dma_buffer::fw
 
uint16_t * dma_buffer::hw
 
uint32_t servo_timer::sysclock
 
const struct
pios_dmashot_timer_cfg
servo_timer::dma
 
const struct pios_tim_channelservo_timer::servo_channels [4]
 
uint8_t servo_timer::low_channel
 
uint8_t servo_timer::high_channel
 
uint32_t servo_timer::dshot_freq
 
uint16_t servo_timer::duty_cycle_0
 
uint16_t servo_timer::duty_cycle_1
 
union dma_buffer servo_timer::buffer
 
uint8_t servo_timer::dma_started
 
const struct pios_dmashot_cfgdmashot_cfg
 
struct servo_timer ** servo_timers
 

Detailed Description

Generates DShot signal by updating timer CC registers via DMA bursts.

Macro Definition Documentation

#define DMASHOT_1200   1200000

Definition at line 44 of file pios_dmashot.h.

#define DMASHOT_150   150000

Definition at line 41 of file pios_dmashot.h.

#define DMASHOT_300   300000

Definition at line 42 of file pios_dmashot.h.

#define DMASHOT_600   600000

Definition at line 43 of file pios_dmashot.h.

#define DMASHOT_MESSAGE_PAUSE   1

Definition at line 68 of file pios_dmashot.c.

#define DMASHOT_MESSAGE_WIDTH   16

Definition at line 67 of file pios_dmashot.c.

#define DMASHOT_STM32_BUFFER   (DMASHOT_MESSAGE_PAUSE + DMASHOT_MESSAGE_WIDTH + DMASHOT_MESSAGE_PAUSE)

Definition at line 69 of file pios_dmashot.c.

#define DSHOT_DUTY_CYCLE_0   36

Definition at line 73 of file pios_dmashot.c.

#define DSHOT_DUTY_CYCLE_1   74

Definition at line 74 of file pios_dmashot.c.

#define MAX_TIMERS   8

Definition at line 33 of file pios_dmashot.c.

#define TIMC_TO_INDEX (   c)    ((c)>>2)

Definition at line 76 of file pios_dmashot.c.

Function Documentation

static uint32_t PIOS_DMAShot_AllocateBuffer ( uint16_t  size)
static

Definition at line 450 of file pios_dmashot.c.

static void PIOS_DMAShot_DMASetup ( struct servo_timer s_timer)
static

Definition at line 399 of file pios_dmashot.c.

static int PIOS_DMAShot_GetNumChannels ( struct servo_timer timer)
static

Definition at line 88 of file pios_dmashot.c.

static struct servo_timer* PIOS_DMAShot_GetServoTimer ( const struct pios_tim_channel servo_channel)
static

Definition at line 126 of file pios_dmashot.c.

static bool PIOS_DMAShot_HalfWord ( struct servo_timer s_timer)
inlinestatic

Definition at line 82 of file pios_dmashot.c.

void PIOS_DMAShot_Init ( const struct pios_dmashot_cfg config)

Initializes the DMAShot driver by loading the configuration.

Parameters
[in]configConfiguration struct.

Definition at line 96 of file pios_dmashot.c.

void PIOS_DMAShot_InitializeDMAs ( )

Initializes and configures the known DMA channels for DMAShot operation.

Definition at line 467 of file pios_dmashot.c.

void PIOS_DMAShot_InitializeGPIOs ( )

Initializes the GPIO on the registered servos for DMAShot operation.

Definition at line 297 of file pios_dmashot.c.

void PIOS_DMAShot_InitializeTimers ( TIM_OCInitTypeDef *  ocinit)

Initializes and configures the registered timers for DMAShot operation.

Definition at line 367 of file pios_dmashot.c.

bool PIOS_DMAShot_IsConfigured ( )

Checks whether DMAShot has been configured.

Return values
TRUEon success, FALSE when there's no configuration.

Definition at line 565 of file pios_dmashot.c.

bool PIOS_DMAShot_IsReady ( )

Checks whether DMAShot is ready for use (i.e. at least one DMA configured timer).

Return values
TRUEon success, FALSE when there's no configuration or DMA capable timers.

Definition at line 552 of file pios_dmashot.c.

void PIOS_DMAShot_Prepare ( )

Makes sure the DMAShot driver has allocated all internal structs.

Definition at line 104 of file pios_dmashot.c.

bool PIOS_DMAShot_RegisterServo ( const struct pios_tim_channel servo_channel)

Tells the DMAShot driver about a servo that needs to be set up.

Parameters
[in]servo_channelThe servo in question.
Return values
TRUEon success, FALSE when the related timer isn't set up, or DMAShot isn't set up correctly.

Definition at line 250 of file pios_dmashot.c.

bool PIOS_DMAShot_RegisterTimer ( TIM_TypeDef *  timer,
uint32_t  clockrate,
uint32_t  dshot_freq 
)

Tells the DMAShot driver about a timer that needs to be set up.

Parameters
[in]timerThe STM32 timer in question.
[in]clockrateThe frequency the timer's set up to run.
[in]dshot_freqThe desired DShot signal frequency (in KHz).
Return values
TRUEon success, FALSE when there's no configuration for the specific timer, or DMAShot isn't set up correctly.

Definition at line 190 of file pios_dmashot.c.

static void PIOS_DMAShot_TimerSetup ( struct servo_timer s_timer,
uint32_t  sysclock,
uint32_t  dshot_freq,
TIM_OCInitTypeDef *  ocinit,
bool  master 
)
static

Definition at line 322 of file pios_dmashot.c.

void PIOS_DMAShot_TriggerUpdate ( )

Triggers the configured DMA channels to fire and send throttle values to the timer DMAR and optional CCRx registers.

Definition at line 489 of file pios_dmashot.c.

void PIOS_DMAShot_Validate ( )

Validates any timer and servo registrations.

Definition at line 279 of file pios_dmashot.c.

void PIOS_DMAShot_WriteValue ( const struct pios_tim_channel servo_channel,
uint16_t  throttle 
)

Sets the throttle value of a specific servo.

Parameters
[in]servo_channelThe servo to update.
[in]throttleThe desired throttle value (0-2047).
Return values
TRUEon success, FALSE if the channel's not set up for DMA.

Definition at line 143 of file pios_dmashot.c.

Variable Documentation

union dma_buffer servo_timer::buffer

Definition at line 60 of file pios_dmashot.c.

uint32_t pios_dmashot_timer_cfg::channel

Definition at line 55 of file pios_dmashot.h.

const struct pios_dmashot_timer_cfg* servo_timer::dma

Definition at line 48 of file pios_dmashot.c.

uint8_t servo_timer::dma_started

Definition at line 61 of file pios_dmashot.c.

const struct pios_dmashot_cfg* dmashot_cfg

Definition at line 78 of file pios_dmashot.c.

uint32_t servo_timer::dshot_freq

Definition at line 55 of file pios_dmashot.c.

uint16_t servo_timer::duty_cycle_0

Definition at line 57 of file pios_dmashot.c.

uint16_t servo_timer::duty_cycle_1

Definition at line 58 of file pios_dmashot.c.

uint32_t* dma_buffer::fw

Definition at line 40 of file pios_dmashot.c.

uint8_t servo_timer::high_channel

Definition at line 53 of file pios_dmashot.c.

uint16_t* dma_buffer::hw

Definition at line 41 of file pios_dmashot.c.

uint8_t servo_timer::low_channel

Definition at line 52 of file pios_dmashot.c.

uint16_t pios_dmashot_timer_cfg::master_config

Definition at line 59 of file pios_dmashot.h.

TIM_TypeDef* pios_dmashot_timer_cfg::master_timer

Definition at line 58 of file pios_dmashot.h.

uint8_t pios_dmashot_cfg::num_timers

Definition at line 69 of file pios_dmashot.h.

uint32_t dma_buffer::ptr

Definition at line 39 of file pios_dmashot.c.

const struct pios_tim_channel* servo_timer::servo_channels[4]

Definition at line 49 of file pios_dmashot.c.

struct servo_timer** servo_timers

Definition at line 79 of file pios_dmashot.c.

DMA_Stream_TypeDef* pios_dmashot_timer_cfg::stream

Definition at line 54 of file pios_dmashot.h.

uint32_t servo_timer::sysclock

Definition at line 46 of file pios_dmashot.c.

uint32_t pios_dmashot_timer_cfg::tcif

Definition at line 56 of file pios_dmashot.h.

TIM_TypeDef* pios_dmashot_timer_cfg::timer

Definition at line 53 of file pios_dmashot.h.

const struct pios_dmashot_timer_cfg* pios_dmashot_cfg::timer_cfg

Definition at line 68 of file pios_dmashot.h.