Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
bluegiga.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kirk Scheper <kirkscheper@gmail.com>
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  *
20  */
21 
27 #ifndef BLUEGIGA_DATA_LINK_H
28 #define BLUEGIGA_DATA_LINK_H
29 
30 #include "mcu_periph/link_device.h"
31 
32 /* The different statuses the communication can be in */
38 };
39 
40 #ifndef BLUEGIGA_BUFFER_SIZE
41 #define BLUEGIGA_BUFFER_SIZE 256 // buffer max value: 256
42 #elif BLUEGIGA_BUFFER_SIZE < 256
43 #warning "BLUEGIGA_BUFFER_SIZE may be smaller than possible message length, check subsystems/datalink/bluegiga.c:dev_check_free_space for more information"
44 #elif BLUEGIGA_BUFFER_SIZE > 256
45 #error "BLUEGIGA_BUFFER_SIZE not made for sizes larger than 256, check subsystems/datalink/bluegiga.c for more information"
46 #endif
47 
49  /* Receive buffer */
53  /* Transmit buffer */
57  /* transmit and receive buffers */
62 
63  /* some administrative variables */
66 
67 };
68 
69 // DEVICE passed to all DOWNLINK_SEND functions
70 extern struct bluegiga_periph bluegiga_p;
71 extern signed char bluegiga_rssi[]; // values initialized with 127
72 
74 void bluegiga_increment_buf(uint8_t *buf_idx, uint8_t len);
75 
76 void bluegiga_init(struct bluegiga_periph *p);
77 void bluegiga_scan(struct bluegiga_periph *p);
79 
80 // BLUEGIGA is using pprz_transport
81 // FIXME it should not appear here, this will be fixed with the rx improvements some day...
82 // BLUEGIGA needs a specific read_buffer function
84 #include "led.h"
85 static inline void bluegiga_read_buffer(struct bluegiga_periph *p, struct pprz_transport *t)
86 {
87  do {
88  uint8_t c = 0;
89  do {
91  } while (((p->rx_extract_idx + c) % BLUEGIGA_BUFFER_SIZE != p->rx_insert_idx)
92  && !(t->trans_rx.msg_received));
93  // reached end of circular read buffer or message received
94  // if received, decode and advance
95  if (t->trans_rx.msg_received) {
96 #ifdef MODEM_LED
97  LED_TOGGLE(MODEM_LED);
98 #endif
101  }
103  } while (bluegiga_ch_available(p)); // continue till all messages read
104 }
105 
106 // transmit previous data in buffer and parse data received
107 #define BlueGigaCheckAndParse(_dev,_trans) { \
108  if (bluegiga_ch_available(&(_dev))) \
109  bluegiga_read_buffer(&(_dev), &(_trans)); \
110  }
111 
112 #endif /* BLUEGIGA_DATA_LINK_H */
struct link_device device
Generic device interface.
Definition: bluegiga.h:61
#define BLUEGIGA_BUFFER_SIZE
Definition: bluegiga.h:41
volatile bool_t msg_received
message received flag
Definition: transport.h:42
void bluegiga_increment_buf(uint8_t *buf_idx, uint8_t len)
Definition: bluegiga.c:103
The com is sending.
Definition: bluegiga.h:36
BlueGigaStatus
Definition: bluegiga.h:33
void bluegiga_request_all_rssi(struct bluegiga_periph *p)
Definition: bluegiga.c:322
static void parse_pprz(struct pprz_transport *t, uint8_t c)
uint8_t rx_buf[BLUEGIGA_BUFFER_SIZE]
Definition: bluegiga.h:50
uint8_t tx_extract_idx
Definition: bluegiga.h:56
Building and parsing Paparazzi frames.
void bluegiga_scan(struct bluegiga_periph *p)
Definition: bluegiga.c:309
uint8_t tx_insert_idx
Definition: bluegiga.h:55
uint32_t bytes_recvd_since_last
Definition: bluegiga.h:64
#define FALSE
Definition: std.h:5
#define LED_TOGGLE(i)
Definition: led_hw.h:44
struct bluegiga_periph bluegiga_p
Definition: bluegiga.c:50
The com is switched from data link to rssi scanning.
Definition: bluegiga.h:37
signed char bluegiga_rssi[]
Definition: bluegiga.c:53
void bluegiga_init(struct bluegiga_periph *p)
Definition: bluegiga.c:126
uint8_t work_rx[20]
Definition: bluegiga.h:59
unsigned long uint32_t
Definition: types.h:18
uint8_t tx_buf[BLUEGIGA_BUFFER_SIZE]
Definition: bluegiga.h:54
uint8_t work_tx[20]
Definition: bluegiga.h:58
uint8_t rx_extract_idx
Definition: bluegiga.h:52
bool_t bluegiga_ch_available(struct bluegiga_periph *p)
Definition: bluegiga.c:97
unsigned char uint8_t
Definition: types.h:14
static void bluegiga_read_buffer(struct bluegiga_periph *p, struct pprz_transport *t)
Definition: bluegiga.h:85
The com isn't initialized.
Definition: bluegiga.h:34
struct transport_rx trans_rx
arch independent LED (Light Emitting Diodes) API
static float p[2][2]
static void pprz_parse_payload(struct pprz_transport *t)
The com is in idle.
Definition: bluegiga.h:35
uint8_t rx_insert_idx
Definition: bluegiga.h:51
uint8_t end_of_msg
Definition: bluegiga.h:65