Paparazzi UAS
v5.15_devel-230-gc96ce27
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>
Go to the source code of this file.
Macros | |
#define | DSHOT_SPEED 600 |
Base freq of DSHOT signal (in kHz) Possible values are: 150, 300, 600, 1200. More... | |
#define | DSHOT_TELEMETRY_BAUD 115200 |
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_TELEMETRY_TIMEOUT_MS 3 |
Telemetry timeout in ms. More... | |
#define | PWM_FREQ (STM32_SYSCLK/2000) |
the timer will beat @84Mhz on STM32F4 // TODO check on F7 More... | |
#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_FREQ (DSHOT_SPEED*1000) |
#define | TICK_FREQ (PWM_FREQ * TICKS_PER_PERIOD) |
#define | DSHOT_PWM_PERIOD (TICK_FREQ/DSHOT_FREQ) |
#define | DSHOT_BIT0_DUTY (DSHOT_PWM_PERIOD * 373 / 1000) |
#define | DSHOT_BIT1_DUTY (DSHOT_BIT0_DUTY*2) |
#define | DCR_DBL ((DSHOT_CHANNELS-1) << 8) |
#define | DCR_DBA(pwmd) (((uint32_t *) (&pwmd->tim->CCR) - ((uint32_t *) pwmd->tim))) |
#define | ARRAY_LEN(a) (sizeof(a)/sizeof(a[0])) |
#define | Min(x, y) (x < y ? x : y) |
#define | DSHOT_MAX_VALUE ((1<<11)-1) |
Functions | |
static DshotPacket | makeDshotPacket (const uint16_t throttle, const bool tlmRequest) |
static void | setDshotPacketThrottle (DshotPacket *const dp, const uint16_t throttle) |
static void | setDshotPacketTlm (DshotPacket *const dp, const bool tlmRequest) |
static void | buildDshotDmaBuffer (DshotPackets *const dsp, DshotDmaBuffer *const dma, const size_t timerWidth) |
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 | 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 | dshotGetCrcErrorsCount (DSHOTDriver *driver) |
return number of telemetry crc error since dshotStart More... | |
const DshotTelemetry * | dshotGetTelemetry (const DSHOTDriver *driver, const 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 84 of file esc_dshot.c.
Referenced by dshotStart().
Definition at line 82 of file esc_dshot.c.
Referenced by dshotStart().
#define DCR_DBL ((DSHOT_CHANNELS-1) << 8) |
Definition at line 81 of file esc_dshot.c.
Referenced by dshotStart().
#define DSHOT_BIT0_DUTY (DSHOT_PWM_PERIOD * 373 / 1000) |
Definition at line 79 of file esc_dshot.c.
Referenced by buildDshotDmaBuffer().
#define DSHOT_BIT1_DUTY (DSHOT_BIT0_DUTY*2) |
Definition at line 80 of file esc_dshot.c.
Referenced by buildDshotDmaBuffer().
#define DSHOT_FREQ (DSHOT_SPEED*1000) |
Definition at line 76 of file esc_dshot.c.
#define DSHOT_MAX_VALUE ((1<<11)-1) |
Definition at line 87 of file esc_dshot.c.
Referenced by dshotSetThrottle().
#define DSHOT_PWM_PERIOD (TICK_FREQ/DSHOT_FREQ) |
Definition at line 78 of file esc_dshot.c.
Referenced by dshotStart().
#define DSHOT_SPEED 600 |
Base freq of DSHOT signal (in kHz) Possible values are: 150, 300, 600, 1200.
Definition at line 48 of file esc_dshot.c.
#define DSHOT_TELEMETRY_BAUD 115200 |
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 55 of file esc_dshot.c.
Referenced by dshotStart().
#define DSHOT_TELEMETRY_TIMEOUT_MS 3 |
#define Min | ( | x, | |
y | |||
) | (x < y ? x : y) |
Definition at line 85 of file esc_dshot.c.
Referenced by computeOptiTrack(), dshotSetThrottle(), e_identification_fr_init(), generic_com_periodic(), gh_set_max_speed(), gps_ubx_parse_nav_sat(), gps_ubx_parse_nav_svinfo(), gps_ubx_parse_rxm_raw(), guidance_h_traj_run(), guidance_v_from_nav(), guidance_v_guided_run(), guidance_v_run(), h_ctl_course_loop(), init_gazebo(), mavlink_send_gps_status(), mt9f002_calc_resolution(), mt9f002_set_resolution(), nav_circle(), nav_circle_XY(), nav_survey_rectangle(), nav_survey_rectangle_init(), nav_survey_rectangle_rotorcraft_run(), nav_survey_rectangle_rotorcraft_setup(), parse_xsens700_msg(), parse_xsens_msg(), syslink_put_buffer(), and tcas_periodic_task_4Hz().
#define PWM_FREQ (STM32_SYSCLK/2000) |
the timer will beat @84Mhz on STM32F4 // TODO check on F7
Definition at line 65 of file esc_dshot.c.
#define TICK_FREQ (PWM_FREQ * TICKS_PER_PERIOD) |
Definition at line 77 of file esc_dshot.c.
Referenced by dshotStart().
#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 73 of file esc_dshot.c.
Referenced by dshotStart().
|
static |
Definition at line 386 of file esc_dshot.c.
References DshotPackets::dp, DSHOT_BIT0_DUTY, DSHOT_BIT1_DUTY, DSHOT_BIT_WIDTHS, DSHOT_CHANNELS, DshotPacket::rawFrame, and DshotDmaBuffer::widths16.
Referenced by dshotSendFrame().
Definition at line 428 of file esc_dshot.c.
References crc, and updateCrc8().
Referenced by dshotTlmRec().
uint32_t dshotGetCrcErrorsCount | ( | DSHOTDriver * | driver | ) |
return number of telemetry crc error since dshotStart
[in] | driver | pointer to the DSHOTDriver object |
Definition at line 330 of file esc_dshot.c.
References DSHOTDriver::crc_errors.
const DshotTelemetry* dshotGetTelemetry | ( | const DSHOTDriver * | driver, |
const 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 343 of file esc_dshot.c.
References DSHOTDriver::dshotMotors, and DshotPackets::dt.
void dshotSendFrame | ( | DSHOTDriver * | driver | ) |
send throttle order
[in] | driver | pointer to the DSHOTDriver object |
Definition at line 303 of file esc_dshot.c.
References buildDshotDmaBuffer(), DSHOTDriver::config, DshotPackets::currentTlmQry, DMA_READY, DSHOTDriver::dmap, dmaStartTransfert(), DshotPackets::dp, DSHOTDriver::dsdb, DSHOT_CHANNELS, DSHOT_DMA_BUFFER_SIZE, DSHOTDriver::dshotMotors, getTimerWidth(), 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 |
Definition at line 240 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_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 287 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 215 of file esc_dshot.c.
References DshotPackets::dp, DSHOT_ALL_MOTORS, 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. |
Definition at line 122 of file esc_dshot.c.
References DSHOTDriver::_mbBuf, ARRAY_LEN, config, DSHOTDriver::config, DSHOTDriver::crc_errors, DCR_DBA, DCR_DBL, DSHOTConfig::dma_channel, DSHOTDriver::dma_conf, DMA_DIR_M2P, DSHOTConfig::dma_stream, dmaObjectInit(), DSHOTDriver::dmap, dmaStart(), DshotPackets::dp, DSHOTDriver::dsdb, DSHOT_CHANNELS, DSHOT_DMA_BUFFER_SIZE, DSHOT_PWM_PERIOD, DSHOT_TELEMETRY_BAUD, DSHOTDriver::dshotMotors, dshotTlmRec(), getTimerWidth(), makeDshotPacket(), DSHOTDriver::mb, DSHOTDriver::pwm_conf, DSHOTConfig::pwmp, DMAConfig::stream, TICK_FREQ, TICKS_PER_PERIOD, and DSHOTConfig::tlm_sd.
Referenced by actuators_dshot_arch_init().
|
static |
Definition at line 463 of file esc_dshot.c.
References calculateCrc8(), DSHOTDriver::config, DshotTelemetry::crc8, DSHOTDriver::crc_errors, DSHOT_TELEMETRY_TIMEOUT_MS, DSHOTDriver::dshotMotors, DshotPackets::dt, idx, DSHOTDriver::mb, DshotPackets::onGoingQry, and DSHOTConfig::tlm_sd.
Referenced by dshotStart().
|
static |
Definition at line 439 of file esc_dshot.c.
References STM32_PWM_USE_TIM2.
Referenced by dshotSendFrame(), and dshotStart().
|
static |
Definition at line 358 of file esc_dshot.c.
References crc.
Referenced by dshotStart().
|
inlinestatic |
Definition at line 375 of file esc_dshot.c.
Referenced by dshotSendSpecialCommand(), dshotSendThrottles(), and dshotSetThrottle().
|
inlinestatic |
Definition at line 381 of file esc_dshot.c.
Referenced by dshotSendFrame(), and dshotSendSpecialCommand().
Definition at line 416 of file esc_dshot.c.
References crc.
Referenced by calculateCrc8().