Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
dshot_erps.c File Reference
Include dependency graph for dshot_erps.c:

Go to the source code of this file.

Functions

static uint8_t crc4 (uint16_t val)
 calculate crc4
static DshotEPeriodPacket eperiodToPacked (const uint32_t eperiod)
 encode packet from eperiod
static uint32_t greyEncode (uint32_t num)
 get grey binary value from natural binary
static uint32_t greyDecode (const uint32_t num)
 get natural binary value from grey binary
static uint32_t gcrEncode (uint32_t from)
 encode 16 bit value to 20 bits GCR
static uint32_t gcrDecode (uint32_t from)
 decode 20 bits GCR value to 16 bits natural
static uint32_t eperiodEncode (const uint16_t eperiod)
 encode eperiod to 20 bits GCR of grey value
static uint32_t eperiodDecode (const uint32_t frame)
 decode 20 bits GCR of grey value to eperiod
static void setFromEperiod (DshotErps *derpsp, uint32_t eperiod)
 initialize from eperiod in microseconds
static void frameToPacket (DshotErps *derpsp)
 decode eperiod
static void packetToFrame (DshotErps *derpsp)
 encode eperiod
const DshotErps * DshotErpsSetFromFrame (DshotErps *derpsp, uint32_t frame)
 initialise from GCR encoded frame
const DshotErps * DshotErpsSetFromRpm (DshotErps *derpsp, uint32_t rpm)
 initialise from rpm value
uint32_t DshotErpsGetEperiod (const DshotErps *derpsp)
 return eperiod from mantisse and exponent
uint32_t DshotErpsGetRpm (const DshotErps *derpsp)
 calculate and return rpm
bool DshotErpsCheckCrc4 (const DshotErps *derpsp)
 check packed validity

Variables

static const uint8_t gcrNibble [16]
 IBM GCR encoding lookup table.
static const uint8_t gcrNibbleInv [32]
 IBM GCR decoding lookup table.

Function Documentation

◆ crc4()

uint8_t crc4 ( uint16_t val)
static

calculate crc4

Parameters
[in]val
Returns
true if CRC is OK

Definition at line 111 of file dshot_erps.c.

References val.

Referenced by DshotErpsCheckCrc4(), and eperiodToPacked().

Here is the caller graph for this function:

◆ DshotErpsCheckCrc4()

bool DshotErpsCheckCrc4 ( const DshotErps * derpsp)

check packed validity

Parameters
[in]derpsppointer to the DshotErps object
Returns
true if CRC is OK @api

Definition at line 99 of file dshot_erps.c.

References crc4(), DshotErps::ep, and DshotEPeriodPacket::rawFrame.

Here is the call graph for this function:

◆ DshotErpsGetEperiod()

uint32_t DshotErpsGetEperiod ( const DshotErps * derpsp)
private

return eperiod from mantisse and exponent

Parameters
[in]derpsppointer to the DshotErps object
Returns
eperiod in microseconds
Note
getEperiod avoid a division and is more cpu friendly than getRpm

Definition at line 72 of file dshot_erps.c.

References DshotErps::ep.

Referenced by DshotErpsGetRpm().

Here is the caller graph for this function:

◆ DshotErpsGetRpm()

uint32_t DshotErpsGetRpm ( const DshotErps * derpsp)

calculate and return rpm

Parameters
[in]derpsppointer to the DshotErps object
Returns
rotational speed in RPM
Note
involve a division, which is a cpu cycle hog, If you can use getEperiod instead, it will be less calculus intensive @api

Definition at line 87 of file dshot_erps.c.

References DshotErpsGetEperiod().

Here is the call graph for this function:

◆ DshotErpsSetFromFrame()

const DshotErps * DshotErpsSetFromFrame ( DshotErps * derpsp,
uint32_t frame )

initialise from GCR encoded frame

Parameters
[in]derpsppointer to the DshotErps object @api

Definition at line 44 of file dshot_erps.c.

References DshotErps::ef, frame, and frameToPacket().

Here is the call graph for this function:

◆ DshotErpsSetFromRpm()

const DshotErps * DshotErpsSetFromRpm ( DshotErps * derpsp,
uint32_t rpm )

initialise from rpm value

Parameters
[in]derpsppointer to the DshotErps object @api

Definition at line 57 of file dshot_erps.c.

References rpm, and setFromEperiod().

Here is the call graph for this function:

◆ eperiodDecode()

