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
link_mcu.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2003-2006 Pascal Brisset, Antoine Drouin
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 #include "link_mcu.h"
26 #include "mcu_periph/spi.h"
27 
30 
32 
33 static uint16_t crc = 0;
34 
35 #define PAYLOAD_LENGTH sizeof(link_mcu_from_fbw_msg.payload)
36 #define LINK_MCU_FRAME_LENGTH sizeof(struct link_mcu_msg)
37 
38 #define ComputeChecksum(_buf) { \
39  uint8_t i; \
40  crc = CRC_INIT; \
41  for(i = 0; i < PAYLOAD_LENGTH; i++) { \
42  uint8_t _byte = ((uint8_t*)&_buf)[i]; \
43  crc = CrcUpdate(crc, _byte); \
44  } \
45 }
46 
47 #ifdef FBW
48 
49 void link_mcu_restart(void) {
52 
56  SpiStart();
57 }
58 
59 void link_mcu_event_task( void ) {
61  /* Got a message on SPI. */
63 
64  /* A message has been received */
69  else
70  fbw_state->nb_err++;
71  }
72 }
73 
74 #endif /* FBW */
75 
76 
77 
78 /*****************************************************************************/
79 #ifdef AP
80 
81 uint8_t link_mcu_nb_err;
82 uint8_t link_mcu_fbw_nb_err;
83 
84 void link_mcu_init(void) {
85  link_mcu_nb_err = 0;
86 }
87 
88 void link_mcu_send(void) {
89 
90  if (!SpiCheckAvailable()) {
91  SpiOverRun();
92  return;
93  }
94 
100  SpiSelectSlave0();
101  SpiStart();
102 }
103 
104 void link_mcu_event_task( void ) {
105  if (spi_message_received) {
106  /* Got a message on SPI. */
108  /* A message has been received */
112  else
113  link_mcu_nb_err++;
114  }
115 }
116 
117 #endif /* AP */
unsigned short uint16_t
Definition: types.h:16
bool_t spi_message_received
Definition: sim_baro.c:8
volatile bool_t inter_mcu_received_ap
Definition: inter_mcu.c:39
volatile bool_t inter_mcu_received_fbw
Definition: inter_mcu.c:38
uint8_t * spi_buffer_output
Definition: spi.c:29
uint8_t * spi_buffer_input
Definition: spi.c:28
struct fbw_state * fbw_state
Definition: inter_mcu.c:34
#define FALSE
Definition: imu_chimu.h:141
arch independent SPI (Serial Peripheral Interface) API
#define TRUE
Definition: imu_chimu.h:144
unsigned char uint8_t
Definition: types.h:14
uint8_t spi_buffer_length
Definition: spi.c:30