paparazzi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paparazzi-commits] [6244] moved radio_control spektrum code to general


From: Felix Ruess
Subject: [paparazzi-commits] [6244] moved radio_control spektrum code to general subsystem
Date: Mon, 25 Oct 2010 21:57:57 +0000

Revision: 6244
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=6244
Author:   flixr
Date:     2010-10-25 21:57:57 +0000 (Mon, 25 Oct 2010)
Log Message:
-----------
moved radio_control spektrum code to general subsystem

Added Paths:
-----------
    
paparazzi3/trunk/sw/airborne/arch/lpc21/subsystems/radio_control/spektrum_arch.c
    
paparazzi3/trunk/sw/airborne/arch/lpc21/subsystems/radio_control/spektrum_arch.h
    
paparazzi3/trunk/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c
    
paparazzi3/trunk/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h
    paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_dummy.c
    paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_dummy.h
    paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby.c
    paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby.h
    
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby_9ch.h
    
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum.c
    
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum.h
    
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum_dx7se.h
    
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum_dx7se_joby.h

Removed Paths:
-------------
    paparazzi3/trunk/sw/airborne/booz/arch/lpc21/radio_control/
    paparazzi3/trunk/sw/airborne/booz/arch/stm32/radio_control/
    paparazzi3/trunk/sw/airborne/booz/radio_control/

Copied: 
paparazzi3/trunk/sw/airborne/arch/lpc21/subsystems/radio_control/spektrum_arch.c
 (from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/arch/lpc21/radio_control/booz_radio_control_spektrum_arch.c)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/arch/lpc21/subsystems/radio_control/spektrum_arch.c
                            (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/arch/lpc21/subsystems/radio_control/spektrum_arch.c
    2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,35 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008-2009 Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <subsystems/radio_control.h>
+#include "booz_radio_control_spektrum_arch.h"
+
+bool_t   rc_spk_parser_status;
+uint8_t  rc_spk_parser_idx;
+uint8_t  rc_spk_parser_buf[RADIO_CONTROL_NB_CHANNEL*2];
+const int16_t rc_spk_throw[RADIO_CONTROL_NB_CHANNEL] = RC_SPK_THROWS;
+
+void radio_control_impl_init(void) {
+  rc_spk_parser_status = RC_SPK_STA_UNINIT;
+  rc_spk_parser_idx = 0;
+}

Copied: 
paparazzi3/trunk/sw/airborne/arch/lpc21/subsystems/radio_control/spektrum_arch.h
 (from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/arch/lpc21/radio_control/booz_radio_control_spektrum_arch.h)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/arch/lpc21/subsystems/radio_control/spektrum_arch.h
                            (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/arch/lpc21/subsystems/radio_control/spektrum_arch.h
    2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,102 @@
+/*
+ * Paparazzi $Id$
+ *
+ * Copyright (C) 2009-2010 The Paparazzi Team
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef BOOZ_RADIO_CONTROL_SPEKTRUM_ARCH_H
+#define BOOZ_RADIO_CONTROL_SPEKTRUM_ARCH_H
+
+#include "std.h"
+#include "uart.h"
+
+#include RADIO_CONTROL_SPEKTRUM_MODEL_H
+
+#define RC_SPK_SYNC_1 0x03
+
+#define RC_SPK_STA_UNINIT     0
+#define RC_SPK_STA_GOT_SYNC_1 1
+#define RC_SPK_STA_GOT_SYNC_2 2
+
+extern bool_t   rc_spk_parser_status;
+extern uint8_t  rc_spk_parser_idx;
+extern uint8_t  rc_spk_parser_buf[RADIO_CONTROL_NB_CHANNEL*2];
+
+#define MAX_SPK 344
+
+
+extern const int16_t rc_spk_throw[RADIO_CONTROL_NB_CHANNEL];
+
+#define __RcLink(dev, _x) dev##_x
+#define _RcLink(dev, _x)  __RcLink(dev, _x)
+#define RcLink(_x) _RcLink(RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT, _x)
+
+#define RcLinkChAvailable() RcLink(ChAvailable())
+#define RcLinkGetCh() RcLink(Getch())
+
+#define RadioControlEventImpl(_received_frame_handler) {                \
+    while (RcLinkChAvailable()) {                                       \
+      int8_t c = RcLinkGetCh();                                         \
+      switch (rc_spk_parser_status) {                                   \
+      case RC_SPK_STA_UNINIT:                                           \
+        if (c==RC_SPK_SYNC_1)                                           \
+          rc_spk_parser_status = RC_SPK_STA_GOT_SYNC_1;                 \
+        break;                                                          \
+      case RC_SPK_STA_GOT_SYNC_1:                                       \
+        if (c==RC_SPK_SYNC_2) {                                         \
+          rc_spk_parser_status = RC_SPK_STA_GOT_SYNC_2;                 \
+          rc_spk_parser_idx = 0;                                        \
+        }                                                               \
+        else                                                            \
+          rc_spk_parser_status = RC_SPK_STA_UNINIT;                     \
+        break;                                                          \
+      case RC_SPK_STA_GOT_SYNC_2:                                       \
+        rc_spk_parser_buf[rc_spk_parser_idx] = c;                       \
+        rc_spk_parser_idx++;                                            \
+        if (rc_spk_parser_idx >= 2*RADIO_CONTROL_NB_CHANNEL) {          \
+          rc_spk_parser_status = RC_SPK_STA_UNINIT;                     \
+          radio_control.frame_cpt++;                                   \
+          radio_control.time_since_last_frame = 0;                     \
+          radio_control.status = RADIO_CONTROL_OK;                     \
+      uint8_t i;                                                       \
+      for (i=0;i<RADIO_CONTROL_NB_CHANNEL;i++) {                       \
+        const int16_t tmp = (rc_spk_parser_buf[2*i]<<8) +              \
+                             rc_spk_parser_buf[2*i+1];         \
+        /*const int16_t chan = (tmp&0xFC00) >> 10;*/           \
+        const int16_t val  = (tmp&0x03FF) - 512;                       \
+        radio_control.values[i] = val;                         \
+        radio_control.values[i] *= rc_spk_throw[i];                    \
+        if (i==RADIO_CONTROL_THROTTLE) {                               \
+          radio_control.values[i] += MAX_PPRZ;                 \
+          radio_control.values[i] /= 2;                                \
+        }                                                              \
+      }                                                                \
+      _received_frame_handler();                                       \
+        }                                                               \
+        break;                                                          \
+      default:                                                         \
+    rc_spk_parser_status = RC_SPK_STA_UNINIT;                  \
+      }                                                                 \
+    }                                                                   \
+  }
+
+
+#endif /* BOOZ_RADIO_CONTROL_SPEKTRUM_ARCH_H */

