Paparazzi UAS  v5.15_devel-109-gee85905
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_xvert.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Kevin van Hecke
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
27 #include "actuators_xvert.h"
28 #include "subsystems/actuators/actuators_pwm_arch.h"
30 
31 #include "mcu_periph/uart.h"
32 
33 #define ESCS_PORT (&((ESCS_UART).device))
34 
35 
36 
38 
39 
40 #define GP 0x107 /* x^8 + x^2 + x + 1 */
41 #define DI 0xE7
42 
43 
44 static unsigned char crc8_table[256]; /* 8-bit table */
45 static int made_table = 0;
46 
47 static void init_crc8(void)
48 /*
49  * Should be called before any other crc function.
50  */
51 {
52  int i, j;
53  unsigned char crc;
54 
55  if (!made_table) {
56  for (i = 0; i < 256; i++) {
57  crc = i;
58  for (j = 0; j < 8; j++) {
59  crc = (crc << 1) ^ ((crc & 0x80) ? DI : 0);
60  }
61  crc8_table[i] = crc & 0xFF;
62  /* printf("table[%d] = %d (0x%X)\n", i, crc, crc); */
63  }
64  made_table = 1;
65  }
66 }
67 
68 
69 void crc8(unsigned char *crc, unsigned char m)
70 /*
71  * For a byte array whose accumulated crc value is stored in *crc, computes
72  * resultant crc obtained by appending m to the byte array
73  */
74 {
75  if (!made_table) {
76  init_crc8();
77  }
78 
79  *crc = crc8_table[(*crc) ^ m];
80  *crc &= 0xFF;
81 }
82 
83 
85 {
87 }
88 
89 
90 
92 {
93  if (ESCS_PORT->char_available(ESCS_PORT->periph)) {
94  //unsigned char b1 = ESCS_PORT->get_byte(ESCS_PORT->periph);
95  }
96 
97  struct EscData package;
98  package.start = ESCS_START_BYTE;
99  package.len = 8;
100  package.id = 2;
101 
104 
105  //do some package magic:
106  static bool bitflipper = true;
107  if (bitflipper) {
108  package.d1 += ESCS_DATA_FLIPBIT;
109  } else {
110  package.d2 += ESCS_DATA_FLIPBIT;
111  }
112  package.d1 += ESCS_DATA_MYSTERYBIT;
113  bitflipper = !bitflipper;
114 
115  unsigned char crc = 0;
116  unsigned char *data = (unsigned char *)&package;
117  for (unsigned char i = 1 ; i < sizeof(struct EscData) - 1; i++) {
118  crc8(&crc, data[i]);
119  }
120  package.crc = crc;
121 
122  ESCS_PORT->put_buffer(ESCS_PORT->periph, 0, (unsigned char *) &package, sizeof(struct EscData));
123 
124 
125  //send the pwm signals for the two elerons to the pwm driver:
129 
130 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned char len
int32_t actuators_xvert_values[ACTUATORS_PWM_NB]
void actuators_pwm_arch_init(void)
Arch dependent init file.
uint32_t d2
#define ESCS_START_BYTE
#define XVERT_ESC_0
Definition: board.h:1327
static unsigned char crc8_table[256]
static int made_table
#define XVERT_ESC_1
Definition: board.h:1328
#define ESCS_DATA_FLIPBIT
uint32_t d1
#define PWM_SERVO_3
Definition: board.h:254
#define ESCS_PORT
#define ACTUATORS_PWM_NB
#define ESCS_DATA_MYSTERYBIT
#define PWM_SERVO_2
Definition: board.h:239
signed long int32_t
Definition: types.h:19
unsigned char crc
void actuators_xvert_commit(void)
unsigned char start
void actuators_pwm_commit(void)
unsigned char id
static void init_crc8(void)
void crc8(unsigned char *crc, unsigned char m)
void actuators_xvert_init(void)
#define DI
int32_t actuators_pwm_values[ACTUATORS_PWM_NB]