Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 More...
 
static DshotEPeriodPacket eperiodToPacked (const uint32_t eperiod)
 encode packet from eperiod More...
 
static uint32_t greyEncode (uint32_t num)
 get grey binary value from natural binary More...
 
static uint32_t greyDecode (const uint32_t num)
 get natural binary value from grey binary More...
 
static uint32_t gcrEncode (uint32_t from)
 encode 16 bit value to 20 bits GCR More...
 
static uint32_t gcrDecode (uint32_t from)
 decode 20 bits GCR value to 16 bits natural More...
 
static uint32_t eperiodEncode (const uint16_t eperiod)
 encode eperiod to 20 bits GCR of grey value More...
 
static uint32_t eperiodDecode (const uint32_t frame)
 decode 20 bits GCR of grey value to eperiod More...
 
static void setFromEperiod (DshotErps *derpsp, uint32_t eperiod)
 initialize from eperiod in microseconds More...
 
static void frameToPacket (DshotErps *derpsp)
 decode eperiod More...
 
static void packetToFrame (DshotErps *derpsp)
 encode eperiod More...
 
const DshotErpsDshotErpsSetFromFrame (DshotErps *derpsp, uint32_t frame)
 initialise from GCR encoded frame More...
 
const DshotErpsDshotErpsSetFromRpm (DshotErps *derpsp, uint32_t rpm)
 initialise from rpm value More...
 
uint32_t DshotErpsGetEperiod (const DshotErps *derpsp)
 return eperiod from mantisse and exponent More...
 
uint32_t DshotErpsGetRpm (const DshotErps *derpsp)
 calculate and return rpm More...
 
bool DshotErpsCheckCrc4 (const DshotErps *derpsp)
 check packed validity More...
 

Variables

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

Function Documentation

◆ crc4()

static 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()

static 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()

static 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()

static 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()

static 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()

static 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()

static 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()

static 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()

static 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()

static 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()

static 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().