Copied: 
paparazzi3/trunk/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c
 (from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/arch/stm32/radio_control/booz_radio_control_spektrum_arch.c)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c
                            (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c
    2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,753 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2010 Eric Parsonage <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdint.h>
+#include <stm32/gpio.h>
+#include <stm32/rcc.h>
+#include <stm32/tim.h>
+#include <stm32/misc.h>
+#include <stm32/usart.h>
+#include "uart.h"
+#include <subsystems/radio_control.h>
+#include "booz_radio_control_spektrum_arch.h"
+#include <firmwares/rotorcraft/autopilot.h>
+
+
+#define SPEKTRUM_CHANNELS_PER_FRAME 7
+#define MAX_SPEKTRUM_FRAMES 2
+#define MAX_SPEKTRUM_CHANNELS 16
+
+#define MAX_DELAY   INT16_MAX
+/* the frequency of the delay timer */
+#define DELAY_TIM_FREQUENCY 1000000
+/* Number of low pulses sent to satellite receivers */
+#define MASTER_RECEIVER_PULSES 5
+#define SLAVE_RECEIVER_PULSES 6
+
+/* The line that is pulled low at power up to initiate the bind process */
+#define BIND_PIN GPIO_Pin_3
+#define BIND_PIN_PORT GPIOC
+#define BIND_PIN_PERIPH RCC_APB2Periph_GPIOC
+
+#define TIM_FREQ_1000000 1000000
+#define TIM_TICS_FOR_100us 100
+#define MIN_FRAME_SPACE  70  // 7ms
+#define MAX_BYTE_SPACE  3   // .3ms
+
+/*
+ * in the makefile we set RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT to be Uartx
+ * but in uart_hw.c the initialisation functions are
+ * defined as uartx these macros give us the glue
+ * that allows static calls at compile time
+ */
+
+#define __PrimaryUart(dev, _x) dev##_x
+#define _PrimaryUart(dev, _x)  __PrimaryUart(dev, _x)
+#define PrimaryUart(_x) _PrimaryUart(RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT, _x)
+
+#define __SecondaryUart(dev, _x) dev##_x
+#define _SecondaryUart(dev, _x)  __SecondaryUart(dev, _x)
+#define SecondaryUart(_x) 
_SecondaryUart(RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT, _x)
+
+struct SpektrumStateStruct {
+    uint8_t ReSync;
+    uint8_t SpektrumTimer;
+    uint8_t Sync;
+    uint8_t ChannelCnt;
+    uint8_t FrameCnt;
+    uint8_t HighByte;
+    uint8_t SecondFrame;
+    uint16_t LostFrameCnt;
+    uint8_t RcAvailable;
+    int16_t values[SPEKTRUM_CHANNELS_PER_FRAME*MAX_SPEKTRUM_FRAMES];
+};
+
+typedef struct SpektrumStateStruct SpektrumStateType;
+
+SpektrumStateType PrimarySpektrumState = {1,0,0,0,0,0,0,0,0};
+#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
+SpektrumStateType SecondarySpektrumState = {1,0,0,0,0,0,0,0,0};
+#endif
+
+int16_t SpektrumBuf[SPEKTRUM_CHANNELS_PER_FRAME*MAX_SPEKTRUM_FRAMES];
+/* the order of the channels on a spektrum is always as follows :
+ *
+ * Throttle   0
+ * Aileron    1
+ * Elevator   2
+ * Rudder     3
+ * Gear       4
+ * Flap/Aux1  5
+ * Aux2       6
+ * Aux3       7
+ * Aux4       8
+ * Aux5       9
+ * Aux6      10
+ * Aux7      11
+ */
+
+/* reverse some channels to suit Paparazzi conventions          */
+/* the maximum number of channels a Spektrum can transmit is 12 */
+int8_t SpektrumSigns[] = RADIO_CONTROL_SPEKTRUM_SIGNS;
+
+/* Parser state variables */
+static uint8_t EncodingType = 0;
+static uint8_t ExpectedFrames = 0;
+/* initialise the uarts used by the parser */
+void SpektrumUartInit(void);
+/* initialise the timer used by the parser to ensure sync */
+void SpektrumTimerInit(void);
+/* sets a GPIO pin as output for debugging */
+void DebugInit(void);
+void tim6_irq_handler(void);
+/* wait busy loop, microseconds */
+static void DelayUs( uint16_t uSecs );
+/* wait busy loop, milliseconds */
+static void DelayMs( uint16_t mSecs );
+/* setup timer 1 for busy wait delays */
+static void SpektrumDelayInit( void );
+
+
+ /*****************************************************************************
+ *
+ * Initialise the timer an uarts used by the Spektrum receiver subsystem
+ *
+ *****************************************************************************/
+void radio_control_impl_init(void) {
+  SpektrumTimerInit();
+  // DebugInit();
+  SpektrumUartInit();
+}
+
+/*****************************************************************************
+ * The bind function means that the satellite receivers believe they are
+ * connected to a 9 channel JR-R921 24 receiver thus during the bind process
+ * they try to get the transmitter to transmit at the highest resolution that
+ * it can manage. The data is contained in 16 byte packets transmitted at
+ * 115200 baud. Depending on the transmitter either 1 or 2 frames are required
+ * to contain the data for all channels. These frames are either 11ms or 22ms
+ * apart.
+ *
+ * The format of each frame for the main receiver is as follows
+ *
+ *  byte1:  frame loss data
+ *  byte2:  transmitter information
+ *  byte3:  and byte4:  channel data
+ *  byte5:  and byte6:  channel data
+ *  byte7:  and byte8:  channel data
+ *  byte9:  and byte10: channel data
+ *  byte11: and byte12: channel data
+ *  byte13: and byte14: channel data
+ *  byte15: and byte16: channel data
+ *
+ *
+ * The format of each frame for the secondary receiver is as follows
+ *
+ *  byte1:  frame loss data
+ *  byte2:  frame loss data
+ *  byte3:  and byte4:  channel data
+ *  byte5:  and byte6:  channel data
+ *  byte7:  and byte8:  channel data
+ *  byte9:  and byte10: channel data
+ *  byte11: and byte12: channel data
+ *  byte13: and byte14: channel data
+ *  byte15: and byte16: channel data
+ *
+ * The frame loss data bytes starts out containing 0 as long as the
+ * transmitter is switched on before the receivers. It then increments
+ * whenever frames are dropped.
+ *
+ * Three values for the transmitter information byte have been seen thus far
+ *
+ * 0x01 From a Spektrum DX7eu which transmits a single frame containing all
+ * channel data every 22ms with 10bit resolution.
+ *
+ * 0x02 From a Spektrum DM9 module which transmits two frames to carry the
+ * data for all channels 11ms apart with 10bit resolution.
+ *
+ * 0x12 From a Spektrum DX7se which transmits two frames to carry the
+ * data for all channels 11ms apart with 11bit resolution.
+ *
+ * 0x12 From a JR X9503 which transmits two frames to carry the
+ * data for all channels 11ms apart with 11bit resolution.
+ *
+ * 0x01 From a Spektrum DX7 which transmits a single frame containing all
+ * channel data every 22ms with 10bit resolution.
+ *
+ * 0x12 From a JR DSX12 which transmits two frames to carry the
+ * data for all channels 11ms apart with 11bit resolution.
+ *
+ * 0x1 From a Spektru DX5e which transmits a single frame containing all
+ * channel data every 22ms with 10bit resolution.
+ *
+ * 0x01 From a Spektrum DX6i which transmits a single frame containing all
+ * channel data every 22ms with 10bit resolution.
+ *
+ * Currently the assumption is that the data has the form :
+ *
+ * [0 0 0 R 0 0 N1 N0]
+ *
+ * where :
+ *
+ * 0 means a '0' bit
+ * R: 0 for 10 bit resolution 1 for 11 bit resolution channel data
+ * N1 to N0 is the number of frames required to receive all channel
+ * data.
+ *
+ * Channels can have either 10bit or 11bit resolution. Data from a tranmitter
+ * with 10 bit resolution has the form:
+ *
+ * [F 0 C3 C2 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0]
+ *
+ * Data from a tranmitter with 11 bit resolution has the form
+ *
+ * [F C3 C2 C1 C0 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0]
+ *
+ * where :
+ *
+ * 0 means a '0' bit
+ * F: Normally 0 but set to 1 for the first channel of the 2nd frame if a
+ * second frame is transmitted.
+ *
+ * C3 to C0 is the channel number, 4 bit, matching the numbers allocated in
+ * the transmitter.
+ *
+ * D9 to D0 is the channel data (10 bit) 0xaa..0x200..0x356 for
+ * 100% transmitter-travel
+ *
+ *
+ * D10 to D0 is the channel data (11 bit) 0x154..0x400..0x6AC for
+ * 100% transmitter-travel
+ *****************************************************************************/
+
+ /*****************************************************************************
+ *
+ * Spektrum Parser captures frame data by using time between frames to sync on
+ *
+ *****************************************************************************/
+
+#define SpektrumParser(_c, _SpektrumState, _receiver)  {                      \
+                                                                              \
+  uint16_t ChannelData;                                                       \
+  uint8_t TimedOut;                                                           \
+  static uint8_t TmpEncType = 0;        /* 0 = 10bit, 1 = 11 bit        */    \
+  static uint8_t TmpExpFrames = 0;      /* # of frames for channel data */    \
+                                                                              \
+   TimedOut = (!_SpektrumState.SpektrumTimer) ? 1 : 0;                        \
+                                                                              \
+  /* If we have just started the resync process or */                         \
+  /* if we have recieved a character before our    */                         \
+  /* 7ms wait has finished                         */                         \
+  if ((_SpektrumState.ReSync == 1) ||                                         \
+      ((_SpektrumState.Sync == 0) && (!TimedOut))) {                          \
+                                                                              \
+    _SpektrumState.ReSync = 0;                                                \
+    _SpektrumState.SpektrumTimer = MIN_FRAME_SPACE;                           \
+    _SpektrumState.Sync = 0;                                                  \
+    _SpektrumState.ChannelCnt = 0;                                            \
+    _SpektrumState.FrameCnt = 0;                                              \
+    _SpektrumState.SecondFrame = 0;                                           \
+    return;                                                                   \
+  }                                                                           \
+                                                                              \
+  /* the first byte of a new frame. It was received */                        \
+  /* more than 7ms after the last received byte.    */                        \
+  /* It represents the number of lost frames so far.*/                        \
+  if (_SpektrumState.Sync == 0) {                                             \
+      _SpektrumState.LostFrameCnt = _c;                                       \
+      if(_receiver) /* secondary receiver */                                  \
+        _SpektrumState.LostFrameCnt = _SpektrumState.LostFrameCnt << 8;       \
+      _SpektrumState.Sync = 1;                                                \
+      _SpektrumState.SpektrumTimer = MAX_BYTE_SPACE;                          \
+      return;                                                                 \
+  }                                                                           \
+                                                                              \
+  /* all other bytes should be recieved within     */                         \
+  /* MAX_BYTE_SPACE time of the last byte received */                         \
+  /* otherwise something went wrong resynchronise  */                         \
+  if(TimedOut) {                                                              \
+    _SpektrumState.ReSync = 1;                                                \
+    /* next frame not expected sooner than 7ms     */                         \
+    _SpektrumState.SpektrumTimer = MIN_FRAME_SPACE;                           \
+    return;                                                                   \
+  }                                                                           \
+                                                                              \
+  /* second character determines resolution and frame rate for main */        \
+  /* receiver or low byte of LostFrameCount for secondary receiver  */        \
+  if(_SpektrumState.Sync == 1) {                                              \
+    if(_receiver) {                                                           \
+      _SpektrumState.LostFrameCnt +=_c;                                       \
+      TmpExpFrames = ExpectedFrames;                                          \
+    } else {                                                                  \
+      /* TODO: collect more data. I suspect that there is a low res         */\
+      /* protocol that is still 10 bit but without using the full range.    */\
+      TmpEncType =(_c & 0x10)>>4;      /* 0 = 10bit, 1 = 11 bit             */\
+      TmpExpFrames = _c & 0x03;        /* 1 = 1 frame contains all channels */\
+                                       /* 2 = 2 channel data in 2 frames    */\
+    }                                                                         \
+    _SpektrumState.Sync = 2;                                                  \
+    _SpektrumState.SpektrumTimer = MAX_BYTE_SPACE;                            \
+    return;                                                                   \
+  }                                                                           \
+                                                                              \
+  /* high byte of channel data if this is the first byte */                   \
+  /* of channel data and the most significant bit is set */                   \
+  /* then this is the second frame of channel data.      */                   \
+  if(_SpektrumState.Sync == 2) {                                              \
+    _SpektrumState.HighByte = _c;                                             \
+    if (_SpektrumState.ChannelCnt == 0) {                                     \
+      _SpektrumState.SecondFrame = (_SpektrumState.HighByte & 0x80) ? 1 : 0;  \
+    }                                                                         \
+    _SpektrumState.Sync = 3;                                                  \
+    _SpektrumState.SpektrumTimer = MAX_BYTE_SPACE;                            \
+    return;                                                                   \
+  }                                                                           \
+                                                                              \
+  /* low byte of channel data */                                              \
+  if(_SpektrumState.Sync == 3) {                                              \
+    _SpektrumState.Sync = 2;                                                  \
+    _SpektrumState.SpektrumTimer = MAX_BYTE_SPACE;                            \
+    /* we overwrite the buffer now so rc data is not available now */         \
+    _SpektrumState.RcAvailable = 0;                                           \
+    ChannelData = ((uint16_t)_SpektrumState.HighByte << 8) | _c;              \
+    _SpektrumState.values[_SpektrumState.ChannelCnt                           \
+                          + (_SpektrumState.SecondFrame * 7)] = ChannelData;  \
+    _SpektrumState.ChannelCnt ++;                                             \
+  }                                                                           \
+                                                                              \
+  /* If we have a whole frame */                                              \
+  if(_SpektrumState.ChannelCnt >= SPEKTRUM_CHANNELS_PER_FRAME) {              \
+    /* how many frames did we expect ? */                                     \
+    ++_SpektrumState.FrameCnt;                                                \
+    if (_SpektrumState.FrameCnt == TmpExpFrames)                              \
+    {                                                                         \
+      /* set the rc_available_flag */                                         \
+      _SpektrumState.RcAvailable = 1;                                         \
+      _SpektrumState.FrameCnt = 0;                                            \
+    }                                                                         \
+    if(!_receiver) { /* main receiver */                                      \
+      EncodingType = TmpEncType;         /* only update on a good */          \
+      ExpectedFrames = TmpExpFrames;     /* main receiver frame   */          \
+    }                                                                         \
+    _SpektrumState.Sync = 0;                                                  \
+    _SpektrumState.ChannelCnt = 0;                                            \
+    _SpektrumState.SecondFrame = 0;                                           \
+    _SpektrumState.SpektrumTimer = MIN_FRAME_SPACE;                           \
+  }                                                                           \
+}                                                                             \
+
+/*****************************************************************************
+ *
+ * RadioControlEventImp decodes channel data stored by uart irq handlers
+ * and calls callback funtion
+ *
+ *****************************************************************************/
+
+void RadioControlEventImp(void (*frame_handler)(void)) {
+  uint8_t ChannelCnt;
+  uint8_t ChannelNum;
+  uint16_t ChannelData;
+  uint8_t MaxChannelNum = 0;
+
+#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
+  /* If we have two receivers and at least one of them has new data */
+  uint8_t BestReceiver;
+  if ((PrimarySpektrumState.RcAvailable) ||
+      (SecondarySpektrumState.RcAvailable)) {
+    /* if both receivers have new data select the one  */
+    /* that has had the least number of frames lost    */
+    if ((PrimarySpektrumState.RcAvailable) &&
+        (SecondarySpektrumState.RcAvailable)) {
+      BestReceiver  = (PrimarySpektrumState.LostFrameCnt
+                       <= SecondarySpektrumState.LostFrameCnt) ? 0 : 1;
+    } else {
+      /* if only one of the receivers have new data use it */
+      BestReceiver  = (PrimarySpektrumState.RcAvailable) ? 0 : 1;
+    }
+    /* clear the data ready flags */
+    PrimarySpektrumState.RcAvailable = 0;
+    SecondarySpektrumState.RcAvailable = 0;
+
+#else
+  /* if we have one receiver and it has new data */
+  if(PrimarySpektrumState.RcAvailable) {
+    PrimarySpektrumState.RcAvailable = 0;
+#endif
+    ChannelCnt = 0;
+    /* for every piece of channel data we have received */
+    for(int i = 0; (i < SPEKTRUM_CHANNELS_PER_FRAME * ExpectedFrames); i++) {
+#ifndef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
+      ChannelData = PrimarySpektrumState.values[i];
+#else
+      ChannelData = (!BestReceiver) ? PrimarySpektrumState.values[i] :
+                                 SecondarySpektrumState.values[i];
+#endif
+      /* find out the channel number and its value by  */
+      /* using the EncodingType which is only received */
+      /* from the main receiver                        */
+      switch(EncodingType) {
+        case(0) : /* 10 bit */
+          ChannelNum = (ChannelData >> 10) & 0x0f;
+          /* don't bother decoding unused channels */
+          if (ChannelNum < RADIO_CONTROL_NB_CHANNEL) {
+           SpektrumBuf[ChannelNum] = ChannelData & 0x3ff;
+           SpektrumBuf[ChannelNum] -= 0x200;
+           SpektrumBuf[ChannelNum] *= MAX_PPRZ/0x156;
+           ChannelCnt++;
+          }
+          break;
+
+        case(1) : /* 11 bit */
+          ChannelNum = (ChannelData >> 11) & 0x0f;
+          /* don't bother decoding unused channels */
+          if (ChannelNum < RADIO_CONTROL_NB_CHANNEL) {
+            SpektrumBuf[ChannelNum] = ChannelData & 0x7ff;
+            SpektrumBuf[ChannelNum] -= 0x400;
+            SpektrumBuf[ChannelNum] *= MAX_PPRZ/0x2AC;
+            ChannelCnt++;
+          }
+          break;
+
+        default : ChannelNum = 0x0F; break;  /* never going to get here */
+      }
+      /* store the value of the highest valid channel */
+      if ((ChannelNum != 0x0F) && (ChannelNum > MaxChannelNum))
+        MaxChannelNum = ChannelNum;
+
+    }
+
+    /* if we have a valid frame the pass it to the frame handler */
+    if (ChannelCnt >= (MaxChannelNum + 1)) {
+      radio_control.frame_cpt++;
+      radio_control.time_since_last_frame = 0;
+      radio_control.status = RADIO_CONTROL_OK;
+      for (int i = 0; i < (MaxChannelNum + 1); i++) {
+        radio_control.values[i] = SpektrumBuf[i];
+        if (i == RADIO_CONTROL_THROTTLE ) {
+          radio_control.values[i] += MAX_PPRZ;
+          radio_control.values[i] /= 2;
+        }
+        radio_control.values[i] *= SpektrumSigns[i];
+      }
+      (*frame_handler)();
+    }
+  }
+}
+
+
+/*****************************************************************************
+ *
+ * Initialise TIM6 to fire an interrupt every 100 microseconds to provide
+ * timebase for SpektrumParser
+ *
+ *****************************************************************************/
+void SpektrumTimerInit( void ) {
+
+  /* enable TIM6 clock */
+  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
+
+  /* TIM6 configuration */
+  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
+  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
+  /* 100 microseconds ie 0.1 millisecond */
+  TIM_TimeBaseStructure.TIM_Period = TIM_TICS_FOR_100us-1;
+  TIM_TimeBaseStructure.TIM_Prescaler = ((AHB_CLK / TIM_FREQ_1000000) - 1);
+  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
+  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
+  TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
+
+  /* Enable TIM6 interrupts */
+  NVIC_InitTypeDef NVIC_InitStructure;
+
+  /* Enable and configure TIM6 IRQ channel */
+  NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
+  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
+  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
+  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+  NVIC_Init(&NVIC_InitStructure);
+
+  /* Enable TIM6 Update interrupt */
+  TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);
+  TIM_ClearFlag(TIM6, TIM_FLAG_Update);
+
+  /* TIM6 enable counter */
+  TIM_Cmd(TIM6, ENABLE);
+}
+
+/*****************************************************************************
+ *
+ * TIM6 interrupt request handler updates times used by SpektrumParser
+ *
+ *****************************************************************************/
+void tim6_irq_handler( void ) {
+
+  TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
+
+  if (PrimarySpektrumState.SpektrumTimer)
+    --PrimarySpektrumState.SpektrumTimer;
+#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
+  if (SecondarySpektrumState.SpektrumTimer)
+    --SecondarySpektrumState.SpektrumTimer;
+#endif
+}
+
+/*****************************************************************************
+ *
+ * Initialise the uarts for the spektrum satellite receivers
+ *
+ *****************************************************************************/
+void SpektrumUartInit(void) {
+  /* init RCC */
+  PrimaryUart(_remap);
+  PrimaryUart(_clk)(PrimaryUart(_UartPeriph), ENABLE);;
+  //RCC_APB1PeriphClockCmd(PrimaryUart(_UartPeriph), ENABLE);
+
+  /* Enable USART interrupts */
+  NVIC_InitTypeDef nvic;
+  nvic.NVIC_IRQChannel = PrimaryUart(_IRQn);
+  nvic.NVIC_IRQChannelPreemptionPriority = 2;
+  nvic.NVIC_IRQChannelSubPriority = 1;
+  nvic.NVIC_IRQChannelCmd = ENABLE;
+  NVIC_Init(&nvic);
+  /* Init GPIOS */
+  GPIO_InitTypeDef GPIO_InitStructure;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+  /* Primary UART Rx pin as floating input */
+  GPIO_InitStructure.GPIO_Pin   = PrimaryUart(_RxPin);
+  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
+  GPIO_Init(PrimaryUart(_RxPort), &GPIO_InitStructure);
+  /* Configure Primary UART */
+  USART_InitTypeDef usart;
+  usart.USART_BaudRate            = B115200;
+  usart.USART_WordLength          = USART_WordLength_8b;
+  usart.USART_StopBits            = USART_StopBits_1;
+  usart.USART_Parity              = USART_Parity_No;
+  usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
+  usart.USART_Mode                = USART_Mode_Rx;
+  USART_Init(PrimaryUart(_reg), &usart);
+  /* Enable Primary UART Receive interrupts */
+  USART_ITConfig(PrimaryUart(_reg), USART_IT_RXNE, ENABLE);
+  /* Enable the Primary UART */
+  USART_Cmd(PrimaryUart(_reg), ENABLE);
+
+
+#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
+   /* init RCC */
+  SecondaryUart(_remap);
+  SecondaryUart(_clk)(SecondaryUart(_UartPeriph), ENABLE);
+  //RCC_APB1PeriphClockCmd(SecondaryUart(_UartPeriph), ENABLE);
+  /* Enable USART interrupts */
+  nvic.NVIC_IRQChannel = SecondaryUart(_IRQn);
+  nvic.NVIC_IRQChannelPreemptionPriority = 2;
+  nvic.NVIC_IRQChannelSubPriority = 2;
+  nvic.NVIC_IRQChannelCmd = ENABLE;
+  NVIC_Init(&nvic);
+  /* Init GPIOS */;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+  /* Secondary UART Rx pin as floating input */
+  GPIO_InitStructure.GPIO_Pin   = SecondaryUart(_RxPin);
+  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
+  GPIO_Init(SecondaryUart(_RxPort), &GPIO_InitStructure);
+  /* Configure secondary UART */
+  usart.USART_BaudRate            = B115200;
+  usart.USART_WordLength          = USART_WordLength_8b;
+  usart.USART_StopBits            = USART_StopBits_1;
+  usart.USART_Parity              = USART_Parity_No;
+  usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
+  usart.USART_Mode                = USART_Mode_Rx;
+  USART_Init(SecondaryUart(_reg), &usart);
+  /* Enable Secondary UART Receive interrupts */
+  USART_ITConfig(SecondaryUart(_reg), USART_IT_RXNE, ENABLE);
+  /* Enable the Primary UART */
+  USART_Cmd(SecondaryUart(_reg), ENABLE);
+#endif
+
+}
+
+/*****************************************************************************
+ *
+ * The primary receiver UART interrupt request handler which passes the
+ * received character to Spektrum Parser.
+ *
+ *****************************************************************************/
+void PrimaryUart(_irq_handler)(void) {
+
+  if(USART_GetITStatus(PrimaryUart(_reg), USART_IT_TXE) != RESET) {
+      USART_ITConfig(PrimaryUart(_reg), USART_IT_TXE, DISABLE);
+  }
+
+  if(USART_GetITStatus(PrimaryUart(_reg), USART_IT_RXNE) != RESET) {
+    uint8_t b =  USART_ReceiveData(PrimaryUart(_reg));
+    SpektrumParser(b, PrimarySpektrumState, 0);
+  }
+}
+
+/*****************************************************************************
+ *
+ * The secondary receiver UART interrupt request handler which passes the
+ * received character to Spektrum Parser.
+ *
+ *****************************************************************************/
+#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
+void SecondaryUart(_irq_handler)(void) {
+
+  if(USART_GetITStatus(SecondaryUart(_reg), USART_IT_TXE) != RESET) {
+      USART_ITConfig(SecondaryUart(_reg), USART_IT_TXE, DISABLE);
+  }
+
+  if(USART_GetITStatus(SecondaryUart(_reg), USART_IT_RXNE) != RESET) {
+    uint8_t b =  USART_ReceiveData(SecondaryUart(_reg));
+    SpektrumParser(b, SecondarySpektrumState, 1);
+  }
+}
+#endif
+
+/*****************************************************************************
+ *
+ * Use pin to output debug information.
+ *
+ *****************************************************************************/
+void DebugInit(void) {
+  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE);
+  GPIO_InitTypeDef GPIO_InitStructure;
+  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+  GPIO_Init(GPIOC, &GPIO_InitStructure);
+  GPIO_WriteBit(GPIOC, GPIO_Pin_5 , Bit_RESET );
+}
+
+/*****************************************************************************
+ *
+ * The following functions provide functionality to allow binding of
+ * spektrum satellite receivers. The pulse train sent to them means
+ * that Lisa is emulating a 9 channel JR-R921 24.
+ *
+ *****************************************************************************/
+/*****************************************************************************
+ *
+ * radio_control_spektrum_try_bind(void) must called on powerup as spektrum
+ * satellites can only bind immediately after power up also it must be called
+ * before the call to SpektrumUartInit as we leave them with their Rx pins set
+ * as outputs.
+ *
+ *****************************************************************************/
+void radio_control_spektrum_try_bind(void) {
+
+  /* init RCC */
+  RCC_APB2PeriphClockCmd(BIND_PIN_PERIPH , ENABLE);
+
+  /* Init GPIO for the bind pin */
+  GPIO_InitTypeDef GPIO_InitStructure;
+  GPIO_InitStructure.GPIO_Pin = BIND_PIN;
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+  GPIO_Init(BIND_PIN_PORT, &GPIO_InitStructure);
+  /* exit if the BIND_PIN is high, it needs to
+     be pulled low at startup to initiate bind */
+  if (GPIO_ReadInputDataBit(BIND_PIN_PORT, BIND_PIN))
+    return;
+
+  /* bind initiated, initialise the delay timer */
+  SpektrumDelayInit();
+
+  /* initialise the uarts rx pins as  GPIOS */
+  RCC_APB2PeriphClockCmd(PrimaryUart(_Periph) , ENABLE);
+  /* Master receiver Rx push-pull */
+  GPIO_InitStructure.GPIO_Pin = PrimaryUart(_RxPin);
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+  GPIO_Init(PrimaryUart(_RxPort), &GPIO_InitStructure);
+  /* Master receiver RX line, drive high */
+  GPIO_WriteBit(PrimaryUart(_RxPort), PrimaryUart(_RxPin) , Bit_SET );
+
+#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
+   RCC_APB2PeriphClockCmd(SecondaryUart(_Periph) , ENABLE);
+  /* Slave receiver Rx push-pull */
+  GPIO_InitStructure.GPIO_Pin = SecondaryUart(_RxPin);
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+  GPIO_Init(SecondaryUart(_RxPort), &GPIO_InitStructure);
+  /* Slave receiver RX line, drive high */
+  GPIO_WriteBit(SecondaryUart(_RxPort), SecondaryUart(_RxPin) , Bit_SET );
+#endif
+
+  /* We have no idea how long the window for allowing binding after
+     power up is .This works for the moment but will need revisiting */
+  DelayMs(61);
+
+  for (int i = 0; i < MASTER_RECEIVER_PULSES ; i++)
+  {
+    GPIO_WriteBit(PrimaryUart(_RxPort), PrimaryUart(_RxPin), Bit_RESET );
+    DelayUs(118);
+    GPIO_WriteBit(PrimaryUart(_RxPort), PrimaryUart(_RxPin), Bit_SET );
+    DelayUs(122);
+  }
+
+#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
+  for (int i = 0; i < SLAVE_RECEIVER_PULSES; i++)
+  {
+    GPIO_WriteBit(SecondaryUart(_RxPort), SecondaryUart(_RxPin), Bit_RESET );
+    DelayUs(120);
+    GPIO_WriteBit(SecondaryUart(_RxPort), SecondaryUart(_RxPin), Bit_SET );
+    DelayUs(120);
+  }
+#endif /* RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT */
+}
+
+/*****************************************************************************
+ *
+ * Functions to implement busy wait loops with micro second granularity
+ *
+ *****************************************************************************/
+
+/* set TIM6 to run at DELAY_TIM_FREQUENCY */
+static void SpektrumDelayInit( void ) {
+  /* Enable timer clock */
+  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
+  /* Time base configuration */
+  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
+  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
+  TIM_TimeBaseStructure.TIM_Prescaler = (AHB_CLK / DELAY_TIM_FREQUENCY) - 1;
+  TIM_TimeBaseStructure.TIM_Period = UINT16_MAX;
+  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
+  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
+  TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
+
+ /* Enable counter */
+  TIM_Cmd(TIM6, ENABLE);
+}
+
+/* wait busy loop, microseconds */
+static void DelayUs( uint16_t uSecs ) {
+  uint16_t start = TIM6->CNT;
+  /* use 16 bit count wrap around */
+  while((uint16_t)(TIM6->CNT - start) <= uSecs);
+}
+
+/* wait busy loop, milliseconds */
+static void DelayMs( uint16_t mSecs ) {
+  for(int i = 0; i < mSecs; i++) {
+    DelayUs(DELAY_TIM_FREQUENCY / 1000);
+  }
+}

