mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 23:05:19 +03:00
fix dshot_600
This commit is contained in:
parent
db66284567
commit
f9da3ea755
2 changed files with 52 additions and 46 deletions
|
@ -129,14 +129,17 @@ uint32_t decode_bb_bitband( uint16_t buffer[], uint32_t count, uint32_t bit)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (endP > p) {
|
while (endP > p) {
|
||||||
while (endP > p) {
|
do {
|
||||||
// Look for next positive edge. Manual loop unrolling and branch hinting to produce faster code.
|
// Look for next positive edge. Manual loop unrolling and branch hinting to produce faster code.
|
||||||
if(__builtin_expect(!(p++)->value, 1) &&
|
if(__builtin_expect((p++)->value, 0) ||
|
||||||
__builtin_expect(!(p++)->value, 1) &&
|
__builtin_expect((p++)->value, 0) ||
|
||||||
__builtin_expect(!(p++)->value, 1) &&
|
__builtin_expect((p++)->value, 0) ||
|
||||||
__builtin_expect(!(p++)->value, 1)) {
|
__builtin_expect((p++)->value, 0)) {
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
|
} while (endP > p);
|
||||||
|
|
||||||
|
if (endP > p) {
|
||||||
|
|
||||||
#ifdef DEBUG_BBDECODE
|
#ifdef DEBUG_BBDECODE
|
||||||
sequence[sequenceIndex++] = p - b;
|
sequence[sequenceIndex++] = p - b;
|
||||||
|
@ -149,17 +152,19 @@ uint32_t decode_bb_bitband( uint16_t buffer[], uint32_t count, uint32_t bit)
|
||||||
value <<= len;
|
value <<= len;
|
||||||
value |= 1 << (len - 1);
|
value |= 1 << (len - 1);
|
||||||
oldP = p;
|
oldP = p;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look for next zero edge. Manual loop unrolling and branch hinting to produce faster code.
|
// Look for next zero edge. Manual loop unrolling and branch hinting to produce faster code.
|
||||||
while (endP > p) {
|
do {
|
||||||
if (__builtin_expect((p++)->value, 1) &&
|
if (__builtin_expect(!(p++)->value, 0) ||
|
||||||
__builtin_expect((p++)->value, 1) &&
|
__builtin_expect(!(p++)->value, 0) ||
|
||||||
__builtin_expect((p++)->value, 1) &&
|
__builtin_expect(!(p++)->value, 0) ||
|
||||||
__builtin_expect((p++)->value, 1)) {
|
__builtin_expect(!(p++)->value, 0)) {
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
|
} while (endP > p);
|
||||||
|
|
||||||
|
if (endP > p) {
|
||||||
|
|
||||||
#ifdef DEBUG_BBDECODE
|
#ifdef DEBUG_BBDECODE
|
||||||
sequence[sequenceIndex++] = p - b;
|
sequence[sequenceIndex++] = p - b;
|
||||||
#endif
|
#endif
|
||||||
|
@ -171,7 +176,7 @@ uint32_t decode_bb_bitband( uint16_t buffer[], uint32_t count, uint32_t bit)
|
||||||
value <<= len;
|
value <<= len;
|
||||||
value |= 1 << (len - 1);
|
value |= 1 << (len - 1);
|
||||||
oldP = p;
|
oldP = p;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,15 +248,13 @@ FAST_CODE uint32_t decode_bb( uint16_t buffer[], uint32_t count, uint32_t bit)
|
||||||
sequence[sequenceIndex++] = p - buffer;
|
sequence[sequenceIndex++] = p - buffer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
while (endP > p ) {
|
||||||
// Look for next edge. Manual loop unrolling and branch hinting to produce faster code.
|
// Look for next edge. Manual loop unrolling and branch hinting to produce faster code.
|
||||||
while (endP > p) {
|
if (__builtin_expect((*p++ & mask) != lastValue, 0) ||
|
||||||
if (__builtin_expect((*p++ & mask) == lastValue, 1) &&
|
__builtin_expect((*p++ & mask) != lastValue, 0) ||
|
||||||
__builtin_expect((*p++ & mask) == lastValue, 1) &&
|
__builtin_expect((*p++ & mask) != lastValue, 0) ||
|
||||||
__builtin_expect((*p++ & mask) == lastValue, 1) &&
|
__builtin_expect((*p++ & mask) != lastValue, 0)) {
|
||||||
__builtin_expect((*p++ & mask) == lastValue, 1)) {
|
if (endP > p) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_BBDECODE
|
#ifdef DEBUG_BBDECODE
|
||||||
sequence[sequenceIndex++] = p - buffer;
|
sequence[sequenceIndex++] = p - buffer;
|
||||||
#endif
|
#endif
|
||||||
|
@ -265,6 +268,8 @@ FAST_CODE uint32_t decode_bb( uint16_t buffer[], uint32_t count, uint32_t bit)
|
||||||
oldP = p;
|
oldP = p;
|
||||||
lastValue = *(p-1) & mask;
|
lastValue = *(p-1) & mask;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// length of last sequence has to be inferred since the last bit with inverted dshot is high
|
// length of last sequence has to be inferred since the last bit with inverted dshot is high
|
||||||
if (bits < 18) {
|
if (bits < 18) {
|
||||||
|
|
|
@ -199,7 +199,8 @@ extern uint32_t bbOutputBuffer[MOTOR_DSHOT_BUFFER_SIZE * MAX_SUPPORTED_MOTOR_POR
|
||||||
// <sampling period> = 0.44us
|
// <sampling period> = 0.44us
|
||||||
// <slack> = 10%
|
// <slack> = 10%
|
||||||
// (30 + 26 + 3) / 0.44 = 134
|
// (30 + 26 + 3) / 0.44 = 134
|
||||||
#define DSHOT_BITBANG_PORT_INPUT_BUFFER_LENGTH 134
|
// In some cases this was not enough, so we add 6 extra samples
|
||||||
|
#define DSHOT_BITBANG_PORT_INPUT_BUFFER_LENGTH 140
|
||||||
extern uint16_t bbInputBuffer[DSHOT_BITBANG_PORT_INPUT_BUFFER_LENGTH * MAX_SUPPORTED_MOTOR_PORTS];
|
extern uint16_t bbInputBuffer[DSHOT_BITBANG_PORT_INPUT_BUFFER_LENGTH * MAX_SUPPORTED_MOTOR_PORTS];
|
||||||
|
|
||||||
void bbGpioSetup(bbMotor_t *bbMotor);
|
void bbGpioSetup(bbMotor_t *bbMotor);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue