#1761 - Radio part done

This commit is contained in:
bsongis
2014-12-08 19:39:54 +01:00
parent 9dd572c191
commit a9e64c3603
14 changed files with 210 additions and 159 deletions
+33 -21
View File
@@ -36,6 +36,9 @@
#include "../opentx.h"
#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;
@@ -45,6 +48,8 @@ uint8_t dsm2Stream[64]; // Likely more than we need
uint8_t *dsm2StreamPtr;
uint8_t dsm2SerialByte ;
uint8_t dsm2SerialBitCount;
uint8_t dsm2BindEnable = 0;
uint8_t dsm2BindTimer = DSM2_BIND_TIMEOUT;
#endif
// DSM2 control bits
@@ -72,21 +77,21 @@ void _send_1(uint8_t v)
void sendByteDsm2(uint8_t b) //max 10 changes 0 10 10 10 10 1
{
bool lev = 0;
uint8_t len = BITLEN_DSM2; //max val: 9*16 < 256
for (uint8_t i=0; i<=8; i++) { //8Bits + Stop=1
bool nlev = b & 1; //lsb first
if (lev == nlev) {
len += BITLEN_DSM2;
}
else {
_send_1(len); // _send_1(nlev ? len-5 : len+3);
len = BITLEN_DSM2;
lev = nlev;
}
b = (b>>1) | 0x80; //shift in stop bit
bool lev = 0;
uint8_t len = BITLEN_DSM2; //max val: 9*16 < 256
for (uint8_t i=0; i<=8; i++) { //8Bits + Stop=1
bool nlev = b & 1; //lsb first
if (lev == nlev) {
len += BITLEN_DSM2;
}
_send_1(len+BITLEN_DSM2); // _send_1(len+BITLEN_DSM2+3); // 2 stop bits
else {
_send_1(len); // _send_1(nlev ? len-5 : len+3);
len = BITLEN_DSM2;
lev = nlev;
}
b = (b>>1) | 0x80; //shift in stop bit
}
_send_1(len+BITLEN_DSM2); // _send_1(len+BITLEN_DSM2+3); // 2 stop bits
}
void putDsm2Flush()
{
@@ -159,15 +164,22 @@ void setupPulsesDSM2(unsigned int port)
break;
}
#if !defined(PCBTARANIS)
if (s_bind_allowed) s_bind_allowed--;
if (s_bind_allowed && switchState(SW_DSM2_BIND))
dsm2Flag = DSM2_BIND_FLAG;
else
dsm2Flag &= ~DSM2_BIND_FLAG;
#if defined(PCBTARANIS)
if (moduleFlag[port] == MODULE_BIND)
dsmDat[0] |= DSM2_SEND_BIND;
else if (moduleFlag[port] == MODULE_RANGECHECK)
dsmDat[0] |= DSM2_SEND_RANGECHECK;
#else
dsm2BindEnable = 0;
if (dsm2BindTimer > 0) {
dsm2BindTimer--;
if (switchState(SW_DSM2_BIND)) {
dsm2BindEnable = DSM2_SEND_BIND;
dsmDat[0] |= DSM2_SEND_BIND;
}
}
#endif
dsmDat[0] |= dsm2Flag;
dsmDat[1] = g_model.header.modelId; // DSM2 Header second byte for model match
for (int i=0; i<DSM2_CHANS; i++) {
+94
View File
@@ -0,0 +1,94 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef PULSES_COMMON_H
#define PULSES_COMMON_H
enum ModuleFlag
{
MODULE_NORMAL_MODE,
MODULE_RANGECHECK,
MODULE_BIND,
MODULE_OFF,
};
#if defined(CPUARM) // (PXX) || defined(DSM2)
extern uint8_t moduleFlag[NUM_MODULES];
#endif
#if NUM_MODULES > 1
#define IS_RANGECHECK_ENABLE() (moduleFlag[0] == MODULE_RANGECHECK || moduleFlag[1] == MODULE_RANGECHECK)
#else
#define IS_RANGECHECK_ENABLE() (moduleFlag[0] == MODULE_RANGECHECK)
#endif
#if defined(DSM2) && !defined(PCBTARANIS)
#define DSM2_BIND_TIMEOUT 255 // 255*11ms
extern uint8_t dsm2BindTimer;
extern uint8_t dsm2BindEnable; // needed to display BIND on screen
#endif
#if defined(CPUARM)
#define IS_PPM_PROTOCOL(protocol) (protocol==PROTO_PPM)
#else
#define IS_PPM_PROTOCOL(protocol) (protocol<=PROTO_PPMSIM)
#endif
#if defined(PXX)
#define IS_PXX_PROTOCOL(protocol) (protocol==PROTO_PXX)
#else
#define IS_PXX_PROTOCOL(protocol) (0)
#endif
#if defined(DSM2)
#define IS_DSM2_PROTOCOL(protocol) (protocol>=PROTO_DSM2_LP45 && protocol<=PROTO_DSM2_DSMX)
#else
#define IS_DSM2_PROTOCOL(protocol) (0)
#endif
#if defined(DSM2_SERIAL)
#define IS_DSM2_SERIAL_PROTOCOL(protocol) (IS_DSM2_PROTOCOL(protocol))
#else
#define IS_DSM2_SERIAL_PROTOCOL(protocol) (0)
#endif
#if defined(CPUARM)
#include "pulses_arm.h"
#else
#include "pulses_avr.h"
#endif
#endif
+7 -2
View File
@@ -39,6 +39,7 @@
uint8_t s_pulses_paused = 0;
uint8_t s_current_protocol[NUM_MODULES] = { MODULES_INIT(255) };
uint32_t failsafeCounter[NUM_MODULES] = { MODULES_INIT(100) };
uint8_t moduleFlag[NUM_MODULES] = { 0 };
void setupPulses(unsigned int port)
{
@@ -62,13 +63,13 @@ void setupPulses(unsigned int port)
case MODULE_TYPE_XJT:
required_protocol = PROTO_PXX;
break;
#if defined(DSM2)
#if defined(PCBTARANIS) && defined(DSM2)
case MODULE_TYPE_DSM2:
required_protocol = limit<uint8_t>(PROTO_DSM2_LP45, PROTO_DSM2_LP45+g_model.moduleData[EXTERNAL_MODULE].rfProtocol, PROTO_DSM2_DSMX);
// The module is set to OFF during one second before BIND start
{
static tmr10ms_t bindStartTime = 0;
if (dsm2Flag == DSM2_BIND_FLAG) {
if (moduleFlag[EXTERNAL_MODULE] == MODULE_BIND) {
if (bindStartTime == 0) bindStartTime = get_tmr10ms();
if ((tmr10ms_t)(get_tmr10ms() - bindStartTime) < 100) {
required_protocol = PROTO_NONE;
@@ -92,6 +93,10 @@ void setupPulses(unsigned int port)
required_protocol = PROTO_NONE;
}
if (moduleFlag[port] == MODULE_OFF) {
required_protocol = PROTO_NONE;
}
if (s_current_protocol[port] != required_protocol) {
switch (s_current_protocol[port]) { // stop existing protocol hardware
+1 -1
View File
@@ -233,7 +233,7 @@ uint8_t PcmByte ;
uint8_t PcmBitCount ;
uint16_t PcmCrc ;
uint8_t PcmOnesCount ;
uint8_t pxxFlag[NUM_MODULES] = { 0 };
uint8_t moduleFlag[NUM_MODULES] = { 0 };
void crc( uint8_t data )
{
+16 -14
View File
@@ -36,7 +36,9 @@
#include "../opentx.h"
uint8_t pxxFlag[NUM_MODULES] = { MODULES_INIT(0) };
#define PXX_SEND_BIND 0x01
#define PXX_SEND_FAILSAFE (1 << 4)
#define PXX_SEND_RANGECHECK (1 << 5)
#if defined(PCBTARANIS)
uint16_t pxxStream[NUM_MODULES][400];
@@ -205,20 +207,20 @@ void setupPulsesPXX(unsigned int port)
putPcmByte(g_model.header.modelId, port);
/* FLAG1 */
uint8_t flag1;
if (pxxFlag[port] & PXX_SEND_RXNUM) {
flag1 = (g_model.moduleData[port].rfProtocol << 6) | (g_eeGeneral.countryCode << 1) | pxxFlag[port];
uint8_t flag1 = (g_model.moduleData[port].rfProtocol << 6);
if (moduleFlag[port] == MODULE_BIND) {
flag1 |= (g_eeGeneral.countryCode << 1) | PXX_SEND_BIND;
}
else {
flag1 = (g_model.moduleData[port].rfProtocol << 6) | pxxFlag[port];
if (g_model.moduleData[port].failsafeMode != FAILSAFE_RECEIVER) {
if (failsafeCounter[port]-- == 0) {
failsafeCounter[port] = 1000;
flag1 |= PXX_SEND_FAILSAFE;
}
if (failsafeCounter[port] == 0 && g_model.moduleData[port].channelsCount > 0) {
flag1 |= PXX_SEND_FAILSAFE;
}
else if (moduleFlag[port] == MODULE_RANGECHECK) {
flag1 |= PXX_SEND_RANGECHECK;
}
else if (g_model.moduleData[port].failsafeMode != FAILSAFE_RECEIVER) {
if (failsafeCounter[port]-- == 0) {
failsafeCounter[port] = 1000;
flag1 |= PXX_SEND_FAILSAFE;
}
if (failsafeCounter[port] == 0 && g_model.moduleData[port].channelsCount > 0) {
flag1 |= PXX_SEND_FAILSAFE;
}
}