|
Paparazzi UAS v7.1_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.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. | |
| #define | DSHOT_BIDIR_EXTENTED_TELEMETRY FALSE |
| #define | DSHOT_TELEMETRY_TIMEOUT_MS 3 |
| Telemetry timeout in ms. | |
| #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. | |
| #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) |
| #define | DSHOT_MAX_VALUE ((1U<<11U)-1U) |
| #define | ARRAY_LEN(a) |
| #define | Min(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. | |
| void | dshotStop (DSHOTDriver *driver) |
| stop the DSHOT driver and free the related resources : pwm driver and dma driver. | |
| void | dshotSetThrottle (DSHOTDriver *driver, const uint8_t index, const uint16_t throttle) |
| prepare throttle order for specified ESC | |
| void | dshotSendSpecialCommand (DSHOTDriver *driver, const uint8_t index, const dshot_special_commands_t specmd) |
| send special order to one of the ESC (BHELIX, KISS, ...) | |
| void | dshotSendThrottles (DSHOTDriver *driver, const uint16_t throttles[DSHOT_CHANNELS]) |
| send throttle packed order to all of the ESCs | |
| void | dshotSendFrame (DSHOTDriver *driver) |
| send throttle order | |
| uint32_t | dshotGetCrcErrorCount (const DSHOTDriver *driver) |
| return number of telemetry crc error since dshotStart | |
| uint32_t | dshotGetTelemetryFrameCount (const DSHOTDriver *driver) |
| return number of telemetry succesfull frame since dshotStart | |
| DshotTelemetry | dshotGetTelemetry (DSHOTDriver *driver, uint32_t index) |
| return last received telemetry data | |
DSHOT driver based on ChibiOS.
Definition in file esc_dshot.c.
| #define ARRAY_LEN | ( | a | ) |
Definition at line 109 of file esc_dshot.c.
Referenced by dshotStart().
| #define DCR_DBA | ( | pwmd | ) |
| #define DCR_DBL ((DSHOT_CHANNELS-1) << 8) |
Definition at line 103 of file esc_dshot.c.
Referenced by dshotStart().
| #define DSHOT_BIDIR_EXTENTED_TELEMETRY FALSE |
Definition at line 55 of file esc_dshot.c.
| #define DSHOT_BIT0_DUTY (driver->bit0Duty) |
Definition at line 96 of file esc_dshot.c.
Referenced by buildDshotDmaBuffer().
| #define DSHOT_BIT0_DUTY_RATIO 373U |
Definition at line 87 of file esc_dshot.c.
Referenced by dshotStart().
| #define DSHOT_BIT1_DUTY (driver->bit1Duty) |
Definition at line 97 of file esc_dshot.c.
Referenced by buildDshotDmaBuffer().
| #define DSHOT_FREQ (driver->config->speed_khz * 1000U) |
Definition at line 95 of file esc_dshot.c.
| #define DSHOT_MAX_VALUE ((1U<<11U)-1U) |
Definition at line 107 of file esc_dshot.c.
Referenced by dshotSetThrottle().
| #define DSHOT_PWM_PERIOD (TICK_FREQ/DSHOT_FREQ) |
Definition at line 100 of file esc_dshot.c.
Referenced by dshotStart().
| #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 51 of file esc_dshot.c.
Referenced by dshotStart().
| #define DSHOT_TELEMETRY_TIMEOUT_MS 3 |
| #define Min | ( | x, | |
| y ) |
Definition at line 110 of file esc_dshot.c.
Referenced by acc_body_bound(), air_data_filter_init(), air_data_finish_calibration(), cam_gimbal_waypoint_target(), chirp_update(), cloud_sensor_callback(), computeOptiTrack(), dshotSetThrottle(), generic_com_periodic(), gh_set_max_speed(), gps_ubx_parse_nav_sat(), gps_ubx_parse_nav_svinfo(), guidance_pid_h_run(), h_ctl_course_loop(), init_gazebo(), ins_ext_pose_check_age(), invensense3_456_parse_fifo_data(), invensense3_456_periodic(), invensense3_event(), invensense3_init(), invensense3_parse_fifo_data(), invensense3_periodic(), mavlink_send_gps_status(), max_speed_for_deceleration(), mcu_get_uid(), mt9f002_calc_resolution(), mt9f002_set_resolution(), nav_circle(), nav_circle(), nav_circle_XY(), nav_survey_rectangle(), nav_survey_rectangle_init(), nav_survey_rectangle_rotorcraft_run(), nav_survey_rectangle_rotorcraft_setup(), node_info_cb(), parse_xsens700_msg(), parse_xsens_msg(), RdMulti(), rtttl_next(), sdlog_report_status(), stabilization_indi_set_wls_settings(), syslink_put_buffer(), tag_tracking_init(), tcas_periodic_task_4Hz(), uavcan_init_reporting(), uid_from_file(), uid_from_mac(), and WrMulti().
| #define PWM_FREQ (STM32_SYSCLK / 2000U) |
Definition at line 72 of file esc_dshot.c.
| #define TICK_FREQ (PWM_FREQ * TICKS_PER_PERIOD) |
Definition at line 99 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 82 of file esc_dshot.c.
Referenced by dshotStart().
|
static |
Definition at line 624 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 666 of file esc_dshot.c.
References 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 443 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 469 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().
| uint32_t dshotGetTelemetryFrameCount | ( | const DSHOTDriver * | driver | ) |
return number of telemetry succesfull frame since dshotStart
| [in] | driver | pointer to the DSHOTDriver object |
Definition at line 455 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 405 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 331 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 386 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 302 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 155 of file esc_dshot.c.
References DSHOTDriver::_mbBuf, ARRAY_LEN, DSHOTDriver::bit0Duty, DSHOTDriver::bit1Duty, DSHOTDriver::config, DSHOTDriver::crc_errors, DshotPackets::currentTlmQry, DCR_DBA, DCR_DBL, DSHOTConfig::dma_buf, DSHOTConfig::dma_channel, DSHOTDriver::dma_conf, DMA_DIR_M2P, DMA_ONESHOT, DSHOTConfig::dma_stream, 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, 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 261 of file esc_dshot.c.
References DSHOTDriver::config, DSHOTDriver::dmap, dmaStop(), dmaStopTransfert(), and DSHOTConfig::pwmp.
Referenced by dshotSendFrame().
|
static |
Definition at line 713 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 688 of file esc_dshot.c.
References getTimerWidth(), STM32_PWM_USE_TIM2, and STM32_PWM_USE_TIM5.
Referenced by buildDshotDmaBuffer(), dshotStart(), and getTimerWidth().
|
static |
Definition at line 602 of file esc_dshot.c.
References setCrc4().
Referenced by dshotStart().
|
static |
Definition at line 588 of file esc_dshot.c.
Referenced by buildDshotDmaBuffer(), and makeDshotPacket().
|
inlinestatic |
Definition at line 613 of file esc_dshot.c.
Referenced by dshotSendSpecialCommand(), dshotSendThrottles(), and dshotSetThrottle().
|
inlinestatic |
Definition at line 619 of file esc_dshot.c.
Referenced by dshotSendFrame(), and dshotSendSpecialCommand().
Definition at line 654 of file esc_dshot.c.
Referenced by calculateCrc8().