Copied: 
paparazzi3/trunk/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h
 (from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/arch/stm32/radio_control/booz_radio_control_spektrum_arch.h)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h
                            (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h
    2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,68 @@
+/*
+ * Paparazzi $Id$
+ *
+ * Copyright (C) 2010 Eric Parsonage <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef BOOZ_RADIO_CONTROL_SPEKTRUM_ARCH_H
+#define BOOZ_RADIO_CONTROL_SPEKTRUM_ARCH_H
+
+
+/*
+ * All Spektrum and JR 2.4 GHz transmitters
+ * have the same channel assignments.
+ */
+
+
+#ifndef RADIO_CONTROL_NB_CHANNEL
+#define RADIO_CONTROL_NB_CHANNEL 12
+#endif
+
+
+#define RADIO_CONTROL_THROTTLE   0
+#define RADIO_CONTROL_ROLL       1
+#define RADIO_CONTROL_PITCH      2
+#define RADIO_CONTROL_YAW        3
+#define RADIO_CONTROL_GEAR       4
+#define RADIO_CONTROL_FLAP       5
+#define RADIO_CONTROL_AUX1       5
+#define RADIO_CONTROL_AUX2       6
+#define RADIO_CONTROL_AUX3       7
+#define RADIO_CONTROL_AUX4       8
+#define RADIO_CONTROL_AUX5       9
+#define RADIO_CONTROL_AUX6       10
+#define RADIO_CONTROL_AUX7       11
+
+/* reverse some channels to suit Paparazzi conventions          */
+/* the maximum number of channels a Spektrum can transmit is 12 */
+#ifndef RADIO_CONTROL_SPEKTRUM_SIGNS
+#define RADIO_CONTROL_SPEKTRUM_SIGNS {1,1,-1,1,1,-1,1,1,1,1,1,1}
+#endif
+
+/* really for a 9 channel transmitter
+   we would swap the order of these */
+#ifndef RADIO_CONTROL_MODE
+#define RADIO_CONTROL_MODE       RADIO_CONTROL_GEAR
+#endif
+
+extern void RadioControlEventImp(void (*_received_frame_handler)(void));
+
+#endif /* BOOZ_RADIO_CONTROL_SPEKTRUM_ARCH_H */

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_dummy.c 
(from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_dummy.c)
===================================================================
--- paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_dummy.c 
                        (rev 0)
+++ paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_dummy.c 
2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,26 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008-2009 Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <subsystems/radio_control.h>
+
+void radio_control_impl_init(void) { }

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_dummy.h 
(from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_dummy.h)
===================================================================
--- paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_dummy.h 
                        (rev 0)
+++ paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_dummy.h 
2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,32 @@
+/*
+ * Paparazzi $Id$
+ *
+ * Copyright (C) 2009 Pascal Brisset <address@hidden>,
+ *                    Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef BOOZ_RADIO_CONTROL_NULL_H
+#define BOOZ_RADIO_CONTROL_NULL_H
+
+#include "conf_radio_control_ppm.h"
+
+#define RadioControlEvent(_received_frame_handler) { }
+
+#endif /* BOOZ_RADIO_CONTROL_NULL_H */

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby.c 
(from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_joby.c)
===================================================================
--- paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby.c  
                        (rev 0)
+++ paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby.c  
2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,95 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008-2009 Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "stdio.h"
+#include <subsystems/radio_control.h>
+
+static struct rc_joby_parser_state parser;
+static const int16_t rc_joby_signs[RADIO_CONTROL_NB_CHANNEL] = RC_JOBY_SIGNS;
+
+
+static void handle_channel(void (* callback)(void))
+{
+ if (parser.parser_normal_buf == RC_JOBY_MAGIC_START) {
+    // got start channel, look for channel 0 next
+    parser.current_channel = 0;
+  } else if (parser.current_channel == -1) {
+    // looking for start channel byte but didn't get it, reset
+    parser.current_byte = READING_HIGH_BYTE;
+    parser.current_inverted = READING_NORMAL;
+  } else {
+    // valid channel, store and look for next
+    radio_control.values[parser.current_channel] = 
rc_joby_signs[parser.current_channel] * parser.parser_normal_buf;
+    parser.current_channel++;
+    if (parser.current_channel == RADIO_CONTROL_NB_CHANNEL) {
+      // all channels read, reset parser and handle message
+      parser.current_channel = -1;
+      radio_control.frame_cpt++;
+      radio_control.status = RADIO_CONTROL_OK;
+      radio_control.time_since_last_frame = 0;
+      if (callback != NULL)
+    callback();
+    }
+  }
+}
+
+static void handle_tuple(void (* callback)(void))
+{
+  if (parser.current_inverted == READING_NORMAL) {
+    parser.parser_normal_buf = ((parser.high_byte_buf << 8) | 
parser.low_byte_buf);
+    parser.current_inverted = READING_INVERTED;
+  } else if (parser.current_inverted == READING_INVERTED) {
+    parser.parser_inverted_buf = ((parser.high_byte_buf << 8) | 
parser.low_byte_buf);
+    parser.current_inverted = READING_NORMAL;
+    if (parser.parser_normal_buf == ~parser.parser_inverted_buf) {
+      handle_channel(callback);
+    } else {
+      // normal didn't match inverted, error, reset
+      parser.current_inverted = READING_NORMAL;
+      parser.current_byte = READING_HIGH_BYTE;
+      parser.current_channel = -1;
+      parser.error_counter++;
+    }
+  }
+}
+
+void rc_joby_parse(int8_t c, void (* callback)(void))
+{
+  if (parser.current_byte == READING_HIGH_BYTE) {
+    parser.high_byte_buf = c;
+    if (parser.current_channel >= 0 || parser.high_byte_buf == 
(RC_JOBY_MAGIC_START >> 8) || parser.current_inverted == READING_INVERTED) {
+       // only advance parser state to low byte if we're not looking for a 
sync byte which we didn't find
+      parser.current_byte = READING_LOW_BYTE;
+    }
+  } else { // READING_LOW_BYTE
+    parser.low_byte_buf = c;
+    parser.current_byte = READING_HIGH_BYTE;
+    handle_tuple(callback);
+  }
+}
+
+void radio_control_impl_init(void) {
+  parser.current_byte = READING_HIGH_BYTE;
+  parser.current_inverted = READING_NORMAL;
+  parser.current_channel = -1;
+}

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby.h 
(from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_joby.h)
===================================================================
--- paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby.h  
                        (rev 0)
+++ paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby.h  
2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,75 @@
+/*
+ * Paparazzi $Id$
+ *
+ * Copyright (C) 2009 Pascal Brisset <address@hidden>,
+ *                    Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef BOOZ_RADIO_CONTROL_JOBY_H
+#define BOOZ_RADIO_CONTROL_JOBY_H
+
+#include "std.h"
+#include "uart.h"
+
+#define RC_JOBY_MAGIC_START   13999
+
+#include RADIO_CONTROL_JOBY_MODEL_H
+
+typedef enum {
+  READING_LOW_BYTE = 0,
+  READING_HIGH_BYTE
+} parser_byte_t;
+
+typedef enum {
+  READING_NORMAL = 0,
+  READING_INVERTED
+} parser_inverted_t;
+
+struct rc_joby_parser_state
+{
+  parser_byte_t current_byte;
+  parser_inverted_t current_inverted;
+  int current_channel;
+
+  int16_t parser_inverted_buf;
+  int16_t parser_normal_buf;
+  uint8_t high_byte_buf;
+  uint8_t low_byte_buf;
+
+  uint32_t error_counter;
+};
+
+void rc_joby_parse(int8_t c, void (* callback)(void));
+
+#define __RcLink(dev, _x) dev##_x
+#define _RcLink(dev, _x)  __RcLink(dev, _x)
+#define RcLink(_x) _RcLink(RADIO_CONTROL_LINK, _x)
+
+#define RcLinkChAvailable() RcLink(ChAvailable())
+#define RcLinkGetCh() RcLink(Getch())
+
+#define RadioControlEvent(_received_frame_handler) {                    \
+    while (RcLinkChAvailable()) {                                       \
+      rc_joby_parse(RcLinkGetCh(), _received_frame_handler);           \
+    }                                                                   \
+  }
+
+
+#endif /* BOOZ_RADIO_CONTROL_JOBY_H */

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby_9ch.h 
(from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_joby_9ch.h)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby_9ch.h  
                            (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_joby_9ch.h  
    2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,51 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008-2009 Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef BOOZ_RADIO_CONTROL_JOBY_9CH_H
+#define BOOZ_RADIO_CONTROL_JOBY_9CH_H
+
+#define RADIO_CONTROL_NB_CHANNEL 9
+
+#define RADIO_CONTROL_THROTTLE   0
+#define RADIO_CONTROL_YAW        1
+#define RADIO_CONTROL_PITCH      2
+#define RADIO_CONTROL_ROLL       3
+#define RADIO_CONTROL_GEAR       4
+#define RADIO_CONTROL_MODE       5
+#define RADIO_CONTROL_AUX2       6
+#define RADIO_CONTROL_AUX3       7
+#define RADIO_CONTROL_KILL       8
+
+#define RC_JOBY_SYNC_2 0x12
+
+#define RC_JOBY_SIGNS { 1, \
+                        1, \
+                        1, \
+                        1, \
+                        1, \
+                        1, \
+                        1, \
+                        1, \
+                        1 }
+
+#endif /* BOOZ_RADIO_CONTROL_JOBY_9CH_H */

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum.c 
(from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_spektrum.c)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum.c  
                            (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum.c  
    2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,31 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008-2009 Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "booz_radio_control_spektrum.h"
+
+/* Currently the functionality has been pushed into the arch directories
+ * both arch directories contain essentially the original parser.
+ * The next step is to implement a new parser for lisa. Once this is complete
+ * hardware dependent functions will be written for booz then the lisa parser
+ * will end up in here
+ */

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum.h 
(from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_spektrum.h)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum.h  
                            (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum.h  
    2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,36 @@
+/*
+ * Paparazzi $Id$
+ *
+ * Copyright (C) 2009-2010 The Paparazzi Team
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef BOOZ_RADIO_CONTROL_SPEKTRUM_H
+#define BOOZ_RADIO_CONTROL_SPEKTRUM_H
+
+/* implemented in 
booz/arch/xxx/radio_control/booz_radio_control_spektrum_arch.c */
+extern void radio_control_spektrum_try_bind(void);
+
+#include "radio_control/booz_radio_control_spektrum_arch.h"
+/* implemented in 
booz/arch/xxx/radio_control/booz_radio_control_spektrum_arch.c */
+
+#define RadioControlEvent(_received_frame_handler) 
RadioControlEventImp(_received_frame_handler)
+
+#endif /* BOOZ_RADIO_CONTROL_SPEKTRUM_H */

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum_dx7se.h
 (from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_spektrum_dx7se.h)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum_dx7se.h
                                (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum_dx7se.h
        2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,54 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008-2009 Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef BOOZ_RADIO_CONTROL_SPEKTRUM_DX7SE_H
+#define BOOZ_RADIO_CONTROL_SPEKTRUM_DX7SE_H
+
+#define RADIO_CONTROL_NB_CHANNEL 7
+#define RADIO_CONTROL_ROLL       0
+#define RADIO_CONTROL_THROTTLE   1
+#define RADIO_CONTROL_PITCH      2
+#define RADIO_CONTROL_YAW        3
+#define RADIO_CONTROL_AUX3       4
+#define RADIO_CONTROL_MODE       5
+#define RADIO_CONTROL_AUX4       6
+
+#define RC_SPK_SYNC_2 0x12
+
+#define RC_SPK_THROWS { MAX_PPRZ/MAX_SPK, \
+                        MAX_PPRZ/MAX_SPK, \
+                       -MAX_PPRZ/MAX_SPK, \
+                        MAX_PPRZ/MAX_SPK, \
+                        MAX_PPRZ/MAX_SPK, \
+                       -MAX_PPRZ/MAX_SPK, \
+                        MAX_PPRZ/MAX_SPK }
+
+/*
+  aileron 1
+  elevator 2
+  rudder 3
+  gear 4
+  throttle 5
+*/
+
+#endif /* BOOZ_RADIO_CONTROL_SPEKTRUM_DX7SE_H */

Copied: 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum_dx7se_joby.h
 (from rev 6243, 
paparazzi3/trunk/sw/airborne/booz/radio_control/booz_radio_control_spektrum_dx7se_joby.h)
===================================================================
--- 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum_dx7se_joby.h
                           (rev 0)
+++ 
paparazzi3/trunk/sw/airborne/subsystems/radio_control/radio_control_spektrum_dx7se_joby.h
   2010-10-25 21:57:57 UTC (rev 6244)
@@ -0,0 +1,54 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008-2009 Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef BOOZ_RADIO_CONTROL_SPEKTRUM_DX7SE_H
+#define BOOZ_RADIO_CONTROL_SPEKTRUM_DX7SE_H
+
+#define RADIO_CONTROL_NB_CHANNEL 7
+
+#define RADIO_CONTROL_ROLL       0
+#define RADIO_CONTROL_THROTTLE   5
+#define RADIO_CONTROL_PITCH      3
+#define RADIO_CONTROL_YAW        6
+#define RADIO_CONTROL_MODE       1
+#define RADIO_CONTROL_KILL_SWITCH 4
+
+#define RC_SPK_SYNC_2 0x01
+
+#define RC_SPK_THROWS { MAX_PPRZ/MAX_SPK, \
+                        MAX_PPRZ/MAX_SPK, \
+                       -MAX_PPRZ/MAX_SPK, \
+                       -MAX_PPRZ/MAX_SPK, \
+                       -MAX_PPRZ/MAX_SPK, \
+                        MAX_PPRZ/MAX_SPK, \
+                        MAX_PPRZ/MAX_SPK }
+
+/*
+  aileron 1
+  elevator 2
+  rudder 3
+  gear 4
+  throttle 5
+*/
+
+#endif /* BOOZ_RADIO_CONTROL_SPEKTRUM_DX7SE_H */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]