uint32_t eperiodDecode ( const uint32_t frame)
static

decode 20 bits GCR of grey value to eperiod

Parameters
[in]GCR(0,2)encoded value received from ESC
Returns
eperiod in microseconds

Definition at line 230 of file dshot_erps.c.

References frame, gcrDecode(), and greyDecode().

Referenced by frameToPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eperiodEncode()

uint32_t eperiodEncode ( const uint16_t eperiod)
static

encode eperiod to 20 bits GCR of grey value

Parameters
[in]eperiodin microseconds
Returns
GCR(0,2) encoded value ready to be transmitted

Definition at line 218 of file dshot_erps.c.

References gcrEncode(), and greyEncode().

Referenced by packetToFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eperiodToPacked()

DshotEPeriodPacket eperiodToPacked ( const uint32_t eperiod)
static

encode packet from eperiod

Parameters
[in]eperiodin microseconds
Returns
encoded DshotEPeriodPacket

Definition at line 124 of file dshot_erps.c.

References crc4(), and p.

Referenced by setFromEperiod().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ frameToPacket()

void frameToPacket ( DshotErps * derpsp)
static

decode eperiod

Parameters
[in,out]derpsppointer to the DshotErps object

Definition at line 254 of file dshot_erps.c.

References DshotErps::ef, DshotErps::ep, eperiodDecode(), and DshotEPeriodPacket::rawFrame.

Referenced by DshotErpsSetFromFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gcrDecode()

uint32_t gcrDecode ( uint32_t from)
static

decode 20 bits GCR value to 16 bits natural

Parameters
[in]GCR(0,2)encoded value
Returns
binary value

Definition at line 194 of file dshot_erps.c.

References gcrNibbleInv.

Referenced by eperiodDecode().

Here is the caller graph for this function:

◆ gcrEncode()

uint32_t gcrEncode ( uint32_t from)
static

encode 16 bit value to 20 bits GCR

Parameters
[in]binaryvalue
Returns
GCR(0,2) encoded value

Definition at line 175 of file dshot_erps.c.

References gcrNibble.

Referenced by eperiodEncode().

Here is the caller graph for this function:

◆ greyDecode()

uint32_t greyDecode ( const uint32_t num)
static

get natural binary value from grey binary

Parameters
[in]greyencoded value
Returns
num natural binary value

Definition at line 163 of file dshot_erps.c.

Referenced by eperiodDecode().

Here is the caller graph for this function:

◆ greyEncode()

uint32_t greyEncode ( uint32_t num)
static

get grey binary value from natural binary

Parameters
[in]numnatural binary value
Returns
grey encoded value

Definition at line 146 of file dshot_erps.c.

Referenced by eperiodEncode().

Here is the caller graph for this function:

◆ packetToFrame()

void packetToFrame ( DshotErps * derpsp)
static

encode eperiod

Parameters
[in,out]derpsppointer to the DshotErps object

Definition at line 266 of file dshot_erps.c.

References DshotErps::ef, DshotErps::ep, eperiodEncode(), and DshotEPeriodPacket::rawFrame.

Referenced by setFromEperiod().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFromEperiod()

void setFromEperiod ( DshotErps * derpsp,
uint32_t eperiod )
static

initialize from eperiod in microseconds

Parameters
[in]derpsppointer to the DshotErps object
[in]eperiodin microseconds

Definition at line 242 of file dshot_erps.c.

References DshotErps::ep, eperiodToPacked(), and packetToFrame().

Referenced by DshotErpsSetFromRpm().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ gcrNibble

const uint8_t gcrNibble[16]
static
Initial value:
= {
0x19, 0x1B, 0x12, 0x13, 0x1D, 0x15, 0x16, 0x17,
0x1A, 0x09, 0x0A, 0x0B, 0x1E, 0x0D, 0x0E, 0x0F}

IBM GCR encoding lookup table.

Definition at line 8 of file dshot_erps.c.

Referenced by gcrEncode().

◆ gcrNibbleInv

const uint8_t gcrNibbleInv[32]
static
Initial value:
= {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x9, 0xa, 0xb, 0xff, 0xd, 0xe, 0xf,
0xff, 0xff, 0x2, 0x3, 0xff, 0x5, 0x6, 0x7,
0xff, 0x0, 0x8, 0x1, 0xff, 0x4, 0xc, 0xff}

IBM GCR decoding lookup table.

Definition at line 15 of file dshot_erps.c.

Referenced by gcrDecode().