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
link_mcu_spi.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2006 Pascal Brisset, Antoine Drouin
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 #include "link_mcu_spi.h"
24 
25 #ifndef LINK_MCU_SPI_DEV
26 #define LINK_MCU_SPI_DEV spi1
27 #endif
28 
31 
33 
35 
36 static uint16_t crc = 0;
37 
38 #define PAYLOAD_LENGTH sizeof(link_mcu_from_fbw_msg.payload)
39 #define LINK_MCU_FRAME_LENGTH sizeof(struct link_mcu_msg)
40 
41 #define ComputeChecksum(_buf) { \
42  uint8_t i; \
43  crc = CRC_INIT; \
44  for(i = 0; i < PAYLOAD_LENGTH; i++) { \
45  uint8_t _byte = ((uint8_t*)&_buf)[i]; \
46  crc = CrcUpdate(crc, _byte); \
47  } \
48 }
49 
50 #ifdef FBW
51 
52 void link_mcu_init(void) {
53 
62 }
63 
64 void link_mcu_restart(void) {
67 
68  // wait for the next transaction
70 }
71 
72 void link_mcu_event_task( void ) {
74  /* Got a message on SPI. */
76 
77  /* A message has been received */
82  else
83  fbw_state->nb_err++;
84  }
88  fbw_state->nb_err++;
89  }
90 }
91 
92 #endif /* FBW */
93 
94 
95 
96 /*****************************************************************************/
97 #ifdef AP
98 
99 #ifndef LINK_MCU_SLAVE_IDX
100 #define LINK_MCU_SLAVE_IDX SPI_SLAVE0
101 #endif
102 
103 uint8_t link_mcu_nb_err;
104 uint8_t link_mcu_fbw_nb_err;
105 
106 void link_mcu_init(void) {
107  link_mcu_nb_err = 0;
108 
113  link_mcu_trans.slave_idx = LINK_MCU_SLAVE_IDX;
118 }
119 
120 void link_mcu_send(void) {
121 
125 }
126 
127 void link_mcu_event_task( void ) {
129  /* Got a message on SPI. */
131  /* A message has been received */
135  else
136  link_mcu_nb_err++;
137  }
141  link_mcu_nb_err++;
142  }
143 }
144 
145 #endif /* AP */
unsigned short uint16_t
Definition: types.h:16
enum SPIClockPolarity cpol
clock polarity control
Definition: spi.h:149
uint8_t input_length
number of data words to read
Definition: spi.h:145
bool_t spi_slave_wait(struct spi_periph *p)
Initialized and wait for the next transaction.
Definition: spi_arch.c:670
enum SPIClockPhase cpha
clock phase control
Definition: spi.h:150
CPHA = 1.
Definition: spi.h:69
volatile bool_t inter_mcu_received_ap
Definition: inter_mcu.c:37
volatile bool_t inter_mcu_received_fbw
Definition: inter_mcu.c:36
volatile uint8_t * input_buf
pointer to receive buffer for DMA
Definition: spi.h:143
enum SPISlaveSelect select
slave selection behavior
Definition: spi.h:148
struct fbw_state * fbw_state
Definition: inter_mcu.c:32
enum SPITransactionStatus status
Definition: spi.h:156
Definition: spi.h:84
bool_t spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit a spi transaction.
Definition: spi_arch.c:469
enum SPIDataSizeSelect dss
data transfer word size
Definition: spi.h:151
uint8_t output_length
number of data words to write
Definition: spi.h:146
CPOL = 0.
Definition: spi.h:77
#define TRUE
Definition: imu_chimu.h:144
bool_t spi_slave_register(struct spi_periph *p, struct spi_transaction *t)
Register one (and only one) transaction to use spi as slave.
Definition: spi_arch.c:647
unsigned char uint8_t
Definition: types.h:14
slave is selected before transaction and unselected after
Definition: spi.h:57
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:147
SPI transaction structure.
Definition: spi.h:142
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
Definition: spi.h:144