[Taranis] Saves around 800bytes RAM (the same space is used for
DSM2/PPM/PXX pulses on external module)
This commit is contained in:
@@ -39,15 +39,7 @@
|
||||
#define DSM2_SEND_BIND (1 << 7)
|
||||
#define DSM2_SEND_RANGECHECK (1 << 5)
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
uint16_t dsm2Stream[400]; // Likely more than we need
|
||||
uint16_t *dsm2StreamPtr;
|
||||
uint16_t dsm2Value;
|
||||
#else
|
||||
uint8_t dsm2Stream[64]; // Likely more than we need
|
||||
uint8_t *dsm2StreamPtr;
|
||||
uint8_t dsm2SerialByte ;
|
||||
uint8_t dsm2SerialBitCount;
|
||||
#if defined(PCBSKY9X)
|
||||
uint8_t dsm2BindTimer = DSM2_BIND_TIMEOUT;
|
||||
#endif
|
||||
|
||||
@@ -60,18 +52,17 @@ uint8_t dsm2BindTimer = DSM2_BIND_TIMEOUT;
|
||||
#define BITLEN_DSM2 (8*2) //125000 Baud => 8uS per bit
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
uint8_t dsm2Index = 0;
|
||||
void _send_1(uint8_t v)
|
||||
{
|
||||
if (dsm2Index == 0)
|
||||
if (modulePulsesData[EXTERNAL_MODULE].dsm2.index == 0)
|
||||
v -= 2;
|
||||
else
|
||||
v += 2;
|
||||
|
||||
dsm2Value += v;
|
||||
*dsm2StreamPtr++ = dsm2Value;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value += v;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.value;
|
||||
|
||||
dsm2Index = (dsm2Index+1) % 2;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index = (modulePulsesData[EXTERNAL_MODULE].dsm2.index+1) % 2;
|
||||
}
|
||||
|
||||
void sendByteDsm2(uint8_t b) //max 10 changes 0 10 10 10 10 1
|
||||
@@ -94,19 +85,19 @@ void sendByteDsm2(uint8_t b) //max 10 changes 0 10 10 10 10 1
|
||||
}
|
||||
void putDsm2Flush()
|
||||
{
|
||||
dsm2StreamPtr--; //remove last stopbits and
|
||||
*dsm2StreamPtr++ = 44010; // Past the 44000 of the ARR
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.ptr--; //remove last stopbits and
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = 44010; // Past the 44000 of the ARR
|
||||
}
|
||||
#else
|
||||
void putDsm2SerialBit(uint8_t bit)
|
||||
{
|
||||
dsm2SerialByte >>= 1;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte >>= 1;
|
||||
if (bit & 1) {
|
||||
dsm2SerialByte |= 0x80;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte |= 0x80;
|
||||
}
|
||||
if (++dsm2SerialBitCount >= 8) {
|
||||
*dsm2StreamPtr++ = dsm2SerialByte;
|
||||
dsm2SerialBitCount = 0;
|
||||
if (++modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount >= 8) {
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0;
|
||||
}
|
||||
}
|
||||
void sendByteDsm2(uint8_t b) // max 10changes 0 10 10 10 10 1
|
||||
@@ -137,18 +128,18 @@ void setupPulsesDSM2(unsigned int port)
|
||||
static uint8_t dsmDat[2+6*2]={0xFF,0x00, 0x00,0xAA, 0x05,0xFF, 0x09,0xFF, 0x0D,0xFF, 0x13,0x54, 0x14,0xAA};
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
dsm2SerialByte = 0 ;
|
||||
dsm2SerialBitCount = 0 ;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte = 0 ;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0 ;
|
||||
#else
|
||||
dsm2Value = 0;
|
||||
dsm2Index = 1;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value = 0;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index = 1;
|
||||
#endif
|
||||
|
||||
dsm2StreamPtr = dsm2Stream;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.ptr = modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
dsm2Value = 100;
|
||||
*dsm2StreamPtr++ = dsm2Value;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value = 100;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.value;
|
||||
#endif
|
||||
|
||||
switch (s_current_protocol[port]) {
|
||||
|
||||
@@ -36,13 +36,6 @@
|
||||
|
||||
#include "../opentx.h"
|
||||
|
||||
#define PPM_STREAM_INIT { 2000, 2200, 2400, 2600, 2800, 3000, 3200, 3400, 9000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
#if defined(PCBTARANIS)
|
||||
uint16_t ppmStream[NUM_MODULES+1][20] = { PPM_STREAM_INIT, PPM_STREAM_INIT, PPM_STREAM_INIT };
|
||||
#else
|
||||
uint16_t ppmStream[NUM_MODULES][20] = { MODULES_INIT(PPM_STREAM_INIT) };
|
||||
#endif
|
||||
|
||||
void setupPulsesPPM(unsigned int port) // Don't enable interrupts through here
|
||||
{
|
||||
int16_t PPM_range = g_model.extendedLimits ? (512*LIMIT_EXT_PERCENT/100) * 2 : 512 * 2; //range of 0.7..1.7msec
|
||||
@@ -65,7 +58,7 @@ void setupPulsesPPM(unsigned int port) // Don't enable interru
|
||||
pwmptr->PWM_CH_NUM[pwmCh].PWM_CMR |= 0x00000200 ; // CPOL
|
||||
#endif
|
||||
|
||||
uint16_t * ptr = ppmStream[port];
|
||||
uint16_t * ptr = (port == TRAINER_MODULE ? trainerPulsesData.ppm.pulses : modulePulsesData[port].ppm.pulses);
|
||||
int32_t rest = 22500u * 2;
|
||||
rest += (int32_t(g_model.moduleData[port].ppmFrameLength)) * 1000;
|
||||
for (uint32_t i=firstCh; i<lastCh; i++) {
|
||||
|
||||
@@ -41,6 +41,9 @@ uint8_t s_current_protocol[NUM_MODULES] = { MODULES_INIT(255) };
|
||||
uint16_t failsafeCounter[NUM_MODULES] = { MODULES_INIT(100) };
|
||||
uint8_t moduleFlag[NUM_MODULES] = { 0 };
|
||||
|
||||
ModulePulsesData modulePulsesData[NUM_MODULES];
|
||||
TrainerPulsesData trainerPulsesData;
|
||||
|
||||
void setupPulses(unsigned int port)
|
||||
{
|
||||
uint8_t required_protocol;
|
||||
|
||||
@@ -47,6 +47,59 @@ extern uint8_t s_current_protocol[NUM_MODULES];
|
||||
extern uint8_t s_pulses_paused;
|
||||
extern uint16_t failsafeCounter[NUM_MODULES];
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
PACK(struct PpmPulsesData {
|
||||
uint16_t pulses[20];
|
||||
uint32_t index;
|
||||
});
|
||||
PACK(struct PxxPulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t *ptr;
|
||||
uint16_t pcmValue;
|
||||
uint16_t pcmCrc;
|
||||
uint32_t pcmOnesCount;
|
||||
uint16_t serialByte;
|
||||
uint16_t serialBitCount;
|
||||
});
|
||||
PACK(struct Dsm2PulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t *ptr;
|
||||
uint8_t serialByte ;
|
||||
uint8_t serialBitCount;
|
||||
});
|
||||
#else
|
||||
PACK(struct PpmPulsesData {
|
||||
uint16_t pulses[20];
|
||||
uint16_t *ptr;
|
||||
});
|
||||
PACK(struct PxxPulsesData {
|
||||
uint16_t pulses[400];
|
||||
uint16_t *ptr;
|
||||
uint16_t pcmValue;
|
||||
uint16_t pcmCrc;
|
||||
uint32_t pcmOnesCount;
|
||||
});
|
||||
PACK(struct Dsm2PulsesData {
|
||||
uint16_t pulses[400];
|
||||
uint16_t *ptr;
|
||||
uint16_t value;
|
||||
uint16_t index;
|
||||
});
|
||||
#endif
|
||||
|
||||
union ModulePulsesData {
|
||||
PxxPulsesData pxx;
|
||||
Dsm2PulsesData dsm2;
|
||||
PpmPulsesData ppm;
|
||||
};
|
||||
|
||||
union TrainerPulsesData {
|
||||
PpmPulsesData ppm;
|
||||
};
|
||||
|
||||
extern ModulePulsesData modulePulsesData[NUM_MODULES];
|
||||
extern TrainerPulsesData trainerPulsesData;
|
||||
|
||||
void setupPulses(unsigned int port);
|
||||
void setupPulsesDSM2(unsigned int port);
|
||||
void setupPulsesPXX(unsigned int port);
|
||||
@@ -64,7 +117,7 @@ inline void startPulses()
|
||||
setupPulses(INTERNAL_MODULE);
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
#else
|
||||
setupPulses(0);
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
#endif
|
||||
|
||||
#if defined(HUBSAN)
|
||||
|
||||
@@ -40,18 +40,6 @@
|
||||
#define PXX_SEND_FAILSAFE (1 << 4)
|
||||
#define PXX_SEND_RANGECHECK (1 << 5)
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
uint16_t pxxStream[NUM_MODULES][400];
|
||||
uint16_t *pxxStreamPtr[NUM_MODULES];
|
||||
#else
|
||||
uint8_t pxxStream[NUM_MODULES][64];
|
||||
uint8_t *pxxStreamPtr[NUM_MODULES];
|
||||
#endif
|
||||
|
||||
uint16_t PxxValue[NUM_MODULES];
|
||||
uint16_t PcmCrc[NUM_MODULES];
|
||||
uint8_t PcmOnesCount[NUM_MODULES];
|
||||
|
||||
const uint16_t CRCTable[]=
|
||||
{
|
||||
0x0000,0x1189,0x2312,0x329b,0x4624,0x57ad,0x6536,0x74bf,
|
||||
@@ -90,40 +78,38 @@ const uint16_t CRCTable[]=
|
||||
|
||||
void crc(uint8_t data, unsigned int port)
|
||||
{
|
||||
PcmCrc[port]=(PcmCrc[port]<<8)^(CRCTable[((PcmCrc[port]>>8)^data) & 0xFF]);
|
||||
modulePulsesData[port].pxx.pcmCrc = (modulePulsesData[port].pxx.pcmCrc<<8) ^ (CRCTable[((modulePulsesData[port].pxx.pcmCrc>>8)^data) & 0xFF]);
|
||||
}
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
|
||||
void putPcmPart(uint8_t value, unsigned int port)
|
||||
{
|
||||
PxxValue[port] += 18 ; // Output 1 for this time
|
||||
*pxxStreamPtr[port]++ = PxxValue[port] ;
|
||||
PxxValue[port] += 14 ;
|
||||
modulePulsesData[port].pxx.pcmValue += 18 ; // Output 1 for this time
|
||||
*modulePulsesData[port].pxx.ptr++ = modulePulsesData[port].pxx.pcmValue ;
|
||||
modulePulsesData[port].pxx.pcmValue += 14 ;
|
||||
if (value) {
|
||||
PxxValue[port] += 16 ;
|
||||
modulePulsesData[port].pxx.pcmValue += 16 ;
|
||||
}
|
||||
*pxxStreamPtr[port]++ = PxxValue[port] ; // Output 0 for this time
|
||||
*modulePulsesData[port].pxx.ptr++ = modulePulsesData[port].pxx.pcmValue ; // Output 0 for this time
|
||||
}
|
||||
|
||||
void putPcmFlush(unsigned int port)
|
||||
{
|
||||
*pxxStreamPtr[port]++ = 18010 ; // Past the 18000 of the ARR
|
||||
*modulePulsesData[port].pxx.ptr++ = 18010 ; // Past the 18000 of the ARR
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
uint8_t pcmSerialByte[NUM_MODULES];
|
||||
uint8_t pcmSerialBitCount[NUM_MODULES];
|
||||
void putPcmSerialBit(uint8_t bit, unsigned int port)
|
||||
{
|
||||
pcmSerialByte[port] >>= 1;
|
||||
modulePulsesData[port].pxx.serialByte >>= 1;
|
||||
if (bit & 1) {
|
||||
pcmSerialByte[port] |= 0x80;
|
||||
modulePulsesData[port].pxx.serialByte |= 0x80;
|
||||
}
|
||||
if (++pcmSerialBitCount[port] >= 8) {
|
||||
*pxxStreamPtr[port]++ = pcmSerialByte[port];
|
||||
pcmSerialBitCount[port] = 0;
|
||||
if (++modulePulsesData[port].pxx.serialBitCount >= 8) {
|
||||
*modulePulsesData[port].pxx.ptr++ = modulePulsesData[port].pxx.serialByte;
|
||||
modulePulsesData[port].pxx.serialBitCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +125,7 @@ void putPcmPart(uint8_t value, unsigned int port)
|
||||
|
||||
void putPcmFlush(unsigned int port)
|
||||
{
|
||||
while (pcmSerialBitCount[port] != 0) {
|
||||
while (modulePulsesData[port].pxx.serialBitCount != 0) {
|
||||
putPcmSerialBit(1, port);
|
||||
}
|
||||
}
|
||||
@@ -149,14 +135,14 @@ void putPcmFlush(unsigned int port)
|
||||
void putPcmBit(uint8_t bit, unsigned int port)
|
||||
{
|
||||
if (bit) {
|
||||
PcmOnesCount[port] += 1;
|
||||
modulePulsesData[port].pxx.pcmOnesCount += 1;
|
||||
putPcmPart(1, port);
|
||||
}
|
||||
else {
|
||||
PcmOnesCount[port] = 0;
|
||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||
putPcmPart(0, port);
|
||||
}
|
||||
if (PcmOnesCount[port] >= 5) {
|
||||
if (modulePulsesData[port].pxx.pcmOnesCount >= 5) {
|
||||
putPcmBit(0, port); // Stuff a 0 bit in
|
||||
}
|
||||
}
|
||||
@@ -189,10 +175,10 @@ void setupPulsesPXX(unsigned int port)
|
||||
{
|
||||
uint16_t chan=0, chan_low=0;
|
||||
|
||||
pxxStreamPtr[port] = pxxStream[port];
|
||||
PxxValue[port] = 0 ;
|
||||
PcmCrc[port] = 0;
|
||||
PcmOnesCount[port] = 0;
|
||||
modulePulsesData[port].pxx.ptr = modulePulsesData[port].pxx.pulses;
|
||||
modulePulsesData[port].pxx.pcmValue = 0 ;
|
||||
modulePulsesData[port].pxx.pcmCrc = 0;
|
||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||
|
||||
/* Preamble */
|
||||
putPcmPart(0, port);
|
||||
@@ -271,7 +257,7 @@ void setupPulsesPXX(unsigned int port)
|
||||
|
||||
/* CRC16 */
|
||||
putPcmByte(0, port);
|
||||
chan = PcmCrc[port];
|
||||
chan = modulePulsesData[port].pxx.pcmCrc;
|
||||
putPcmByte(chan>>8, port);
|
||||
putPcmByte(chan, port);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user