Paparazzi UAS  v5.15_devel-81-gd13dafb
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 {
54 
63 }
64 
65 void link_mcu_restart(void)
66 {
69 
70  // wait for the next transaction
72 }
73 
74 void link_mcu_event_task(void)
75 {
77  /* Got a message on SPI. */
79 
80  /* A message has been received */
82  link_mcu_received = true;
84  inter_mcu_received_ap = true;
85  } else {
86  fbw_state->nb_err++;
87  }
88  }
91  link_mcu_received = true;
92  fbw_state->nb_err++;
93  }
94 }
95 
96 #endif /* FBW */
97 
98 
99 
100 /*****************************************************************************/
101 #ifdef AP
102 
103 #ifndef LINK_MCU_SLAVE_IDX
104 #define LINK_MCU_SLAVE_IDX SPI_SLAVE0
105 #endif
106 
107 uint8_t link_mcu_nb_err;
108 uint8_t link_mcu_fbw_nb_err;
109 
110 #if PERIODIC_TELEMETRY
112 
113 static void send_debug_link(struct transport_tx *trans, struct link_device *dev)
114 {
115  uint8_t mcu1_ppm_cpt_foo = 0; //FIXME
116  pprz_msg_send_DEBUG_MCU_LINK(trans, dev, AC_ID,
117  &link_mcu_nb_err, &link_mcu_fbw_nb_err, &mcu1_ppm_cpt_foo);
118 }
119 #endif
120 
121 void link_mcu_init(void)
122 {
123  link_mcu_nb_err = 0;
124 
129  link_mcu_trans.slave_idx = LINK_MCU_SLAVE_IDX;
134 
135 #if PERIODIC_TELEMETRY
136  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_DEBUG_MCU_LINK, send_debug_link);
137 #endif
138 }
139 
140 void link_mcu_send(void)
141 {
142 
146 }
147 
148 void link_mcu_event_task(void)
149 {
151  /* Got a message on SPI. */
153  /* A message has been received */
156  inter_mcu_received_fbw = true;
157  } else {
158  link_mcu_nb_err++;
159  }
160  }
163  link_mcu_received = true;
164  link_mcu_nb_err++;
165  }
166 }
167 
168 #endif /* AP */
unsigned short uint16_t
Definition: types.h:16
enum SPIClockPolarity cpol
clock polarity control
Definition: spi.h:149
bool 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:679
uint16_t output_length
number of data words to write
Definition: spi.h:146
Periodic telemetry system header (includes downlink utility and generated code).
CPHA = 1.
Definition: spi.h:69
SPI transaction structure.
Definition: spi.h:142
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
Definition: spi_arch.c:505
volatile bool inter_mcu_received_ap
Definition: inter_mcu.c:41
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
Definition: spi.h:144
enum SPISlaveSelect select
slave selection behavior
Definition: spi.h:148
struct fbw_state * fbw_state
Definition: inter_mcu.c:36
enum SPIClockPhase cpha
clock phase control
Definition: spi.h:150
Definition: spi.h:84
bool spi_slave_wait(struct spi_periph *p)
Initialized and wait for the next transaction.
Definition: spi_arch.c:703
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
CPOL = 0.
Definition: spi.h:77
uint16_t input_length
number of data words to read
Definition: spi.h:145
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
volatile bool inter_mcu_received_fbw
Definition: inter_mcu.c:40
unsigned char uint8_t
Definition: types.h:14
slave is selected before transaction and unselected after
Definition: spi.h:57
enum SPIDataSizeSelect dss
data transfer word size
Definition: spi.h:151
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:147
volatile uint8_t * input_buf
pointer to receive buffer for DMA
Definition: spi.h:143
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
enum SPITransactionStatus status
Definition: spi.h:156