Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
spektrum_arch.h
Go to the documentation of this file.
1 /*
2  * Paparazzi $Id$
3  *
4  * Copyright (C) 2009-2010 The Paparazzi Team
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
25 #ifndef RADIO_CONTROL_SPEKTRUM_ARCH_H
26 #define RADIO_CONTROL_SPEKTRUM_ARCH_H
27 
28 #include "std.h"
29 #include "mcu_periph/uart.h"
30 
31 #include RADIO_CONTROL_SPEKTRUM_MODEL_H
32 
33 #define RC_SPK_SYNC_1 0x03
34 
35 #define RC_SPK_STA_UNINIT 0
36 #define RC_SPK_STA_GOT_SYNC_1 1
37 #define RC_SPK_STA_GOT_SYNC_2 2
38 
39 extern bool_t rc_spk_parser_status;
42 
43 #define MAX_SPK 344
44 
45 
47 
48 #define __RcLink(dev, _x) dev##_x
49 #define _RcLink(dev, _x) __RcLink(dev, _x)
50 #define RcLink(_x) _RcLink(RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT, _x)
51 
52 #define RcLinkChAvailable() RcLink(ChAvailable())
53 #define RcLinkGetCh() RcLink(Getch())
54 
55 #define RadioControlEventImpl(_received_frame_handler) { \
56  while (RcLinkChAvailable()) { \
57  int8_t c = RcLinkGetCh(); \
58  switch (rc_spk_parser_status) { \
59  case RC_SPK_STA_UNINIT: \
60  if (c==RC_SPK_SYNC_1) \
61  rc_spk_parser_status = RC_SPK_STA_GOT_SYNC_1; \
62  break; \
63  case RC_SPK_STA_GOT_SYNC_1: \
64  if (c==RC_SPK_SYNC_2) { \
65  rc_spk_parser_status = RC_SPK_STA_GOT_SYNC_2; \
66  rc_spk_parser_idx = 0; \
67  } \
68  else \
69  rc_spk_parser_status = RC_SPK_STA_UNINIT; \
70  break; \
71  case RC_SPK_STA_GOT_SYNC_2: \
72  rc_spk_parser_buf[rc_spk_parser_idx] = c; \
73  rc_spk_parser_idx++; \
74  if (rc_spk_parser_idx >= 2*RADIO_CONTROL_NB_CHANNEL) { \
75  rc_spk_parser_status = RC_SPK_STA_UNINIT; \
76  radio_control.frame_cpt++; \
77  radio_control.time_since_last_frame = 0; \
78  radio_control.status = RC_OK; \
79  uint8_t i; \
80  for (i=0;i<RADIO_CONTROL_NB_CHANNEL;i++) { \
81  const int16_t tmp = (rc_spk_parser_buf[2*i]<<8) + \
82  rc_spk_parser_buf[2*i+1]; \
83  /*const int16_t chan = (tmp&0xFC00) >> 10;*/ \
84  const int16_t val = (tmp&0x03FF) - 512; \
85  radio_control.values[i] = val; \
86  radio_control.values[i] *= rc_spk_throw[i]; \
87  if (i==RADIO_CONTROL_THROTTLE) { \
88  radio_control.values[i] += MAX_PPRZ; \
89  radio_control.values[i] /= 2; \
90  } \
91  } \
92  _received_frame_handler(); \
93  } \
94  break; \
95  default: \
96  rc_spk_parser_status = RC_SPK_STA_UNINIT; \
97  } \
98  } \
99  }
100 
101 
102 #endif /* RADIO_CONTROL_SPEKTRUM_ARCH_H */
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint8_t rc_spk_parser_buf[RADIO_CONTROL_NB_CHANNEL *2]
Definition: spektrum_arch.c:29
signed short int16_t
Definition: types.h:17
#define RADIO_CONTROL_NB_CHANNEL
Definition: spektrum_arch.h:36
unsigned char uint8_t
Definition: types.h:14
uint8_t rc_spk_parser_idx
Definition: spektrum_arch.c:28
const int16_t rc_spk_throw[RADIO_CONTROL_NB_CHANNEL]
Definition: spektrum_arch.c:30
bool_t rc_spk_parser_status
Definition: spektrum_arch.c:27