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