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
w5100.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Gerard Toonstra
3  * Copyright (C) 2014 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  */
22 
28 #ifndef W5100_H
29 #define W5100_H
30 
31 #include "mcu_periph/link_device.h"
32 #include "generated/airframe.h"
33 
34 #define W5100_RX_BUFFER_SIZE 80
35 #define W5100_TX_BUFFER_SIZE 80
36 #define W5100_BUFFER_NUM 2
37 
42 };
43 
44 struct w5100_periph {
45  volatile enum W5100Status status;
46  int curbuf;
47  /* Receive buffer */
51  /* Transmit buffer */
55  volatile uint8_t work_tx[4];
56  volatile uint8_t work_rx[4];
60 };
61 
63 
64 extern struct w5100_periph chip0;
65 
66 void w5100_init(void);
67 void w5100_transmit(uint8_t data);
69 void w5100_send(void);
71 bool_t w5100_ch_available(void);
72 
73 
74 // W5100 is using pprz_transport
75 // FIXME it should not appear here, this will be fixed with the rx improvements some day...
76 // W5100 needs a specific read_buffer function
78 
79 static inline void w5100_read_buffer(struct pprz_transport *t)
80 {
81  while (w5100_ch_available()) {
83  int c = 0;
84  do {
85  parse_pprz(t, w5100_rx_buf[ c++ ]);
86  } while ((t->status != UNINIT) && !(t->trans_rx.msg_received));
87  }
88 }
89 
90 #define W5100CheckAndParse(_dev, _trans) w5100_check_and_parse(&(_dev).device, &(_trans))
91 
92 static inline void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans) {
93  if (dev->char_available(dev->periph)) {
94  w5100_read_buffer(trans);
95  if (trans->trans_rx.msg_received) {
96  pprz_parse_payload(trans);
97  trans->trans_rx.msg_received = FALSE;
98  }
99  }
100 }
101 
102 #endif /* W5100_H */
103 
W5100Status
Definition: w5100.h:38
unsigned short uint16_t
Definition: types.h:16
bool_t w5100_ch_available(void)
Definition: w5100.c:364
volatile bool_t msg_received
message received flag
Definition: transport.h:42
volatile uint8_t work_tx[4]
Definition: w5100.h:55
#define W5100_TX_BUFFER_SIZE
Definition: w5100.h:35
void w5100_send(void)
Definition: w5100.c:275
volatile uint16_t rx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:49
uint8_t w5100_rx_buf[W5100_RX_BUFFER_SIZE]
Definition: w5100.c:91
static void parse_pprz(struct pprz_transport *t, uint8_t c)
#define W5100_RX_BUFFER_SIZE
Definition: w5100.h:34
Building and parsing Paparazzi frames.
#define W5100_BUFFER_NUM
Definition: w5100.h:36
uint16_t w5100_rx_size(uint8_t _s)
Definition: w5100.c:317
volatile uint8_t tx_buf[W5100_BUFFER_NUM][W5100_TX_BUFFER_SIZE]
Definition: w5100.h:52
volatile uint8_t rx_buf[W5100_BUFFER_NUM][W5100_RX_BUFFER_SIZE]
Definition: w5100.h:48
#define FALSE
Definition: std.h:5
volatile uint16_t rx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:50
static void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
Definition: w5100.h:92
void w5100_transmit(uint8_t data)
Definition: w5100.c:260
volatile uint16_t tx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:53
volatile uint16_t tx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:54
volatile uint8_t work_rx[4]
Definition: w5100.h:56
uint8_t tx_running
Definition: w5100.h:57
enum W5100Status status
Definition: w5100.h:45
uint16_t w5100_receive(uint8_t *buf, uint16_t len)
Definition: w5100.c:372
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
struct adc_buf * buf
Definition: adc_arch.c:587
unsigned char uint8_t
Definition: types.h:14
struct w5100_periph chip0
Definition: w5100.c:89
void w5100_init(void)
Definition: w5100.c:183
struct transport_rx trans_rx
static void w5100_read_buffer(struct pprz_transport *t)
Definition: w5100.h:79
int curbuf
Definition: w5100.h:46
static void pprz_parse_payload(struct pprz_transport *t)
struct link_device device
Generic device interface.
Definition: w5100.h:59
#define UNINIT
Receiving pprz messages.
Definition: protocol.c:11