Paparazzi UAS
v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
|
DSHOT driver based on ChibiOS. More...
#include "modules/actuators/esc_dshot.h"
#include <stdnoreturn.h>
#include <math.h>
#include <string.h>
#include "mcu_periph/sys_time_arch.h"
Go to the source code of this file.
Macros | |
#define | DSHOT_TELEMETRY_BAUD 115200U |
Baudrate of the serial link used for telemetry data Can depend on the ESC, but only 115k have been used so far. More... | |
#define | DSHOT_BIDIR_EXTENTED_TELEMETRY FALSE |
#define | DSHOT_TELEMETRY_TIMEOUT_MS 3 |
Telemetry timeout in ms. More... | |
#define | PWM_FREQ (STM32_SYSCLK / 2000U) |
#define | TICKS_PER_PERIOD 1000 |
Ticks per period that let use any timer: does not care if linked to PCLK1 or PCLK2 tick_per_period will be dynamically calculated after pwm init. More... | |
#define | DSHOT_BIT0_DUTY_RATIO 373U |
#define | DSHOT_FREQ (driver->config->speed_khz * 1000U) |
#define | DSHOT_BIT0_DUTY (driver->bit0Duty) |
#define | DSHOT_BIT1_DUTY (driver->bit1Duty) |
#define | TICK_FREQ (PWM_FREQ * TICKS_PER_PERIOD) |
#define | DSHOT_PWM_PERIOD (TICK_FREQ/DSHOT_FREQ) |
#define | DCR_DBL ((DSHOT_CHANNELS-1) << 8) |
#define | DCR_DBA(pwmd) (((uint32_t *) (&pwmd->tim->CCR) - ((uint32_t *) pwmd->tim))) |
#define | DSHOT_MAX_VALUE ((1U<<11U)-1U) |
#define | ARRAY_LEN(a) (sizeof(a)/sizeof(a[0])) |
#define | Min(x, y) (x < y ? x : y) |
Functions | |
static DshotPacket | makeDshotPacket (const uint16_t throttle, const bool tlmRequest) |
static void | setCrc4 (DshotPacket *dp) |
static void | setDshotPacketThrottle (DshotPacket *const dp, const uint16_t throttle) |
static void | setDshotPacketTlm (DshotPacket *const dp, const bool tlmRequest) |
static void | buildDshotDmaBuffer (DSHOTDriver *driver) |
static uint8_t | updateCrc8 (uint8_t crc, uint8_t crc_seed) |
static uint8_t | calculateCrc8 (const uint8_t *Buf, const uint8_t BufLen) |
static noreturn void | dshotTlmRec (void *arg) |
static size_t | getTimerWidth (const PWMDriver *pwmp) |
void | dshotStart (DSHOTDriver *driver, const DSHOTConfig *config) |
Configures and activates the DSHOT peripheral. More... | |
void | dshotStop (DSHOTDriver *driver) |
stop the DSHOT driver and free the related resources : pwm driver and dma driver. More... | |
void | dshotSetThrottle (DSHOTDriver *driver, const uint8_t index, const uint16_t throttle) |
prepare throttle order for specified ESC More... | |
void | dshotSendSpecialCommand (DSHOTDriver *driver, const uint8_t index, const dshot_special_commands_t specmd) |
send special order to one of the ESC (BHELIX, KISS, ...) More... | |
void | dshotSendThrottles (DSHOTDriver *driver, const uint16_t throttles[DSHOT_CHANNELS]) |
send throttle packed order to all of the ESCs More... | |
void | dshotSendFrame (DSHOTDriver *driver) |
send throttle order More... | |
uint32_t | dshotGetCrcErrorCount (const DSHOTDriver *driver) |
return number of telemetry crc error since dshotStart More... | |
uint32_t | dshotGetTelemetryFrameCount (const DSHOTDriver *driver) |
return number of telemetry succesfull frame since dshotStart More... | |
DshotTelemetry | dshotGetTelemetry (DSHOTDriver *driver, uint32_t index) |
return last received telemetry data More... | |
DSHOT driver based on ChibiOS.
Definition in file esc_dshot.c.
#define ARRAY_LEN | ( | a | ) | (sizeof(a)/sizeof(a[0])) |
Definition at line 108 of file esc_dshot.c.
Definition at line 104 of file esc_dshot.c.
#define DCR_DBL ((DSHOT_CHANNELS-1) << 8) |
Definition at line 102 of file esc_dshot.c.
#define DSHOT_BIDIR_EXTENTED_TELEMETRY FALSE |
Definition at line 54 of file esc_dshot.c.
#define DSHOT_BIT0_DUTY (driver->bit0Duty) |
Definition at line 95 of file esc_dshot.c.
#define DSHOT_BIT0_DUTY_RATIO 373U |
Definition at line 86 of file esc_dshot.c.
#define DSHOT_BIT1_DUTY (driver->bit1Duty) |
Definition at line 96 of file esc_dshot.c.
#define DSHOT_FREQ (driver->config->speed_khz * 1000U) |
Definition at line 94 of file esc_dshot.c.
#define DSHOT_MAX_VALUE ((1U<<11U)-1U) |
Definition at line 106 of file esc_dshot.c.
#define DSHOT_PWM_PERIOD (TICK_FREQ/DSHOT_FREQ) |
Definition at line 99 of file esc_dshot.c.
#define DSHOT_TELEMETRY_BAUD 115200U |
Baudrate of the serial link used for telemetry data Can depend on the ESC, but only 115k have been used so far.
Definition at line 50 of file esc_dshot.c.
#define DSHOT_TELEMETRY_TIMEOUT_MS 3 |
Telemetry timeout in ms.
Definition at line 60 of file esc_dshot.c.
#define Min | ( | x, | |
y | |||
) | (x < y ? x : y) |
Definition at line 109 of file esc_dshot.c.
#define PWM_FREQ (STM32_SYSCLK / 2000U) |
Definition at line 71 of file esc_dshot.c.
#define TICK_FREQ (PWM_FREQ * TICKS_PER_PERIOD) |
Definition at line 98 of file esc_dshot.c.
#define TICKS_PER_PERIOD 1000 |
Ticks per period that let use any timer: does not care if linked to PCLK1 or PCLK2 tick_per_period will be dynamically calculated after pwm init.
Definition at line 81 of file esc_dshot.c.
|
static |
Definition at line 623 of file esc_dshot.c.
References DSHOTDriver::config, DSHOTConfig::dma_buf, DshotPackets::dp, DSHOT_BIT0_DUTY, DSHOT_BIT1_DUTY, DSHOT_BIT_WIDTHS, DSHOT_CHANNELS, DSHOT_PRE_FRAME_SILENT_SYNC_BITS, DSHOTDriver::dshotMotors, getTimerWidth(), DSHOTConfig::pwmp, DshotPacket::rawFrame, setCrc4(), and DshotDmaBuffer::widths16.
Referenced by dshotSendFrame().
Definition at line 665 of file esc_dshot.c.
References logger_uart_parse::crc, and updateCrc8().
Referenced by dshotTlmRec().
uint32_t dshotGetCrcErrorCount | ( | const DSHOTDriver * | driver | ) |
return number of telemetry crc error since dshotStart
[in] | driver | pointer to the DSHOTDriver object |
Definition at line 442 of file esc_dshot.c.
References DSHOTDriver::crc_errors.
DshotTelemetry dshotGetTelemetry | ( | DSHOTDriver * | driver, |
uint32_t | index | ||
) |
return last received telemetry data
[in] | driver | pointer to the DSHOTDriver object |
[in] | index | channel : [0..3] or [0..1] depending on driver used |
Definition at line 468 of file esc_dshot.c.
References DSHOT_CHANNEL_FIRST_INDEX, DSHOT_CHANNELS, DSHOTDriver::dshotMotors, DshotPackets::dt, and DshotPackets::tlmMtx.
Referenced by actuators_dshot_arch_commit(), and esc_msg_send().
uint32_t dshotGetTelemetryFrameCount | ( | const DSHOTDriver * | driver | ) |
return number of telemetry succesfull frame since dshotStart
[in] | driver | pointer to the DSHOTDriver object |
Definition at line 454 of file esc_dshot.c.
References DSHOTDriver::tlm_frame_nb.
void dshotSendFrame | ( | DSHOTDriver * | driver | ) |
send throttle order
[in] | driver | pointer to the DSHOTDriver object |
Definition at line 404 of file esc_dshot.c.
References buildDshotDmaBuffer(), DSHOTDriver::config, DshotPackets::currentTlmQry, DSHOTConfig::dma_buf, DMA_READY, DSHOTDriver::dmap, dmaTransfert(), DshotPackets::dp, DSHOT_CHANNELS, DSHOT_DMA_BUFFER_SIZE, DSHOTDriver::dshotMotors, dshotRpmCatchErps(), dshotStop(), DSHOTDriver::mb, DshotPackets::onGoingQry, DSHOTConfig::pwmp, setDshotPacketTlm(), DMADriver::state, and DSHOTConfig::tlm_sd.
Referenced by actuators_dshot_arch_commit(), dshotSendSpecialCommand(), and dshotSendThrottles().
void dshotSendSpecialCommand | ( | DSHOTDriver * | driver, |
const uint8_t | index, | ||
const dshot_special_commands_t | specmd | ||
) |
send special order to one of the ESC (BHELIX, KISS, ...)
[in] | driver | pointer to the DSHOTDriver object |
[in] | index | channel : [0..3] or [0..1] depending on driver used |
[in] | specmd | special commands, see enum @api |
Definition at line 330 of file esc_dshot.c.
References DSHOTDriver::config, DshotPackets::dp, DSHOT_ALL_MOTORS, DSHOT_CHANNELS, DSHOT_CMD_3D_MODE_OFF, DSHOT_CMD_3D_MODE_ON, DSHOT_CMD_AUDIO_STREAM_MODE_ON_OFF, DSHOT_CMD_BIDIR_EDT_MODE_OFF, DSHOT_CMD_BIDIR_EDT_MODE_ON, DSHOT_CMD_MAX, DSHOT_CMD_SAVE_SETTINGS, DSHOT_CMD_SETTINGS_REQUEST, DSHOT_CMD_SILENT_MODE_ON_OFF, DSHOT_CMD_SPIN_DIRECTION_1, DSHOT_CMD_SPIN_DIRECTION_2, DSHOTDriver::dshotMotors, dshotSendFrame(), setDshotPacketThrottle(), setDshotPacketTlm(), and DSHOTConfig::tlm_sd.
void dshotSendThrottles | ( | DSHOTDriver * | driver, |
const uint16_t | throttles[DSHOT_CHANNELS] | ||
) |
send throttle packed order to all of the ESCs
[in] | driver | pointer to the DSHOTDriver object |
[in] | throttle[DSHOT_CHANNELS] | [48 .. 2047] |
Definition at line 385 of file esc_dshot.c.
References DshotPackets::dp, DSHOT_CHANNELS, DSHOTDriver::dshotMotors, dshotSendFrame(), and setDshotPacketThrottle().
void dshotSetThrottle | ( | DSHOTDriver * | driver, |
const uint8_t | index, | ||
const uint16_t | throttle | ||
) |
prepare throttle order for specified ESC
[in] | driver | pointer to the DSHOTDriver object |
[in] | index | channel : [0..3] or [0..1] depending on driver used |
[in] | throttle | [48 .. 2047] |
Definition at line 301 of file esc_dshot.c.
References DshotPackets::dp, DSHOT_ALL_MOTORS, DSHOT_CHANNEL_FIRST_INDEX, DSHOT_CHANNELS, DSHOT_CMD_MAX, DSHOT_MAX_VALUE, DSHOTDriver::dshotMotors, Min, and setDshotPacketThrottle().
Referenced by actuators_dshot_arch_commit().
void dshotStart | ( | DSHOTDriver * | driver, |
const DSHOTConfig * | config | ||
) |
Configures and activates the DSHOT peripheral.
[in] | driver | pointer to the DSHOTDriver object |
[in] | config | pointer to the DSHOTConfig object. @api |
Definition at line 154 of file esc_dshot.c.
References DSHOTDriver::_mbBuf, ARRAY_LEN, DSHOTDriver::bit0Duty, DSHOTDriver::bit1Duty, DSHOTDriver::config, config, DSHOTDriver::crc_errors, DshotPackets::currentTlmQry, DCR_DBA, DCR_DBL, DSHOTDriver::dma_conf, DMA_DIR_M2P, DMA_ONESHOT, dmaObjectInit(), DSHOTDriver::dmap, dmaStart(), DshotPackets::dp, DSHOT_BIDIR, DSHOT_BIT0_DUTY_RATIO, DSHOT_CHANNELS, DSHOT_PWM_PERIOD, DSHOT_TELEMETRY_BAUD, DSHOTDriver::dshotMotors, dshotRpmCaptureStart(), dshotTlmRec(), getTimerWidth(), makeDshotPacket(), DSHOTDriver::mb, DshotPackets::onGoingQry, DSHOTDriver::pwm_conf, DSHOTConfig::pwmp, DMAConfig::stream, TICK_FREQ, TICKS_PER_PERIOD, DSHOTDriver::tlm_frame_nb, DSHOTConfig::tlm_sd, and DshotPackets::tlmMtx.
Referenced by actuators_dshot_arch_init().
void dshotStop | ( | DSHOTDriver * | driver | ) |
stop the DSHOT driver and free the related resources : pwm driver and dma driver.
[in] | driver | pointer to the DSHOTDriver object @api |
Definition at line 260 of file esc_dshot.c.
References DSHOTDriver::config, DSHOTDriver::dmap, dmaStop(), dmaStopTransfert(), and DSHOTConfig::pwmp.
Referenced by dshotSendFrame().
|
static |
Definition at line 712 of file esc_dshot.c.
References calculateCrc8(), DSHOTDriver::config, DshotTelemetryFrame::crc8, DSHOTDriver::crc_errors, DSHOT_TELEMETRY_TIMEOUT_MS, DSHOTDriver::dshotMotors, DshotPackets::dt, DshotTelemetry::frame, idx, DSHOTDriver::mb, DshotPackets::onGoingQry, DSHOTDriver::tlm_frame_nb, DSHOTConfig::tlm_sd, DshotPackets::tlmMtx, and DshotTelemetry::ts.
Referenced by dshotStart().
|
static |
Definition at line 687 of file esc_dshot.c.
References STM32_PWM_USE_TIM2.
Referenced by buildDshotDmaBuffer(), and dshotStart().
|
static |
Definition at line 601 of file esc_dshot.c.
References logger_uart_parse::crc, and setCrc4().
Referenced by dshotStart().
|
static |
Definition at line 587 of file esc_dshot.c.
Referenced by buildDshotDmaBuffer(), and makeDshotPacket().
|
inlinestatic |
Definition at line 612 of file esc_dshot.c.
Referenced by dshotSendSpecialCommand(), dshotSendThrottles(), and dshotSetThrottle().
|
inlinestatic |
Definition at line 618 of file esc_dshot.c.
Referenced by dshotSendFrame(), and dshotSendSpecialCommand().
Definition at line 653 of file esc_dshot.c.
References logger_uart_parse::crc.
Referenced by calculateCrc8().